Commit d606f7fa authored by fred's avatar fred
Browse files

performance: split week template in navigation and main view

parent b0f18775
......@@ -110,11 +110,10 @@ def metanav(context, active=None):
'sectionName': context.get('sectionName')
}
@register.inclusion_tag('includes/week.html', takes_context=True)
def weekview(context, year=None, week=None, weekday=None, fragment=None):
@register.inclusion_tag('includes/week.html')
def weekview(year=None, week=None):
year = year if year else datetime.today().isocalendar()[0]
week = week if week else datetime.today().isocalendar()[1]
weekday = weekday if weekday else datetime.today().weekday()
date = utils.tofirstdayinisoweek(year, week)
date = datetime(*date.timetuple()[:3])
......@@ -125,6 +124,25 @@ def weekview(context, year=None, week=None, weekday=None, fragment=None):
days.append({'cells': [x for x in program if x.is_on_weekday(day+1)],
'datetime': date+timedelta(days=day)})
return {
'days': days,
'week': week,
'year': year,
}
@register.inclusion_tag('includes/week-nav.html')
def weeknav(year=None, week=None, weekday=None):
year = year if year else datetime.today().isocalendar()[0]
week = week if week else datetime.today().isocalendar()[1]
weekday = weekday if weekday else datetime.today().weekday()
date = utils.tofirstdayinisoweek(year, week)
date = datetime(*date.timetuple()[:3])
days = []
for day in range(7):
days.append({'datetime': date+timedelta(days=day)})
previous_week = date - timedelta(days=7)
previous_week_year, previous_week_no = previous_week.isocalendar()[:2]
......@@ -132,7 +150,6 @@ def weekview(context, year=None, week=None, weekday=None, fragment=None):
next_week_year, next_week_no = next_week.isocalendar()[:2]
return {
'fragment': fragment,
'days': days,
'weekday': weekday,
'week': week,
......@@ -143,6 +160,7 @@ def weekview(context, year=None, week=None, weekday=None, fragment=None):
'next_week_no': next_week_no,
}
@register.inclusion_tag('news/inline.html', takes_context=True)
def news_inline(context, klass=None, logo=None):
return {
......
......@@ -15,6 +15,8 @@
<div class="sided wrapper padded">
<div class="leftPart">
<h2><a href="{% url 'program' %}">Cette semaine sur Panik</a></h2>
{% weeknav %}
{% weekview %}
<form method="post" action="{% url 'newsletter-subscribe' %}"
......
<div class="program tabs" data-tab-about="#weekProgramContent-{{ week|slugify }}">
<nav class="">
<ul class="days custom distributed">
<li class="week-arrow"><a href="{% url 'program_week' year=previous_week_year week=previous_week_no %}"
class="icon-chevron-sign-left" ></a></li>
{% for day in days %}
<li class=""><button class="{% if day.datetime.weekday = weekday %}active{% endif %}" data-tab="#Program-week-{{ day.datetime|slugify }}">{{ day.datetime|date:"D d" }}</button></li>
{% endfor %}
<li class="week-arrow"><a href="{% url 'program_week' year=next_week_year week=next_week_no %}"
class="icon-chevron-sign-right" ></a></li>
</ul>
</nav>
</div>
{% load paniktags %}
{% if not fragment or fragment = "nav" %}
<div class="program tabs" data-tab-about="#weekProgramContent-{{ week|slugify }}">
<nav class="">
<ul class="days custom distributed">
<li class="week-arrow"><a href="{% url 'program_week' year=previous_week_year week=previous_week_no %}"
class="icon-chevron-sign-left" ></a></li>
{% for day in days %}
<li class=""><button class="{% if day.datetime.weekday = weekday %}active{% endif %}" data-tab="#Program-week-{{ day.datetime|slugify }}">{{ day.datetime|date:"D d" }}</button></li>
{% endfor %}
<li class="week-arrow"><a href="{% url 'program_week' year=next_week_year week=next_week_no %}"
class="icon-chevron-sign-right" ></a></li>
</ul>
</nav>
</div>
{% endif %}
{% if not fragment or fragment = "program" %}
<div id="weekProgramContent-{{ week|slugify }}" class="program">
{% for day in days %}
......@@ -40,4 +24,3 @@
</div>
{% endfor %}
</div>
{% endif %}
......@@ -10,13 +10,13 @@
Du {{week_first_day|date:"l j N"}} au {{week_last_day|date:"l j N"}}
</nav>
</div>
{% weekview year=year week=week fragment="nav" %}
{% weeknav year=year week=week %}
</div>
{% endblock %}
{% block main %}
<div class="wrapper">
<div class="program marged">
{% weekview year=year week=week fragment="program" %}
{% weekview year=year week=week %}
</div>
</div>
{% endblock %}
......@@ -23,12 +23,12 @@
</ul>
</nav>
</div>
{% weekview year=year week=week fragment="nav" %}
{% weeknav year=year week=week %}
{% endblock %}
{% block main %}
<div class="padded">
<div class="wrapper">
{% weekview year=year week=week fragment="program" %}
{% weekview year=year week=week %}
</div>
</div>
{% endblock %}
Supports Markdown
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