Added unsubscribe ability
This commit is contained in:
parent
667a470f41
commit
c70e07e5fc
@ -37,6 +37,7 @@ urlpatterns = [
|
||||
url(r'^logout/', main.views.logout, name='logout'),
|
||||
url(r'^media/secure/(?P<path>.*)$', protected_serve, {'document_root': os.path.join(settings.MEDIA_ROOT, 'secure')}, name='secure media'),
|
||||
url(r'^media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT}, name='media'),
|
||||
url(r'^newsletter/unsubscribe', newsletters.views.unsubscribe, name='unsubscribe'),
|
||||
url(r'^newsletter/', newsletters.views.newsletters, name='newsletters'),
|
||||
url(r'^tinymce/', include('tinymce.urls'))
|
||||
]
|
||||
|
@ -19,7 +19,7 @@ class Command(BaseCommand):
|
||||
print('Found %s subscribers' % len(subscribers))
|
||||
for newsletter in newsletters:
|
||||
print('Sending newsletter: "%s"' % newsletter.subject)
|
||||
mail.send_mail(newsletter.subject, strip_tags(newsletter.body), settings.EMAIL_HOST_USER, subscribers, html_message=url_fix_render_to_string('email.html', {'content': newsletter.body}))
|
||||
mail.send_mail(newsletter.subject, strip_tags(newsletter.body), settings.EMAIL_HOST_USER, subscribers, html_message=url_fix_render_to_string('email.html', {'content': newsletter.body, 'unsubscribe': True}))
|
||||
newsletter.sent = True
|
||||
newsletter.save()
|
||||
print('Complete!')
|
||||
|
25
newsletters/templates/unsubscribe.html
Normal file
25
newsletters/templates/unsubscribe.html
Normal file
@ -0,0 +1,25 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block body %}
|
||||
<div class="container-fluid bg-dark-primary">
|
||||
<div class="container py-3">
|
||||
<div class="row">
|
||||
<div class="col-12 col-md-8 mx-auto">
|
||||
<h3 class="text-white">Unsubscribe From Newsletters</h3>
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<div class="input-group pt-2">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-envelope-o"></i></span>
|
||||
</div>
|
||||
<input name="email" class="form-control" type="email" placeholder="Email">
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-danger" type="submit">Unsubscribe</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
@ -1,7 +1,5 @@
|
||||
import json
|
||||
|
||||
from django.db.models import Q
|
||||
from django.shortcuts import render
|
||||
from django.shortcuts import render, redirect
|
||||
from django.utils import timezone
|
||||
|
||||
from .models import Newsletter, Subscriber
|
||||
@ -10,5 +8,14 @@ from .models import Newsletter, Subscriber
|
||||
def newsletters(request):
|
||||
if request.method == 'POST':
|
||||
Subscriber.objects.create(email=request.POST.get('email'))
|
||||
|
||||
newsletters = Newsletter.objects.filter(Q(publish__lte=timezone.now())).order_by('-publish')
|
||||
return render(request, 'newsletters.html', {'newsletters': newsletters})
|
||||
|
||||
|
||||
def unsubscribe(request):
|
||||
if request.method == 'POST':
|
||||
Subscriber.objects.get(email=request.POST.get('email')).delete()
|
||||
return redirect('newsletters')
|
||||
|
||||
return render(request, 'unsubscribe.html')
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<div style="width: calc(100% - 2px); border: solid 1px rgba(0,0,0,0.2)">
|
||||
<div style="width: calc(100% - 1rem); background-color: #00305b; color: #ffffff; padding: 0.5rem">
|
||||
<img src="{{ base_url }}{% static 'main/img/logo.png' %}" width="30" height="30" style="display: inline-block; vertical-align: top" alt="">
|
||||
<img src="{{ base_url }}{% static 'main/img/logo.png' %}" width="30" height="30" style="display: inline-block; vertical-align: top; margin: 1em;" alt="">
|
||||
<div style="display: inline-block; font-size: 1.25rem;">
|
||||
ONTARIO ASSOCIATION OF
|
||||
<br>
|
||||
@ -33,7 +33,7 @@
|
||||
</div>
|
||||
<div style="background-color: #00305b; color: #ffffff; width:100%">
|
||||
<div style="text-align: center">
|
||||
<p style="margin-bottom: 0;">© 2017 Ontario Association of Child Protection Lawyers.</p>
|
||||
<p style="margin-bottom: 0;">© 2017 Ontario Association of Child Protection Lawyers.{% if unsubscribe %} Unsubscribe <a href="{% url 'unsubscribe' %}">here</a>{% endif %}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user