Skip to content
This repository has been archived by the owner on Sep 3, 2019. It is now read-only.

Commit

Permalink
Fixed up the year tempalte/view.
Browse files Browse the repository at this point in the history
  • Loading branch information
myles committed Mar 5, 2010
1 parent 4cf57ac commit ad7bfe3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
4 changes: 2 additions & 2 deletions events/templates/events/year.html
Expand Up @@ -9,8 +9,8 @@ <h2>{{ year }}</h2>
{% block content %}
<ul class="link_list">
{% for month in months %}
<li><a href="{% url events_month month|date:"Y" month|date:"b" %}">
{{ month|date:"F" }}
<li><a href="{% url events_month month.month|date:"Y" month.month|date:"b" %}" title="{{ month.count }} Events">
{{ month.month|date:"F" }}
</a></li>
{% endfor %}
</ul>
Expand Down
44 changes: 34 additions & 10 deletions events/views.py
Expand Up @@ -8,8 +8,12 @@
from events.models import Event
from events.forms import CalendarYearMonthForm

def events_month(request, year=str(datetime.date.today().year),
month=datetime.date.today().strftime('%b').lower()):
def events_month(request, year=None, month=None):
if not year:
year = str(datetime.date.today().year)

if not month:
month = datetime.date.today().strftime('%b').lower()

if request.GET:
new_data = request.GET.copy()
Expand Down Expand Up @@ -105,8 +109,12 @@ def events_month(request, year=str(datetime.date.today().year),

return render_to_response('events/month.html', payload, context_instance=RequestContext(request))

def events_week(request, year=str(datetime.date.today().year),
week=str(datetime.date.today().isocalendar()[1])):
def events_week(request, year=None, week=None):
if not year:
year = str(datetime.date.today().year)

if not week:
week = str(datetime.date.today().isocalendar()[1])

try:
date = datetime.date(*time.strptime(year + '-0-' + week, '%Y-%w-%U')[:3])
Expand Down Expand Up @@ -167,25 +175,41 @@ def events_week(request, year=str(datetime.date.today().year),

return render_to_response('events/week.html', context_payload, context_instance=RequestContext(request))

def events_year(request, year=str(datetime.date.today().year)):
def events_year(request, year=None):
if not year:
year = str(datetime.date.today().year)

prev_year = year - 1
next_year = year + 1

events = Event.objects.filter(start_date__year=year)

months = []

for i in range(1, 13):
months += [datetime.date(int(year), i, 1),]
month = datetime.date(int(year), i, 1)
events_count = Event.objects.filter(start_date__month=i, start_date__year=year).count()
months += [{'month': month, 'count': events_count},]

context_payload = {
'events': events,
'months': months,
'year': year
'year': year,
'next_year': next_year,
'prev_year': prev_year
}

return render_to_response('events/year.html', context_payload, context_instance=RequestContext(request))

def events_day(request, year=str(datetime.date.today().year),
month=datetime.date.today().strftime('%b').lower(),
day=str(datetime.date.today().day)):
def events_day(request, year=None, month=None, day=None):
if not year:
year = str(datetime.date.today().year)

if not month:
month = datetime.date.today().strftime('%b').lower()

if not day:
day = str(datetime.date.today().day)

try:
date = datetime.date(*time.strptime(year+month+day, '%Y%b%d')[:3])
Expand Down

0 comments on commit ad7bfe3

Please sign in to comment.