Ejemplo n.º 1
0
 def post(self, request, list_id):
     """
     Subscribes an email address to a mailing list via POST and
     redirects to the `list_summary` view.
     This view is used for unauthenticated users and asks Mailman core to
     verify the supplied email address.
     """
     try:
         form = ListAnonymousSubscribe(request.POST)
         if form.is_valid():
             email = form.cleaned_data.get('email')
             self.mailing_list.subscribe(email, pre_verified=False,
                                         pre_confirmed=False)
             messages.success(request, _('Please check your inbox for '
                                         'further instructions'))
         else:
             messages.error(request,
                            _('Something went wrong. Please try again.'))
     except HTTPError as e:
         messages.error(request, e.msg)
     return redirect('list_summary', self.mailing_list.list_id)
Ejemplo n.º 2
0
 def get(self, request, list_id):
     data = {
         'list': self.mailing_list,
         'user_subscribed': False,
         'subscribed_address': None,
         'public_archive': False,
         'hyperkitty_enabled': False
     }
     if self.mailing_list.settings['archive_policy'] == 'public':
         data['public_archive'] = True
     if getattr(settings, 'TESTING', False) and \
             'hyperkitty' not in settings.INSTALLED_APPS:
         # avoid systematic test failure when HyperKitty is installed
         # (missing VCR request, see below).
         list(self.mailing_list.archivers)
     if ('hyperkitty' in settings.INSTALLED_APPS
             and 'hyperkitty' in self.mailing_list.archivers
             and self.mailing_list.archivers['hyperkitty']):
         data['hyperkitty_enabled'] = True
     if request.user.is_authenticated():
         user_emails = EmailAddress.objects.filter(
             user=request.user,
             verified=True).order_by("email").values_list("email",
                                                          flat=True)
         pending_requests = [r['email'] for r in self.mailing_list.requests]
         for address in user_emails:
             if address in pending_requests:
                 data['user_request_pending'] = True
                 break
             try:
                 self.mailing_list.get_member(address)
             except ValueError:
                 pass
             else:
                 data['user_subscribed'] = True
                 data['subscribed_address'] = address
                 break  # no need to test more addresses
         data['subscribe_form'] = ListSubscribe(user_emails)
     else:
         user_emails = None
         data['anonymous_subscription_form'] = ListAnonymousSubscribe()
     return render(request, 'postorius/lists/summary.html', data)