Verified Commit 40cb0685 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg Committed by Sébastiaan Versteeg
Browse files

Change newsletter automatic agenda range to 2 weeks instead of 1. And fill until 10 at minimum

parent 2f0ce2a8
"""The emails defined by the newsletters package"""
from django.conf import settings
from django.core.mail import EmailMultiAlternatives
from django.template.loader import get_template
from django.utils import translation, timezone
from django.utils import translation
from events.models import Event
from members.models import Member
from partners.models import Partner
from newsletters import services
from partners.models import Partner
def send_newsletter(newsletter):
......@@ -19,13 +18,7 @@ def send_newsletter(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')
events = services.get_agenda(newsletter.date) if newsletter.date else None
from_email = settings.NEWSLETTER_FROM_ADDRESS
html_template = get_template('newsletters/email.html')
......
......@@ -2,8 +2,9 @@ import os
from django.conf import settings
from django.template.loader import get_template
from django.utils import translation
from django.utils import translation, timezone
from events.models import Event
from partners.models import Partner
......@@ -49,3 +50,13 @@ def save_to_disk(newsletter, request):
html_message = html_template.render(context)
write_to_file(newsletter.pk, language[0], html_message)
def get_agenda(start_date):
end_date = start_date + timezone.timedelta(weeks=2)
base_events = Event.objects.filter(
start__gte=start_date, end__lt=end_date).order_by('start')
if base_events.count() < 10:
more_events = Event.objects.filter(end__gte=end_date).order_by('start')
return [*base_events, *more_events][:10]
return base_events
"""Views provided by the newsletters package"""
from datetime import datetime, timedelta, date
import os
from datetime import datetime, timedelta, date
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 sendfile import sendfile
from events.models import Event
from newsletters import emails
from newsletters import emails, services
from newsletters.models import Newsletter
from partners.models import Partner
from sendfile import sendfile
def preview(request, pk, lang=None):
"""
......@@ -51,13 +46,7 @@ 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')
events = services.get_agenda(newsletter.date) if newsletter.date else None
return render(request, 'newsletters/email.html', {
'newsletter': newsletter,
......
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