-
Notifications
You must be signed in to change notification settings - Fork 8
Commit v0.27
kwmccabe edited this page Apr 17, 2018
·
9 revisions
v0.27 - @app.context_processor: current_datetime(), debug_queries()
- +1 -1 [M] web/app/item/models.py
- +12 -4 [M] web/app/item/views.py
- +7 -5 [M] web/app/main/templates/base.html
- +15 -21 [M] web/app/static/css/flaskapp.css
- +2 -1 [M] web/app/user/models.py
- +1 -3 [M] web/app/user/views.py
- +15 -0 [M] web/flaskapp.py
- Reorder columns.
class ItemModel(db.Model):
__tablename__ = 'item'
id = db.Column(db.BigInteger, autoincrement=True, primary_key=True)
- keyname = db.Column(db.String(63), nullable=False, index=True, unique=True, default='')
active = db.Column(db.Boolean, nullable=False, index=True, default=1)
+ keyname = db.Column(db.String(63), nullable=False, index=True, unique=True, default='')
item_title = db.Column(db.String(255))
- Remove
item_text
from columns at/admin/item/list
. - Remove data prefetch in
rows = rows.all()
. - Replace
rowcnt = len(rows)
withrowcnt = rows.count()
.
@login_required
def item_list():
cols = ItemModel.__table__.columns.keys()
+ cols_filtered = list(filter(lambda x: x not in ['item_text'], cols))
rows = db.session.query(ItemModel)
...
if S['sort'] == 'owner_id':
from ..user.models import UserModel
rows = rows.outerjoin(UserModel)
+ #rows = rows.options( db.joinedload(ItemModel.owner_id).load_only("keyname", "user_email") )
+ rows = rows.options( \
+ db.Load(ItemModel).defer("item_text"), \
+ db.Load(UserModel).load_only("keyname", "user_email"), \
+ )
...
- elif S['sort'] in cols:
+ elif S['sort'] in cols_filtered:
...
- rows = rows.all()
- rowcnt = len(rows)
+ #rows = rows.all()
+ #rowcnt = len(rows)
+ rowcnt = rows.count()
logging.debug('item_list - %s' % (rowcnt))
- return render_template('item_list.html', cols=cols,rows=rows,rowcnt=rowcnt,opts_key=opts_key)
+ return render_template('item_list.html', cols=cols_filtered,rows=rows,rowcnt=rowcnt,opts_key=opts_key)
- Add calls to new
@app.context_processor
:debug_queries()
andcurrent_datetime()
.
<div id="debuginfo"><pre>
DEBUG:
-{% if current_user.user_email %}LOGGED IN: {{ current_user.user_email }}{% else %}LOGGED OUT{% endif %}
-TEMPLATES: {% block templates %}base.html{% endblock %}
-REQUEST.ARGS: {{ request.args }}
-REQUEST.COOKIES: {{ request.cookies }}
-SESSION: {{ session }}
+{% if current_user.user_email %}<b>LOGGED IN:</b> {{ current_user.user_email }}{% else %}<b>LOGGED OUT</b>{% endif %}
+<b>TEMPLATES:</b> {% block templates %}base.html{% endblock %}
+<b>REQUEST.ARGS:</b> {{ request.args }}
+<b>REQUEST.COOKIES:</b> {{ request.cookies }}
+<b>SESSION:</b> {{ session }}
+<b>QUERIES :</b> {{ debug_queries() }}
+<b>DATETIME :</b> {{ current_datetime() }}
</pre></div>
- Reorder sections
@charset "utf-8";
/**
- * layout
- * @see base.html
+ * generic element attributes
+ */
+h1.condensed, h2.condensed, h3.condensed, h4.condensed { margin: 10px 0 5px 0; }
+
+form { padding: 15px; }
+.form-submit-buttons { padding-left: 15px; }
+
+.table-condensed { margin-bottom: 0; }
+.table-borderless td,
+.table-borderless th {
+ border: none !important;
+}
+
+/**
+ * layout elements defined in base.html
*/
#header { min-height: 80px; }
...
-/**
- * generic element attributes
- */
-h1.condensed, h2.condensed, h3.condensed, h4.condensed { margin: 10px 0 5px 0; }
-
-form { padding: 15px; }
-.form-submit-buttons { padding-left: 15px; }
-
-.table-condensed { margin-bottom: 0; }
-.table-borderless td,
-.table-borderless th {
- border: none !important;
-}
- Reorder columns.
- keyname = db.Column(db.String(63), nullable=False, unique=True, index=True, default='')
+ keyname = db.Column(db.String(63), nullable=False, index=True, unique=True, default='')
- Remove data prefetch in
rows = rows.all()
. - Replace
rowcnt = len(rows)
withrowcnt = rows.count()
.
if S['limit'] > 0:
rows = rows.limit(S['limit'])
- rows = rows.all()
- rowcnt = len(rows)
-
+ rowcnt = rows.count()
logging.debug('user_list - %s' % (rowcnt))
return render_template('user_list.html', cols=cols_filtered,rows=rows,rowcnt=rowcnt,opts_key=opts_key)
- Add
@app.context_processor
to create template functions. - Define function
current_datetime()
. - Define function
debug_queries()
.
+# Utility functions available within templates
+@app.context_processor
+def utility_processor():
+ def current_datetime():
+ import datetime
+ return datetime.datetime.now().strftime("%Y/%m/%d @ %H:%M:%S")
+ def debug_queries():
+ from flask_sqlalchemy import get_debug_queries
+ return get_debug_queries()
+ return dict(\
+ current_datetime=current_datetime, \
+ debug_queries=debug_queries, \
+ )
Commit-v0.26 | Commit-v0.27 | Commit-v0.28
- 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