добавил вывод периода

remotes/origin/stage5
Alexander Burdeiny 10 years ago
parent ab42541497
commit b9ba51e2ea
  1. 39
      events/forms.py
  2. 62
      functions/model_mixin.py
  3. 1
      templates/client/includes/events/filter_form.html

@ -31,6 +31,7 @@ from django.conf import settings
from haystack.query import SearchQuerySet, RelatedSearchQuerySet, SQ
from functions.model_utils import EnumChoices
from functions.model_mixin import get_dates
from exposition.models import Exposition
from conference.models import Conference
from theme.models import Theme, Tag
@ -209,20 +210,6 @@ class FilterForm(forms.Form):
city = CountModelMultipleChoiceField(
label=_(u'Города'), required=False, cache_choices=True,
queryset=City.objects.language().values('pk', 'name'))
price = FilterTypedMultipleChoiceField(
label=_(u'Стоимость'), coerce=int,
choices=PRICE,
required=False, widget=FilterCheckboxSelectMultiple(),
# help_text=_(u'За 1 м<sub>2</sub> необорудованной площади')
)
members = FilterTypedMultipleChoiceField(
label=_(u'Участники'), coerce=int,
choices=MEMBERS,
required=False, widget=FilterCheckboxSelectMultiple())
visitors = FilterTypedMultipleChoiceField(
label=_(u'Посетители'), coerce=int,
choices=VISITORS,
required=False, widget=FilterCheckboxSelectMultiple())
year = forms.RegexField(r'^(?P<year>\d{4})$', max_length=4, min_length=4,
required=False, widget=forms.HiddenInput())
default_month = forms.CharField(max_length=3, min_length=3,
@ -239,6 +226,25 @@ class FilterForm(forms.Form):
date_to = forms.DateField(required=False, input_formats=('%d.%m.%Y',),
widget=forms.DateInput(attrs={'class': 'date', 'id': 'dateTo',
'placeholder': _(u'дд.мм.гггг')}))
price = FilterTypedMultipleChoiceField(
label=_(u'Стоимость'), coerce=int,
choices=PRICE,
required=False, widget=FilterCheckboxSelectMultiple(),
# help_text=_(u'За 1 м<sub>2</sub> необорудованной площади')
)
members = FilterTypedMultipleChoiceField(
label=_(u'Участники'), coerce=int,
choices=MEMBERS,
required=False, widget=FilterCheckboxSelectMultiple())
visitors = FilterTypedMultipleChoiceField(
label=_(u'Посетители'), coerce=int,
choices=VISITORS,
required=False, widget=FilterCheckboxSelectMultiple())
rating = FilterTypedMultipleChoiceField(
label=_(u'Рейтинги'), coerce=int,
choices=[],
required=False, widget=FilterCheckboxSelectMultiple())
def __init__(self, *args, **kwargs):
super(FilterForm, self).__init__(*args, **kwargs)
@ -264,6 +270,11 @@ class FilterForm(forms.Form):
else:
self.fields[field].choice_cache = choices
def get_dates(self):
if not (self.cleaned_data.get('date_from') or self.cleaned_data.get('date_to')):
return None
return get_dates(self.cleaned_data.get('date_from'), self.cleaned_data.get('date_to'))
@classmethod
def month_choices(cls):
month = datetime.today().month

@ -34,39 +34,43 @@ class ExpoMixin(object):
return photos
class EventMixin(object):
@property
def get_dates(self):
lang = get_language()
if self.data_end and self.data_begin:
delta = self.data_end - self.data_begin
if delta.days > 28 and self.data_end.month == self.data_begin.month:
return self.data_begin.strftime('%B')
elif delta.days < 1:
if lang == 'ru':
return ru_strftime("%d %B %Y", date=self.data_begin, inflected=True)
return self.data_begin
if self.data_begin.month != self.data_end.month:
if lang == 'ru':
start = ru_strftime("%d %B", date=self.data_begin, inflected=True)
else:
start = u'{month} {day}'.format(
month=self.data_begin.strftime('%B'),
day=self.data_begin.day)
else:
start = self.data_begin.day
def get_dates(data_begin, data_end):
lang = get_language()
if data_end and data_begin:
delta = data_end - data_begin
if delta.days > 28 and data_end.month == data_begin.month:
return data_begin.strftime('%B')
elif delta.days < 1:
if lang == 'ru':
return ru_strftime("%d %B %Y", date=data_begin, inflected=True)
return data_begin
if data_begin.month != data_end.month:
if lang == 'ru':
end = ru_strftime("%d %B", date=self.data_end, inflected=True)
start = ru_strftime("%d %B", date=data_begin, inflected=True)
else:
end = u'{month} {day}'.format(
month=self.data_end.strftime('%B'),
day=self.data_end.day)
return _(u'c {start} по {end}').format(start=start, end=end)
start = u'{month} {day}'.format(
month=data_begin.strftime('%B'),
day=data_begin.day)
else:
start = data_begin.day
if lang == 'ru':
return ru_strftime("%d %B %Y", date=self.data_begin, inflected=True)
return self.data_begin
end = ru_strftime("%d %B", date=data_end, inflected=True)
else:
end = u'{month} {day}'.format(
month=data_end.strftime('%B'),
day=data_end.day)
return _(u'c {start} по {end}').format(start=start, end=end)
if lang == 'ru':
return ru_strftime("%d %B %Y", date=data_begin, inflected=True)
return data_begin
class EventMixin(object):
@property
def get_dates(self):
return get_dates(self.data_begin, self.data_end)
@property
def get_place_name(self):

@ -29,6 +29,7 @@
{{ field.errors }}
{% endfor %}
{{ form.get_dates }}
{# <button type="submit">{% trans "Применить" %}</button> #}
</div>
</form>

Loading…
Cancel
Save