Files
@ 024ef59428cf
Branch filter:
Location: website/conservancy/contacts/views.py - annotation
024ef59428cf
1.4 KiB
text/x-python
Improve home page video layout
789d0c8c843a 789d0c8c843a 8e6ea8ad71bf 789d0c8c843a 47a30a750ad1 8e6ea8ad71bf 789d0c8c843a b7e2ce2a4d44 789d0c8c843a 8e6ea8ad71bf 789d0c8c843a 789d0c8c843a 789d0c8c843a 495f841d3938 8e6ea8ad71bf 8e6ea8ad71bf 495f841d3938 789d0c8c843a 495f841d3938 495f841d3938 495f841d3938 495f841d3938 495f841d3938 495f841d3938 495f841d3938 495f841d3938 495f841d3938 495f841d3938 495f841d3938 495f841d3938 8e6ea8ad71bf 789d0c8c843a 789d0c8c843a 495f841d3938 8e6ea8ad71bf 8e6ea8ad71bf 789d0c8c843a 789d0c8c843a 8e6ea8ad71bf 789d0c8c843a 789d0c8c843a | import logging
from django.forms import ModelForm
from django.views.decorators.csrf import csrf_exempt
from django.shortcuts import render
from .models import Unsubscription
logger = logging.getLogger(__name__)
class UnsubscribeForm(ModelForm):
class Meta:
model = Unsubscription
fields = ['email', 'mailout']
@csrf_exempt # Submitted directly by Gmail and similar - no CSRF token.
def unsubscribe(request):
"""Endpoint for use with Gmail one-click unsubscribe or similar.
Gmail now requires "List-Unsubscribe" headers for senders over a certain
monthly volume (currently 5000 emails). Add the following headers to your
mailout:
List-Unsubscribe: <https://sfconservancy.org/contacts/unsubscribe/?email=foo@bar.com&mailout=jan2024-news>
List-Unsubscribe-Post: List-Unsubscribe=One-Click
Interfaces like Gmail will then provide a user interface to unsubscribe
which will hit this endpoint.
"""
if request.method == 'POST':
logger.debug('Unsubscribe GET: %s', request.GET)
logger.debug('Unsubscribe POST: %s', request.POST)
form = UnsubscribeForm(request.GET)
if form.is_valid():
form.save()
logger.info('Unsubscribed %s', form.cleaned_data['email'])
return render(request, 'contacts/unsubscribe_success.html')
else:
form = UnsubscribeForm()
return render(request, 'contacts/unsubscribe.html', {'form': form})
|