Commit fe207bb8 authored by fred's avatar fred
Browse files

customise newsletter/add to use a template

parent f8c545b8
<h1>Cette semaine du côté du 105.4</h1>
{% if soundfiles.exists %}
<h2>Nouveaux podcasts</h2>
{% for soundfile in soundfiles %}
<li><a href="{{ soundfile.episode.get_absolute_url }}">{{ soundfile.episode.emission.title }} - {{ soundfile.episode.title }}</a></li>
{% endfor %}
{% endif %}
Cette semaine sur le 105.4, en modulation de fréquence analogique, il y a
(entre autres) :
{% for diffusion in diffusions %}
<h2>{{ diffusion.datetime|date:"D d M Y H:i"|lower }} {{ diffusion.episode.emission.title }}</h2>
<p><strong>{{ diffusion.episode.title }}</strong></p>
<p>{{ diffusion.episode.text|safe|striptags|truncatewords:50 }}</p>
{% endfor %}
À bientôt !
(newsletter du {{ date }})
......@@ -31,6 +31,7 @@ urlpatterns = patterns('',
decorated_includes(login_required, include(emissions_urlpatterns))),
url(r'^newsletters/add$', 'panikdb.views.newsletter_create', name='newsletter-create'),
decorated_includes(login_required, include(newsletter_urlpatterns))),
import datetime
from django.contrib.auth.decorators import login_required
from django.template import loader, Context
from django.views.generic.base import TemplateView
from django.views.generic.list import ListView
from emissions.models import Emission, NewsCategory, NewsItem
from emissions.models import Emission, NewsCategory, NewsItem, SoundFile, Diffusion
from emissions.utils import period_program
import emissions.views
import newsletter.views
class Home(TemplateView):
template_name = 'home.html'
......@@ -38,3 +43,39 @@ class NewsListView(ListView):
return context
news = login_required(NewsListView.as_view())
class NewsletterCreateView(newsletter.views.NewsletterCreateView):
def get_initial(self):
initial = super(NewsletterCreateView, self).get_initial()
newsletter_body = loader.get_template('newsletter/body.html')
context = Context()
date =
if date.weekday() > 0:
date = date + datetime.timedelta(days=7-date.weekday())
date = datetime.datetime(*date.timetuple()[:3])
context['date'] = date
context['soundfiles'] = SoundFile.objects.filter(
podcastable=True, fragment=False).select_related().filter(
context['diffusions'] = list(Diffusion.objects.select_related().filter(
# remove rebroadcasts made during the same week
seen_episodes = {}
for diff in context['diffusions'][:]:
if in seen_episodes:
seen_episodes[] = True
initial['text'] = newsletter_body.render(context)
return initial
newsletter_create = NewsletterCreateView.as_view()
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