diff --git a/app.py b/app.py index f01d1f0..1d3dfa3 100644 --- a/app.py +++ b/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) diff --git a/templates/layouts/index.html b/templates/layouts/index.html index 26befbf..57c1bc2 100644 --- a/templates/layouts/index.html +++ b/templates/layouts/index.html @@ -16,19 +16,22 @@

runnerspace Statistics

-
+ {% with comments = stats['total_comments'], posts = stats['total_posts'], users = stats['total_users'] %}
-
    -
  • - {{ stats['total_comments'] }} comments across {{ stats['total_posts'] }} posts
    -
  • -
  • - {{ stats['total_users'] }} users -
  • -
+
+
    +
  • + {{ comments }} comment across {{ posts }} + post{{ posts|pluralize }}
    +
  • +
  • + {{ users }} user{{ users|pluralize }} +
  • +
+
-
+ {% endwith %}
{% endblock %}