From a8b3005740b78df0898b5659c2997e4fe7ff8d7a Mon Sep 17 00:00:00 2001 From: Slava Kyrachevsky Date: Fri, 3 Mar 2017 13:02:28 +0200 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81=20=D0=BE=D0=BF=D0=B8?= =?UTF-8?q?=D1=81=D0=B0=D0=BD=D0=B8=D1=8F=20=D1=81=D0=BE=D0=B1=D1=8B=D1=82?= =?UTF-8?q?=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/conference/views.py | 12 ++++--- apps/exposition/views.py | 13 +++++--- apps/functions/utils.py | 33 ------------------- apps/settings/forms.py | 4 +-- proj/settings.py | 8 ++--- .../exposition/exposition_object.html | 2 +- 6 files changed, 23 insertions(+), 49 deletions(-) diff --git a/apps/conference/views.py b/apps/conference/views.py index 6fea0850..6631a7d7 100644 --- a/apps/conference/views.py +++ b/apps/conference/views.py @@ -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): diff --git a/apps/exposition/views.py b/apps/exposition/views.py index ce81b82e..bfb82852 100644 --- a/apps/exposition/views.py +++ b/apps/exposition/views.py @@ -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() diff --git a/apps/functions/utils.py b/apps/functions/utils.py index 89498487..5d606de6 100644 --- a/apps/functions/utils.py +++ b/apps/functions/utils.py @@ -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 diff --git a/apps/settings/forms.py b/apps/settings/forms.py index 63c4758b..81dc507b 100644 --- a/apps/settings/forms.py +++ b/apps/settings/forms.py @@ -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) diff --git a/proj/settings.py b/proj/settings.py index 6d5dca18..c781bae0 100644 --- a/proj/settings.py +++ b/proj/settings.py @@ -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: '', diff --git a/templates/client/includes/exposition/exposition_object.html b/templates/client/includes/exposition/exposition_object.html index c219923e..898e627e 100644 --- a/templates/client/includes/exposition/exposition_object.html +++ b/templates/client/includes/exposition/exposition_object.html @@ -179,7 +179,7 @@

{% trans 'О выставке' %} {{ exposition.name|safe }}

{% if exposition.description %}
{{ exposition.description|safe }}
- {%elif default_description %} + {% elif default_description %}
{{ default_description|safe }}