Verified Commit ff499fb7 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Populate newsletter agenda using events package

parent 11163857
......@@ -2,8 +2,9 @@
from django.conf import settings
from django.core.mail import EmailMultiAlternatives
from django.template.loader import get_template
from django.utils import translation
from django.utils import translation, timezone
from events.models import Event
from members.models import Member
from partners.models import Partner
......@@ -19,6 +20,13 @@ def send_newsletter(request, newsletter):
"""
partners = Partner.objects.filter(is_main_partner=True)
main_partner = partners[0] if len(partners) > 0 else None
events = None
if newsletter.date:
start_date = newsletter.date
end_date = start_date + timezone.timedelta(weeks=1)
events = Event.objects.filter(
start__gte=start_date, end__lt=end_date).order_by('start')
from_email = settings.NEWSLETTER_FROM_ADDRESS
html_template = get_template('newsletters/email.html')
......@@ -37,11 +45,7 @@ def send_newsletter(request, newsletter):
context = {
'newsletter': newsletter,
'agenda_events': (
newsletter.newslettercontent_set
.filter(newsletteritem=None)
.order_by('newsletterevent__start_datetime')
),
'agenda_events': events,
'main_partner': main_partner,
'lang_code': language[0],
'request': request
......
......@@ -60,7 +60,7 @@
{{ newsletter.description|safe }}
</td>
</tr>
{% if agenda_events %}
<tr>
<td colspan="2" style="{{ item_tr_style }}">
<h2 style="{{ item_h2_style }}">{% trans "agenda"|upper %}</h2>
......@@ -74,7 +74,7 @@
{% for row in agenda_events|rows_distributed:2 %}
<td style="vertical-align: top;">
{% for item in row %}
<li style="font-family: Arial, sans-serif;"><i>{{ item.title }} - {{ item.newsletterevent.start_datetime|date:"d F" }}</i></li>
<li style="font-family: Arial, sans-serif;"><i>{{ item.title }} - {{ item.start|date:"d F" }}</i></li>
{% endfor %}
</td>
{% endfor %}
......@@ -83,7 +83,7 @@
</table>
</td>
</tr>
{% endif %}
{% for item in newsletter.newslettercontent_set.all %}
<tr>
<td colspan="2" style="{{ item_tr_style }}">
......
......@@ -6,7 +6,7 @@
{% trans "agenda"|upper %}:
{% for item in agenda_events %} {{ item.title }} - {{ item.start_datetime|date:"d F" }}
{% for item in agenda_events %} {{ item.title }} - {{ item.start|date:"d F" }}
{% endfor %}
{% for item in newsletter.newslettercontent_set.all %}{{ item.title|upper }}:
......
......@@ -8,8 +8,10 @@ from django.conf import settings
from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.auth.decorators import permission_required
from django.shortcuts import get_object_or_404, redirect, render
from django.utils import timezone
from django.utils.translation import activate, get_language_info
from events.models import Event
from newsletters import emails
from newsletters.models import Newsletter
from partners.models import Partner
......@@ -49,11 +51,17 @@ def preview(request, pk, lang=None):
newsletter = get_object_or_404(Newsletter, pk=pk)
partners = Partner.objects.filter(is_main_partner=True)
main_partner = partners[0] if len(partners) > 0 else None
events = None
if newsletter.date:
start_date = newsletter.date
end_date = start_date + timezone.timedelta(weeks=1)
events = Event.objects.filter(
start__gte=start_date, end__lt=end_date).order_by('start')
return render(request, 'newsletters/email.html', {
'newsletter': newsletter,
'agenda_events': newsletter.newslettercontent_set.filter(
newsletteritem=None).order_by('newsletterevent__start_datetime'),
'agenda_events': events,
'main_partner': main_partner,
'lang_code': lang_code
})
......
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