| |
---|
| | import csv |
---|
| | import email.utils |
---|
| | import logging |
---|
| | |
---|
| | from allauth.account.models import EmailAddress |
---|
| | from django.http import HttpResponse, HttpResponseNotAllowed, Http404 |
---|
| | |
---|
| | from django.contrib import messages |
---|
| | from django.contrib.auth.decorators import login_required |
---|
| | from django.core.urlresolvers import reverse |
---|
| | from django.core.validators import validate_email |
---|
| |
---|
| | data = {'list': self.mailing_list, |
---|
| | 'userSubscribed': False, |
---|
| | 'subscribed_address': None} |
---|
| | if request.user.is_authenticated(): |
---|
| | user_emails = [request.user.email] + request.user.other_emails |
---|
| | user_emails = EmailAddress.objects.filter( |
---|
| | user=request.user, verified=True).order_by( |
---|
| | "email").values_list("email", flat=True) |
---|
| | for address in user_emails: |
---|
| | try: |
---|
| | self.mailing_list.get_member(address) |
---|
| | except ValueError: |
---|
| |
---|
| | |
---|
| | @method_decorator(login_required) |
---|
| | def post(self, request, list_id): |
---|
| | try: |
---|
| | user_emails = [request.user.email] + request.user.other_emails |
---|
| | user_emails = EmailAddress.objects.filter( |
---|
| | user=request.user, verified=True).order_by( |
---|
| | "email").values_list("email", flat=True) |
---|
| | form = ListSubscribe(user_emails, request.POST) |
---|
| | # Find the currently subscribed email |
---|
| | old_email = None |
---|
| | for address in user_emails: |
---|
| |
---|
| | Subscribes an email address to a mailing list via POST and |
---|
| | redirects to the `list_summary` view. |
---|
| | """ |
---|
| | try: |
---|
| | user_addresses = [request.user.email] + request.user.other_emails |
---|
| | form = ListSubscribe(user_addresses, request.POST) |
---|
| | user_emails = EmailAddress.objects.filter( |
---|
| | user=request.user, verified=True).order_by( |
---|
| | "email").values_list("email", flat=True) |
---|
| | form = ListSubscribe(user_emails, request.POST) |
---|
| | if form.is_valid(): |
---|
| | email = request.POST.get('email') |
---|
| | response = self.mailing_list.subscribe( |
---|
| | email, pre_verified=True, pre_confirmed=True) |
---|
| |
---|
| | if role == 'owner': |
---|
| | if len(roster) == 1: |
---|
| | messages.error(request, _('Removing the last owner is impossible')) |
---|
| | return redirect('list_members', the_list.list_id, role) |
---|
| | # the user may not have a other_emails property if it's a superuser |
---|
| | user_addresses = set([request.user.email]) | \ |
---|
| | set(getattr(request.user, 'other_emails', [])) |
---|
| | if address in user_addresses: |
---|
| | user_emails = EmailAddress.objects.filter( |
---|
| | user=request.user, verified=True).order_by( |
---|
| | "email").values_list("email", flat=True) |
---|
| | if address in user_emails: |
---|
| | # The user is removing themselves, redirect to the list info page |
---|
| | # because they won't have access to the members page anyway. |
---|
| | redirect_on_success = redirect('list_summary', the_list.list_id) |
---|
| | |
---|
| |
---|
| | |