|
|
|
|
@ -8,6 +8,7 @@ from emencia.django.newsletter.models import MailingList |
|
|
|
|
from functions.form_check import translit_with_separator as tr |
|
|
|
|
from theme.models import Theme |
|
|
|
|
from country.models import Country, Area |
|
|
|
|
from city.models import City |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MailingListSubscriptionForm(forms.ModelForm): |
|
|
|
|
@ -83,29 +84,56 @@ class ContactSettingsForm(forms.ModelForm): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ContactFilterForm(forms.Form): |
|
|
|
|
email = forms.EmailField(label="Email", max_length=255, required=False, |
|
|
|
|
widget=forms.TextInput(attrs={'class':'input-xlarge search-query','placeholder':'Email'})) |
|
|
|
|
theme = forms.MultipleChoiceField(label="Тематика", choices = [(t.id, t.name) for t in Theme.objects.language()], |
|
|
|
|
required=False) |
|
|
|
|
country = forms.MultipleChoiceField(label="Страна", |
|
|
|
|
choices = [(c.id, c.name) for c in list(set(Country.objects.language('ru').all()))], |
|
|
|
|
required=False) |
|
|
|
|
area = forms.MultipleChoiceField(label="Area", choices = [(c.id, c.name) for c in list(set(Area.objects.language()))], |
|
|
|
|
required=False) |
|
|
|
|
email = forms.EmailField( |
|
|
|
|
label="Email", |
|
|
|
|
max_length=255, |
|
|
|
|
required=False, |
|
|
|
|
widget=forms.TextInput(attrs={'class':'input-xlarge search-query','placeholder': 'Email'}) |
|
|
|
|
) |
|
|
|
|
theme = forms.MultipleChoiceField( |
|
|
|
|
label="Тематика", |
|
|
|
|
choices=[(t.id, t.name) for t in Theme.objects.language()], |
|
|
|
|
required=False |
|
|
|
|
) |
|
|
|
|
country = forms.MultipleChoiceField( |
|
|
|
|
label="Страна", |
|
|
|
|
choices=[(c.id, c.name) for c in list(set(Country.objects.language('ru').all()))], |
|
|
|
|
required=False |
|
|
|
|
) |
|
|
|
|
city = forms.MultipleChoiceField( |
|
|
|
|
label="Город", |
|
|
|
|
choices=[(c.id, c.name) for c in list(set(City.objects.language('ru').filter(contactsettings__isnull=False)))], |
|
|
|
|
required=False |
|
|
|
|
) |
|
|
|
|
area = forms.MultipleChoiceField( |
|
|
|
|
label="Area", choices=[(c.id, c.name) for c in list(set(Area.objects.language()))], |
|
|
|
|
required=False |
|
|
|
|
) |
|
|
|
|
mailinglist = forms.ChoiceField( |
|
|
|
|
choices=[(ml.id, ml.name) for ml in MailingList.objects.all()], |
|
|
|
|
label="Список рассылки", |
|
|
|
|
required=False |
|
|
|
|
) |
|
|
|
|
active = forms.BooleanField(label="Подтверждена подписка", required=False) |
|
|
|
|
valid = forms.BooleanField(label="Валидный Email", required=False) |
|
|
|
|
|
|
|
|
|
def filter(self): |
|
|
|
|
title = 'contact list ' |
|
|
|
|
qs = Contact.objects.all() |
|
|
|
|
if self.cleaned_data.get('mailinglist'): |
|
|
|
|
qs = qs.filter(mailinglist_subscriber__id=self.cleaned_data['mailinglist']) |
|
|
|
|
title += " mailinglist: %s" % MailingList.objects.get(id=self.cleaned_data['mailinglist']).name |
|
|
|
|
if self.cleaned_data.get('country'): |
|
|
|
|
qs = qs.filter(contactsettings__country__id__in=self.cleaned_data['country']) |
|
|
|
|
title += " countries: %s" % ','.join([obj.url for obj in Country.objects.language().filter(id__in=self.cleaned_data['country'])]) |
|
|
|
|
if self.cleaned_data.get('email'): |
|
|
|
|
qs = qs.filter(email__icontains=self.cleaned_data['email']) |
|
|
|
|
if self.cleaned_data.get('theme'): |
|
|
|
|
qs = qs.filter(contactsettings__theme__id__in=self.cleaned_data['theme']) |
|
|
|
|
title += " themes: %s" % ','.join([obj.url for obj in Theme.objects.language().filter(id__in=self.cleaned_data['theme'])]) |
|
|
|
|
if self.cleaned_data.get('country'): |
|
|
|
|
qs = qs.filter(contactsettings__country__id__in=self.cleaned_data['country']) |
|
|
|
|
title += " countries: %s" % ','.join([obj.url for obj in Country.objects.language().filter(id__in=self.cleaned_data['country'])]) |
|
|
|
|
if self.cleaned_data.get('city'): |
|
|
|
|
qs = qs.filter(contactsettings__city__id__in=self.cleaned_data['city']) |
|
|
|
|
title += " cities: %s" % ','.join([obj.url for obj in Country.objects.language().filter(id__in=self.cleaned_data['country'])]) |
|
|
|
|
if self.cleaned_data.get('area'): |
|
|
|
|
qs = qs.filter(contactsettings__area__id__in=self.cleaned_data['area']) |
|
|
|
|
title += " geo area: %s" % ','.join([tr(obj.name) for obj in Area.objects.language('en').filter(id__in=self.cleaned_data['area'])]) |
|
|
|
|
|