oacpl/newsletters/views.py

22 lines
679 B
Python
Raw Normal View History

2017-09-15 10:48:42 -04:00
from django.db.models import Q
2018-01-14 17:15:28 -05:00
from django.shortcuts import render, redirect
2017-09-15 10:48:42 -04:00
from django.utils import timezone
from .models import Newsletter, Subscriber
2017-09-03 17:02:57 -04:00
def newsletters(request):
2018-01-14 16:48:55 -05:00
if request.method == 'POST':
Subscriber.objects.create(email=request.POST.get('email'))
2018-01-14 17:15:28 -05:00
2017-09-15 10:48:42 -04:00
newsletters = Newsletter.objects.filter(Q(publish__lte=timezone.now())).order_by('-publish')
2017-09-03 17:02:57 -04:00
return render(request, 'newsletters.html', {'newsletters': newsletters})
2018-01-14 17:15:28 -05:00
def unsubscribe(request):
if request.method == 'POST':
Subscriber.objects.get(email=request.POST.get('email')).delete()
return redirect('newsletters')
return render(request, 'unsubscribe.html')