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.
32 lines
940 B
32 lines
940 B
# -*- coding: utf-8 -*-
|
|
from django import forms
|
|
from django.utils.translation import ugettext_lazy as _
|
|
from haystack.query import EmptySearchQuerySet, SearchQuerySet
|
|
|
|
from exposition.models import Exposition
|
|
from conference.models import Conference
|
|
from seminar.models import Seminar
|
|
from webinar.models import Webinar
|
|
|
|
class EventSearchForm(forms.Form):
|
|
q = forms.CharField(label=_(u'Поиск'), required=False)
|
|
w = forms.CharField(label=_(u'Где'), required=False)
|
|
|
|
def search(self):
|
|
|
|
if not self.is_valid():
|
|
return EmptySearchQuerySet()
|
|
q = self.cleaned_data.get('q')
|
|
w = self.cleaned_data.get('w')
|
|
|
|
if not q and not w:
|
|
return EmptySearchQuerySet()
|
|
sqs = SearchQuerySet().models(Exposition, Conference, Seminar, Webinar)
|
|
|
|
if q:
|
|
sqs = sqs.auto_query(q)
|
|
if w:
|
|
sqs = sqs.filter(where__contains=w)
|
|
|
|
return sqs
|
|
|
|
|