Commit fe207bb8 authored by fred's avatar fred

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>
<ul>
{% for soundfile in soundfiles %}
<li><a href="{{ soundfile.episode.get_absolute_url }}">{{ soundfile.episode.emission.title }} - {{ soundfile.episode.title }}</a></li>
</ul>
{% endfor %}
{% endif %}
<hr/>
<p>
Cette semaine sur le 105.4, en modulation de fréquence analogique, il y a
(entre autres) :
</p>
{% 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 %}
<hr/>
À bientôt !
(newsletter du {{ date }})
......@@ -31,6 +31,7 @@ urlpatterns = patterns('',
url(r'^emissions/',
decorated_includes(login_required, include(emissions_urlpatterns))),
url(r'^newsletters/add$', 'panikdb.views.newsletter_create', name='newsletter-create'),
url(r'^newsletters/',
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 = datetime.datetime.today()
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(
creation_timestamp__gte=date-datetime.timedelta(days=7))
context['diffusions'] = list(Diffusion.objects.select_related().filter(
datetime__gte=date,
datetime__lte=date+datetime.timedelta(days=7)).order_by('datetime'))
# remove rebroadcasts made during the same week
seen_episodes = {}
for diff in context['diffusions'][:]:
if diff.episode.id in seen_episodes:
context['diffusions'].remove(diff)
seen_episodes[diff.episode.id] = 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