From 08157c45654ec66c0eb971de58695e3e4a33ba1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Thu, 12 Jul 2018 12:19:26 +0000 Subject: [PATCH] Add context processor to get the current date --- re2o/context_processors.py | 13 ++++++++++++- re2o/settings.py | 1 + users/templates/users/aff_listright.html | 4 ++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/re2o/context_processors.py b/re2o/context_processors.py index a2e205c2..ceb03be2 100644 --- a/re2o/context_processors.py +++ b/re2o/context_processors.py @@ -21,8 +21,10 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. """Fonction de context, variables renvoyées à toutes les vues""" - from __future__ import unicode_literals + +import datetime + from django.contrib import messages from preferences.models import GeneralOption, OptionalMachine @@ -47,3 +49,12 @@ def context_user(request): 'name_website': GeneralOption.get_cached_value('site_name'), 'ipv6_enabled': OptionalMachine.get_cached_value('ipv6'), } + + +def date_now(request): + """Add the current date in the context for quick informations and + comparisons""" + return { + 'now_aware': datetime.datetime.now(datetime.timezone.utc), + 'now_naive': datetime.datetime.now() + } diff --git a/re2o/settings.py b/re2o/settings.py index 1117dd77..71bd266f 100644 --- a/re2o/settings.py +++ b/re2o/settings.py @@ -125,6 +125,7 @@ TEMPLATES = [ 'django.contrib.messages.context_processors.messages', 'django.template.context_processors.request', 're2o.context_processors.context_user', + 're2o.context_processors.date_now', ], }, }, diff --git a/users/templates/users/aff_listright.html b/users/templates/users/aff_listright.html index e7d3e64a..f4ed1e83 100644 --- a/users/templates/users/aff_listright.html +++ b/users/templates/users/aff_listright.html @@ -70,7 +70,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% for user in superusers %} {{ user.pseudo }} - {% if user.end_adhesion is not None and user.end_adhesion >= now %} + {% if user.end_adhesion is not None and user.end_adhesion >= now_aware %} {% trans "Member" %} {% elif not user.end_adhesion %} {% trans "No membership records" %} @@ -175,7 +175,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% for user in users %} {{ user.pseudo }} - {% if user.end_adhesion is not None and user.end_adhesion >= now %} + {% if user.end_adhesion is not None and user.end_adhesion >= now_aware %} {% trans "Member" %} {% elif not user.end_adhesion %} {% trans "No membership records" %}