From 774a6634865a67238837d1edde3a437d0dde8e16 Mon Sep 17 00:00:00 2001 From: lxf Date: Thu, 28 Oct 2021 20:50:06 -0400 Subject: lttr: added a form for people to get postcards --- app/lttr/forms.py | 9 ++++++++- app/lttr/models.py | 12 ++++++++++++ app/lttr/send.py | 6 ++++++ app/lttr/urls.py | 5 +++++ app/lttr/views.py | 19 +++++++++++++++++-- 5 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 app/lttr/send.py (limited to 'app/lttr') diff --git a/app/lttr/forms.py b/app/lttr/forms.py index e3fb272..5718d6e 100644 --- a/app/lttr/forms.py +++ b/app/lttr/forms.py @@ -2,7 +2,7 @@ from django import forms from django.forms.utils import ValidationError from .validators import validate_email_nouser -from .models import Subscriber +from .models import Subscriber, PostcardSubscriber class SubscribeForm(forms.ModelForm): @@ -98,3 +98,10 @@ class UpdateForm(NewsletterForm): user_activation_code = forms.CharField( label=("Activation code"), max_length=40 ) + + +class PostcardForm(forms.ModelForm): + + class Meta: + model = PostcardSubscriber + fields = ['name', 'address'] diff --git a/app/lttr/models.py b/app/lttr/models.py index 653eded..863d4e4 100644 --- a/app/lttr/models.py +++ b/app/lttr/models.py @@ -468,3 +468,15 @@ newsletter = Newsletter.objects.get(pk=3) n = SendShit(newsletter, mailing, 1) n.send_mailings() ''' + + +class PostcardSubscriber(models.Model): + """ A model for grabbing addresses to send postcards """ + date_created = models.DateTimeField(blank=True, auto_now_add=True, editable=False) + date_updated = models.DateTimeField(blank=True, auto_now=True, editable=False) + address = models.TextField() + name = models.CharField(max_length=120) + + def __str__(self): + return self.name + diff --git a/app/lttr/send.py b/app/lttr/send.py new file mode 100644 index 0000000..cd012e2 --- /dev/null +++ b/app/lttr/send.py @@ -0,0 +1,6 @@ +from lttr.models import Newsletter, NewsletterMailing +from lttr.mailer import SendShit +n = Newsletter.objects.get(pk=tk) +m = NewsletterMailing.objects.get(pk=tk) +s = SendShit(n, m) +s.send_mailings() diff --git a/app/lttr/urls.py b/app/lttr/urls.py index abeac11..d790f0f 100644 --- a/app/lttr/urls.py +++ b/app/lttr/urls.py @@ -5,6 +5,11 @@ from . import views app_name = "lttr" urlpatterns = [ + path( + 'postcardsubscribe', + views.PostcardSubscribeView.as_view(), + name='postcard_subscribe' + ), path( '/unsubscribe/', views.UnsubscribeRequestView.as_view(), diff --git a/app/lttr/views.py b/app/lttr/views.py index 3980fd4..c4414b2 100644 --- a/app/lttr/views.py +++ b/app/lttr/views.py @@ -13,8 +13,8 @@ from django.urls import reverse, reverse_lazy from utils.views import PaginatedListView, LuxDetailView from smtplib import SMTPException -from .models import OldNewsletterMailing, Subscriber, Newsletter -from .forms import SubscribeRequestForm, UpdateForm +from .models import OldNewsletterMailing, Subscriber, Newsletter, PostcardSubscriber +from .forms import SubscribeRequestForm, UpdateForm, PostcardForm ACTIONS = ('subscribe', 'unsubscribe', 'update') @@ -104,3 +104,18 @@ class UnsubscribeRequestView(DetailView): context['subscriber'] = self.get_object() context['newsletter'] = self.kwargs['slug'] return context + +class PostcardSubscribeView(CreateView): + """ + Return a subscribe form for iframe embedding + """ + model = PostcardSubscriber + form_class = PostcardForm + + + def get_template_names(self): + return ["lttr/%s_subscribe.html" % self.slug, 'lttr/subscribe.html'] + + def get_success_url(self): + return reverse_lazy('card:subscribed') + -- cgit v1.2.3-70-g09d2