コード例 #1
0
ファイル: home.py プロジェクト: blancheta/codeforlife-portal
def contact(request):
    increment_count = False
    should_use_captcha = captcha.CAPTCHA_ENABLED

    anchor = ''

    if request.method == 'POST':
        contact_form = ContactForm(request.POST)
        if not should_use_captcha:
            remove_captcha_from_forms(contact_form)
        increment_count = True
        if contact_form.is_valid():
            anchor = "top"
            email_message = emailMessages.contactEmail(
                request, contact_form.cleaned_data['name'],
                contact_form.cleaned_data['telephone'],
                contact_form.cleaned_data['email'],
                contact_form.cleaned_data['message'],
                contact_form.cleaned_data['browser'])
            send_email(CONTACT_EMAIL, app_settings.CONTACT_FORM_EMAILS,
                       email_message['subject'], email_message['message'])

            confirmed_email_message = emailMessages.confirmationContactEmailMessage(
                request, contact_form.cleaned_data['name'],
                contact_form.cleaned_data['telephone'],
                contact_form.cleaned_data['email'],
                contact_form.cleaned_data['message'])
            send_email(CONTACT_EMAIL, [contact_form.cleaned_data['email']],
                       confirmed_email_message['subject'],
                       confirmed_email_message['message'])

            messages.success(request, 'Your message was sent successfully.')
            return render(request, 'portal/help-and-support.html', {
                'form': contact_form,
                'anchor': anchor
            })
        else:
            contact_form = ContactForm(request.POST)
            anchor = "contact"

    else:
        contact_form = ContactForm()

    if not should_use_captcha:
        remove_captcha_from_forms(contact_form)

    response = render(
        request, 'portal/help-and-support.html', {
            'form': contact_form,
            'anchor': anchor,
            'captcha': should_use_captcha,
            'settings': app_settings
        })

    response.count = increment_count
    return response
コード例 #2
0
def contact(request):
    increment_count = False
    limits = getattr(request, 'limits', {'ip': [0]})
    captcha_limit = 5

    using_captcha = (limits['ip'][0] > captcha_limit)
    should_use_captcha = (limits['ip'][0] >= captcha_limit)

    ContactFormWithCaptcha = partial(
        create_form_subclass_with_recaptcha(ContactForm, recaptcha_client),
        request)
    InputContactForm = ContactFormWithCaptcha if using_captcha else ContactForm
    OutputContactForm = ContactFormWithCaptcha if should_use_captcha else ContactForm

    anchor = ''

    if request.method == 'POST':
        contact_form = InputContactForm(request.POST)
        increment_count = True

        if contact_form.is_valid():
            email_message = emailMessages.contactEmail(
                request, contact_form.cleaned_data['name'],
                contact_form.cleaned_data['telephone'],
                contact_form.cleaned_data['email'],
                contact_form.cleaned_data['message'],
                contact_form.cleaned_data['browser'])
            send_email(CONTACT_EMAIL, CONTACT_FORM_EMAILS,
                       email_message['subject'], email_message['message'])

            confirmed_email_message = emailMessages.confirmationContactEmailMessage(
                request, contact_form.cleaned_data['name'],
                contact_form.cleaned_data['telephone'],
                contact_form.cleaned_data['email'],
                contact_form.cleaned_data['message'])
            send_email(CONTACT_EMAIL, [contact_form.cleaned_data['email']],
                       confirmed_email_message['subject'],
                       confirmed_email_message['message'])

            messages.success(request, 'Your message was sent successfully.')
            return HttpResponseRedirect('.')
        else:
            contact_form = OutputContactForm(request.POST)
            anchor = "contact"

    else:
        contact_form = OutputContactForm()

    response = render(request, 'portal/help-and-support.html', {
        'form': contact_form,
        'anchor': anchor
    })

    response.count = increment_count
    return response
コード例 #3
0
ファイル: home.py プロジェクト: takluyver/codeforlife-portal
def contact(request):
    increment_count = False
    limits = getattr(request, 'limits', {'ip': [0]})
    captcha_limit = 5

    using_captcha = (limits['ip'][0] > captcha_limit)
    should_use_captcha = (limits['ip'][0] >= captcha_limit)

    anchor = ''

    if request.method == 'POST':
        contact_form = ContactForm(request.POST)
        increment_count = True
        contact_form.view_options['is_recaptcha_visible'] = should_use_captcha
        contact_form.view_options['is_recaptcha_valid'] = check_recaptcha(
            request) if using_captcha else False
        if contact_form.is_valid():
            email_message = emailMessages.contactEmail(
                request, contact_form.cleaned_data['name'],
                contact_form.cleaned_data['telephone'],
                contact_form.cleaned_data['email'],
                contact_form.cleaned_data['message'],
                contact_form.cleaned_data['browser'])
            send_email(CONTACT_EMAIL, app_settings.CONTACT_FORM_EMAILS,
                       email_message['subject'], email_message['message'])

            confirmed_email_message = emailMessages.confirmationContactEmailMessage(
                request, contact_form.cleaned_data['name'],
                contact_form.cleaned_data['telephone'],
                contact_form.cleaned_data['email'],
                contact_form.cleaned_data['message'])
            send_email(CONTACT_EMAIL, [contact_form.cleaned_data['email']],
                       confirmed_email_message['subject'],
                       confirmed_email_message['message'])

            messages.success(request, 'Your message was sent successfully.')
            return HttpResponseRedirect('.')
        else:
            contact_form = ContactForm(request.POST)
            anchor = "contact"

    else:
        contact_form = ContactForm()

    response = render(
        request, 'portal/help-and-support.html', {
            'form': contact_form,
            'anchor': anchor,
            'captcha': should_use_captcha,
            'settings': app_settings
        })

    response.count = increment_count
    return response
コード例 #4
0
ファイル: home.py プロジェクト: javicg/codeforlife-portal
def contact(request):
    increment_count = False
    limits = getattr(request, 'limits', {'ip': [0]})
    captcha_limit = 5

    using_captcha = (limits['ip'][0] > captcha_limit)
    should_use_captcha = (limits['ip'][0] >= captcha_limit)

    ContactFormWithCaptcha = partial(
        create_form_subclass_with_recaptcha(ContactForm, recaptcha_client), request)
    InputContactForm = ContactFormWithCaptcha if using_captcha else ContactForm
    OutputContactForm = ContactFormWithCaptcha if should_use_captcha else ContactForm

    if request.method == 'POST':
        contact_form = InputContactForm(request.POST)
        increment_count = True

        if contact_form.is_valid():
            emailMessage = emailMessages.contactEmail(
                request, contact_form.cleaned_data['name'], contact_form.cleaned_data['telephone'],
                contact_form.cleaned_data['email'], contact_form.cleaned_data['message'],
                contact_form.cleaned_data['browser'])
            send_email(CONTACT_EMAIL, CONTACT_FORM_EMAILS, emailMessage['subject'],
                       emailMessage['message'])

            confirmedEmailMessage = emailMessages.confirmationContactEmailMessage(
                request, contact_form.cleaned_data['name'], contact_form.cleaned_data['telephone'],
                contact_form.cleaned_data['email'], contact_form.cleaned_data['message'])
            send_email(CONTACT_EMAIL, [contact_form.cleaned_data['email']],
                       confirmedEmailMessage['subject'], confirmedEmailMessage['message'])

            messages.success(request, 'Your message was sent successfully.')
            return HttpResponseRedirect('.')

        else:
            contact_form = OutputContactForm(request.POST)

    else:
        contact_form = OutputContactForm()

    response = render(request, 'portal/contact.html', {'form': contact_form})

    response.count = increment_count
    return response