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.
40 lines
1.2 KiB
40 lines
1.2 KiB
# -*- coding: utf-8 -*-
|
|
from django import forms
|
|
from django.utils.translation import ugettext as _
|
|
|
|
from haystack.query import SearchQuerySet
|
|
|
|
from functions.model_utils import EnumChoices
|
|
from exposition.models import Exposition
|
|
from conference.models import Conference
|
|
|
|
|
|
class FilterForm(forms.Form):
|
|
# class Meta:
|
|
# widgets = {
|
|
# 'model': forms.CheckboxSelectMultiple(),
|
|
# }
|
|
|
|
TYPES = EnumChoices(
|
|
EXPO=(1, _(u'Выставки')),
|
|
CONF=(2, _(_(u'Конференции'))),
|
|
)
|
|
|
|
model = forms.TypedMultipleChoiceField(label=_(u'Тип события'), coerce=int, choices=TYPES, required=False, widget=forms.CheckboxSelectMultiple())
|
|
|
|
def get_models(self):
|
|
val = self.cleaned_data.get('model')
|
|
models = []
|
|
if val:
|
|
if self.TYPES.EXPO in val:
|
|
models.append(Exposition)
|
|
if self.TYPES.CONF in val:
|
|
models.append(Conference)
|
|
else:
|
|
models = [Conference, Exposition]
|
|
return models
|
|
|
|
def filter(self):
|
|
qs = SearchQuerySet().models(*self.get_models()).all()
|
|
d = self.cleaned_data
|
|
return qs
|
|
|