From: Emilie Date: Thu, 17 Nov 2016 11:51:07 +0000 (+0100) Subject: Event : format date FR / EN X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=e1db207ab1a254661cf9eb40aeedd8f24a1f9ebc;p=mezzo.git Event : format date FR / EN --- diff --git a/app/local_settings.py b/app/local_settings.py index 845c36b4..e3ab9f24 100644 --- a/app/local_settings.py +++ b/app/local_settings.py @@ -236,3 +236,7 @@ SHOP_USE_RATINGS = False PROJECT_DEMOS_DIR = '/srv/media/projects/demos/' if not os.path.exists(PROJECT_DEMOS_DIR): os.makedirs(PROJECT_DEMOS_DIR) + +FORMAT_MODULE_PATH = [ + 'organization.formats', +] diff --git a/app/organization/core/context_processors.py b/app/organization/core/context_processors.py index bc1e71b3..f0cc3e06 100644 --- a/app/organization/core/context_processors.py +++ b/app/organization/core/context_processors.py @@ -5,14 +5,17 @@ from organization.network.models import Organization def settings(request): date_now = datetime.now() + # SEASON CURRENT_SEASON = int(date_now.year) - 1 if datetime(date_now.year, 1,1) <= date_now and date_now <= datetime(date_now.year, 7, 31) else date_now.year CURRENT_SEASON_STYLED = str(CURRENT_SEASON)[-2:]+"."+str(CURRENT_SEASON+1)[-2:] + # NEWSLETTER newsletter_page = Page.objects.filter(slug="newsletter") NEWSLETTER_SUBSCRIBING_URL = "" if newsletter_page: NEWSLETTER_SUBSCRIBING_URL = newsletter_page.first().get_absolute_url() + # HOST ORGANIZATION host_organization = Organization.objects.get(is_host=True) return {'CURRENT_SEASON': CURRENT_SEASON, diff --git a/app/organization/core/templatetags/organization_tags.py b/app/organization/core/templatetags/organization_tags.py index 5e2a9b44..731abfd0 100644 --- a/app/organization/core/templatetags/organization_tags.py +++ b/app/organization/core/templatetags/organization_tags.py @@ -180,3 +180,7 @@ def is_not_host(organizations): @register.filter def unspam(email): return email.replace('@', ' (at) ') + +@register.filter +def get_attr(obj, attr): + return getattr(obj, attr) diff --git a/app/organization/formats/__init__.py b/app/organization/formats/__init__.py new file mode 100644 index 00000000..38c15a2d --- /dev/null +++ b/app/organization/formats/__init__.py @@ -0,0 +1,7 @@ +""" +Provides abstract models and admin features used throughout the various +Mezzanine apps. +""" +from __future__ import unicode_literals + +default_app_config = 'organization.formats.apps.FormatsConfig' diff --git a/app/organization/formats/apps.py b/app/organization/formats/apps.py new file mode 100644 index 00000000..02608a37 --- /dev/null +++ b/app/organization/formats/apps.py @@ -0,0 +1,9 @@ +from django.apps import AppConfig + +from django.core.checks import register + + +class FormatsConfig(AppConfig): + + name = 'organization.formats' + label = 'organization-formats' diff --git a/app/organization/formats/en/__init__.py b/app/organization/formats/en/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/app/organization/formats/en/formats.py b/app/organization/formats/en/formats.py new file mode 100644 index 00000000..1a36aa21 --- /dev/null +++ b/app/organization/formats/en/formats.py @@ -0,0 +1,45 @@ +# -*- encoding: utf-8 -*- +# This file is distributed under the same license as the Django package. +# +from __future__ import unicode_literals + +# The *_FORMAT strings use the Django date format syntax, +# see http://docs.djangoproject.com/en/dev/ref/templates/builtins/#date +DATE_FORMAT = 'N j, Y' +DATE_EVENT_FORMAT = 'D, F jS' +WEEK_DAY_FORMAT = 'D, jS' +TIME_FORMAT = 'P' +DATETIME_FORMAT = 'N j, Y, P' +YEAR_MONTH_FORMAT = 'F Y' +MONTH_DAY_FORMAT = 'F j' +SHORT_DATE_FORMAT = 'm/d/Y' +SHORT_DATETIME_FORMAT = 'm/d/Y P' +FIRST_DAY_OF_WEEK = 0 # Sunday + +# The *_INPUT_FORMATS strings use the Python strftime format syntax, +# see http://docs.python.org/library/datetime.html#strftime-strptime-behavior +# Kept ISO formats as they are in first position +DATE_INPUT_FORMATS = [ + '%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y', # '2006-10-25', '10/25/2006', '10/25/06' + # '%b %d %Y', '%b %d, %Y', # 'Oct 25 2006', 'Oct 25, 2006' + # '%d %b %Y', '%d %b, %Y', # '25 Oct 2006', '25 Oct, 2006' + # '%B %d %Y', '%B %d, %Y', # 'October 25 2006', 'October 25, 2006' + # '%d %B %Y', '%d %B, %Y', # '25 October 2006', '25 October, 2006' +] +DATETIME_INPUT_FORMATS = [ + '%Y-%m-%d %H:%M:%S', # '2006-10-25 14:30:59' + '%Y-%m-%d %H:%M:%S.%f', # '2006-10-25 14:30:59.000200' + '%Y-%m-%d %H:%M', # '2006-10-25 14:30' + '%Y-%m-%d', # '2006-10-25' + '%m/%d/%Y %H:%M:%S', # '10/25/2006 14:30:59' + '%m/%d/%Y %H:%M:%S.%f', # '10/25/2006 14:30:59.000200' + '%m/%d/%Y %H:%M', # '10/25/2006 14:30' + '%m/%d/%Y', # '10/25/2006' + '%m/%d/%y %H:%M:%S', # '10/25/06 14:30:59' + '%m/%d/%y %H:%M:%S.%f', # '10/25/06 14:30:59.000200' + '%m/%d/%y %H:%M', # '10/25/06 14:30' + '%m/%d/%y', # '10/25/06' +] +DECIMAL_SEPARATOR = '.' +THOUSAND_SEPARATOR = ',' +NUMBER_GROUPING = 3 diff --git a/app/organization/formats/formats.py b/app/organization/formats/formats.py new file mode 100644 index 00000000..016adb48 --- /dev/null +++ b/app/organization/formats/formats.py @@ -0,0 +1,3 @@ +from __future__ import unicode_literals + +TIME_FORMAT = 'H\hi' diff --git a/app/organization/formats/fr/__init__.py b/app/organization/formats/fr/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/app/organization/formats/fr/formats.py b/app/organization/formats/fr/formats.py new file mode 100644 index 00000000..55c33f50 --- /dev/null +++ b/app/organization/formats/fr/formats.py @@ -0,0 +1,38 @@ +# -*- encoding: utf-8 -*- +# This file is distributed under the same license as the Django package. +# +from __future__ import unicode_literals + +# The *_FORMAT strings use the Django date format syntax, +# see http://docs.djangoproject.com/en/dev/ref/templates/builtins/#date +DATE_FORMAT = 'j F Y' +DATE_EVENT_FORMAT = 'D j F' +WEEK_DAY_FORMAT = 'D j' +TIME_FORMAT = 'H\hi' +DATETIME_FORMAT = 'j F Y H:i' +YEAR_MONTH_FORMAT = 'F Y' +MONTH_DAY_FORMAT = 'j F' +SHORT_DATE_FORMAT = 'j N Y' +SHORT_DATETIME_FORMAT = 'j N Y H:i' +FIRST_DAY_OF_WEEK = 1 # Monday + +# The *_INPUT_FORMATS strings use the Python strftime format syntax, +# see http://docs.python.org/library/datetime.html#strftime-strptime-behavior +DATE_INPUT_FORMATS = [ + '%d/%m/%Y', '%d/%m/%y', # '25/10/2006', '25/10/06' + '%d.%m.%Y', '%d.%m.%y', # Swiss [fr_CH), '25.10.2006', '25.10.06' + # '%d %B %Y', '%d %b %Y', # '25 octobre 2006', '25 oct. 2006' +] +DATETIME_INPUT_FORMATS = [ + '%d/%m/%Y %H:%M:%S', # '25/10/2006 14:30:59' + '%d/%m/%Y %H:%M:%S.%f', # '25/10/2006 14:30:59.000200' + '%d/%m/%Y %H:%M', # '25/10/2006 14:30' + '%d/%m/%Y', # '25/10/2006' + '%d.%m.%Y %H:%M:%S', # Swiss [fr_CH), '25.10.2006 14:30:59' + '%d.%m.%Y %H:%M:%S.%f', # Swiss (fr_CH), '25.10.2006 14:30:59.000200' + '%d.%m.%Y %H:%M', # Swiss (fr_CH), '25.10.2006 14:30' + '%d.%m.%Y', # Swiss (fr_CH), '25.10.2006' +] +DECIMAL_SEPARATOR = ',' +THOUSAND_SEPARATOR = '\xa0' # non-breaking space +NUMBER_GROUPING = 3 diff --git a/app/organization/pages/context_processors.py b/app/organization/pages/context_processors.py deleted file mode 100644 index 767d86ad..00000000 --- a/app/organization/pages/context_processors.py +++ /dev/null @@ -1,9 +0,0 @@ -from django.conf import settings # import the settings file -from organization.pages.models import Page - -def page_static(request): - newsletter_page = Page.objects.filter(slug="newsletter") - NEWSLETTER_SUBSCRIBING_URL = "" - if newsletter_page: - NEWSLETTER_SUBSCRIBING_URL = newsletter_page.first().get_absolute_url() - return {'NEWSLETTER_SUBSCRIBING_URL': NEWSLETTER_SUBSCRIBING_URL,} diff --git a/app/templates/agenda/includes/event_date.html b/app/templates/agenda/includes/event_date.html index cb31a618..fc043556 100644 --- a/app/templates/agenda/includes/event_date.html +++ b/app/templates/agenda/includes/event_date.html @@ -1,34 +1,31 @@ -{% load i18n %} -{% load event_tags pages_tags mezzanine_tags %} - +{% load event_tags pages_tags mezzanine_tags organization_tags i18n %} {% if event.start and not event.end %} - {{ event.start|date:event.date_format }} + {{ event.start|date:"DATE_EVENT_FORMAT" }},
{% if event.start and event.start|date:"H:i" != "23:59" %} - - {{ event.start|date:"H\hi" }} + {{ event.start|time:"TIME_FORMAT" }} {% endif %} - {% else %} {% if event.start|date:"d.m.y" == event.end|date:"d.m.y" %} {% if not event.periods.all %} - {{ event.start|date:event.date_format }} + {{ event.start|date:"DATE_EVENT_FORMAT" }},
{% if event.end and event.end|date:"H:i" != "23:59" %} - , {{ event.start|date:" H\hi" }} - {{ event.end|date:"H\hi" }} + {{ event.start|time:"TIME_FORMAT" }} - {{ event.end|time:"TIME_FORMAT" }} {% else %} - , {{ event.start|date:" H\hi" }} + {{ event.start|time:"TIME_FORMAT" }} {% endif %} {% else %} - {{ event.start|date:event.date_format }} + {{ event.start|date:"DATE_EVENT_FORMAT" }},
{% for period in event.periods.all %} {% if period.date_to and period.date_to|date:"H:i" != "23:59" %} - ,{{ period.date_from|date:"H\hi" }} - {{ period.date_to|date:"H\hi" }} + {{ period.date_from|time:"TIME_FORMAT" }} - {{ period.date_to|time:"TIME_FORMAT" }} {% else %} {% if forloop.last or event.periods.all|length == 2 %} {% trans "and"%} {% elif not forloop.first %}, {% endif %} - {{ period.date_from|date:"H\hi" }} + {{ period.date_from|time:"TIME_FORMAT" }} {% endif %} {% endfor %} {% endif %} @@ -39,39 +36,45 @@ {% with event.periods.all|same_time_in_periods as same_time_in_periods %} {% for period in event.periods.all %} {% if period.date_to and period.date_to|date:"H:i" != "23:59" %} - {{ period.date_from|date:event.date_format }} + {{ period.date_from|date:"DATE_EVENT_FORMAT" }},
{% if period|period_is_more_than_hours:4 %} - , {{ period.date_from|date:"H\hi" }} {% trans "to" %} {{ period.date_to|date:"H\hi" }} + {{ period.date_from|time:"WEEK_DAY_FORMAT" }} {% trans "to" %} {{ period.date_to|time:"TIME_FORMAT" }} {% else %} - , {{ period.date_from|date:"H\hi" }} + {{ period.date_from|time:"TIME_FORMAT" }} {% endif %} {% else %} {% if event.periods.all|length > 1 and not forloop.last %} - {{ period.date_from|date:event.date_format }}{% if event.periods.all|length == 2 %} {% trans "and" %} {% else %}{% endif %} + {{ period.date_from|date:"DATE_EVENT_FORMAT" }}{% if event.periods.all|length == 2 %} {% trans "and" %} {% else %}{% endif %} {% else %} - {{ period.date_from|date:event.date_format }} - {% if event.periods.all|length > 1 and forloop.first %} {% trans "and" %}{% endif %} + {{ period.date_from|date:"DATE_EVENT_FORMAT" }},
+ {% if event.periods.all|length > 1 and forloop.first %}{% trans "and" %}{% endif %} {% endif %} {% if same_time_in_periods and forloop.last %} - {{ period.date_from|date:"H\hi" }} + {{ period.date_from|time:"TIME_FORMAT" }} {% elif not same_time_in_periods %} - , {{ period.date_from|date:"H\hi" }} +
, {{ period.date_from|time:"TIME_FORMAT" }} {% endif %} {% endif %}
{% endfor %} {% endwith %} {% else %} - {{ event.start|date:event.date_format }} {% trans "to" %} {{ event.end|date:event.date_format }} - {{ event.start|date:"H\hi" }} - {{ event.end|date:"H\hi" }} + {{ event.start|date:"WEEK_DAY_FORMAT" }} + {% if event.end|subtract:event.start|get_attr:"days" > 1 %} + {% trans "to" %} + {% else %} + {% trans "and" %} + {% endif %} + {{ event.end|date:"DATE_EVENT_FORMAT" }},
{{ event.start|time:"TIME_FORMAT" }} - {{ event.end|time:"TIME_FORMAT" }} {% endif %} {% else %} - {{ event.start|date:"j F" }} {% trans "to" %} {{ event.end|date:"j F" }} + {{ event.start|date:"WEEK_DAY_FORMAT" }} {% trans "to" %} {{ event.end|date:"DATE_EVENT_FORMAT" }},
{% if event.end and event.end|date:"H:i" != "23:59" %} - , {{ event.start|date:" H\hi" }} - {{ event.end|date:"H\hi" }} + {{ event.start|time:"TIME_FORMAT" }} - {{ event.end|time:"TIME_FORMAT" }} {% else %} - , {{ event.start|date:" H\hi" }} + {{ event.start|time:"TIME_FORMAT" }} {% endif %} {% endif %}