Browse Source

templates: add a pluralize filter

master
Lephe 8 months ago
parent
commit
8211183b5c
3 changed files with 15 additions and 2 deletions
  1. 1
    0
      app/__init__.py
  2. 3
    2
      app/templates/admin/delete_account.html
  3. 11
    0
      app/utils/pluralize.py

+ 1
- 0
app/__init__.py View File

@@ -15,3 +15,4 @@ login.login_message = "Veuillez vous authentifier avant de continuer."

from app import models
from app.routes import index, login, search, account, admin, users
from app.utils import pluralize

+ 3
- 2
app/templates/admin/delete_account.html View File

@@ -9,8 +9,9 @@
<h2>Confirmer la suppression du compte</h2>
<p>Le compte '{{ user.name }}' que vous allez supprimer est lié à :</p>
<ul>
<li>{{ user.groups | length }} groupes</li>
<li>{{ user.special_privileges() | length }} privilèges spéciaux</li>
<li>{{ user.groups | length }} groupe{{ user.groups|length|pluralize }}</li>
<li>{% set sp = user.special_privileges() | length %}
{{- sp }} privilège{{sp|pluralize}} spéci{{sp|pluralize("al","aux")}}</li>
</ul>

<form action="{{ url_for('adm_delete_account', user_id=user.id) }}" method=post>

+ 11
- 0
app/utils/pluralize.py View File

@@ -0,0 +1,11 @@
from app import app

@app.template_filter('pluralize')
def pluralize(count, singular="", plural="s"):
"""
Make a noun plural. Meant for templates; use it like this:
Il y a {{ n }} groupe{{ n | pluralize }}.
You can specify different suffixes if "s" is not relevant;
Il y a {{ n }} hibou{{ n | pluralize("", "x") }}.
"""
return singular if count <= 1 else plural

Loading…
Cancel
Save