oacpl/newsletters/views.py

19 lines
573 B
Python
Raw Normal View History

import json
2017-08-18 21:25:17 -04:00
from django.shortcuts import render, HttpResponse
from .models import Newsletter, Subscriber
2017-09-03 17:02:57 -04:00
def newsletters(request):
newsletters = Newsletter.objects.filter(sent=True).order_by('-publish')
2017-09-03 17:02:57 -04:00
return render(request, 'newsletters.html', {'newsletters': newsletters})
def subscribe(request):
try:
Subscriber.objects.create(email=request.POST.get('email'))
return HttpResponse(json.dumps({'success': True}), content_type='json')
except Exception:
return HttpResponse(json.dumps({'success': False}), content_type='json')