From 67bf96aaaed9d19e5b1713cc5d26c4dc7595da92 Mon Sep 17 00:00:00 2001 From: Seb Date: Thu, 7 May 2020 13:54:25 +1000 Subject: [PATCH] Unsubscribe url + view --- birdsong/templates/unsubscribe.html | 8 ++++++++ birdsong/urls.py | 9 ++++++++ birdsong/views/actions.py | 1 + birdsong/views/unsubscribe.py | 32 +++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 birdsong/templates/unsubscribe.html create mode 100644 birdsong/urls.py create mode 100644 birdsong/views/unsubscribe.py diff --git a/birdsong/templates/unsubscribe.html b/birdsong/templates/unsubscribe.html new file mode 100644 index 0000000..b3e8dba --- /dev/null +++ b/birdsong/templates/unsubscribe.html @@ -0,0 +1,8 @@ + + +
+

The email '{{ contact.email }}' has been unsubscribed from {{ site.site_name }}'s mailing list.


+

If this was a mistake head back to the site to resubscribe.

+
+ + \ No newline at end of file diff --git a/birdsong/urls.py b/birdsong/urls.py new file mode 100644 index 0000000..0b4ae60 --- /dev/null +++ b/birdsong/urls.py @@ -0,0 +1,9 @@ +from django.urls import path +from .views import unsubscribe + + +app_name = 'birdsong' + +urlpatterns = [ + path('unsubscribe//', unsubscribe.unsubscribe_user, name='unsubscribe') +] diff --git a/birdsong/views/actions.py b/birdsong/views/actions.py index e0d8ac0..a9f4580 100644 --- a/birdsong/views/actions.py +++ b/birdsong/views/actions.py @@ -5,6 +5,7 @@ from wagtail.contrib.modeladmin.helpers.url import AdminURLHelper from birdsong.models import Receipt, Contact + def redirect_helper(campaign): url_helper = AdminURLHelper(type(campaign)) campaign_list_url = url_helper.get_action_url('index') diff --git a/birdsong/views/unsubscribe.py b/birdsong/views/unsubscribe.py new file mode 100644 index 0000000..ff20ab1 --- /dev/null +++ b/birdsong/views/unsubscribe.py @@ -0,0 +1,32 @@ +from django.conf import settings +from django.shortcuts import get_object_or_404, render +from wagtail.core.models import Site + +from birdsong.models import Contact + + +def unsubscribe_user(request, user_id): + contact = get_object_or_404(Contact, id=user_id) + # contact.delete() + + site = Site.find_for_request(request) + + template = getattr( + settings, + 'BIRDSONG_UNSUBSCRIBE_TEMPLATE', + 'unsubscribe.html' + ) + + return render( + request, template, context={ + 'site': site, + 'contact': contact, + } + ) + + + + + + +