diff --git a/functions/model_mixin.py b/functions/model_mixin.py index 3102881b..f8a89157 100644 --- a/functions/model_mixin.py +++ b/functions/model_mixin.py @@ -1,12 +1,17 @@ # -*- coding: utf-8 -*- import copy -from django.db.models import Q +import calendar as python_calendar +from pytils.dt import ru_strftime + from django.conf import settings +from django.db.models import Q +from django.utils.translation import ugettext as _ +from django.utils.translation import get_language +from hvad.utils import get_translation, set_cached_translation, get_cached_translation + from functions.translate import fill_with_signal -import calendar as python_calendar from service.models import Service from photologue.models import Gallery -from django.utils.translation import ugettext as _ class ExpoMixin(object): @@ -30,6 +35,47 @@ class ExpoMixin(object): 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 + + if lang == 'ru': + end = ru_strftime("%d %B", date=self.data_end, 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) + if lang == 'ru': + return ru_strftime("%d %B %Y", date=self.data_begin, inflected=True) + return self.data_begin + + @property + def get_place_name(self): + tr = get_cached_translation(self.place) + if tr is None: + tr = get_translation(self.place) + set_cached_translation(self.place, tr) + return self.place.name + def get_permanent_url(self): url = '%s%s/'%(self.get_catalog_url(), self.url) return url diff --git a/meta/models.py b/meta/models.py index 9643ad96..f93faaec 100644 --- a/meta/models.py +++ b/meta/models.py @@ -66,6 +66,8 @@ class MetaSetting(TranslatableModel): 'object_title_l': lambda obj: getattr(obj, 'main_title', '')[:1].lower() + getattr(obj, 'main_title', '')[1:] if getattr(obj, 'main_title', None) else '', 'city': 'city', 'country': 'country', + 'object_dates': 'get_dates', + 'object_place': 'get_place_name' } # default params diff --git a/templates/c_admin/meta/meta_setting.html b/templates/c_admin/meta/meta_setting.html index 295f5bc9..d4b3dc55 100644 --- a/templates/c_admin/meta/meta_setting.html +++ b/templates/c_admin/meta/meta_setting.html @@ -24,6 +24,8 @@
{object_name} - название события (выставки/конференции)
{object_title} - краткое описание события (выставки/конференции)/ заголовок новости или статьи
{object_title_l} - краткое описание события (выставки/конференции)/ заголовок новости или статьи (с маленькой буквы) +
{object_dates} - даты проведения события (выставки/конференции) +
{object_place} - место проведения события (выставки/конференции)
{city} - город
{country} - страна diff --git a/templates/client/includes/show_date_block.html b/templates/client/includes/show_date_block.html index 42343411..14942b34 100644 --- a/templates/client/includes/show_date_block.html +++ b/templates/client/includes/show_date_block.html @@ -21,6 +21,7 @@ {% if obj.data_end %} {% trans 'с' %} + {% ifnotequal obj.data_begin|date:"F" obj.data_end|date:"F" %} {% ifequal LANGUAGE_CODE 'ru' %} {{ obj.data_begin|ru_strftime:"%d %B" }} @@ -28,12 +29,17 @@ {{ obj.data_begin|date:"F j" }} {% endifequal %} {% else %} - {{ obj.data_begin|date:"j" }}{% endifnotequal %} {% trans 'по' %} - {% ifequal LANGUAGE_CODE 'ru' %} - {{ obj.data_end|ru_strftime:"%d %B" }} - {% else %} - {{ obj.data_end }} - {% endifequal %} + {{ obj.data_begin|date:"j" }} + {% endifnotequal %} + + {% trans 'по' %} + + {% ifequal LANGUAGE_CODE 'ru' %} + {{ obj.data_end|ru_strftime:"%d %B" }} + {% else %} + {{ obj.data_end }} + {% endifequal %} + {% else %} {{ obj.data_begin }} {% endif %}