фикс описания событий

remotes/origin/HEAD
Slava Kyrachevsky 9 years ago
parent 25515eec99
commit a8b3005740
  1. 12
      apps/conference/views.py
  2. 13
      apps/exposition/views.py
  3. 33
      apps/functions/utils.py
  4. 4
      apps/settings/forms.py
  5. 8
      proj/settings.py
  6. 2
      templates/client/includes/exposition/exposition_object.html

@ -13,6 +13,7 @@ from django.http import (
HttpResponseRedirect
)
from django.shortcuts import get_object_or_404
from django.template.loader import render_to_string
from django.utils import translation
from django.utils.translation import ugettext as _
from django.views.generic import DetailView
@ -22,7 +23,6 @@ from comments.views import CommentMixin
from functions.cache_mixin import CacheMixin, JitterCacheMixin
from functions.custom_views import ListView, ReverseOrderMixin
from functions.views_help import get_side_items
from functions.utils import CachedSting
from accounts.models import User
from article.models import Article
@ -439,9 +439,13 @@ class ConferenceDetail(ObjectStatMixin, CommentMixin, JitterCacheMixin, Metadata
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')),
}
'ru': render_to_string(
settings.DEFAULT_DESCRIPTION.get('c_description_ru')
),
'en': render_to_string(
settings.DEFAULT_DESCRIPTION.get('c_description_en')
),
}
def dispatch(self, request, *args, **kwargs):

@ -16,6 +16,7 @@ from django.http import (
HttpResponseRedirect
)
from django.shortcuts import get_object_or_404
from django.template.loader import render_to_string
from django.utils.translation import ugettext as _
from django.utils import translation
from django.views.generic import DetailView
@ -25,7 +26,6 @@ from functions.cache_mixin import JitterCacheMixin
from functions.custom_views import ExpoSearchView, ListView, ReverseOrderMixin
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
@ -33,7 +33,6 @@ from note.models import Note
from service.models import Service
from service.order_forms import AdvertiseForm
from service.views import order_forms, get_userlog_data
# from stats_collector.models import SectionStats
from stats_collector.mixin import (
ExpoSectionKindMixin,
ExpoSectionMixin,
@ -188,9 +187,13 @@ class ExpoDetail(ObjectStatMixin, JitterCacheMixin, MetadataMixin, DetailView):
.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')),
}
'ru': render_to_string(
settings.DEFAULT_DESCRIPTION.get('e_description_ru')
),
'en': render_to_string(
settings.DEFAULT_DESCRIPTION.get('e_description_en')
),
}
def get_context_data(self, **kwargs):
lang = translation.get_language()

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# from string import Template
import string
from datetime import timedelta, datetime
@ -16,35 +15,3 @@ def strfdelta(tdelta, fmt):
d["S"] = '{:02d}'.format(seconds)
t = DeltaTemplate(fmt)
return t.substitute(**d)
class CachedSting(object):
def __init__(self, path, timeout=None):
super(CachedSting, self).__init__()
self.path = path
self.timeout = timeout or timedelta(days=1)
self.get_object()
def __repr__(self):
return self.__str__()
def __str__(self):
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
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

@ -184,7 +184,7 @@ class EventDefaultDescriptionEditForm(forms.Form):
templates = settings.DEFAULT_DESCRIPTION
for field_name, path in templates.iteritems():
try:
with open(os.path.join(settings.SITE_ROOT, path), 'r') as f:
with open(os.path.join(settings.SITE_ROOT, 'templates', path), 'r') as f:
self.initial[field_name] = f.read()
except Exception as e:
print(e)
@ -196,7 +196,7 @@ class EventDefaultDescriptionEditForm(forms.Form):
templates = settings.DEFAULT_DESCRIPTION
for field_name, path in templates.iteritems():
try:
with open(os.path.join(settings.SITE_ROOT, path), 'w+') as f:
with open(os.path.join(settings.SITE_ROOT, 'templates', path), 'w+') as f:
f.write(self.cleaned_data.get(field_name).encode('utf-8'))
except Exception as e:
print(e)

@ -486,10 +486,10 @@ C_COUNTRY_CATALOG_KEY = 'conf_country_catalog'
E_CITY_CATALOG_KEY = 'expo_city_catalog'
E_COUNTRY_CATALOG_KEY = 'expo_country_catalog'
DEFAULT_DESCRIPTION = {
'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': 'client/includes/conference/default_description_ru.html',
'e_description_en': 'client/includes/conference/default_description_en.html',
'c_description_ru': 'client/includes/exposition/default_description_ru.html',
'c_description_en': 'client/includes/exposition/default_description_en.html',
}
PERIODIC = {
0: '',

@ -179,7 +179,7 @@
<h2 class="ied-title">{% trans 'О выставке' %} {{ exposition.name|safe }}</h2>
{% if exposition.description %}
<div class="ied-text">{{ exposition.description|safe }}</div>
{%elif default_description %}
{% elif default_description %}
<div class="ied-text" style="text-align: justify">
{{ default_description|safe }}
</div>

Loading…
Cancel
Save