calendar date is updated + correct today

This commit is contained in:
bkfox 2016-07-06 16:43:52 +02:00
parent ff02258d8b
commit 8ff67fe68a
2 changed files with 12 additions and 6 deletions

View File

@ -2,6 +2,7 @@
Define different Section css_class that can be used by views.Sections; Define different Section css_class that can be used by views.Sections;
""" """
import re import re
import datetime # used in calendar
from random import shuffle from random import shuffle
from django.utils import timezone as tz from django.utils import timezone as tz
@ -509,7 +510,7 @@ class Calendar(Section):
import aircox.cms.routes as routes import aircox.cms.routes as routes
context = super().get_context_data(*args, **kwargs) context = super().get_context_data(*args, **kwargs)
date = tz.datetime.today() date = datetime.date.today()
if year: if year:
date = date.replace(year = year) date = date.replace(year = year)
if month: if month:
@ -520,14 +521,15 @@ class Calendar(Section):
context.update({ context.update({
'first_weekday': first, 'first_weekday': first,
'days': [ 'days': [
(day, self.model.reverse( (date + tz.timedelta(days=day), self.model.reverse(
routes.DateRoute, year = date.year, month = date.month, routes.DateRoute, year = date.year, month = date.month,
day = day day = day
) )
) for day in range(1, count+1) ) for day in range(0, count)
], ],
'today': tz.datetime.today(), 'today': datetime.date.today(),
'this_month': date,
'prev_month': date - tz.timedelta(days=10), 'prev_month': date - tz.timedelta(days=10),
'next_month': date + tz.timedelta(days=count), 'next_month': date + tz.timedelta(days=count),
}) })

View File

@ -6,7 +6,7 @@
<a href="{% url exp.name key="render" year=prev_month.year month=prev_month.month %}" <a href="{% url exp.name key="render" year=prev_month.year month=prev_month.month %}"
onclick="return Section.load_event(event);">&lt;</a> onclick="return Section.load_event(event);">&lt;</a>
<h3>{{ today|date:'F Y' }}</h3> <h3>{{ this_month|date:'F Y' }}</h3>
<a href="{% url exp.name key="render" year=next_month.year month=next_month.month %}" <a href="{% url exp.name key="render" year=next_month.year month=next_month.month %}"
onclick="return Section.load_event(event);">&gt;</a> onclick="return Section.load_event(event);">&gt;</a>
@ -19,7 +19,11 @@
<div class="content"> <div class="content">
<div first_weekday="{{ first_weekday }}">&nbsp;</div> <div first_weekday="{{ first_weekday }}">&nbsp;</div>
{% for day, url in days %} {% for day, url in days %}
<a href="{{ url }}" {% if day == today.day %}class="today"{% endif %}>{{ day }}</a> {% if day == today %}
<a href="{{ url }}" weekday="{{ day.weekday }}" class="today">{{ day.day }}</a>
{% else %}
<a href="{{ url }}" weekday="{{ day.weekday }}">{{ day.day }}</a>
{% endif %}
{% endfor %} {% endfor %}
</div> </div>
{% endspaceless %} {% endspaceless %}