mirror of
https://github.com/Xevion/runnerspace.git
synced 2025-12-11 21:11:15 -06:00
Add pluralizing macro filter to templating engine
- Only some plural edits are included here - some are locked behind commits coming soon™️
- Also made index template statistics variables read better
- Fixed spelling error in CSRF Error template rendering (hadn't hit the page yet)
This commit is contained in:
9
app.py
9
app.py
@@ -58,7 +58,7 @@ def create_app():
|
||||
|
||||
@app.errorhandler(CSRFError)
|
||||
def handle_csrf_error(e):
|
||||
return render_template('errprs/csrf.html', reason=e.description), 400
|
||||
return render_template('errors/csrf.html', reason=e.description), 400
|
||||
|
||||
@app.before_request
|
||||
def update_last_seen():
|
||||
@@ -68,6 +68,13 @@ def create_app():
|
||||
db.session.add(current_user)
|
||||
db.session.commit()
|
||||
|
||||
@app.template_filter('pluralize')
|
||||
def pluralize(number, singular='', plural='s'):
|
||||
if number == 1:
|
||||
return singular
|
||||
else:
|
||||
return plural
|
||||
|
||||
@app.context_processor
|
||||
def inject():
|
||||
return dict(now=datetime.utcnow)
|
||||
|
||||
@@ -16,19 +16,22 @@
|
||||
</div>
|
||||
<div class="statistics" style="margin: 1em;">
|
||||
<h2>runnerspace Statistics</h2>
|
||||
{% with comments = stats['total_comments'], posts = stats['total_posts'], users = stats['total_users'] %}
|
||||
<div>
|
||||
<div>
|
||||
<ul>
|
||||
<li>
|
||||
<strong>{{ stats['total_comments'] }}</strong> comments across <strong>{{ stats['total_posts'] }}</strong> posts<br>
|
||||
<strong>{{ comments }}</strong> comment across <strong>{{ posts }}</strong>
|
||||
post{{ posts|pluralize }}<br>
|
||||
</li>
|
||||
<li>
|
||||
<strong>{{ stats['total_users'] }}</strong> users
|
||||
<strong>{{ users }}</strong> user{{ users|pluralize }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endwith %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user