-
Notifications
You must be signed in to change notification settings - Fork 8
Commit v0.18
kwmccabe edited this page Apr 17, 2018
·
9 revisions
v0.18 - Init item_list() options for ItemModel filter,sort,paginate
- +1 -1 [M] web/app/item/templates/item_create.html
- +4 -4 [M] web/app/item/templates/item_edit.html
- +3 -0 [M] web/app/item/templates/item_index.html
- +1 -1 [M] web/app/item/templates/item_list.html
- +3 -3 [M] web/app/item/templates/item_view.html
- +19 -4 [M] web/app/item/views.py
- +4 -0 [M] web/app/main/templates/index.html
<!-- BLOCK: title -->
-{% block title %}{{super()}} - Create Item{% endblock %}
+{% block title %}{{super()}} - Admin - Create Item{% endblock %}
<!-- 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>
+<!-- BLOCK: title -->
+{% block title %}{{super()}} - Items{% endblock %}
<!-- BLOCK: title -->
-{% block title %}{{super()}} - Items{% endblock %}
+{% block title %}{{super()}} - Admin - Items{% endblock %}
<!-- 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>
- Create variables for basic list filtering, sorting, and pagination.
-
status
used inrows.filter()
-[all, active, inactive]
-
sort
+order
used inrows.order_by()
-column name + [asc, desc]
-
offset
used inrows.offset()
-[none, (page-1)*perpage]
-
limit
used inrows.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))
+<!-- BLOCK: title -->
+{% block title %}{{super()}} - Home{% endblock %}
Commit-v0.17 | Commit-v0.18 | Commit-v0.19
- FlaskApp Tutorial
- Table of Contents
- About
- Application Setup
- Modules, Templates, and Layouts
- Database Items, Forms, and CRUD
- List Filter, Sort, and Paginate
- Users and Login
- Database Relationships
- API Module, HTTPAuth and JSON
- Refactoring User Roles and Item Status
- AJAX and Public Pages