Commit f66d8e64 authored by fred's avatar fred
Browse files

add sample week view

parent 5861e6bb
...@@ -11,6 +11,7 @@ urlpatterns = patterns('', ...@@ -11,6 +11,7 @@ urlpatterns = patterns('',
url(r'^$', 'panikweb.views.home', name='home'), url(r'^$', 'panikweb.views.home', name='home'),
url(r'^onair.json$', 'panikweb.views.onair', name='onair'), url(r'^onair.json$', 'panikweb.views.onair', name='onair'),
url(r'^program$', 'panikweb.views.program', name='program'), url(r'^program$', 'panikweb.views.program', name='program'),
url(r'^(?P<year>\d{4})/(?P<week>\d+)/$', 'panikweb.views.week', name='program_week'),
url(r'^grid$', 'panikweb.views.grid', name='grid'), url(r'^grid$', 'panikweb.views.grid', name='grid'),
url(r'^emissions/$', 'panikweb.views.emissions', name='emissions'), url(r'^emissions/$', 'panikweb.views.emissions', name='emissions'),
url(r'^emissions/', include('emissions.urls')), url(r'^emissions/', include('emissions.urls')),
......
...@@ -4,13 +4,14 @@ import math ...@@ -4,13 +4,14 @@ import math
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from django.views.generic.dates import _date_from_string
from jsonresponse import to_json from jsonresponse import to_json
from emissions.models import Category, Emission, Episode, Diffusion, SoundFile, \ from emissions.models import Category, Emission, Episode, Diffusion, SoundFile, \
Schedule, Nonstop, NewsItem, NewsCategory Schedule, Nonstop, NewsItem, NewsCategory
from emissions.utils import whatsonair from emissions.utils import whatsonair, period_program
class ProgramView(TemplateView): class ProgramView(TemplateView):
template_name = 'program.html' template_name = 'program.html'
...@@ -27,6 +28,26 @@ class ProgramView(TemplateView): ...@@ -27,6 +28,26 @@ class ProgramView(TemplateView):
program = ProgramView.as_view() program = ProgramView.as_view()
class ProgramWeekView(TemplateView):
template_name = 'week.html'
def get_context_data(self, year, week, **kwargs):
context = super(ProgramWeekView, self).get_context_data(**kwargs)
date = _date_from_string(year, '%Y', '1', '%w', week, '%W')
date = datetime(*date.timetuple()[:3])
program = period_program(date, date+timedelta(days=7))
days = []
for day in range(7):
days.append({'cells': [x for x in program if x.is_on_weekday(day+1)],
'datetime': date+timedelta(days=day)})
context['days'] = days
return context
week = ProgramWeekView.as_view()
class TimeCell: class TimeCell:
nonstop = None nonstop = None
w = 1 w = 1
......
{% block main %}
{% for day in days %}
<h2>{{ day.datetime|date:"D Y-m-d" }}</h2>
<ul>
{% for cell in day.cells %}
<li>{{ cell.datetime|date:"H:i" }} -
{% if cell.episode %}
{{ cell.episode.emission.title }} - {{ cell.episode.title }}
{% elif cell.emission %}
{{ cell.emission.title }}
{% endif %}
</li>
{% endfor %}
</ul>
{% endfor %}
{% endblock %}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment