]> git.0d.be Git - panikweb.git/commitdiff
add month archives for agenda
authorFrédéric Péters <fpeters@0d.be>
Mon, 6 Apr 2015 10:13:13 +0000 (12:13 +0200)
committerFrédéric Péters <fpeters@0d.be>
Mon, 6 Apr 2015 10:13:13 +0000 (12:13 +0200)
panikweb/urls.py
panikweb/views.py
panikweb_templates/static/css/specifics.css
panikweb_templates/templates/agenda.html

index 8885b1ce69f86759739c9ed23e1ca698598c13ce..1008afed23ec07d359e345fb7147861b78844d32 100644 (file)
@@ -22,6 +22,8 @@ urlpatterns = patterns('',
     url(r'^sons/archives/$', 'panikweb.search.listenArchives', name='listenArchives'),
     url(r'^actus/$', 'panikweb.views.news', name='news'),
     url(r'^actus/agenda/$', 'panikweb.views.agenda', name='agenda'),
+    url(r'^actus/agenda/(?P<year>[0-9]{4})/(?P<month>[0-9]+)/$',
+            'panikweb.views.agenda_by_month', name='agenda_by_month'),
     url(r'^actus/agenda$', RedirectView.as_view(pattern_name='agenda')),
     url(r'^actus/archives/$', 'panikweb.search.newsArchives', name='newsArchives'),
     url(r'^actus/(?P<slug>[\w,-]+)$', 'panikweb.views.newsitemview', name='newsitem-view'),
index 26339866477e3e438202a8461a96a78e6a9e4e7e..2131cc71140534f060eb952e099fae3b4c07325b 100644 (file)
@@ -13,6 +13,7 @@ from django.views.generic.base import TemplateView
 from django.views.generic.detail import DetailView
 from django.views.decorators.csrf import csrf_exempt
 from django.views.generic.dates import _date_from_string
+from django.views.generic.dates import MonthArchiveView
 
 from django.core.paginator import Paginator
 
@@ -476,11 +477,29 @@ class Agenda(TemplateView):
         context['agenda'] = NewsItem.objects.filter(
                 event_date__gte=date.today()).order_by('date')[:20]
         context['news'] = NewsItem.objects.all().order_by('-date')
+        context['previous_month'] = datetime.today().replace(day=1) - timedelta(days=2)
         return context
 
 agenda = Agenda.as_view()
 
 
+class AgendaByMonth(MonthArchiveView):
+    template_name = 'agenda.html'
+    queryset = NewsItem.objects.filter(event_date__isnull=False)
+    allow_future = True
+    date_field = 'event_date'
+    month_format = '%m'
+
+    def get_context_data(self, **kwargs):
+        context = super(AgendaByMonth, self).get_context_data(**kwargs)
+        context['sectionName'] = "News"
+        context['agenda'] = context['object_list']
+        context['news'] = NewsItem.objects.all().order_by('-date')
+        return context
+
+agenda_by_month = AgendaByMonth.as_view()
+
+
 class Emissions(TemplateView):
     template_name = 'emissions.html'
 
index 66eeed5fa748f246c886ffedaa1afbb1e8a236ee..441f9e2de12d9be5324d60ecc7390d84cee09519 100644 (file)
@@ -1559,3 +1559,7 @@ div.episode-detail div.sound div.download-links {
 div.extra-soundfiles div.download-links {
        background: white;
 }
+
+div.previous-and-next-months {
+       margin-top: 1em;
+}
index a445731f8fb560ae2ce3bb4446c6e7851173acf2..4e0aa916e86742ea0e3859dac723a12fa84f0db8 100644 (file)
 
 <div class="detail marged news cf">
        <div class="wrapper navigation">
+{% if month %}
+<h2>{{month|date:"E Y"}}</h2>
+{% else %}
 <p class="intro leftPart">
 Tous les jours, il s'en passe des choses que Panik fomente, fait résonner et
 vous fait savoir.
 </p>
+{% endif %}
 
                <div class="leftPart">
             <div class="news">
@@ -28,6 +32,21 @@ vous fait savoir.
                {% if not agenda %}
                        <div class="big error center">Misère, c'est l'hiver ?!</div>
                {% endif %}
+
+    <div class="previous-and-next-months">
+<h4>
+    {% if previous_month %}
+        <a href="{% url 'agenda_by_month' year=previous_month.year month=previous_month.month %}"
+           >&lt; {{previous_month|date:'E Y'}}</a>
+    {% endif %}
+    {% if previous_month and next_month %}—{% endif %}
+    {% if next_month %}
+        <a href="{% url 'agenda_by_month' year=next_month.year month=next_month.month %}"
+           >{{next_month|date:'E Y'}} &gt;</a>
+    {% endif %}
+</h4>
+    </div>
+
             </div>
                </div>
                <div class="rightPart">