|
|
|
|
@ -25,7 +25,7 @@ from conference.models import Conference |
|
|
|
|
from theme.models import Theme, Tag |
|
|
|
|
from country.models import Country |
|
|
|
|
from city.models import City |
|
|
|
|
from events.common import MEMBERS, VISITORS, PRICE |
|
|
|
|
from events.common import MEMBERS, VISITORS, PRICE, TYPES |
|
|
|
|
from events.common import members_mapping, visitors_mapping, price_mapping |
|
|
|
|
from events.common import ExtraWhere, OR, AND |
|
|
|
|
|
|
|
|
|
@ -120,14 +120,11 @@ values_mapping = { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FilterForm(forms.Form): |
|
|
|
|
TYPES = EnumChoices( |
|
|
|
|
EXPO=(1, _(u'Выставки')), |
|
|
|
|
CONF=(2, _(_(u'Конференции'))), |
|
|
|
|
) |
|
|
|
|
# TYPES = TYPES |
|
|
|
|
# MEMBERS = MEMBERS |
|
|
|
|
# VISITORS = VISITORS |
|
|
|
|
# PRICE = PRICE |
|
|
|
|
model = FilterTypedMultipleChoiceField( |
|
|
|
|
event_type = FilterTypedMultipleChoiceField( |
|
|
|
|
label=_(u'Тип события'), coerce=int, |
|
|
|
|
choices=TYPES, required=False, widget=FilterCheckboxSelectMultiple()) |
|
|
|
|
theme = CountModelMultipleChoiceField( |
|
|
|
|
@ -183,11 +180,11 @@ class FilterForm(forms.Form): |
|
|
|
|
@property |
|
|
|
|
def models(self): |
|
|
|
|
if self._models is None and self._is_valid: |
|
|
|
|
val = self.cleaned_data.get('model') |
|
|
|
|
val = self.cleaned_data.get('event_type') |
|
|
|
|
self._models = [] |
|
|
|
|
if self.TYPES.EXPO in val: |
|
|
|
|
if TYPES.EXPO in val: |
|
|
|
|
self._models.append(Exposition) |
|
|
|
|
if self.TYPES.CONF in val: |
|
|
|
|
if TYPES.CONF in val: |
|
|
|
|
self._models.append(Conference) |
|
|
|
|
return self._models or [Exposition, Conference] |
|
|
|
|
|
|
|
|
|
@ -223,13 +220,14 @@ class FilterForm(forms.Form): |
|
|
|
|
def filter(self, qs=None): |
|
|
|
|
qs = qs or self.default_filter() |
|
|
|
|
# lookup_kwargs = dict(ChainMap({}, *(lookup_kwargs or self.lookup_kwargs).values())) |
|
|
|
|
return qs.filter(**self.lookup_kwargs) |
|
|
|
|
return qs.filter(**self.lookup_kwargs).order_by('data_begin') |
|
|
|
|
|
|
|
|
|
def default_filter(self, load_all=True): |
|
|
|
|
qs = RelatedSearchQuerySet().models(*self.models) |
|
|
|
|
def default_filter(self, load_all=True, _models=None): |
|
|
|
|
models = _models or self.models |
|
|
|
|
qs = RelatedSearchQuerySet().models(*models) |
|
|
|
|
if load_all: |
|
|
|
|
qs = qs.load_all() |
|
|
|
|
for model in self.models: |
|
|
|
|
for model in models: |
|
|
|
|
qs = qs.load_all_queryset(model, model.enable.all()) |
|
|
|
|
qs = qs.filter(data_end__gte=datetime.now()) |
|
|
|
|
return qs |
|
|
|
|
@ -270,11 +268,21 @@ class FilterForm(forms.Form): |
|
|
|
|
for field in ['members', 'visitors', 'price']: |
|
|
|
|
self.fields[field].choices = self.make_local_field_count(field) or self.fields[field].choices |
|
|
|
|
|
|
|
|
|
self.make_event_type_choices_count() |
|
|
|
|
# for field in self.fields: |
|
|
|
|
# field = self.fields[field] |
|
|
|
|
# if hasattr(field, 'queryset'): |
|
|
|
|
# field.queryset = field.queryset[:15] |
|
|
|
|
|
|
|
|
|
def make_event_type_choices_count(self): |
|
|
|
|
types = {1: Exposition, 2: Conference} |
|
|
|
|
choices = [] |
|
|
|
|
for _type, label in TYPES: |
|
|
|
|
qs = self.default_filter(load_all=False, _models=[types.get(_type)]) |
|
|
|
|
count = qs.filter(**self.lookup_kwargs).count() |
|
|
|
|
choices.append((_type, label + ' <i>({count})</i>'.format(count=count))) |
|
|
|
|
self.fields['event_type'].choices = choices |
|
|
|
|
|
|
|
|
|
def make_ids_in_sql_format(self, values): |
|
|
|
|
return tuple(values) if len(values) > 1 else '({})'.format(*values) |
|
|
|
|
|
|
|
|
|
|