8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 19:33:11 +00:00

Add context processor to get the current date

This commit is contained in:
Maël Kervella 2018-07-12 12:19:26 +00:00
parent 6a08e14165
commit 08157c4565
3 changed files with 15 additions and 3 deletions

View file

@ -21,8 +21,10 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""Fonction de context, variables renvoyées à toutes les vues""" """Fonction de context, variables renvoyées à toutes les vues"""
from __future__ import unicode_literals from __future__ import unicode_literals
import datetime
from django.contrib import messages from django.contrib import messages
from preferences.models import GeneralOption, OptionalMachine from preferences.models import GeneralOption, OptionalMachine
@ -47,3 +49,12 @@ def context_user(request):
'name_website': GeneralOption.get_cached_value('site_name'), 'name_website': GeneralOption.get_cached_value('site_name'),
'ipv6_enabled': OptionalMachine.get_cached_value('ipv6'), '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()
}

View file

@ -125,6 +125,7 @@ TEMPLATES = [
'django.contrib.messages.context_processors.messages', 'django.contrib.messages.context_processors.messages',
'django.template.context_processors.request', 'django.template.context_processors.request',
're2o.context_processors.context_user', 're2o.context_processors.context_user',
're2o.context_processors.date_now',
], ],
}, },
}, },

View file

@ -70,7 +70,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% for user in superusers %} {% for user in superusers %}
<tr> <tr>
<td>{{ user.pseudo }}</td> <td>{{ user.pseudo }}</td>
{% 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 %}
<td class="text-success">{% trans "Member" %}</td> <td class="text-success">{% trans "Member" %}</td>
{% elif not user.end_adhesion %} {% elif not user.end_adhesion %}
<td class="text-warning">{% trans "No membership records" %}</td> <td class="text-warning">{% trans "No membership records" %}</td>
@ -175,7 +175,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% for user in users %} {% for user in users %}
<tr> <tr>
<td>{{ user.pseudo }}</td> <td>{{ user.pseudo }}</td>
{% 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 %}
<td class="text-success">{% trans "Member" %}</td> <td class="text-success">{% trans "Member" %}</td>
{% elif not user.end_adhesion %} {% elif not user.end_adhesion %}
<td class="text-warning">{% trans "No membership records" %}</td> <td class="text-warning">{% trans "No membership records" %}</td>