summaryrefslogtreecommitdiff
path: root/app/lttr/views.py
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2019-02-11 13:51:21 -0600
committerluxagraf <sng@luxagraf.net>2019-02-11 13:51:21 -0600
commitee2803d2f85888ce42fd6371ef606f4a9c6fd88b (patch)
treed115dcdc3e4cf5640c0cd5f216bafe880f3c5574 /app/lttr/views.py
parente7d938a42424fd31d36d7cfdd1533d87f236b05a (diff)
added newsletter
Diffstat (limited to 'app/lttr/views.py')
-rw-r--r--app/lttr/views.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/app/lttr/views.py b/app/lttr/views.py
new file mode 100644
index 0000000..786bc5c
--- /dev/null
+++ b/app/lttr/views.py
@@ -0,0 +1,54 @@
+from django.views.generic import ListView, CreateView
+from django.views.generic.detail import DetailView
+from django.views.generic.dates import YearArchiveView, MonthArchiveView
+from django.contrib.syndication.views import Feed
+from django.db.models import Q
+from django.conf import settings
+
+from utils.views import PaginatedListView
+
+from .models import NewsletterMailing, Subscriber, Newsletter
+from .forms import SubscribeRequestForm
+
+
+class NewsletterMailingDetail(DetailView):
+ model = NewsletterMailing
+ slug_field = "slug"
+
+ def get_queryset(self):
+ queryset = super(NewsletterMailingDetail, self).get_queryset()
+ return queryset.select_related('location').prefetch_related('field_notes').prefetch_related('books')
+
+ def get_object(self, queryset=None):
+ obj = super(NewsletterMailingDetail, self).get_object(queryset=queryset)
+ self.location = obj.location
+ return obj
+
+ def get_context_data(self, **kwargs):
+ context = super(NewsletterMailingDetail, self).get_context_data(**kwargs)
+ return context
+
+
+class NewsletterListView(CreateView):
+ model = Subscriber
+ form_class = SubscribeRequestForm
+ """
+ Return a subscribe form and list of Newsletter posts in reverse chronological order
+ """
+
+ def get_form_kwargs(self):
+ kwargs = super(NewsletterListView, self).get_form_kwargs()
+ kwargs['newsletter'] = Newsletter.objects.get(title="Friends of a Long Year")
+ return kwargs
+
+ def get_context_data(self, **kwargs):
+ context = super(NewsletterListView, self).get_context_data(**kwargs)
+ context['mailings'] = NewsletterMailing.objects.filter(status=1)
+ return context
+
+ def form_valid(self, form, **kwargs):
+ form.instance.user = settings.AUTH_USER_MODEL.objects.get_or_create(email=form.instance.email)
+ self.object = form.save()
+ return super(NewsletterListView, self).form_valid(form)
+
+ #super(NewsletterListView, self).form_valid()