Пример #1
0
def contact(request):
    captcha = None
    show_captcha = (settings.REGISTRATION_CAPTCHA
                    and not request.user.is_authenticated)

    if request.method == 'POST':
        form = ContactForm(request.POST)
        if show_captcha:
            captcha = CaptchaForm(request, form, request.POST)
        if not check_rate_limit('message', request):
            messages.error(
                request, _('Too many messages sent, please try again later!'))
        elif (captcha is None or captcha.is_valid()) and form.is_valid():
            mail_admins_contact(
                request,
                '%(subject)s',
                CONTACT_TEMPLATE,
                form.cleaned_data,
                form.cleaned_data['email'],
                settings.ADMINS_CONTACT,
            )
            return redirect('home')
    else:
        initial = get_initial_contact(request)
        if request.GET.get('t') in CONTACT_SUBJECTS:
            initial['subject'] = CONTACT_SUBJECTS[request.GET['t']]
        form = ContactForm(initial=initial)
        if show_captcha:
            captcha = CaptchaForm(request)

    return render(request, 'accounts/contact.html', {
        'form': form,
        'captcha_form': captcha,
        'title': _('Contact'),
    })
Пример #2
0
def contact(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            mail_admins_contact(
                request,
                '%(subject)s',
                CONTACT_TEMPLATE,
                form.cleaned_data,
                form.cleaned_data['email'],
            )
            return redirect('home')
    else:
        initial = get_initial_contact(request)
        if 'subject' in request.GET:
            initial['subject'] = request.GET['subject']
        form = ContactForm(initial=initial)

    return render(
        request,
        'accounts/contact.html',
        {
            'form': form,
            'title': _('Contact'),
        }
    )
Пример #3
0
def contact(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            mail_admins_contact(
                '%(subject)s',
                CONTACT_TEMPLATE,
                form.cleaned_data,
                form.cleaned_data['email'],
            )
            messages.info(
                request,
                _('Message has been sent to administrator.')
            )
            return redirect('home')
    else:
        initial = get_initial_contact(request)
        if 'subject' in request.GET:
            initial['subject'] = request.GET['subject']
        form = ContactForm(initial=initial)

    return render_to_response(
        'accounts/contact.html',
        RequestContext(
            request,
            {
                'form': form,
                'title': _('Contact'),
            }
        )
    )
Пример #4
0
def contact(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            mail_admins_sender(
                form.cleaned_data['subject'],
                'Message from %s <%s>:\n\n%s' % (
                    form.cleaned_data['name'],
                    form.cleaned_data['email'],
                    form.cleaned_data['message']
                ),
                form.cleaned_data['email'],
            )
            messages.info(request, _('Message has been sent to administrator.'))
            return HttpResponseRedirect('/')
    else:
        initial = {}
        if request.user.is_authenticated():
            initial['name'] = request.user.get_full_name()
            initial['email'] = request.user.email
        if 'subject' in request.GET:
            initial['subject'] = request.GET['subject']
        form = ContactForm(initial = initial)

    return render_to_response('contact.html', RequestContext(request, {
        'form': form,
        'title': _('Contact'),
    }))
Пример #5
0
def contact(request):
    captcha = None
    show_captcha = settings.REGISTRATION_CAPTCHA and not request.user.is_authenticated

    if request.method == "POST":
        form = ContactForm(request.POST)
        if show_captcha:
            captcha = CaptchaForm(request, form, request.POST)
        if not check_rate_limit("message", request):
            messages.error(
                request, _("Too many messages sent, please try again later.")
            )
        elif (captcha is None or captcha.is_valid()) and form.is_valid():
            mail_admins_contact(
                request,
                "%(subject)s",
                CONTACT_TEMPLATE,
                form.cleaned_data,
                form.cleaned_data["email"],
                settings.ADMINS_CONTACT,
            )
            return redirect("home")
    else:
        initial = get_initial_contact(request)
        if request.GET.get("t") in CONTACT_SUBJECTS:
            initial["subject"] = CONTACT_SUBJECTS[request.GET["t"]]
        form = ContactForm(initial=initial)
        if show_captcha:
            captcha = CaptchaForm(request)

    return render(
        request,
        "accounts/contact.html",
        {"form": form, "captcha_form": captcha, "title": _("Contact")},
    )
Пример #6
0
def contact(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if not check_rate_limit(request):
            messages.error(
                request,
                _('Too many messages sent, please try again later!')
            )
        elif form.is_valid():
            mail_admins_contact(
                request,
                '%(subject)s',
                CONTACT_TEMPLATE,
                form.cleaned_data,
                form.cleaned_data['email'],
            )
            return redirect('home')
    else:
        initial = get_initial_contact(request)
        if request.GET.get('t') in CONTACT_SUBJECTS:
            initial['subject'] = CONTACT_SUBJECTS[request.GET['t']]
        form = ContactForm(initial=initial)

    return render(
        request,
        'accounts/contact.html',
        {
            'form': form,
            'title': _('Contact'),
        }
    )
Пример #7
0
def contact(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if not check_rate_limit(request):
            messages.error(
                request, _('Too many messages sent, please try again later!'))
        elif form.is_valid():
            mail_admins_contact(
                request,
                '%(subject)s',
                CONTACT_TEMPLATE,
                form.cleaned_data,
                form.cleaned_data['email'],
            )
            return redirect('home')
    else:
        initial = get_initial_contact(request)
        if request.GET.get('t') in CONTACT_SUBJECTS:
            initial['subject'] = CONTACT_SUBJECTS[request.GET['t']]
        form = ContactForm(initial=initial)

    return render(request, 'accounts/contact.html', {
        'form': form,
        'title': _('Contact'),
    })
Пример #8
0
def contact(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            mail_admins_sender(
                form.cleaned_data['subject'],
                'Message from %s <%s>:\n\n%s' % (
                    form.cleaned_data['name'],
                    form.cleaned_data['email'],
                    form.cleaned_data['message']
                ),
                form.cleaned_data['email'],
            )
            messages.info(request, _('Message has been sent to administrator.'))
            return HttpResponseRedirect('/')
    else:
        initial = {}
        if request.user.is_authenticated():
            initial['name'] = request.user.get_full_name()
            initial['email'] = request.user.email
        if 'subject' in request.GET:
            initial['subject'] = request.GET['subject']
        form = ContactForm(initial = initial)

    return render_to_response('contact.html', RequestContext(request, {
        'form': form,
        'title': _('Contact'),
    }))
Пример #9
0
def contact(request):
    if request.method == "POST":
        form = ContactForm(request.POST)
        if form.is_valid():
            mail_admins_contact(request, "%(subject)s", CONTACT_TEMPLATE, form.cleaned_data, form.cleaned_data["email"])
            return redirect("home")
    else:
        initial = get_initial_contact(request)
        if "subject" in request.GET:
            initial["subject"] = request.GET["subject"]
        form = ContactForm(initial=initial)

    return render(request, "accounts/contact.html", {"form": form, "title": _("Contact")})
Пример #10
0
def contact(request):
    captcha = None
    show_captcha = (
        settings.REGISTRATION_CAPTCHA and
        not request.user.is_authenticated
    )

    if request.method == 'POST':
        form = ContactForm(request.POST)
        if show_captcha:
            captcha = CaptchaForm(request, form, request.POST)
        if not check_rate_limit('message', request):
            messages.error(
                request,
                _('Too many messages sent, please try again later!')
            )
        elif (captcha is None or captcha.is_valid()) and form.is_valid():
            mail_admins_contact(
                request,
                '%(subject)s',
                CONTACT_TEMPLATE,
                form.cleaned_data,
                form.cleaned_data['email'],
                settings.ADMINS_CONTACT,
            )
            return redirect('home')
    else:
        initial = get_initial_contact(request)
        if request.GET.get('t') in CONTACT_SUBJECTS:
            initial['subject'] = CONTACT_SUBJECTS[request.GET['t']]
        form = ContactForm(initial=initial)
        if show_captcha:
            captcha = CaptchaForm(request)

    return render(
        request,
        'accounts/contact.html',
        {
            'form': form,
            'captcha_form': captcha,
            'title': _('Contact'),
        }
    )
Пример #11
0
def contact(request):
    if request.method == "POST":
        form = ContactForm(request.POST)
        if form.is_valid():
            mail_admins_sender(
                form.cleaned_data["subject"],
                "Message from %s <%s>:\n\n%s"
                % (form.cleaned_data["name"], form.cleaned_data["email"], form.cleaned_data["message"]),
                form.cleaned_data["email"],
            )
            messages.info(request, _("Message has been sent to administrator."))
            return HttpResponseRedirect(reverse("home"))
    else:
        initial = {}
        if request.user.is_authenticated():
            initial["name"] = request.user.get_full_name()
            initial["email"] = request.user.email
        if "subject" in request.GET:
            initial["subject"] = request.GET["subject"]
        form = ContactForm(initial=initial)

    return render_to_response("contact.html", RequestContext(request, {"form": form, "title": _("Contact")}))