]> git.parisson.com Git - mezzo.git/commitdiff
Event : format date FR / EN
authorEmilie <zawadzki@ircam.fr>
Thu, 17 Nov 2016 11:51:07 +0000 (12:51 +0100)
committerEmilie <zawadzki@ircam.fr>
Thu, 17 Nov 2016 11:51:07 +0000 (12:51 +0100)
12 files changed:
app/local_settings.py
app/organization/core/context_processors.py
app/organization/core/templatetags/organization_tags.py
app/organization/formats/__init__.py [new file with mode: 0644]
app/organization/formats/apps.py [new file with mode: 0644]
app/organization/formats/en/__init__.py [new file with mode: 0644]
app/organization/formats/en/formats.py [new file with mode: 0644]
app/organization/formats/formats.py [new file with mode: 0644]
app/organization/formats/fr/__init__.py [new file with mode: 0644]
app/organization/formats/fr/formats.py [new file with mode: 0644]
app/organization/pages/context_processors.py [deleted file]
app/templates/agenda/includes/event_date.html

index 845c36b4b24142670db3a33b03ec783b58abe171..e3ab9f24013c4cc2ca8b39d1af6c776424ea7ce7 100644 (file)
@@ -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',
+]
index bc1e71b380eb0e1249c9f0fcdbd9861d48057a53..f0cc3e061ba09ad9a02b6c5568e7dd48f2c34294 100644 (file)
@@ -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,
index 5e2a9b4461e046d0ae0ddc000cf9e2f7cc2eb45c..731abfd02de2e36d46b924fdad22bde72611eb18 100644 (file)
@@ -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 (file)
index 0000000..38c15a2
--- /dev/null
@@ -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 (file)
index 0000000..02608a3
--- /dev/null
@@ -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 (file)
index 0000000..e69de29
diff --git a/app/organization/formats/en/formats.py b/app/organization/formats/en/formats.py
new file mode 100644 (file)
index 0000000..1a36aa2
--- /dev/null
@@ -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 (file)
index 0000000..016adb4
--- /dev/null
@@ -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 (file)
index 0000000..e69de29
diff --git a/app/organization/formats/fr/formats.py b/app/organization/formats/fr/formats.py
new file mode 100644 (file)
index 0000000..55c33f5
--- /dev/null
@@ -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 (file)
index 767d86a..0000000
+++ /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,}
index cb31a618335d0a1f815a0769820596725f240eb5..fc0435560a8428553df2fe66682b6d14bb51ecdb 100644 (file)
@@ -1,34 +1,31 @@
-{% load i18n %}
-{% load event_tags pages_tags mezzanine_tags %}
-
+{% load event_tags pages_tags mezzanine_tags organization_tags i18n  %}
     <!-- Start date only  -->
     {% if event.start and not event.end %}
-        {{ event.start|date:event.date_format }}
+        {{ event.start|date:"DATE_EVENT_FORMAT" }},<br>
         <!-- Start date with hour  -->
         {% if event.start and event.start|date:"H:i" != "23:59" %}
-            - {{ event.start|date:"H\hi" }}
+            {{ event.start|time:"TIME_FORMAT" }}
         {% endif %}
-
     <!-- Start and end date  -->
     {% else %}
         <!-- Start and end date is the same day  -->
         {% 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" }},<br>
                 <!-- Start date with hour  -->
                 {% 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" }},<br>
                 {% 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 %}
             {% 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" }},<br>
                     {% 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" }},<br>
+                        {% 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" }}
+                        <br>, {{ period.date_from|time:"TIME_FORMAT" }}
                     {% endif %}
                 {% endif %}
                 <br />
             {% 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" }},<br> {{ event.start|time:"TIME_FORMAT" }} - {{ event.end|time:"TIME_FORMAT" }}
           {% endif %}
         <!-- Start and end date are completely different  -->
         {% 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" }},<br>
             <!-- Start date with hour  -->
             {% 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 %}