|
|
|
|
@ -1,11 +1,15 @@ |
|
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
from django import forms |
|
|
|
|
|
|
|
|
|
from captcha.fields import CaptchaField |
|
|
|
|
|
|
|
|
|
from . import models |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ReqAvailForm(forms.ModelForm): |
|
|
|
|
"""Форма заказа товара.""" |
|
|
|
|
captcha = CaptchaField(label=u'Введите код с картинки') |
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
|
model = models.ReqAvail |
|
|
|
|
fields = ('name', 'phone', 'message') |
|
|
|
|
@ -18,14 +22,22 @@ class ReqAvailForm(forms.ModelForm): |
|
|
|
|
self.fields['name'].widget.attrs['width'] = u'Ваше имя, отчество' |
|
|
|
|
|
|
|
|
|
def clean(self): |
|
|
|
|
super(ReqAvailForm, self).clean() |
|
|
|
|
name = self.cleaned_data.get('name', '').strip() |
|
|
|
|
phone = self.cleaned_data.get('phone', '').strip() |
|
|
|
|
|
|
|
|
|
if not name: |
|
|
|
|
raise forms.ValidationError(u'Укажите Ваше имя.') |
|
|
|
|
|
|
|
|
|
if not phone: |
|
|
|
|
raise forms.ValidationError(u'Укажите Ваш телефон.') |
|
|
|
|
cleaned_data = super(ReqAvailForm, self).clean() |
|
|
|
|
if (cleaned_data.get('name') and cleaned_data.get('message') and cleaned_data.get('phone')) and not(cleaned_data.get('captcha')): |
|
|
|
|
raise forms.ValidationError(u"Проверьте правильность кода проверки") |
|
|
|
|
elif not (cleaned_data.get('name') and cleaned_data.get('message') and cleaned_data.get('phone') and cleaned_data.get('captcha')): |
|
|
|
|
if self.errors.get('phone') and self.data.get('phone'): |
|
|
|
|
raise forms.ValidationError(u"Проверьте правильность ввода контактов") |
|
|
|
|
else: |
|
|
|
|
raise forms.ValidationError(u"Заполните все поля") |
|
|
|
|
return cleaned_data |
|
|
|
|
#name = self.cleaned_data.get('name', '').strip() |
|
|
|
|
#phone = self.cleaned_data.get('phone', '').strip() |
|
|
|
|
|
|
|
|
|
#if not name: |
|
|
|
|
# raise forms.ValidationError(u'Укажите Ваше имя.') |
|
|
|
|
|
|
|
|
|
#if not phone: |
|
|
|
|
# raise forms.ValidationError(u'Укажите Ваш телефон.') |
|
|
|
|
|
|
|
|
|
return self.cleaned_data |
|
|
|
|
|