Commit 33ba9c96 authored by Luko van der Maas's avatar Luko van der Maas Committed by Sébastiaan Versteeg

Merge branch 'fix/add-send-date' into 'master'

Fix add send date to admin and fix cronjob

See merge request !1282

(cherry picked from commit b33e9c0f)

38b9cb5b Fix add send date to admin
2209a1ec Set newsletter sent to True on management command
38baaca8 Fix timezone aware and add services code
parent 104213bb
......@@ -31,7 +31,7 @@ class NewsletterAdmin(TranslatedModelAdmin):
fieldsets = (
(None, {
'fields': (
'title', 'date', 'description'
'title', 'date', 'send_date', 'description'
)
}),
)
......
......@@ -3,7 +3,8 @@
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 django.utils.timezone import make_aware
from members.models import Member
from newsletters import services
......@@ -18,7 +19,15 @@ def send_newsletter(newsletter):
"""
partners = Partner.objects.filter(is_main_partner=True)
main_partner = partners[0] if len(partners) > 0 else None
events = services.get_agenda(newsletter.date) if newsletter.date else None
events = None
if newsletter.date:
datetime = make_aware(timezone.datetime(
year=newsletter.date.year,
month=newsletter.date.month,
day=newsletter.date.day,
)) if newsletter.date else None
events = services.get_agenda(datetime)
from_email = settings.NEWSLETTER_FROM_ADDRESS
html_template = get_template('newsletters/email.html')
......
from django.core.management.base import BaseCommand
from django.utils import timezone
from newsletters import emails
from newsletters import services
from newsletters.models import Newsletter
......@@ -13,4 +13,4 @@ class Command(BaseCommand):
sent=False
)
for n in newsletters:
emails.send_newsletter(n)
services.send_newsletter(n)
......@@ -5,6 +5,7 @@ from django.template.loader import get_template
from django.utils import translation, timezone
from events.models import Event
from newsletters import emails
from partners.models import Partner
......@@ -60,3 +61,9 @@ def get_agenda(start_date):
more_events = Event.objects.filter(end__gte=end_date).order_by('start')
return [*base_events, *more_events][:10]
return base_events
def send_newsletter(newsletter):
emails.send_newsletter(newsletter)
newsletter.sent = True
newsletter.save()
......@@ -9,7 +9,7 @@ from django.shortcuts import get_object_or_404, redirect, render
from django.utils.translation import activate, get_language_info
from sendfile import sendfile
from newsletters import emails, services
from newsletters import services
from newsletters.models import Newsletter
from partners.models import Partner
......@@ -95,9 +95,7 @@ def admin_send(request, pk):
return redirect(newsletter)
if request.POST:
emails.send_newsletter(newsletter)
newsletter.sent = True
newsletter.save()
services.send_newsletter(newsletter)
return redirect('admin:newsletters_newsletter_changelist')
else:
......
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