Nettoyage dates et calendrier
This commit is contained in:
parent
954a6fdb53
commit
1e3850bb6b
8 changed files with 54 additions and 51 deletions
0
cof/locale/en/__init__.py
Normal file
0
cof/locale/en/__init__.py
Normal file
11
cof/locale/en/formats.py
Normal file
11
cof/locale/en/formats.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
Formats français.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
DATETIME_FORMAT = r'l N j, Y \a\t P'
|
||||||
|
DATE_FORMAT = r'l N j, Y'
|
||||||
|
TIME_FORMAT = r'P'
|
|
@ -6,4 +6,6 @@ Formats français.
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
DATETIME_FORMAT = r'l j F Y \à H:i'
|
DATETIME_FORMAT = r'l j F Y \à H\hi'
|
||||||
|
DATE_FORMAT = r'l j F Y'
|
||||||
|
TIME_FORMAT = r'H\hi'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{% load wagtailcore_tags wagtailroutablepage_tags static %}
|
{% load wagtailcore_tags wagtailroutablepage_tags static i18n %}
|
||||||
<table class="calendar">
|
<table class="calendar">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -6,7 +6,7 @@
|
||||||
<th colspan="5">{{ this_month|date:"F Y" }}</th>
|
<th colspan="5">{{ this_month|date:"F Y" }}</th>
|
||||||
<th><a href="javascript:void(0);" cal-dest="{{ next_month }}" class="cal-btn">></a></th>
|
<th><a href="javascript:void(0);" cal-dest="{{ next_month }}" class="cal-btn">></a></th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr><th>L</th><th>M</th><th>M</th><th>J</th><th>V</th><th>S</th><th>D</th></tr>
|
<tr>{% blocktrans %}<th>L</th><th>M</th><th>M</th><th>J</th><th>V</th><th>S</th><th>D</th>{% endblocktrans %}</tr>
|
||||||
{% for week in weeks %}
|
{% for week in weeks %}
|
||||||
<tr>
|
<tr>
|
||||||
{% for day in week %}
|
{% for day in week %}
|
||||||
|
@ -14,7 +14,7 @@
|
||||||
{% if day.events %}
|
{% if day.events %}
|
||||||
<a href="javascript:void(0)">{{ day.day }}</a>
|
<a href="javascript:void(0)">{{ day.day }}</a>
|
||||||
<ul class="cal-events">
|
<ul class="cal-events">
|
||||||
<li class="datename">Le {{ day.date|date:"d F Y" }}</li>
|
<li class="datename">{% trans "Le " %}{{ day.date|date }}</li>
|
||||||
{% for event in day.events %}
|
{% for event in day.events %}
|
||||||
<li><a href="{% pageurl event %}">{{ event.title }}</a></li>
|
<li><a href="{% pageurl event %}">{{ event.title }}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% get_current_language as curlang %}
|
|
||||||
<section class="intro">
|
<section class="intro">
|
||||||
<h1>{{ page.title }}</h1>
|
<h1>{{ page.title }}</h1>
|
||||||
<div>{{ page.introduction|safe }}</div>
|
<div>{{ page.introduction|safe }}</div>
|
||||||
|
@ -35,7 +34,7 @@
|
||||||
<div class="actu-infos">
|
<div class="actu-infos">
|
||||||
<h2><a href="{% pageurl actu %}">{{ actu.title }}</a></h2>
|
<h2><a href="{% pageurl actu %}">{{ actu.title }}</a></h2>
|
||||||
{% if actu.is_event %}
|
{% if actu.is_event %}
|
||||||
<p><span class="actu-dates">{{ actu|dates:curlang|capfirst }}</span><br />{{ actu.chapo }}</p>
|
<p><span class="actu-dates">{{ actu|dates|capfirst }}</span><br />{{ actu.chapo }}</p>
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ actu.body|safe|truncatewords_html:15 }}
|
{{ actu.body|safe|truncatewords_html:15 }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -2,10 +2,9 @@
|
||||||
{% load wagtailimages_tags cofcms_tags i18n %}
|
{% load wagtailimages_tags cofcms_tags i18n %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% get_current_language as curlang %}
|
|
||||||
<section class="intro">
|
<section class="intro">
|
||||||
<h1>{{ page.title }}</h1>
|
<h1>{{ page.title }}</h1>
|
||||||
<p class="date">A lieu {{ page|dates:curlang }}</p>
|
<p class="date">A lieu {{ page|dates }}</p>
|
||||||
<p>{{ page.chapo }}</p>
|
<p>{{ page.chapo }}</p>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% get_current_language as curlang %}
|
|
||||||
<section class="intro">
|
<section class="intro">
|
||||||
<h1>{{ page.title }}</h1>
|
<h1>{{ page.title }}</h1>
|
||||||
<div>{{ page.introduction|safe }}</div>
|
<div>{{ page.introduction|safe }}</div>
|
||||||
|
@ -30,7 +29,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="actu-misc">
|
<div class="actu-misc">
|
||||||
{% if actu.is_event %}
|
{% if actu.is_event %}
|
||||||
<span class="actu-minical">{% mini_calendar actu %}</span><span class="actu-dates">{{ actu|dates:curlang }}</span>
|
<span class="actu-minical">{% mini_calendar actu %}</span><span class="actu-dates">{{ actu|dates }}</span>
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ actu.body|safe|truncatewords_html:10 }}
|
{{ actu.body|safe|truncatewords_html:10 }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from datetime import timedelta, date
|
from datetime import timedelta, date
|
||||||
from django import template
|
from django import template
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils import timezone
|
from django.utils import timezone, formats
|
||||||
import locale
|
import locale
|
||||||
|
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
@ -51,9 +51,7 @@ def calendar(context, month=None, year=None):
|
||||||
curevents.append(e)
|
curevents.append(e)
|
||||||
day = {'day': curday.day,
|
day = {'day': curday.day,
|
||||||
'date': curday,
|
'date': curday,
|
||||||
'class': (('today ' if (curday.day == now.day
|
'class': (('today ' if curday == now.date() else '')
|
||||||
and curday.month == now.month
|
|
||||||
and curday.year == now.year) else '')
|
|
||||||
+ ('in ' if (curday.month == month_start.month
|
+ ('in ' if (curday.month == month_start.month
|
||||||
and curday.year == month_start.year)
|
and curday.year == month_start.year)
|
||||||
else 'out ')
|
else 'out ')
|
||||||
|
@ -72,11 +70,11 @@ def calendar(context, month=None, year=None):
|
||||||
request = context['request']
|
request = context['request']
|
||||||
burl = utilpage.debugged_get_url(request) + "/"
|
burl = utilpage.debugged_get_url(request) + "/"
|
||||||
prev_url = burl + utilpage.reverse_subpage("calendar",
|
prev_url = burl + utilpage.reverse_subpage("calendar",
|
||||||
args=["%d" % (prev_month.year,),
|
args=[str(prev_month.year),
|
||||||
"%d" % (prev_month.month,)])
|
str(prev_month.month)])
|
||||||
next_url = burl + utilpage.reverse_subpage("calendar",
|
next_url = burl + utilpage.reverse_subpage("calendar",
|
||||||
args=["%d" % (next_month.year,),
|
args=[str(next_month.year),
|
||||||
"%d" % (next_month.month,)])
|
str(next_month.month)])
|
||||||
context.push({"events": events, "weeks": weeks, "this_month": month_start,
|
context.push({"events": events, "weeks": weeks, "this_month": month_start,
|
||||||
"prev_month": prev_url, "next_month": next_url})
|
"prev_month": prev_url, "next_month": next_url})
|
||||||
return context
|
return context
|
||||||
|
@ -98,48 +96,43 @@ def mini_calendar(event):
|
||||||
|
|
||||||
|
|
||||||
@register.filter()
|
@register.filter()
|
||||||
def dates(event, loc=None):
|
def dates(event):
|
||||||
try:
|
def factorize_suffix(a, b):
|
||||||
if loc == "fr":
|
i = -1
|
||||||
locale.setlocale(locale.LC_TIME, "fr_FR.UTF-8")
|
imin = -min(len(a), len(b))
|
||||||
|
while i>imin and a[i] == b[i]:
|
||||||
|
i -= 1
|
||||||
|
if i == -1:
|
||||||
|
return (a, b, '')
|
||||||
else:
|
else:
|
||||||
locale.setlocale(locale.LC_TIME, "en_US.UTF-8")
|
return (a[:i+1], b[:i+1], a[i+1:])
|
||||||
except locale.Error as e:
|
|
||||||
pass
|
datestart_string = formats.date_format(event.date_start)
|
||||||
|
timestart_string = formats.time_format(event.date_start)
|
||||||
if event.date_end:
|
if event.date_end:
|
||||||
if event.date_end.date() == event.date_start.date():
|
if event.date_end.date() == event.date_start.date():
|
||||||
if event.all_day:
|
if event.all_day:
|
||||||
return event.date_start.strftime(_("le %A %d %B %Y"))
|
return _("le %s") % datestart_string
|
||||||
else:
|
else:
|
||||||
return _("le %s de %s à %s") % \
|
return _("le %s de %s à %s") % \
|
||||||
(event.date_start.strftime("%A %d %B %Y"),
|
(datestart_string,
|
||||||
event.date_start.strftime(_("%Hh%M")),
|
timestart_string,
|
||||||
event.date_end.strftime(_("%Hh%M")))
|
formats.time_format(event.date_end))
|
||||||
else:
|
else:
|
||||||
tmpl = "%A %d %B %Y"
|
dateend_string = formats.date_format(event.date_end)
|
||||||
diff_i = len(tmpl)
|
timeend_string = formats.time_format(event.date_end)
|
||||||
if event.date_end.year != event.date_start.year:
|
diffstart, diffend, common = factorize_suffix(datestart_string,
|
||||||
diff_i = len(tmpl)
|
dateend_string)
|
||||||
elif event.date_end.month != event.date_start.month:
|
|
||||||
diff_i = len(tmpl) - 3
|
|
||||||
elif event.date_end.day != event.date_start.day:
|
|
||||||
diff_i = len(tmpl) - 6
|
|
||||||
common = tmpl[diff_i:]
|
|
||||||
diff = tmpl[:diff_i]
|
|
||||||
if event.all_day:
|
if event.all_day:
|
||||||
return _("du %s au %s%s") % \
|
return _("du %s au %s%s") % \
|
||||||
(event.date_start.strftime(diff),
|
(diffstart, diffend, common)
|
||||||
event.date_end.strftime(diff),
|
|
||||||
event.date_end.strftime(common))
|
|
||||||
else:
|
else:
|
||||||
return _("du %s%s à %s au %s à %s") % \
|
return _("du %s%s à %s au %s à %s") % \
|
||||||
(event.date_start.strftime(diff),
|
(diffstart, common, timestart_string,
|
||||||
event.date_start.strftime(common),
|
diffend, formats.time_format(event.date_end))
|
||||||
event.date_start.strftime("%Hh%M"),
|
|
||||||
event.date_end.strftime(diff),
|
|
||||||
event.date_end.strftime("%Hh%M"))
|
|
||||||
else:
|
else:
|
||||||
if event.all_day:
|
if event.all_day:
|
||||||
return event.date_start.strftime(_("le %A %d %B %Y"))
|
return _("le %s") % datestart_string
|
||||||
else:
|
else:
|
||||||
return event.date_start.strftime(_("le %A %d %B %Y à %Hh%M"))
|
return _("le %s à %s") % (datestart_string, timestart_string)
|
||||||
|
|
Loading…
Reference in a new issue