Skip to content

Commit v0.18

kwmccabe edited this page Apr 17, 2018 · 9 revisions

v0.18 - Init item_list() options for ItemModel filter,sort,paginate


Files changed (7)

File web/app/item/templates/item_create.html MODIFIED

 <!-- BLOCK: title -->
-{% block title %}{{super()}} - Create Item{% endblock %}
+{% block title %}{{super()}} - Admin - Create Item{% endblock %}

File web/app/item/templates/item_edit.html MODIFIED

 <!-- BLOCK: title -->
-{% block title %}{{super()}}Item Edit{% endblock %}
+{% block title %}{{super()}} - Admin - Edit '{{ form.item.keyname }}'{% endblock %}
 
...
 
-<li><a href="{{ url_for('.item_edit', id=form.id.data) }}">Edit {{ form.item.keyname }}</a></li>
+<li><a href="{{ url_for('.item_edit', id=form.id.data) }}">Edit '{{ form.item.keyname }}'</a></li>
 
...
 
-        <h3 class="condensed">Edit : {{ form.item.keyname }}</h3>
+        <h3 class="condensed">Edit Item</h3>

...
 
     <span class="form-submit-buttons">
-        [ <a data-confirm-link="Delete Item? This action cannot be undone." href="{{ url_for('.item_delete', id=form.id.data) }}">Delete Item</a> ]
+        <a data-confirm-link="Delete Item? This action cannot be undone." href="{{ url_for('.item_delete', id=form.id.data) }}"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete Item</a>
     </span>

File web/app/item/templates/item_index.html MODIFIED

+<!-- BLOCK: title -->
+{% block title %}{{super()}} - Items{% endblock %}

File web/app/item/templates/item_list.html MODIFIED

 <!-- BLOCK: title -->
-{% block title %}{{super()}} - Items{% endblock %}
+{% block title %}{{super()}} - Admin - Items{% endblock %}

File web/app/item/templates/item_view.html MODIFIED

 <!-- BLOCK: title -->
-{% block title %}{{super()}} - Item - {{ item.keyname }}{% endblock %}
+{% block title %}{{super()}} - Admin - View '{{ item.keyname }}'{% endblock %}

...

-<li><a href="{{ url_for('.item_view', id=item.id) }}">{{ item.keyname }}</a></li>
+<li><a href="{{ url_for('.item_view', id=item.id) }}">View '{{ item.keyname }}'</a></li>

... 
 
-        <h3 class="condensed">Item : {{ item.keyname }}</h3>
+        <h3 class="condensed">View Item</h3>

File web/app/item/views.py MODIFIED

  • Create variables for basic list filtering, sorting, and pagination.
  • status used in rows.filter() - [all, active, inactive]
  • sort + order used in rows.order_by() - column name + [asc, desc]
  • offset used in rows.offset() - [none, (page-1)*perpage]
  • limit used in rows.limit() - [unlimited, per page]
 @item.route('/admin/item/list')
 def item_list():
     cols = ItemModel.__table__.columns.keys()
-
     rows = db.session.query(ItemModel)
-    rows = rows.order_by(getattr( ItemModel, 'id' ).asc())
-    rows = rows.all()
 
+    status = 'all'  # in [all, active, inactive]
+    sort   = 'id'   # in [cols]
+    order  = 'asc'  # in [asc, desc]
+    offset = 0      # [none, (page-1)*perpage]
+    limit  = 0      # [unlimited, per page]
+
+    if status in ['active', 'inactive']:
+        rows = rows.filter(ItemModel.active == (status == 'active'))
+    if sort in cols:
+        if order == 'desc':
+            rows = rows.order_by(getattr( ItemModel, sort ).desc())
+        else:
+            rows = rows.order_by(getattr( ItemModel, sort ).asc())
+    if offset > 0:
+        rows = rows.offset(offset)
+    if limit > 0:
+        rows = rows.limit(limit)
+
+    rows = rows.all()
     rowcnt = len(rows)
 
     logging.debug('item_list - %s' % (rowcnt))

File web/app/main/templates/index.html MODIFIED

+<!-- BLOCK: title -->
+{% block title %}{{super()}} - Home{% endblock %}

Commit-v0.17 | Commit-v0.18 | Commit-v0.19

Clone this wiki locally