Exemple #1
0
def contacts(request):
    if request.method == "POST":
        form = ContactsForm(request.POST)
        if form.is_valid():
            form.save()

            subject = u"Сообщения с сайта profsoux.ru"
            message = u"""Имя: %s
                email: %s
                Сайт: %s
                Сообщение: %s""" % (
                form.cleaned_data["name"],
                form.cleaned_data["email"],
                form.cleaned_data["site"],
                form.cleaned_data["comment"],
            )
            sender = "*****@*****.**"
            recipients = ["*****@*****.**"]

            from django.core.mail import send_mail

            send_mail(subject, message, sender, recipients)

            c = {"state": "thanks", "form": ContactsForm()}
        else:
            c = {"state": "default", "form": form}
    else:
        form = ContactsForm()
        c = {"state": "default", "form": form}
    c.update(csrf(request))
    return render(request, get_template("contacts.html", request), c)
Exemple #2
0
def contacts(request):
    if request.method == 'POST':
        form = ContactsForm(request.POST)
        if form.is_valid():
            form.save()

            subject = u'Сообщения с сайта profsoux.ru'
            message = u'''Имя: %s
                email: %s
                Сайт: %s
                Сообщение: %s''' % (
                form.cleaned_data['name'], form.cleaned_data['email'],
                form.cleaned_data['site'], form.cleaned_data['comment'])
            sender = '*****@*****.**'
            recipients = ['*****@*****.**']

            from django.core.mail import send_mail
            send_mail(subject, message, sender, recipients)

            c = {'state': 'thanks', 'form': ContactsForm()}
        else:
            c = {'state': 'default', 'form': form}
    else:
        form = ContactsForm()
        c = {'state': 'default', 'form': form}
    c.update(csrf(request))
    return render(request, get_template('contacts.html', request), c)
Exemple #3
0
def contacts(request):
    from utils import antispam
    from django.template import loader

    if request.method == 'POST':
        form = ContactsForm(request.POST)
        if form.is_valid():
            form.save()

            comment = form.cleaned_data['comment']
            email_data = {
                'name': form.cleaned_data['name'],
                'comment': comment,
                'email': form.cleaned_data['email'],
                'site': form.cleaned_data['site'],
                'timestamp': datetime.now(),
                'user_ip': request.META['REMOTE_ADDR'],
            }

            if not antispam.check_spam(comment, request):
                subject = u'Сообщения с сайта profsoux.ru'

                message = loader.render_to_string('email/contact_form.html', email_data)
                sender = '*****@*****.**'
                recipients = ['*****@*****.**']

                from django.core.mail import send_mail
                send_mail(subject, message, sender, recipients)

            c = {
                'state': 'thanks',
                'form': ContactsForm()
            }
        else:
            c = {
                'state': 'default',
                'form': form
            }
    else:
        form = ContactsForm()
        c = {
            'state': 'default',
            'form': form
        }
    c.update(csrf(request))
    return render(request,
                  get_template('contacts.html', request),
                  c)
Exemple #4
0
def contacts(request):
    if request.method == 'POST':
        form = ContactsForm(request.POST)
        if form.is_valid():
            form.save()

            subject = u'Сообщения с сайта profsoux.ru'
            message = u'''Имя: %s
                email: %s
                Сайт: %s
                Сообщение: %s''' % (form.cleaned_data['name'],
                    form.cleaned_data['email'],
                    form.cleaned_data['site'],
                    form.cleaned_data['comment'])
            sender = '*****@*****.**'
            recipients = ['*****@*****.**']

            from django.core.mail import send_mail
            send_mail(subject, message, sender, recipients)

            c = {
                'state': 'thanks',
                'form': ContactsForm()
            }
        else:
            c = {
                'state': 'default',
                'form': form
            }
    else:
        form = ContactsForm()
        c = {
            'state': 'default',
            'form': form
        }
    c.update(csrf(request))
    return render(request,
                  get_template('contacts.html', request),
                  c)
Exemple #5
0
def contacts(request):
    from utils import antispam
    from django.template import loader

    if request.method == 'POST':
        form = ContactsForm(request.POST)
        if form.is_valid():
            form.save()

            comment = form.cleaned_data['comment']
            email_data = {
                'name': form.cleaned_data['name'],
                'comment': comment,
                'email': form.cleaned_data['email'],
                'site': form.cleaned_data['site'],
                'timestamp': datetime.now(),
                'user_ip': request.META['REMOTE_ADDR'],
            }

            if not antispam.check_spam(comment, request):
                subject = u'Сообщения с сайта profsoux.ru'

                message = loader.render_to_string('email/contact_form.html',
                                                  email_data)
                sender = '*****@*****.**'
                recipients = ['*****@*****.**']

                from django.core.mail import send_mail
                send_mail(subject, message, sender, recipients)

            c = {'state': 'thanks', 'form': ContactsForm()}
        else:
            c = {'state': 'default', 'form': form}
    else:
        form = ContactsForm()
        c = {'state': 'default', 'form': form}
    c.update(csrf(request))
    return render(request, get_template('contacts.html', request), c)