|
|
|
|
@ -1,9 +1,14 @@ |
|
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
import json |
|
|
|
|
import ast |
|
|
|
|
from django import forms |
|
|
|
|
from django.contrib.auth.forms import ReadOnlyPasswordHashField |
|
|
|
|
from django.forms.util import ErrorList |
|
|
|
|
from django.utils.translation import ugettext as _ |
|
|
|
|
from models import User, Profile |
|
|
|
|
from theme.models import Theme, Tag |
|
|
|
|
from country.models import Area |
|
|
|
|
from django.utils import translation |
|
|
|
|
from country.models import Country |
|
|
|
|
from city.models import City |
|
|
|
|
from company.models import Company |
|
|
|
|
@ -302,4 +307,125 @@ class UserFilterForm(forms.Form): |
|
|
|
|
if email: |
|
|
|
|
qs = qs.filter(email__contains=email) |
|
|
|
|
|
|
|
|
|
return qs |
|
|
|
|
return qs |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FeedFilterForm(forms.Form): |
|
|
|
|
data_with_parents = None |
|
|
|
|
filter = None |
|
|
|
|
th = forms.MultipleChoiceField(label=_(u'Тематика'), choices=[(item.id, item.name) for item in Theme.active.all()], |
|
|
|
|
required=False, widget=forms.CheckboxSelectMultiple()) |
|
|
|
|
tg = forms.CharField(label=_(u'Теги'), required=False, widget=forms.CheckboxSelectMultiple()) |
|
|
|
|
area = forms.MultipleChoiceField(label=_(u'Регион'), choices=[(item.id, item.name) for item in Area.objects.all_sorted()], |
|
|
|
|
required=False, widget=forms.CheckboxSelectMultiple()) |
|
|
|
|
co = forms.MultipleChoiceField(label=_(u'Страна'), required=False, widget=forms.CheckboxSelectMultiple(), |
|
|
|
|
choices=[(item.id, item.name) for item in Country.objects.select_related('exposition_country')\ |
|
|
|
|
.filter(exposition_country__country__isnull=False, translations__language_code=translation.get_language())\ |
|
|
|
|
.order_by('translations__name').distinct()] |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
ci = forms.MultipleChoiceField(label=_(u'Город'), required=False, widget=forms.CheckboxSelectMultiple(), |
|
|
|
|
choices=[(item.id, item.name) for item in City.objects.select_related('exposition_city')\ |
|
|
|
|
.filter(exposition_city__city__isnull=False, translations__language_code=translation.get_language())\ |
|
|
|
|
.order_by('translations__name').distinct()] |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
fr = forms.DateField(required=False, |
|
|
|
|
widget=forms.DateInput(attrs={'class': 'date', 'id': 'dateFrom', |
|
|
|
|
'placeholder': _(u'дд.мм.гггг')})) |
|
|
|
|
to = forms.DateField(required=False, |
|
|
|
|
widget=forms.DateInput(attrs={'class': 'date', 'id': 'dateTo', |
|
|
|
|
'placeholder': _(u'дд.мм.гггг')})) |
|
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs): |
|
|
|
|
user = kwargs.get('user') |
|
|
|
|
if 'user' in kwargs: del kwargs['user'] |
|
|
|
|
super(FeedFilterForm, self).__init__(*args, **kwargs) |
|
|
|
|
filter = user.eventfilter |
|
|
|
|
self.filter = filter |
|
|
|
|
self.data_with_parents = self.get_form_data(filter) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_form_data(self, filter): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if filter.area.exists(): |
|
|
|
|
areas = [{'name':'area', 'id':item.id, 'parent':None, 'text':item.name} for item in filter.area.all()] |
|
|
|
|
else: |
|
|
|
|
areas = [] |
|
|
|
|
|
|
|
|
|
if filter.country.exists(): |
|
|
|
|
cos = [] |
|
|
|
|
for country in filter.country.all(): |
|
|
|
|
cos.append({'name':'area', 'id':country.area_id, 'text': country.area.name, 'children':{ |
|
|
|
|
'id': country.id, 'name':'co', 'text': country.name |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
else: |
|
|
|
|
cos = [] |
|
|
|
|
|
|
|
|
|
if filter.city.exists(): |
|
|
|
|
cis = [] |
|
|
|
|
for city in filter.city.all(): |
|
|
|
|
cis.append({'name':'area', 'id': city.country.area_id, 'text': city.country.area.name, 'children':{ |
|
|
|
|
'id': city.country_id, 'name':'co', 'text': city.country.name, 'children':{ |
|
|
|
|
'name':'ci', 'id':city.id, 'text':city.name |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
else: |
|
|
|
|
cis = [] |
|
|
|
|
|
|
|
|
|
if filter.theme.exists(): |
|
|
|
|
|
|
|
|
|
ths = [{'name':'th', 'id':item.id, 'parent':None, 'text':item.name} for item in filter.theme.all()] |
|
|
|
|
else: |
|
|
|
|
ths = [] |
|
|
|
|
|
|
|
|
|
if filter.tag.exists(): |
|
|
|
|
tgs = [] |
|
|
|
|
for tag in filter.tag.all(): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tgs.append({'name':'th', 'id':tag.theme_id, 'text': tag.theme.name, 'children':{ |
|
|
|
|
'id': tag.id, 'name':'tg', 'text': tag.name |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
else: |
|
|
|
|
tgs = [] |
|
|
|
|
|
|
|
|
|
finale_list = areas + cos + cis + ths + tgs |
|
|
|
|
result = {'inputs': finale_list} |
|
|
|
|
result = json.dumps(result) |
|
|
|
|
return result |
|
|
|
|
|
|
|
|
|
def filter_save(self): |
|
|
|
|
theme = self.cleaned_data['th'] |
|
|
|
|
tag = self.cleaned_data['tg'] |
|
|
|
|
area = self.cleaned_data['area'] |
|
|
|
|
country = self.cleaned_data['co'] |
|
|
|
|
city = self.cleaned_data['ci'] |
|
|
|
|
filter = self.filter |
|
|
|
|
|
|
|
|
|
filter.theme.clear() |
|
|
|
|
filter.theme.add(*Theme.objects.filter(id__in=theme)) |
|
|
|
|
|
|
|
|
|
filter.tag.clear() |
|
|
|
|
filter.tag.add(*Tag.objects.filter(id__in=tag)) |
|
|
|
|
|
|
|
|
|
filter.area.clear() |
|
|
|
|
filter.area.add(*Area.objects.filter(id__in=area)) |
|
|
|
|
filter.country.clear() |
|
|
|
|
filter.country.add(*Country.objects.filter(id__in=country)) |
|
|
|
|
|
|
|
|
|
filter.city.clear() |
|
|
|
|
filter.city.add(*City.objects.filter(id__in=city)) |
|
|
|
|
|
|
|
|
|
def clean_tg(self): |
|
|
|
|
|
|
|
|
|
tg = self.cleaned_data.get('tg') |
|
|
|
|
if tg: |
|
|
|
|
res = ast.literal_eval(tg) |
|
|
|
|
return res |
|
|
|
|
return tg |