You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.5 KiB
47 lines
1.5 KiB
# -*- coding: utf-8 -*-
|
|
from django import forms
|
|
from django.conf import settings
|
|
from django.core.mail import send_mail
|
|
from place_exposition.models import PlaceExposition
|
|
from place_conference.models import PlaceConference
|
|
from django.utils.translation import ugettext_lazy as _
|
|
from haystack.query import SearchQuerySet, EmptySearchQuerySet
|
|
|
|
|
|
class PlaceSearchForm(forms.Form):
|
|
q = forms.CharField(label=_(u'Поиск'), required=False)
|
|
w = forms.CharField(label=_(u'Где'), required=False)
|
|
|
|
def search(self):
|
|
q = self.cleaned_data.get('q')
|
|
w = self.cleaned_data.get('w')
|
|
|
|
if not q and not w:
|
|
return EmptySearchQuerySet()
|
|
|
|
sqs = SearchQuerySet().models(PlaceExposition, PlaceConference)
|
|
|
|
if q:
|
|
sqs = sqs.auto_query(q)
|
|
if w:
|
|
sqs = sqs.filter(where__contains=w)
|
|
|
|
return sqs
|
|
|
|
class CallbackForm(forms.Form):
|
|
callback_phone = forms.CharField()
|
|
|
|
def clean_callback_phone(self):
|
|
phone = self.cleaned_data['callback_phone']
|
|
phone_str = self.cleaned_data['callback_phone']
|
|
deduct = ('-','(',')','.',' ')
|
|
for elem in deduct:
|
|
phone = phone.replace(elem, '')
|
|
if phone.isdigit():
|
|
return phone_str
|
|
else:
|
|
raise forms.ValidationError(_(u'Введите правильный телефон'))
|
|
|
|
def send(self):
|
|
phone = self.cleaned_data['callback_phone']
|
|
send_mail(phone, phone, None, [settings.CALLBACK_EMAIL])
|
|
|