2017-09-04 01:16:49 -04:00
|
|
|
import json
|
2017-08-18 21:25:17 -04:00
|
|
|
|
2017-09-15 10:48:42 -04:00
|
|
|
from django.db.models import Q
|
2017-09-04 01:16:49 -04:00
|
|
|
from django.shortcuts import render, HttpResponse
|
2017-09-15 10:48:42 -04:00
|
|
|
from django.utils import timezone
|
2017-09-04 01:16:49 -04:00
|
|
|
|
|
|
|
from .models import Newsletter, Subscriber
|
2017-09-03 17:02:57 -04:00
|
|
|
|
|
|
|
|
|
|
|
def newsletters(request):
|
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})
|
2017-09-04 01:16:49 -04:00
|
|
|
|
|
|
|
|
|
|
|
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')
|