1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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()
|