remotes/origin/stage6
Alexander Burdeiny 9 years ago
parent be6f78eb31
commit 65587bfcbf
  1. 11
      conference/views.py
  2. 13
      exposition/views.py
  3. 37
      functions/model_mixin.py
  4. 21
      functions/utils.py
  5. 27
      settings/forms.py
  6. 14
      templates/c_admin/settings/default_description.html
  7. 5
      templates/client/includes/conference/conference_object.html
  8. 5
      templates/client/includes/conference/conference_paid.html
  9. 0
      templates/client/includes/conference/default_description_en.html
  10. 1
      templates/client/includes/conference/default_description_ru.html
  11. 1
      templates/client/includes/exposition/default_description_en.html
  12. 0
      templates/client/includes/exposition/default_description_ru.html
  13. 7
      templates/client/includes/exposition/exposition_object.html

@ -21,7 +21,7 @@ from django.views.generic.edit import FormMixin
from functions.cache_mixin import CacheMixin, JitterCacheMixin
from functions.custom_views import ListView
from functions.views_help import get_side_items
from functions.utils import CachedSting
from accounts.models import User
from article.models import Article
@ -42,6 +42,8 @@ from theme.models import Tag, Theme
from events.mixin import ConfFilterMixin
MONTHES = settings.MONTHES
description_templates = settings.DEFAULT_DESCRIPTION
class ConferenceBy(ConfFilterMixin, ConfSectionMixin, JitterCacheMixin, MetadataMixin, ListView):
cache_range = settings.CACHE_RANGE
@ -428,6 +430,10 @@ class ConferenceDetail(ObjectStatMixin, JitterCacheMixin, MetadataMixin, DetailV
model = Conference
slug_field = 'url'
template_name = 'client/conference/conference_detail.html'
descriptions = {
'ru': CachedSting(settings.DEFAULT_DESCRIPTION.get('c_description_ru')),
'en': CachedSting(settings.DEFAULT_DESCRIPTION.get('c_description_en')),
}
def dispatch(self, request, *args, **kwargs):
@ -446,9 +452,12 @@ class ConferenceDetail(ObjectStatMixin, JitterCacheMixin, MetadataMixin, DetailV
raise Http404('NotFound')
def get_context_data(self, **kwargs):
lang = translation.get_language()
context = super(ConferenceDetail, self).get_context_data(**kwargs)
context['advertising_form'] = AdvertiseForm()
obj = self.object
if not obj.description:
context['default_description'] = unicode(self.descriptions[lang]).format(**obj.default_description_context())
context['city'] = str(obj.city_id)
context['country'] = str(obj.country_id)
context['themes'] = [str(item.id) for item in obj.theme.all()]

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
import datetime
import json
@ -18,12 +17,15 @@ from django.http import (
)
from django.shortcuts import get_object_or_404
from django.utils.translation import ugettext as _
from django.utils import translation
from django.views.generic import DetailView
from django.views.generic.edit import FormMixin
from functions.cache_mixin import JitterCacheMixin
from functions.custom_views import ExpoSearchView, ListView
from functions.search_forms import ExpositionSearchForm
from functions.views_help import get_side_items
from functions.utils import CachedSting
from meta.views import MetadataMixin
from models import Exposition
@ -40,6 +42,8 @@ from stats_collector.mixin import (
from theme.models import Tag, Theme
from events.mixin import ExpoFilterMixin, SearchFilterMixin
description_templates = settings.DEFAULT_DESCRIPTION
class ExpositionBy(ExpoFilterMixin, ExpoSectionMixin, JitterCacheMixin, MetadataMixin, ListView):
template_name = 'exposition/exposition_by.html'
@ -183,11 +187,18 @@ class ExpoDetail(ObjectStatMixin, JitterCacheMixin, MetadataMixin, DetailView):
queryset = Exposition.objects.language()\
.select_related('place', 'city', 'country', 'paid_new')\
.prefetch_related('theme', 'tag')
descriptions = {
'ru': CachedSting(settings.DEFAULT_DESCRIPTION.get('e_description_ru')),
'en': CachedSting(settings.DEFAULT_DESCRIPTION.get('e_description_en')),
}
def get_context_data(self, **kwargs):
lang = translation.get_language()
context = super(ExpoDetail, self).get_context_data(**kwargs)
context['advertising_form'] = AdvertiseForm()
obj = self.object
if not obj.description:
context['default_description'] = unicode(self.descriptions[lang]).format(**obj.default_description_context())
context['city'] = str(obj.city_id)
context['country'] = str(obj.country_id)
context['themes'] = [str(item.id) for item in obj.theme.all()]

@ -7,6 +7,8 @@ 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 django.http import QueryDict
from hvad.utils import get_translation, set_cached_translation, get_cached_translation
from functions.translate import fill_with_signal
@ -16,14 +18,12 @@ from photologue.models import Gallery
class ExpoMixin(object):
def get_logo(self):
logo = self.files.filter(purpose='logo')
if logo:
return logo[0]
return self.logo
def get_preview(self):
preview = self.files.filter(purpose='preview')
if preview:
return preview[0]
@ -68,6 +68,39 @@ def get_dates(data_begin, data_end):
class EventMixin(object):
def default_description_context(self):
lang = get_language()
booking_url_params = QueryDict('', mutable=True)
booking_url_params.update({
'aid': 333667,
'city': self.city_id,
'do_availability_check': 'on',
'label': '{}_search'.format(self.event_type),
'lang': lang,
'checkin_monthday': self.data_begin.strftime('%d'),
'checkin_year_month': self.data_begin.strftime('%Y-%m'),
'checkout_monthday': self.data_end.strftime('%d'),
'checkout_year_month': self.data_end.strftime('%Y-%m'),
})
booking_url = 'http://www.booking.com/searchresults.html?' + booking_url_params.urlencode()
try:
theme_name = self.theme.language().all()[0]
except IndexError:
theme_name = ''
ctx = {
'name': self.name,
'short_descr': self.main_title,
'dates': self.get_dates,
'country': self.country.name if self.country else '',
'city': self.city.name if self.city else '',
'place': self.get_event_place_name(),
'theme': theme_name,
'tags': ', '.join([t.name for t in self.tag.language().all()]),
'booking_url': booking_url,
}
return ctx
@property
def get_dates(self):
return get_dates(self.data_begin, self.data_end)

@ -21,6 +21,7 @@ def strfdelta(tdelta, fmt):
class CachedSting(object):
def __init__(self, path, timeout=None):
super(CachedSting, self).__init__()
print('initiated', path)
self.path = path
self.timeout = timeout or timedelta(days=1)
self.get_object()
@ -29,12 +30,22 @@ class CachedSting(object):
return self.__str__()
def __str__(self):
if self.timeto > datetime.now():
return self.object
self.get_object()
return self.object
# .encode('utf-8')
def __unicode__(self):
return self.object.decode('utf-8')
def get_object(self):
self.timeto = datetime.now() + self.timeout
with open(self.path, 'r') as f:
self.object = f.read()
try:
with open(self.path, 'r') as f:
self._object = f.read()
except:
self._object = ''
@property
def object(self):
if self.timeto < datetime.now():
self.get_object()
return self._object

@ -174,12 +174,6 @@ class EventSectionSettingsForm(forms.Form):
class EventDefaultDescriptionEditForm(forms.Form):
data_mapping = {
'e_description_ru': 'templates/client/includes/conference/default_description_ru.html',
'e_description_en': 'templates/client/includes/conference/default_description_en.html',
'c_description_ru': 'templates/client/includes/exposition/default_description_ru.html',
'c_description_en': 'templates/client/includes/exposition/default_description_en.html',
}
e_description_ru = forms.CharField(label=_(u'Описание для выставки'), required=False, widget=CKEditorWidget)
e_description_en = forms.CharField(label=_(u'Описание для выставки'), required=False, widget=CKEditorWidget)
c_description_ru = forms.CharField(label=_(u'Описание для конференции'), required=False, widget=CKEditorWidget)
@ -187,17 +181,24 @@ class EventDefaultDescriptionEditForm(forms.Form):
def __init__(self, *args, **kwargs):
super(EventDefaultDescriptionEditForm, self).__init__(*args, **kwargs)
for field_name, path in self.data_mapping.iteritems():
templates = settings.DEFAULT_DESCRIPTION
for field_name, path in templates.iteritems():
try:
with open(os.path.join(settings.SITE_ROOT, path), 'r') as f:
self.initial[field_name] = f.read()
except:
pass
except Exception as e:
print(e)
# except:
# pass
def save(self):
for field_name, path in self.data_mapping.iteritems():
templates = settings.DEFAULT_DESCRIPTION
for field_name, path in templates.iteritems():
try:
with open(os.path.join(settings.SITE_ROOT, path), 'w+') as f:
f.write(self.cleaned_data.get(field_name))
except:
pass
print(self.cleaned_data.get(field_name))
f.write(self.cleaned_data.get(field_name).encode('utf-8'))
except Exception as e:
print(e)
# pass

@ -10,6 +10,20 @@
{% block body %}
<form method="post" action="." class="form-horizontal">{% csrf_token %}
<div class="span8">
Доступные параметры:
<br>{name} - название события
<br>{short_descr} - краткое описание события
<br>{dates} - даты проведения события
<br>{country} - страна
<br>{city} - город
<br>{place} - место проведения
<br>{theme} - тема
<br>{tags} - теги
<br>{booking_url} - ссылка на букинг
</div>
<div class="box span8">
<div class="box-header well" data-original-title>
<h2><i class="icon-tasks"></i>{{ form.verbose }}</h2>

@ -148,7 +148,10 @@
{% if event.description %}
<div class="ied-text">{{ event.description|safe }}</div>
{% else %}
{% include "client/includes/conference/default_description.html" with conf=event %}
<div class="ied-text" style="text-align: justify">
{{ default_description|safe }}
</div>
{# {% include "client/includes/conference/default_description.html" with conf=event %} #}
{% endif %}
</div>
<hr />

@ -189,7 +189,10 @@
{% if event.description %}
<div class="ied-text">{{ event.description|safe }}</div>
{% else %}
{% include "client/includes/conference/default_description.html" with conf=event %}
<div class="ied-text" style="text-align: justify">
{{ default_description|safe }}
</div>
{# {% include "client/includes/conference/default_description.html" with conf=event %} #}
{% endif %}
</div>
<hr />

@ -150,9 +150,12 @@
<div class="i-event-description">
<h2 class="ied-title">{% trans 'О выставке' %} {{ exposition.name|safe }}</h2>
{% if exposition.description %}
<div class="ied-text">{{ exposition.description|safe }}</div>
<div class="ied-text">{{ exposition.description|safe }}</div>
{%else %}
{% include "client/includes/exposition/default_description.html" with expo=exposition %}
<div class="ied-text" style="text-align: justify">
{{ default_description|safe }}
</div>
{# {% include "client/includes/exposition/default_description.html" with expo=exposition %} #}
{% endif %}
</div>

Loading…
Cancel
Save