Commit 2cec8070 authored by Simon Daron's avatar Simon Daron

Use templatetag for week view

parent 38b5d7b2
......@@ -5,6 +5,10 @@ import uuid
from django import template
from django.db.models.query import QuerySet
from django.utils import simplejson
from datetime import datetime, timedelta
from django.views.generic.dates import _date_from_string
from emissions.utils import period_program
register = template.Library()
......@@ -43,6 +47,25 @@ def player():
def metanav():
return {}
@register.inclusion_tag('includes/week.html', takes_context=True)
def weekview(context, year=None, week=None, fragment= None):
year = year if year else str(datetime.today().year)
week = week if week else str(datetime.today().isocalendar()[1])
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)})
return {
'fragment': fragment,
'days': days,
'week': week,
'year': year,
}
@register.inclusion_tag('news/inline.html', takes_context=False)
def news_inline(content=None, klass=None, logo=None):
return {
......
......@@ -34,16 +34,8 @@ class ProgramWeekView(TemplateView):
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
context['week'] = week
context['year'] = year
return context
week = ProgramWeekView.as_view()
......
......@@ -57,36 +57,8 @@
<div class="program padded">
<div class="wrapper">
<h2>Cette semaine sur Panik</h2>
<div class="program tabs" data-tab-about="#ProgramContent">
<nav class="">
<ul class="days custom distributed">
{% for day in days %}
<li class=""><button data-tab="#Program-tabs-{{ day.datetime|date:"w" }}">{{ day.datetime|date:"D d" }}</button></li>
{% endfor %}
</ul>
</nav>
</div>
<div id="ProgramContent" class="program" >
{% for day in days %}
<div data-tabbed="true" class="content padded" id="Program-tabs-{{ day.datetime|date:"w" }}">
<ul class="custom emission-list list">
{% if day.schedules %}
{% for schedule in day.schedules %}
<li>
<div class="date dateBloc">
<div class="time">{{ schedule.datetime|date:"H:i" }}</div>
</div>
<div class="schedule">{% include "emissions/inline.html" with emission=schedule.emission %}</div>
</li>
{% endfor %}
{% else %}
<li>Non stop</li>
{% endif %}
</ul>
</div>
{% endfor %}
</div>
</div>
{% weekview %}
</div>
</div>
{% endblock %}
......
......@@ -14,10 +14,12 @@
<span class="icon-bullhorn" ></span>
<span class="iconLabel">News</span>
</a></li>
<!--
<li><a href="{% url 'program' %}">
<span class="icon-calendar" ></span>
<span class="iconLabel">Program</span>
</a></li>
-->
<li><a href="{% url 'grid' %}">
<span class="icon-th-large" ></span>
<span class="iconLabel">Grid</span>
......
{% if not fragment or fragment = "nav" %}
<div class="program tabs" data-tab-about="#weekProgramContent-{{ week|slugify }}">
<nav class="">
<ul class="days custom distributed">
{% for day in days %}
<li class=""><button data-tab="#Program-week-{{ day.datetime|slugify }}">{{ day.datetime|date:"D d" }}</button></li>
{% endfor %}
</ul>
</nav>
</div>
{% endif %}
{% if not fragment or fragment = "program" %}
<div id="weekProgramContent-{{ week|slugify }}" class="program wrapper">
{% for day in days %}
<div data-tabbed="true" class="content padded" id="Program-week-{{ day.datetime|slugify }}">
<ul class="custom emission-list list">
{% if day.cells %}
{% for cell in day.cells %}
<li>
<strong>{{ cell.datetime|date:"H:i" }}</strong>
{% if cell.episode %}
<a href="{% url 'episode-view' emission_slug=cell.episode.emission.slug slug=cell.episode.slug %}">
{{ cell.episode.emission.title }} - {{ cell.episode.title }}
</a>
{% elif cell.emission %}
<a href="{% url 'emission-view' slug=cell.emission.slug %}">
{{ cell.emission.title }}
</a>
{% endif %}
</li>
{% endfor %}
{% else %}
<li><div class="info">Non stop only!</div></li>
{% endif %}
</ul>
</div>
{% endfor %}
</div>
{% endif %}
<a href="{% url 'news-view' slug=result.object.slug %}">{{ result.object.title }}</a>
{% extends "base.html" %}
{% load paniktags %}
{% block bodyID %}Program{% endblock %}
{% block title %}Programme{% endblock %}
{% block nav %}
<div class="program">
<nav class="center">
<ul class="custom distributed">
<li>
<a
href="{% url 'program_week' year=year week=week|add:"-1" %}"
class="icon-chevron-sign-left"
></a>
</li>
<li>Semaine {{ week }}</li>
<li>
<a
href="{% url 'program_week' year=year week=week|add:"1" %}"
class="icon-chevron-sign-right"
></a>
</li>
</ul>
</nav>
{% weekview year=year week=week fragment="nav" %}
</div>
{% endblock %}
{% 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 %}
{% weekview year=year week=week fragment="program" %}
{% 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