Example #1
0
def one_newsletter_subscribe(request, template_name, target=None):
    success = False

    # not in a footer, but we use the same form
    form = NewsletterFooterForm(request.locale, request.POST or None)

    if form.is_valid():
        data = form.cleaned_data
        request.newsletter_lang = data.get('lang', 'en') or 'en'
        kwargs = {
            'format': data['fmt'],
        }
        # add optional data
        kwargs.update(dict((k, data[k]) for k in ['country',
                                                  'lang',
                                                  'source_url']
                           if data[k]))
        newsletter_subscribe(data['email'])
        success = True

    request.newsletter_form = form
    request.newsletter_success = success

    return l10n_utils.render(request,
                             template_name,
                             {'target': target})
Example #2
0
def handle_form(request, form):
    if form.is_valid():
        data = form.cleaned_data
        send(request, data)
        autorespond(request, data)

        if data.get('newsletter', False):
            newsletter_subscribe(data['email'])
        return True
    return False
Example #3
0
    def process_request(self, request):
        success = False

        is_footer_form = (request.method == 'POST' and
                          'newsletter-footer' in request.POST)
        if is_footer_form:
            form = NewsletterFooterForm(request.locale, request.POST or None)
            if form.is_valid():
                data = form.cleaned_data
                kwargs = {
                    'format': data['fmt'],
                }
                # add optional data
                kwargs.update(dict((k, data[k]) for k in ['country',
                                                          'lang',
                                                          'source_url']
                                   if data[k]))
                result = newsletter_subscribe(data['email'])
                request.newsletter_subscriber = data['email']
                request.new_subscription = result
                success = True
            request.newsletter_form = form
        else:
            request.newsletter_form = NewsletterFooterForm(request.locale, None)
        request.newsletter_success = success
Example #4
0
def contribute(request, template, return_to_form):
    has_contribute_form = (request.method == 'POST' and
                           'contribute-form' in request.POST)

    has_newsletter_form = (request.method == 'POST' and
                           'newsletter-form' in request.POST)

    locale = getattr(request, 'locale', 'en-US')

    contribute_success = False
    newsletter_success = False

    # This is ugly, but we need to handle two forms. I would love if
    # these forms could post to separate pages and get redirected
    # back, but we're forced to keep the error/success workflow on the
    # same page. Please change this.
    if has_contribute_form:
        form = ContributeForm(request.POST)
        contribute_success = email_contribute.handle_form(request, form)
        if contribute_success:
            # If form was submitted successfully, return a new, empty
            # one.
            form = ContributeForm()
    else:
        form = ContributeForm()

    if has_newsletter_form:
        newsletter_form = NewsletterFooterForm(locale, request.POST)
        if newsletter_form.is_valid():
            data = newsletter_form.cleaned_data
            newsletter_subscribe(data['email'])
            newsletter_success = True
    else:
        newsletter_form = NewsletterFooterForm(locale, None)

    return l10n_utils.render(request,
                             template,
                             {'form': form,
                              'contribute_success': contribute_success,
                              'newsletter_form': newsletter_form,
                              'newsletter_success': newsletter_success,
                              'return_to_form': return_to_form,
                              'hide_form': hide_contrib_form(request.locale),
                              'has_moz15': locale in settings.LOCALES_WITH_MOZ15})
Example #5
0
 def save(self):
     data = self.cleaned_data
     send_fsa_form(data)
     send_fsa_welcome_letter(data['email'], data['fmt'])
     if data.get('nl_mozilla_taiwan', False):
         newsletter_subscribe(data['email'])
     result = basket.subscribe(data['email'], self.newsletters(),
                               format=data['fmt'], country=data['country'],
                               welcome_message='Student_Ambassadors_Welcome',
                               source_url=data['source_url'])
     data = {
         'FIRST_NAME': data['first_name'],
         'LAST_NAME': data['last_name'],
         'STUDENTS_CURRENT_STATUS': data['current_status'],
         'STUDENTS_SCHOOL': data['school'],
         'STUDENTS_GRAD_YEAR': data['expected_graduation_year'],
         'STUDENTS_MAJOR': data['area'],
         'COUNTRY_': data['country'],
         'STUDENTS_CITY': data['city'],
         'STUDENTS_ALLOW_SHARE': data['share_information'],
     }
     request('post', 'custom_update_student_ambassadors',
             token=result['token'], data=data)
Example #6
0
 def handle(self, *args, **options):
     self.options = options
     filename = 'offline-subscriptions.txt'
     if args and len(args) > 0:
         filename = args[0]
     with open(filename, 'r') as file:
         subscriptions = file.readlines()
         count = 0
         for subscription in subscriptions:
             email = subscription.strip()
             if email_re.match(email):
                 result = newsletter_subscribe(email)
                 count += 1 if result else 0
             # file.write(subscription.u_email + '\n')
         file.close()
         print '%d new subscriptions.' % count
Example #7
0
def subscribe(request):
    if request.method == 'POST' and 'secret' in request.POST and request.POST['secret'] == API_SECRET and 'email' in request.POST:
        result = newsletter_subscribe(request.POST['email'])
    else:
        raise PermissionDenied
    return HttpResponse(str(result), content_type='application/json')