diff options
| author | Thibaut Horel <thibaut.horel@gmail.com> | 2012-11-08 20:46:11 +0100 |
|---|---|---|
| committer | Thibaut Horel <thibaut.horel@gmail.com> | 2012-11-08 20:46:11 +0100 |
| commit | 4138a537f3167d54cd7cf56c741d35a9016d4b24 (patch) | |
| tree | 461dce7036910356ed97f0da7a6aebb30273f378 | |
| parent | 9b2f907dfffd92b6f236d73cc5d0c3b9fb92cc53 (diff) | |
| download | famille-flask-4138a537f3167d54cd7cf56c741d35a9016d4b24.tar.gz | |
Filter improvements
| -rw-r--r-- | famille.py | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -19,20 +19,22 @@ app = Flask(__name__) app.config.from_envvar('CONF') @app.template_filter('format_date') -def format_date(datetime_string, format="%a %d %b %Y"): +def format_date(datetime_string, format=u"%a %d %b %Y à %Hh%M".encode("utf8")): if not datetime_string: return "" - return datetime.strptime(datetime_string[:-1], - "%Y-%m-%dT%H:%M:%S").strftime(format) + return datetime.strptime(datetime_string[:-1], + "%Y-%m-%dT%H:%M:%S").strftime(format).decode("utf8") @app.template_filter('pluralize') -def pluralize(ncomments): - if ncomments==0: - return "Aucun Commentaire" - elif ncomments==1: - return "1 Commentaire" +def pluralize(word, count, plural=None): + if count == 0: + return "Aucun {}".format(word) + elif count == 1: + return "1 {}".format(word) + elif plural: + return "{} {}".format(count, plural) else: - return "{0} Commentaires".format(ncomments) + return "{} {}s".format(count, word) def query_db(query, args=(), one=False): cur = g.db.execute(query, args) |
