diff --git a/crudkit/templates/crudkit/_macros.html b/crudkit/html/templates/crudkit/_macros.html similarity index 97% rename from crudkit/templates/crudkit/_macros.html rename to crudkit/html/templates/crudkit/_macros.html index be86b57..38a1a4e 100644 --- a/crudkit/templates/crudkit/_macros.html +++ b/crudkit/html/templates/crudkit/_macros.html @@ -1,6 +1,6 @@ {% macro options(items, value_attr="id", label_path="name", getp=None) -%} {%- for obj in items -%} - + {%- endfor -%} {% endmacro %} diff --git a/crudkit/templates/crudkit/form.html b/crudkit/html/templates/crudkit/form.html similarity index 92% rename from crudkit/templates/crudkit/form.html rename to crudkit/html/templates/crudkit/form.html index aab8133..0c2c226 100644 --- a/crudkit/templates/crudkit/form.html +++ b/crudkit/html/templates/crudkit/form.html @@ -1,4 +1,4 @@ -{% import "crudkit/_macros.html" as ui %} +{% import "_macros.html" as ui %} {# The action points at your JSON endpoints. Adjust 'crud' if you named it differently. #} {% if obj %} {% set action = url_for('crud.update_item', model=model, id=obj.id) %} diff --git a/crudkit/templates/crudkit/lis.html b/crudkit/html/templates/crudkit/lis.html similarity index 66% rename from crudkit/templates/crudkit/lis.html rename to crudkit/html/templates/crudkit/lis.html index 3ce62e7..e9b1813 100644 --- a/crudkit/templates/crudkit/lis.html +++ b/crudkit/html/templates/crudkit/lis.html @@ -1,2 +1,2 @@ -{% import "crudkit/_macros.html" as ui %} +{% import "_macros.html" as ui %} {{ ui.lis(items, label_path=label_path, sublabel_path=sublabel_path, getp=getp) }} diff --git a/crudkit/templates/crudkit/options.html b/crudkit/html/templates/crudkit/options.html similarity index 75% rename from crudkit/templates/crudkit/options.html rename to crudkit/html/templates/crudkit/options.html index 0f66d2d..34d6a2b 100644 --- a/crudkit/templates/crudkit/options.html +++ b/crudkit/html/templates/crudkit/options.html @@ -1,3 +1,3 @@ {# Renders only rows #} -{% import "crudkit/_macros.html" as ui %} +{% import "_macros.html" as ui %} {{ ui.options(items, value_attr=value_attr, label_path=label_path, getp=getp) }} diff --git a/crudkit/templates/crudkit/rows.html b/crudkit/html/templates/crudkit/rows.html similarity index 70% rename from crudkit/templates/crudkit/rows.html rename to crudkit/html/templates/crudkit/rows.html index 1c740f1..7fafa3a 100644 --- a/crudkit/templates/crudkit/rows.html +++ b/crudkit/html/templates/crudkit/rows.html @@ -1,3 +1,3 @@ -{% import "crudkit/_macros.html" as ui %} +{% import "_macros.html" as ui %} {{ ui.rows(items, fields, getp=getp) }} {{ ui.pager(model, page, pages, per_page, sort, filters) }} diff --git a/crudkit/html/ui_fragments.py b/crudkit/html/ui_fragments.py index 6dff4e1..37d0743 100644 --- a/crudkit/html/ui_fragments.py +++ b/crudkit/html/ui_fragments.py @@ -18,7 +18,7 @@ def make_fragments_blueprint(db_session_factory, registry: Dict[str, Any], *, na GET //frag/rows -> ... + pager markup if wanted GET //frag/form ->
...
(auto-generated) """ - bp = Blueprint(name, __name__, template_folder="../templates/crudkit") + bp = Blueprint(name, __name__, template_folder="templates/crudkit") def session(): return scoped_session(db_session_factory)() def _parse_filters(args): diff --git a/example_app/app.py b/example_app/app.py index c617d9a..b7f9909 100644 --- a/example_app/app.py +++ b/example_app/app.py @@ -1,8 +1,9 @@ -from flask import Flask +from flask import Flask, render_template from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from .models import Base, Author, Book -from crudkit import make_blueprint +from crudkit.blueprint import make_blueprint as make_json_blueprint +from crudkit.html import make_fragments_blueprint engine = create_engine("sqlite:///example.db", echo=True, future=True) SessionLocal = sessionmaker(bind=engine, expire_on_commit=False) @@ -15,7 +16,8 @@ registry = {"author": Author, "book": Book} def create_app(): app = Flask(__name__) Base.metadata.create_all(engine) - app.register_blueprint(make_blueprint(session_factory, registry), url_prefix="/api") + app.register_blueprint(make_json_blueprint(session_factory, registry), url_prefix="/api") + app.register_blueprint(make_fragments_blueprint(session_factory, registry), url_prefix="/ui") return app if __name__ == "__main__":