forked from DGNum/gestioCOF
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
|
||||
|
||||
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">
|
||||
<tbody>
|
||||
<tr>
|
||||
|
@ -6,7 +6,7 @@
|
|||
<th colspan="5">{{ this_month|date:"F Y" }}</th>
|
||||
<th><a href="javascript:void(0);" cal-dest="{{ next_month }}" class="cal-btn">></a></th>
|
||||
</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 %}
|
||||
<tr>
|
||||
{% for day in week %}
|
||||
|
@ -14,7 +14,7 @@
|
|||
{% if day.events %}
|
||||
<a href="javascript:void(0)">{{ day.day }}</a>
|
||||
<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 %}
|
||||
<li><a href="{% pageurl event %}">{{ event.title }}</a></li>
|
||||
{% endfor %}
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% get_current_language as curlang %}
|
||||
<section class="intro">
|
||||
<h1>{{ page.title }}</h1>
|
||||
<div>{{ page.introduction|safe }}</div>
|
||||
|
@ -35,7 +34,7 @@
|
|||
<div class="actu-infos">
|
||||
<h2><a href="{% pageurl actu %}">{{ actu.title }}</a></h2>
|
||||
{% 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 %}
|
||||
{{ actu.body|safe|truncatewords_html:15 }}
|
||||
{% endif %}
|
||||
|
|
|
@ -2,10 +2,9 @@
|
|||
{% load wagtailimages_tags cofcms_tags i18n %}
|
||||
|
||||
{% block content %}
|
||||
{% get_current_language as curlang %}
|
||||
<section class="intro">
|
||||
<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>
|
||||
</section>
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% get_current_language as curlang %}
|
||||
<section class="intro">
|
||||
<h1>{{ page.title }}</h1>
|
||||
<div>{{ page.introduction|safe }}</div>
|
||||
|
@ -30,7 +29,7 @@
|
|||
</div>
|
||||
<div class="actu-misc">
|
||||
{% 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 %}
|
||||
{{ actu.body|safe|truncatewords_html:10 }}
|
||||
{% endif %}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from datetime import timedelta, date
|
||||
from django import template
|
||||
from django.conf import settings
|
||||
from django.utils import timezone
|
||||
from django.utils import timezone, formats
|
||||
import locale
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
|
@ -51,9 +51,7 @@ def calendar(context, month=None, year=None):
|
|||
curevents.append(e)
|
||||
day = {'day': curday.day,
|
||||
'date': curday,
|
||||
'class': (('today ' if (curday.day == now.day
|
||||
and curday.month == now.month
|
||||
and curday.year == now.year) else '')
|
||||
'class': (('today ' if curday == now.date() else '')
|
||||
+ ('in ' if (curday.month == month_start.month
|
||||
and curday.year == month_start.year)
|
||||
else 'out ')
|
||||
|
@ -72,11 +70,11 @@ def calendar(context, month=None, year=None):
|
|||
request = context['request']
|
||||
burl = utilpage.debugged_get_url(request) + "/"
|
||||
prev_url = burl + utilpage.reverse_subpage("calendar",
|
||||
args=["%d" % (prev_month.year,),
|
||||
"%d" % (prev_month.month,)])
|
||||
args=[str(prev_month.year),
|
||||
str(prev_month.month)])
|
||||
next_url = burl + utilpage.reverse_subpage("calendar",
|
||||
args=["%d" % (next_month.year,),
|
||||
"%d" % (next_month.month,)])
|
||||
args=[str(next_month.year),
|
||||
str(next_month.month)])
|
||||
context.push({"events": events, "weeks": weeks, "this_month": month_start,
|
||||
"prev_month": prev_url, "next_month": next_url})
|
||||
return context
|
||||
|
@ -98,48 +96,43 @@ def mini_calendar(event):
|
|||
|
||||
|
||||
@register.filter()
|
||||
def dates(event, loc=None):
|
||||
try:
|
||||
if loc == "fr":
|
||||
locale.setlocale(locale.LC_TIME, "fr_FR.UTF-8")
|
||||
def dates(event):
|
||||
def factorize_suffix(a, b):
|
||||
i = -1
|
||||
imin = -min(len(a), len(b))
|
||||
while i>imin and a[i] == b[i]:
|
||||
i -= 1
|
||||
if i == -1:
|
||||
return (a, b, '')
|
||||
else:
|
||||
locale.setlocale(locale.LC_TIME, "en_US.UTF-8")
|
||||
except locale.Error as e:
|
||||
pass
|
||||
return (a[:i+1], b[:i+1], a[i+1:])
|
||||
|
||||
datestart_string = formats.date_format(event.date_start)
|
||||
timestart_string = formats.time_format(event.date_start)
|
||||
if event.date_end:
|
||||
if event.date_end.date() == event.date_start.date():
|
||||
if event.all_day:
|
||||
return event.date_start.strftime(_("le %A %d %B %Y"))
|
||||
return _("le %s") % datestart_string
|
||||
else:
|
||||
return _("le %s de %s à %s") % \
|
||||
(event.date_start.strftime("%A %d %B %Y"),
|
||||
event.date_start.strftime(_("%Hh%M")),
|
||||
event.date_end.strftime(_("%Hh%M")))
|
||||
(datestart_string,
|
||||
timestart_string,
|
||||
formats.time_format(event.date_end))
|
||||
else:
|
||||
tmpl = "%A %d %B %Y"
|
||||
diff_i = len(tmpl)
|
||||
if event.date_end.year != event.date_start.year:
|
||||
diff_i = len(tmpl)
|
||||
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]
|
||||
dateend_string = formats.date_format(event.date_end)
|
||||
timeend_string = formats.time_format(event.date_end)
|
||||
diffstart, diffend, common = factorize_suffix(datestart_string,
|
||||
dateend_string)
|
||||
if event.all_day:
|
||||
return _("du %s au %s %s") % \
|
||||
(event.date_start.strftime(diff),
|
||||
event.date_end.strftime(diff),
|
||||
event.date_end.strftime(common))
|
||||
return _("du %s au %s%s") % \
|
||||
(diffstart, diffend, common)
|
||||
|
||||
else:
|
||||
return _("du %s %s à %s au %s à %s") % \
|
||||
(event.date_start.strftime(diff),
|
||||
event.date_start.strftime(common),
|
||||
event.date_start.strftime("%Hh%M"),
|
||||
event.date_end.strftime(diff),
|
||||
event.date_end.strftime("%Hh%M"))
|
||||
return _("du %s%s à %s au %s à %s") % \
|
||||
(diffstart, common, timestart_string,
|
||||
diffend, formats.time_format(event.date_end))
|
||||
else:
|
||||
if event.all_day:
|
||||
return event.date_start.strftime(_("le %A %d %B %Y"))
|
||||
return _("le %s") % datestart_string
|
||||
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