From 09e78a6d3878aebdf416ab37ab51c1563f8da465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80=20=D0=9A=D0=BE=D1=82=D1=8E?= =?UTF-8?q?=D0=BA?= Date: Thu, 16 Apr 2015 16:34:31 +0300 Subject: [PATCH] Big import commit. Refactoring. Debuging --- article/forms.py | 40 +++- article/urls.py | 12 +- city/models.py | 6 +- company/search_indexes.py | 5 +- conference/management/commands/conf_old.py | 218 ++++++++++++++++++ conference/models.py | 14 +- conference/search_indexes.py | 29 +++ country/models.py | 10 +- exposition/management/commands/expo_old.py | 103 +++++++++ exposition/management/commands/test.py | 20 ++ exposition/models.py | 15 +- exposition/search_indexes.py | 5 +- exposition/urls.py | 129 +++++------ exposition/views.py | 8 +- functions/cache_mixin.py | 50 ++++ functions/form_check.py | 2 +- functions/model_mixin.py | 5 +- functions/models_methods.py | 18 ++ functions/search_forms.py | 13 +- functions/translate.py | 13 +- import_xls/admin.py | 11 +- import_xls/admin_urls.py | 3 +- import_xls/export_forms.py | 10 + meta/admin.py | 13 +- place_exposition/urls.py | 3 +- place_exposition/views.py | 3 +- proj/settings.py | 103 ++++++--- proj/urls.py | 64 +---- service/forms.py | 7 +- service/models.py | 5 +- service/order_forms.py | 6 +- service/views.py | 7 +- settings/conference_old_urls.py | 28 +++ settings/management/__init__.py | 1 + settings/management/commands/__init__.py | 1 + .../management/commands/update_views_cache.py | 22 ++ settings/old_urls.py | 79 +++++++ settings/redirect_views.py | 97 ++++++++ templates/admin/service/service_add.html | 39 ++++ .../client/exposition/exposition_by.html | 30 +-- .../conference/conference_object.html | 14 +- .../conference/conference_services.html | 12 + templates/client/includes/event_steps.html | 4 +- .../client/includes/exposition/statistic.html | 114 +++++---- .../client/includes/place/place_object.html | 23 +- templates/client/service/build_stand.html | 199 ++++++++++++++++ templates/debug_toolbar/base.html | 70 ++++++ templates/debug_toolbar/panels/cache.html | 69 ++++++ templates/debug_toolbar/panels/headers.html | 60 +++++ templates/debug_toolbar/panels/logging.html | 28 +++ templates/debug_toolbar/panels/profiling.html | 37 +++ templates/debug_toolbar/panels/request.html | 124 ++++++++++ templates/debug_toolbar/panels/settings.html | 17 ++ templates/debug_toolbar/panels/signals.html | 19 ++ templates/debug_toolbar/panels/sql.html | 95 ++++++++ .../debug_toolbar/panels/sql_explain.html | 37 +++ .../debug_toolbar/panels/sql_profile.html | 44 ++++ .../debug_toolbar/panels/sql_select.html | 41 ++++ .../debug_toolbar/panels/staticfiles.html | 57 +++++ .../debug_toolbar/panels/template_source.html | 14 ++ templates/debug_toolbar/panels/templates.html | 46 ++++ templates/debug_toolbar/panels/timer.html | 44 ++++ templates/debug_toolbar/panels/versions.html | 17 ++ templates/debug_toolbar/redirect.html | 16 ++ .../registration/activation_complete.html | 2 +- .../registration/activation_email_subject.txt | 3 +- theme/management/commands/old_urls.py | 52 +++++ theme/models.py | 4 + 68 files changed, 2213 insertions(+), 296 deletions(-) create mode 100644 conference/management/commands/conf_old.py create mode 100644 exposition/management/commands/expo_old.py create mode 100644 exposition/management/commands/test.py create mode 100644 functions/cache_mixin.py create mode 100644 settings/conference_old_urls.py create mode 100644 settings/management/__init__.py create mode 100644 settings/management/commands/__init__.py create mode 100644 settings/management/commands/update_views_cache.py create mode 100644 settings/old_urls.py create mode 100644 settings/redirect_views.py create mode 100644 templates/client/includes/conference/conference_services.html create mode 100644 templates/client/service/build_stand.html create mode 100644 templates/debug_toolbar/base.html create mode 100644 templates/debug_toolbar/panels/cache.html create mode 100644 templates/debug_toolbar/panels/headers.html create mode 100644 templates/debug_toolbar/panels/logging.html create mode 100644 templates/debug_toolbar/panels/profiling.html create mode 100644 templates/debug_toolbar/panels/request.html create mode 100644 templates/debug_toolbar/panels/settings.html create mode 100644 templates/debug_toolbar/panels/signals.html create mode 100644 templates/debug_toolbar/panels/sql.html create mode 100644 templates/debug_toolbar/panels/sql_explain.html create mode 100644 templates/debug_toolbar/panels/sql_profile.html create mode 100644 templates/debug_toolbar/panels/sql_select.html create mode 100644 templates/debug_toolbar/panels/staticfiles.html create mode 100644 templates/debug_toolbar/panels/template_source.html create mode 100644 templates/debug_toolbar/panels/templates.html create mode 100644 templates/debug_toolbar/panels/timer.html create mode 100644 templates/debug_toolbar/panels/versions.html create mode 100644 templates/debug_toolbar/redirect.html create mode 100644 theme/management/commands/old_urls.py diff --git a/article/forms.py b/article/forms.py index 72315264..0f7c8537 100644 --- a/article/forms.py +++ b/article/forms.py @@ -229,7 +229,45 @@ class BlogForm(forms.ModelForm): widget=forms.TextInput(attrs={'style':'width: 550px'})) """ + + class ArticleFilterForm(forms.Form): theme = forms.MultipleChoiceField(label=_(u'Тематика:'), required=False, choices=[(item.id, item.name) for item in Theme.objects.language().all()]) - tag = forms.CharField(label=_(u'Теги:'), widget=forms.HiddenInput(), required=False) \ No newline at end of file + tag = forms.CharField(label=_(u'Теги:'), widget=forms.HiddenInput(), required=False) + + ''' + + def __init__(self, *args, **kwargs): + """ + create dynamical translated fields fields + """ + super(ArticleFilterForm, self).__init__(*args, **kwargs) + ids = [item['theme_id'] for item in list(Article.objects.blogs().values('theme_id').distinct())] + self.fields['theme'] = forms.MultipleChoiceField(label=_(u'Тематика:'), required=False, + choices=[(item.id, item.name) for item in Theme.objects.language().filter(id__in=ids)]) + ''' + +class BlogFilterForm(forms.Form): + tag = forms.CharField(label=_(u'Теги:'), widget=forms.HiddenInput(), required=False) + + def __init__(self, *args, **kwargs): + """ + create dynamical translated fields fields + """ + super(BlogFilterForm, self).__init__(*args, **kwargs) + ids = [item['theme'] for item in list(Article.objects.blogs().values('theme').distinct())] + self.fields['theme'] = forms.MultipleChoiceField(label=_(u'Тематика:'), required=False, + choices=[(item.id, item.name) for item in Theme.objects.language().filter(id__in=ids)]) + +class NewsFilterForm(forms.Form): + tag = forms.CharField(label=_(u'Теги:'), widget=forms.HiddenInput(), required=False) + + def __init__(self, *args, **kwargs): + """ + create dynamical translated fields fields + """ + super(NewsFilterForm, self).__init__(*args, **kwargs) + ids = [item['theme'] for item in list(Article.objects.news().values('theme').distinct())] + self.fields['theme'] = forms.MultipleChoiceField(label=_(u'Тематика:'), required=False, + choices=[(item.id, item.name) for item in Theme.objects.language().filter(id__in=ids)]) \ No newline at end of file diff --git a/article/urls.py b/article/urls.py index ea86eb8f..d2476430 100644 --- a/article/urls.py +++ b/article/urls.py @@ -3,10 +3,10 @@ from django.conf.urls import patterns, url from views import BlogList, NewsList, BlogDetail, NewsDetail urlpatterns = patterns('', - url(r'blogs/page/(?P\d+)/$', BlogList.as_view()), - url(r'blogs/$', BlogList.as_view()), - url(r'news/page/(?P\d+)/$', NewsList.as_view()), - url(r'news/$', NewsList.as_view()), - url(r'blogs/(?P.*)/$', BlogDetail.as_view(), {'meta_id':19}), - url(r'news/(?P.*)/$', NewsDetail.as_view(), {'meta_id':19}), + url(r'^blogs/page/(?P\d+)/$', BlogList.as_view()), + url(r'^blogs/$', BlogList.as_view()), + url(r'^news/page/(?P\d+)/$', NewsList.as_view()), + url(r'^news/$', NewsList.as_view()), + url(r'^blogs/(?P.*)/$', BlogDetail.as_view(), {'meta_id':19}), + url(r'^news/(?P.*)/$', NewsDetail.as_view(), {'meta_id':19}), ) diff --git a/city/models.py b/city/models.py index 0e523876..77920a05 100644 --- a/city/models.py +++ b/city/models.py @@ -17,7 +17,7 @@ from webinar.models import Webinar # custom functions from functions.db import db_table_exists from functions.signal_handlers import post_save_handler -from functions.models_methods import ExpoManager +from functions.models_methods import ExpoManager, CityManager #check if table exist and create flags if true flags = [str(item.url) for item in Service.objects.all()] if db_table_exists('service_service') else [] @@ -31,6 +31,7 @@ class City(TranslatableModel): """ objects = ExpoManager() + used = CityManager() catalog = '/city/' services = BitField(flags=flags) @@ -62,6 +63,9 @@ class City(TranslatableModel): created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) + class Meta: + ordering = ['translations__name'] + def __unicode__(self): return self.lazy_translation_getter('name', self.pk) diff --git a/company/search_indexes.py b/company/search_indexes.py index 1d197d9e..7a3f23fb 100644 --- a/company/search_indexes.py +++ b/company/search_indexes.py @@ -35,4 +35,7 @@ class CompanyExpositionIndex(indexes.SearchIndex, indexes.Indexable, ExpoSearchM def index_queryset(self, using=None): - return self.get_model().objects.filter() \ No newline at end of file + return self.get_model().objects.filter() + + def get_updated_field(self): + return 'modified' \ No newline at end of file diff --git a/conference/management/commands/conf_old.py b/conference/management/commands/conf_old.py new file mode 100644 index 00000000..3ccb0658 --- /dev/null +++ b/conference/management/commands/conf_old.py @@ -0,0 +1,218 @@ +# -*- coding: utf-8 -*- +import os +import MySQLdb +from MySQLdb.cursors import DictCursor +from django.core.management.base import BaseCommand +from django.conf import settings +from conference.models import Conference +from django.core.files import File +from functions.translate import fill_with_signal +from country.models import Country +from city.models import City + +class Command(BaseCommand): + def handle(self, *args, **options): + db = MySQLdb.connect(host="localhost", + user="expomap", + passwd="7FbLtAGjse", + db="old_db", + charset='utf8', + cursorclass=DictCursor) + cursor = db.cursor() + sql = """ + SELECT products.products_id as id, products_date_added as created, products_last_modified as modified, + discount, expohit, ufi, products_name as name, products_description as description, + products_short_description as main_title, products_viewed as viewed, products_period as period, + products_org as organiser,products_products as products, products_official as web_page, + products_img1 as logo, products_startdate as data_begin, products_enddate as data_end, + url as old_url, places_id + FROM `products` + LEFT JOIN `products_description` ON products.products_id=products_description.products_id + WHERE `products_status` =1 + AND `conference` =1 AND places_id >0 + """ + cursor.execute(sql) + result = cursor.fetchall() + + names = [item['name'] for item in result] + media = settings.MEDIA_ROOT.replace('media/', '') + for i, item in enumerate(result): + name = item['name'] + print('number: %d, name: %s'%(i, name.encode('utf8'))) + if Conference.objects.filter(translations__name=name).exists(): + continue + + data_begin = item['data_begin'] + data_end= item['data_end'] + + + place_id = item['places_id'] # convert to country and city + country, city = get_places(place_id) + #if isinstance(city, unicode): + #print(city.encode('utf8')) + # value = bad_cities.get(city) + # if value: + # bad_cities[city] = value + 1 + # else: + # bad_cities[city] = 1 + + # counter += 1 + # continue + + if not country or not city: + continue + + old_url = item['old_url'] + periodic = item['period'] + periodic = get_periodic(periodic) + web_page = item['web_page'] + currency = 'USD' + expohit = item['expohit'] + ufi = item['ufi'] + if ufi: + ufi = 1 + else: + ufi = 0 + + created = item['created'] + modified = item['modified'] + + + + data = {'name_ru': name, 'main_title_ru': item['main_title'], 'description_ru': item['description'], + 'main_themes_ru': item['products'], 'time_ru': '', 'discount_description_ru': '', 'title_ru': '', + 'descriptions_ru': '', 'keywords_ru': ''} + + conference = Conference(data_begin=data_begin, data_end=data_end, city=city, country=country, + web_page=web_page, old_url=old_url, periodic=periodic, currency=currency, + expohit=expohit, created=created, modified=modified) + try: + fill_with_signal(Conference, conference, data) + except: + continue + print('conference: %s'%str(conference)) + + + + #print(len(bad_cities.keys())) + #print(len(result)) + #print(Conference.objects.filter().count()) + #print(Conference.objects.exclude(translations__name__in=names).count()) + + +def get_periodic(value): + PERIODIC = {u'Ежегодно': 1.0, u'Раз в 2 года': 0.5, u'2 раза в год': 2.0, u'4 раза в год': 4.0, + u'3 раза в год': 3.0, u'Раз в 3 года': 0.33, u'Раз в 4 года': 0.25, u'5 раз в год': 5.0, + u'Раз в два года': 0.5, u'Три раза в год': 3.0} + return PERIODIC.get(value, 0) + +def get_logo(value): + if not value: + return None + if value.startswith('..'): + value = value.replace('..', 'media') + elif value.startswith('/'): + value = 'media'+value + + return value + +def get_places(place_id): + db = MySQLdb.connect(host="localhost", + user="expomap", + passwd="7FbLtAGjse", + db="old_db", + charset='utf8', + cursorclass=DictCursor) + cursor = db.cursor() + sql_city = """ + SELECT title as city_name, url as city_old_url, inflect as city_inflect, parent_id as country_id + FROM `products_places` + WHERE `places_id` =%s + """%place_id + + cursor.execute(sql_city) + result = cursor.fetchone() + city_name, city_old_url, city_inflect = result['city_name'], result['city_old_url'], result['city_inflect'] + country_id = result['country_id'] + if city_name: + city_name = city_name.strip() + if city_name==u'Гонконг': + country = Country.objects.get(id=76) + city = City.objects.get(url='hong-kong') + return (country, city) + + sql_country = """ + SELECT title as country_name, url as country_old_url, inflect as country_inflect + FROM `products_places` + WHERE `places_id` =%s + """%country_id + + cursor.execute(sql_country) + result = cursor.fetchone() + country_name, country_old_url, country_inflect = result['country_name'], result['country_old_url'], result['country_inflect'] + country_name = filter_country(country_name) + try: + country = Country.objects.get(translations__name=country_name) + except Country.DoesNotExist: + country = None + except Country.MultipleObjectsReturned: + country = Country.objects.filter(translations__name=country_name)[0] + + city_name = filter_city(city_name) + try: + city = City.objects.get(translations__name=city_name, country=country) + except City.DoesNotExist: + #city = city_name + city = None + #print(city_name.encode('utf8')) + except City.MultipleObjectsReturned: + city = City.objects.filter(translations__name=city_name, country=country)[0] + #print('----------------') + #print(city_name.encode('utf8')) + #print('----------------') + + + + return (country, city) + +def filter_country(name): + if name == u'ЮАР': + name = u'Южно-Африканская Республика' + elif name == u'Танзания': + name = u'Объединенная Республика Танзания' + elif name == u'Гавайи': + name = u'США' + elif name == u'Бирма': + name = u'Мьянма' + elif name == u'Босния и Герцоговина': + name = u'Босния и Герцеговина' + + return name + +def filter_city(name): + cities = {u'Дели': u'Нью-Дели', u'Дэли': u'Нью-Дели', u'Пуна': u'Пуне', u'Лонг-Бич': u'Лонг Бич', + u'Калифорния': u'Лос-Анджелес', u'Санта-Клара': u'Санта Клара', u'Скотсдейл': u'Скоттсдейл', + u'Пенанг': u'Пинанг', u'Лейк Буэна Виста': u'Лейк-Буэна-Виста', u'Лиллестрём': u'Лиллештром', + u'Хертогенбош': u'Ден Бош', u'Марбелла': u'Марбелья', u'Лилль': u'Лилль', u'Ла Рош-сюр-Форон': u'Ла-Рош-сюр-Форон', + u'Эль-Кувейт': u'Кувейт', u'Харрогит': u'Харрогейт', u'Иокогама': u'Йокогама', u'Палм Бич': u'Палм-Бич', + u'Фрайбург': u'Фрейбург в Брейсгау', u'Колмар': u'Кольмар', u'Мускат': u'Маскат', u'Бад Зальцуфлен': u'Бад-Зальцуфлен'} + new_name = cities.get(name) + if new_name: + return new_name + else: + return name + + + + +""" + # convert logo + logo = item['logo'] + logo = get_logo(logo) + if logo and logo.startswith('media/images'): + file = media + logo + if os.path.isfile(file): + f = open('mytest.pdf') + else: + logo = None +""" \ No newline at end of file diff --git a/conference/models.py b/conference/models.py index 8a970194..4ba66129 100644 --- a/conference/models.py +++ b/conference/models.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from django.utils.translation import ugettext as _ from django.db import models +from django.db.models import Q from django.db.models.signals import post_save, pre_save from django.contrib.contenttypes import generic from exposition.manager import ClientManager @@ -19,7 +20,7 @@ from functions.model_mixin import EventMixin, ExpoMixin from functions.models_methods import hvad_to_dict # check if table exist and create flags if true -flags = [str(item.id) for item in Service.objects.all()] if db_table_exists('service_service') else [] +flags = [item.url for item in Service.objects.all()] if db_table_exists('service_service') else [] from django.conf import settings CURRENCY = settings.CURRENCY @@ -40,6 +41,7 @@ class Conference(TranslatableModel, EventMixin, ExpoMixin): enable = ClientManager() url = models.SlugField(unique=True, max_length=255) + old_url = models.SlugField(unique=True, max_length=255) data_begin = models.DateField(verbose_name='Дата начала') data_end = models.DateField(verbose_name='Дата окончания') services = BitField(flags=flags) @@ -116,6 +118,16 @@ class Conference(TranslatableModel, EventMixin, ExpoMixin): def __unicode__(self): return self.lazy_translation_getter('name', unicode(self.pk)) + def get_services(self): + + country_ids = [item for item, bool in self.country.services if bool==True] + ids = [item for item, bool in self.services if bool==True] + + qs = Service.objects.filter(Q(Q(url__in=country_ids) & Q(type=Service.type.conference)) | Q(url__in=ids)) + + return list(qs) + #return list(Service.objects.language().filter(url__in=ids, type=Service.type.conference).order_by('sort')) + def get_nearest_events(self): conferences = Conference.objects.all()[:5] return conferences diff --git a/conference/search_indexes.py b/conference/search_indexes.py index 64929dca..3266fb52 100644 --- a/conference/search_indexes.py +++ b/conference/search_indexes.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from haystack import indexes from models import Conference @@ -5,6 +6,32 @@ from models import Conference class ConferenceIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) where = indexes.MultiValueField() + url = indexes.CharField() + data_begin = indexes.DateField(model_attr='data_begin') + data_end = indexes.DateField(model_attr='data_end') + theme = indexes.MultiValueField() + tag = indexes.MultiValueField() + country_id = indexes.IntegerField() + city_id = indexes.IntegerField() + area_id = indexes.IntegerField() + content_auto = indexes.EdgeNgramField() + form_name = indexes.CharField() + # translated fields + name_en = indexes.CharField() + name_ru = indexes.CharField() + catalog_name_en = indexes.CharField() + catalog_name_ru = indexes.CharField() + + def prepare_form_name(self, obj): + return None + + def prepare_catalog_name_en(self, obj): + return u'Conferences' + + def prepare_catalog_name_ru(self, obj): + return u'Конференции' + + def prepare_where(self, obj): country = [tr.name for tr in obj.country.translations.all()] city = [tr.name for tr in obj.city.translations.all()] @@ -18,3 +45,5 @@ class ConferenceIndex(indexes.SearchIndex, indexes.Indexable): return self.get_model().objects.filter(is_published=True) + def get_updated_field(self): + return "modified" diff --git a/country/models.py b/country/models.py index 4b387d58..0f2a1381 100644 --- a/country/models.py +++ b/country/models.py @@ -40,6 +40,11 @@ class CountryManager(TranslationManager): except: return None + def expo_countries(self): + countries_id = [item['country_id'] for item in Exposition.objects.values('country_id').distinct()] + return self.language().filter(id__in=countries_id) + + class AreaManager(TranslationManager): def all_sorted(self): """ @@ -92,6 +97,7 @@ class Country(TranslatableModel): """ objects = CountryManager() + used = CountryManager() catalog = '/country/' services = BitField(flags=flags) @@ -138,8 +144,8 @@ class Country(TranslatableModel): ) country_code = models.CharField(max_length=2) -# class Meta: -# ordering = ['translations__name'] + class Meta: + ordering = ['translations__name'] def __unicode__(self): return self.lazy_translation_getter('name', unicode(self.pk)) diff --git a/exposition/management/commands/expo_old.py b/exposition/management/commands/expo_old.py new file mode 100644 index 00000000..03a53ce8 --- /dev/null +++ b/exposition/management/commands/expo_old.py @@ -0,0 +1,103 @@ +# -*- coding: utf-8 -*- +import os +import MySQLdb +from MySQLdb.cursors import DictCursor +from django.core.management.base import BaseCommand +from django.conf import settings +from exposition.models import Exposition +from conference.management.commands.conf_old import filter_city, filter_country, get_periodic, get_logo, get_places +from django.core.files import File +from functions.translate import fill_with_signal +from country.models import Country +from city.models import City + +file_path = settings.MEDIA_ROOT + 'exposition/bad_expos.txt' + +class Command(BaseCommand): + def handle(self, *args, **options): + db = MySQLdb.connect(host="localhost", + user="expomap", + passwd="7FbLtAGjse", + db="old_db", + charset='utf8', + cursorclass=DictCursor) + cursor = db.cursor() + sql = """ + SELECT products.products_id as id, products_date_added as created, products_last_modified as modified, + discount, expohit, ufi, products_name as name, products_description as description, + products_short_description as main_title, products_viewed as viewed, products_period as period, + products_org as organiser,products_products as products, products_official as web_page, + products_img1 as logo, products_startdate as data_begin, products_enddate as data_end, + url as old_url, places_id + FROM `products` + LEFT JOIN `products_description` ON products.products_id=products_description.products_id + WHERE `products_status` =1 + AND `conference` =0 AND places_id >0 + """ + + cursor.execute(sql) + result = cursor.fetchall() + + names = [item['name'] for item in result] + #media = settings.MEDIA_ROOT.replace('media/', '') + #counter = 0 + #bad_cities = {} + + bad_expos = [] + for i, item in enumerate(result): + + print('number: %d, errors: %d'%(i, len(bad_expos))) + name = item['name'] + if Exposition.objects.filter(translations__name=name).exists(): + msg = u'%s|||%s|||%s'%(name, item['old_url'], 'already exist') + bad_expos.append(msg) + continue + + data_begin = item['data_begin'] + data_end= item['data_end'] + + + place_id = item['places_id'] # convert to country and city + country, city = get_places(place_id) + + if not country or not city: + msg = u'%s|||%s|||%s'%(name, item['old_url'], 'bad country or city') + bad_expos.append(msg) + continue + old_url = item['old_url'] + periodic = item['period'] + periodic = get_periodic(periodic) + web_page = item['web_page'] + currency = 'USD' + expohit = item['expohit'] + ufi = item['ufi'] + if ufi: + ufi = 1 + else: + ufi = 0 + + created = item['created'] + modified = item['modified'] + + data = {'name_ru': name, 'main_title_ru': item['main_title'], 'description_ru': item['description'], + 'products_ru': item['products'], 'discount_description_ru': '', 'time_ru': '', 'price_day_ru':'', + 'price_all_ru': '', 'price_day_bar_ru': '', 'price_all_bar_ru': '', 'stat_countries_ru': '', + 'pre_condition_ru':'', 'stand_condition_ru': '', 'visit_note_ru': '', 'participation_note_ru': '', + 'title_ru': '', 'descriptions_ru': '', 'keywords_ru': ''} + + exposition = Exposition(data_begin=data_begin, data_end=data_end, city=city, country=country, + web_page=web_page, old_url=old_url, periodic=periodic, currency=currency, + expohit=expohit, created=created, modified=modified, quality_label=ufi) + + try: + fill_with_signal(Exposition, exposition, data) + except Exception as e: + msg = u'%s|||%s|||%s'%(name, item['old_url'], str(e)) + bad_expos.append(msg) + continue + + print('saving file') + file = open(file_path, 'w') + for item in bad_expos: + file.write("%s\n" % item) + file.close() \ No newline at end of file diff --git a/exposition/management/commands/test.py b/exposition/management/commands/test.py new file mode 100644 index 00000000..271b6d8d --- /dev/null +++ b/exposition/management/commands/test.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from django.core.management.base import BaseCommand +from meta.models import MetaSetting + + +class Command(BaseCommand): + def handle(self, *args, **options): + a = MetaSetting.objects.filter(translations__h1__contains='«').count() + qs = MetaSetting.objects.language('ru').all() + for item in qs: + item.title = item.title.replace(u'«', u'').replace(u'»', u'') + item.description = item.title.replace(u'«', u'').replace(u'»', u'') + item.h1 = item.h1.replace(u'«', u'').replace(u'»', u'') + #item.save() + + + + + + diff --git a/exposition/models.py b/exposition/models.py index 777a9b48..ed205f6a 100644 --- a/exposition/models.py +++ b/exposition/models.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import copy, datetime from django.db import models +from django.db.models import Q from django.db.models.signals import post_save, pre_save from django.utils.translation import ugettext as _ from django.utils import translation @@ -36,7 +37,7 @@ BIT_AUDIENCE = settings.BIT_AUDIENCE CURRENCY = settings.CURRENCY # check if table exist and create flags if true -flags = [str(item.id) for item in Service.objects.all()] if db_table_exists('service_service') else [] +flags = [item.url for item in Service.objects.all()] if db_table_exists('service_service') else [] class Exposition(TranslatableModel, EventMixin, ExpoMixin): @@ -53,6 +54,7 @@ class Exposition(TranslatableModel, EventMixin, ExpoMixin): event_type = 'expo' url = models.SlugField(unique=True, max_length=255) + old_url = models.SlugField(unique=True, max_length=255) data_begin = models.DateField(verbose_name='Дата начала') data_end = models.DateField(verbose_name='Дата окончания') services = BitField(flags=flags) @@ -162,6 +164,15 @@ class Exposition(TranslatableModel, EventMixin, ExpoMixin): def __unicode__(self): return self.lazy_translation_getter('name', unicode(self.pk)) + def get_services(self): + + country_ids = [item for item, bool in self.country.services if bool==True] + ids = [item for item, bool in self.services if bool==True] + + qs = Service.objects.filter(Q(Q(url__in=country_ids) & Q(type=Service.type.expo)) | Q(url__in=ids)) + + return list(qs) + def get_parent(self): return {} @@ -232,7 +243,7 @@ class Exposition(TranslatableModel, EventMixin, ExpoMixin): for k, v in BIT_AUDIENCE: for item in checked: if item == k: - audience.append(v) + audience.append(unicode(v)) return ', '.join(audience) diff --git a/exposition/search_indexes.py b/exposition/search_indexes.py index 906c835e..630015b9 100644 --- a/exposition/search_indexes.py +++ b/exposition/search_indexes.py @@ -48,4 +48,7 @@ class ExpositionIndex(indexes.SearchIndex, indexes.Indexable, ExpoSearchMixin): elif lang=='en': return self.name_en else: - return self.name_ru \ No newline at end of file + return self.name_ru + + def get_updated_field(self): + return 'modified' \ No newline at end of file diff --git a/exposition/urls.py b/exposition/urls.py index 03f6711a..b747313b 100644 --- a/exposition/urls.py +++ b/exposition/urls.py @@ -4,87 +4,80 @@ from views import ExpositionStatistic, ExpositionPrice,\ ExpositionProgramme, ExpositionSearchView, ExpositionByCountry, ExpositionByTheme, ExpositionByCity -from django.http import HttpResponse +from django.views.decorators.cache import cache_page from views import ExpositionServiceView from views import ExpoCountryCatalog, ExpoCityCatalog, ExpoThemeCatalog, ExpoTagCatalog, ExpoList, ExpoDetail,\ ExpoVisitors, ExpoMembers urlpatterns = patterns('', - url(r'expo/add-note/(?P.*)/$', 'exposition.views.add_note'), - url(r'exposition-add-calendar/(?P\d+)/$', 'exposition.views.exposition_add_calendar'), - url(r'exposition-visit/(?P\d+)/$', 'exposition.views.exposition_visit'), + url(r'^expo/add-note/(?P.*)/$', 'exposition.views.add_note'), + url(r'^exposition-add-calendar/(?P\d+)/$', 'exposition.views.exposition_add_calendar'), + url(r'^exposition-visit/(?P\d+)/$', 'exposition.views.exposition_visit'), # search - url(r'expo/search/', ExpositionSearchView.as_view()), + url(r'^expo/search/', ExpositionSearchView.as_view()), # country catalog - url(r'expo/country/$', ExpositionByCountry.as_view()), - url(r'expo/country/(?P.*)/(?P\d+)/(?P.*)/page/(?P\d+)/$', ExpoCountryCatalog.as_view(), {'meta_id':7}), - url(r'expo/country/(?P.*)/(?P\d+)/page/(?P\d+)/$', ExpoCountryCatalog.as_view(), {'meta_id':6}), - url(r'expo/country/(?P.*)/page/(?P\d+)/$', ExpoCountryCatalog.as_view(), {'meta_id':5}), - url(r'expo/country/(?P.*)/(?P\d+)/(?P.*)/$', ExpoCountryCatalog.as_view(), {'meta_id':7}), - url(r'expo/country/(?P.*)/(?P\d+)/$', ExpoCountryCatalog.as_view(), {'meta_id':6}), - url(r'expo/country/(?P.*)/$', ExpoCountryCatalog.as_view(), {'meta_id':5}), + url(r'^expo/country/$', ExpositionByCountry.as_view()), + url(r'^expo/country/(?P.*)/(?P\d+)/(?P.*)/page/(?P\d+)/$', ExpoCountryCatalog.as_view(), {'meta_id':7}), + url(r'^expo/country/(?P.*)/(?P\d+)/page/(?P\d+)/$', ExpoCountryCatalog.as_view(), {'meta_id':6}), + url(r'^expo/country/(?P.*)/page/(?P\d+)/$', ExpoCountryCatalog.as_view(), {'meta_id':5}), + url(r'^expo/country/(?P.*)/(?P\d+)/(?P.*)/$', ExpoCountryCatalog.as_view(), {'meta_id':7}), + url(r'^expo/country/(?P.*)/(?P\d+)/$', ExpoCountryCatalog.as_view(), {'meta_id':6}), + url(r'^expo/country/(?P.*)/$', ExpoCountryCatalog.as_view(), {'meta_id':5}), # city catalog - url(r'expo/city/$', ExpositionByCity.as_view()), - url(r'expo/city/(?P.*)/(?P\d+)/(?P.*)/page/(?P\d+)/$', ExpoCityCatalog.as_view(), {'meta_id':10}), - url(r'expo/city/(?P.*)/(?P\d+)/page/(?P\d+)/$', ExpoCityCatalog.as_view(), {'meta_id':9}), - url(r'expo/city/(?P.*)/page/(?P\d+)/$', ExpoCityCatalog.as_view(), {'meta_id':8}), - url(r'expo/city/(?P.*)/(?P\d+)/(?P.*)/$', ExpoCityCatalog.as_view(), {'meta_id':10}), - url(r'expo/city/(?P.*)/(?P\d+)/$', ExpoCityCatalog.as_view(), {'meta_id':9}), - url(r'expo/city/(?P.*)/$', ExpoCityCatalog.as_view(), {'meta_id':8}), + url(r'^expo/city/$', ExpositionByCity.as_view()), + url(r'^expo/city/(?P.*)/(?P\d+)/(?P.*)/page/(?P\d+)/$', ExpoCityCatalog.as_view(), {'meta_id':10}), + url(r'^expo/city/(?P.*)/(?P\d+)/page/(?P\d+)/$', ExpoCityCatalog.as_view(), {'meta_id':9}), + url(r'^expo/city/(?P.*)/page/(?P\d+)/$', ExpoCityCatalog.as_view(), {'meta_id':8}), + url(r'^expo/city/(?P.*)/(?P\d+)/(?P.*)/$', ExpoCityCatalog.as_view(), {'meta_id':10}), + url(r'^expo/city/(?P.*)/(?P\d+)/$', ExpoCityCatalog.as_view(), {'meta_id':9}), + url(r'^expo/city/(?P.*)/$', ExpoCityCatalog.as_view(), {'meta_id':8}), # theme catalog - url(r'expo/theme/$', ExpositionByTheme.as_view()), - - url(r'expo/theme/(?P.*)/country/(?P.*)/page/(?P\d+)/$', ExpoThemeCatalog.as_view(), {'meta_id':44}), - url(r'expo/theme/(?P.*)/country/(?P.*)/$', ExpoThemeCatalog.as_view(), {'meta_id':44}), - url(r'expo/theme/(?P.*)/city/(?P.*)/page/(?P\d+)/$', ExpoThemeCatalog.as_view(), {'meta_id':42}), - url(r'expo/theme/(?P.*)/city/(?P.*)/$', ExpoThemeCatalog.as_view(), {'meta_id':42}), - - url(r'expo/theme/(?P.*)/(?P\d+)/(?P.*)/page/(?P\d+)/$', ExpoThemeCatalog.as_view(), {'meta_id':13}), - url(r'expo/theme/(?P.*)/(?P\d+)/page/(?P\d+)/$', ExpoThemeCatalog.as_view(), {'meta_id':12}), - url(r'expo/theme/(?P.*)/page/(?P\d+)/$', ExpoThemeCatalog.as_view(), {'meta_id':11}), - url(r'expo/theme/(?P.*)/(?P\d+)/(?P.*)/$', ExpoThemeCatalog.as_view(), {'meta_id':13}), - url(r'expo/theme/(?P.*)/(?P\d+)/$', ExpoThemeCatalog.as_view(), {'meta_id':12}), - url(r'expo/theme/(?P.*)/$', ExpoThemeCatalog.as_view(), {'meta_id':11}), + url(r'^expo/theme/$', ExpositionByTheme.as_view()), + url(r'^expo/theme/(?P.*)/country/(?P.*)/(?P\d+)/(?P.*)/page/(?P\d+)/$', ExpoThemeCatalog.as_view(), {'meta_id':44}), + url(r'^expo/theme/(?P.*)/country/(?P.*)/(?P\d+)/(?P.*)/$', ExpoThemeCatalog.as_view(), {'meta_id':44}), + url(r'^expo/theme/(?P.*)/country/(?P.*)/(?P\d+)/page/(?P\d+)/$', ExpoThemeCatalog.as_view(), {'meta_id':44}), + url(r'^expo/theme/(?P.*)/country/(?P.*)/(?P\d+)/$', ExpoThemeCatalog.as_view(), {'meta_id':44}), + url(r'^expo/theme/(?P.*)/country/(?P.*)/page/(?P\d+)/$', ExpoThemeCatalog.as_view(), {'meta_id':44}), + url(r'^expo/theme/(?P.*)/country/(?P.*)/$', ExpoThemeCatalog.as_view(), {'meta_id':44}), + + url(r'^expo/theme/(?P.*)/city/(?P.*)/(?P\d+)/(?P.*)/page/(?P\d+)/$', ExpoThemeCatalog.as_view(), {'meta_id':42}), + url(r'^expo/theme/(?P.*)/city/(?P.*)/(?P\d+)/(?P.*)/$', ExpoThemeCatalog.as_view(), {'meta_id':42}), + url(r'^expo/theme/(?P.*)/city/(?P.*)/(?P\d+)/page/(?P\d+)/$', ExpoThemeCatalog.as_view(), {'meta_id':42}), + url(r'^expo/theme/(?P.*)/city/(?P.*)/(?P\d+)/$', ExpoThemeCatalog.as_view(), {'meta_id':42}), + + url(r'^expo/theme/(?P.*)/city/(?P.*)/page/(?P\d+)/$', ExpoThemeCatalog.as_view(), {'meta_id':42}), + url(r'^expo/theme/(?P.*)/city/(?P.*)/$', ExpoThemeCatalog.as_view(), {'meta_id':42}), + url(r'^expo/theme/(?P.*)/(?P\d+)/(?P.*)/page/(?P\d+)/$', ExpoThemeCatalog.as_view(), {'meta_id':13}), + url(r'^expo/theme/(?P.*)/(?P\d+)/page/(?P\d+)/$', ExpoThemeCatalog.as_view(), {'meta_id':12}), + url(r'^expo/theme/(?P.*)/page/(?P\d+)/$', ExpoThemeCatalog.as_view(), {'meta_id':11}), + url(r'^expo/theme/(?P.*)/(?P\d+)/(?P.*)/$', ExpoThemeCatalog.as_view(), {'meta_id':13}), + url(r'^expo/theme/(?P.*)/(?P\d+)/$', ExpoThemeCatalog.as_view(), {'meta_id':12}), + url(r'^expo/theme/(?P.*)/$', ExpoThemeCatalog.as_view(), {'meta_id':11}), # tag catalog - url(r'expo/tag/(?P.*)/(?P\d+)/(?P.*)/page/(?P\d+)/$', ExpoTagCatalog.as_view(), {'meta_id':17}), - url(r'expo/tag/(?P.*)/(?P\d+)/page/(?P\d+)/$', ExpoTagCatalog.as_view(), {'meta_id':15}), - url(r'expo/tag/(?P.*)/page/(?P\d+)/$', ExpoTagCatalog.as_view(), {'meta_id':14}), - url(r'expo/tag/(?P.*)/(?P\d+)/(?P.*)/$', ExpoTagCatalog.as_view(), {'meta_id':17}), - url(r'expo/tag/(?P.*)/(?P\d+)/$', ExpoTagCatalog.as_view(), {'meta_id':15}), - url(r'expo/tag/(?P.*)/$', ExpoTagCatalog.as_view(), {'meta_id':14}), + url(r'^expo/tag/(?P.*)/(?P\d+)/(?P.*)/page/(?P\d+)/$', ExpoTagCatalog.as_view(), {'meta_id':17}), + url(r'^expo/tag/(?P.*)/(?P\d+)/page/(?P\d+)/$', ExpoTagCatalog.as_view(), {'meta_id':15}), + url(r'^expo/tag/(?P.*)/page/(?P\d+)/$', ExpoTagCatalog.as_view(), {'meta_id':14}), + url(r'^expo/tag/(?P.*)/(?P\d+)/(?P.*)/$', ExpoTagCatalog.as_view(), {'meta_id':17}), + url(r'^expo/tag/(?P.*)/(?P\d+)/$', ExpoTagCatalog.as_view(), {'meta_id':15}), + url(r'^expo/tag/(?P.*)/$', ExpoTagCatalog.as_view(), {'meta_id':14}), # expo additional pages - url(r'expo/(?P.*)/statistic/$', ExpositionStatistic.as_view()), - url(r'expo/(?P.*)/price/$', ExpositionPrice.as_view()), - url(r'expo/(?P.*)/program/$', ExpositionProgramme.as_view()), - url(r'expo/(?P.*)/visitors/page/(?P\d+)/$', ExpoVisitors.as_view()), - url(r'expo/(?P.*)/visitors/$', ExpoVisitors.as_view()), - url(r'expo/(?P.*)/members/page/(?P\d+)/$', ExpoMembers.as_view()), - url(r'expo/(?P.*)/members/$', ExpoMembers.as_view()), - url(r'expo/(?P.*)/service/(?P.*)/', ExpositionServiceView.as_view()), - + url(r'^expo/(?P.*)/statistic/$', ExpositionStatistic.as_view()), + url(r'^expo/(?P.*)/price/$', ExpositionPrice.as_view()), + url(r'^expo/(?P.*)/program/$', ExpositionProgramme.as_view()), + url(r'^expo/(?P.*)/visitors/page/(?P\d+)/$', ExpoVisitors.as_view()), + url(r'^expo/(?P.*)/visitors/$', ExpoVisitors.as_view()), + url(r'^expo/(?P.*)/members/page/(?P\d+)/$', ExpoMembers.as_view()), + url(r'^expo/(?P.*)/members/$', ExpoMembers.as_view()), + url(r'^expo/(?P.*)/service/(?P.*)/', ExpositionServiceView.as_view()), # expo list - url(r'expo/(?P\d+)/(?P.*)/page/(?P\d+)/$', ExpoList.as_view(), {'meta_id':4}), - url(r'expo/(?P\d+)/page/(?P\d+)/$', ExpoList.as_view(), {'meta_id':3}), - url(r'expo/(?P\d+)/(?P.*)/$', ExpoList.as_view(), {'meta_id':4}), - url(r'expo/(?P\d+)/$', ExpoList.as_view(), {'meta_id':3}), - url(r'expo/page/(?P\d+)/$', ExpoList.as_view(), {'meta_id':2}), + url(r'^expo/(?P\d+)/(?P.*)/page/(?P\d+)/$', ExpoList.as_view(), {'meta_id':4}), + url(r'^expo/(?P\d+)/page/(?P\d+)/$', ExpoList.as_view(), {'meta_id':3}), + url(r'^expo/(?P\d+)/(?P.*)/$', ExpoList.as_view(), {'meta_id':4}), + url(r'^expo/(?P\d+)/$', ExpoList.as_view(), {'meta_id':3}), + url(r'^expo/page/(?P\d+)/$', ExpoList.as_view(), {'meta_id':2}), # expo page - url(r'expo/(?P.*)/$', ExpoDetail.as_view(), {'meta_id':18}),# event - url(r'expo/$', ExpoList.as_view(), {'meta_id':2}), - - - - - - - - - #url(r'expo/(?P.*)/service/(?P.*)/$', ExpositionServiceView.as_view()), - - #url(r'expo/(?P.*)/service/(?P.*)/$', ExpositionServiceView.as_view()), - #url(r'expo/(?P.*)/statistic/$', ExpositionStatistic.as_view()), - - + url(r'^expo/(?P.*)/$', ExpoDetail.as_view(), {'meta_id':18}),# event + url(r'^expo/$', ExpoList.as_view() , {'meta_id':2}), ) diff --git a/exposition/views.py b/exposition/views.py index ac75bfe9..440ab266 100644 --- a/exposition/views.py +++ b/exposition/views.py @@ -68,13 +68,19 @@ class ExpositionByTheme(ExpositionBy): .order_by('translations__name').distinct() -class ExpositionByCity(ExpositionBy): +from functions.cache_mixin import CacheMixin + +class ExpositionByCity(CacheMixin, ExpositionBy): + cache_timeout = 60 model = City title1 = _(u'По городам') title2 = _(u'Выставки мира по городам') catalog = 'city/' def get_queryset(self): + + #cities_id = [item['city_id'] for item in Exposition.objects.values('city_id').distinct()] + #return self.model.objects.language().filter(id__in=cities_id).order_by('translations__name').distinct() lang = translation.get_language() return self.model.objects.select_related('exposition_city')\ .filter(exposition_city__city__isnull=False, translations__language_code=lang)\ diff --git a/functions/cache_mixin.py b/functions/cache_mixin.py new file mode 100644 index 00000000..9e8474f2 --- /dev/null +++ b/functions/cache_mixin.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +import random +from django.contrib.auth.decorators import login_required +from django.utils.cache import patch_response_headers +from django.utils.decorators import method_decorator +from django.views.decorators.cache import cache_page, never_cache +from django.views.decorators.csrf import csrf_exempt + +class NeverCacheMixin(object): + @method_decorator(never_cache) + def dispatch(self, *args, **kwargs): + return super(NeverCacheMixin, self).dispatch(*args, **kwargs) + + +class LoginRequiredMixin(object): + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(LoginRequiredMixin, self).dispatch(*args, **kwargs) + + +class CacheMixin(object): + cache_timeout = 60 + + def get_cache_timeout(self): + return self.cache_timeout + + def dispatch(self, *args, **kwargs): + return cache_page(self.get_cache_timeout())(super(CacheMixin, self).dispatch)(*args, **kwargs) + + +class CacheControlMixin(object): + cache_timeout = 60 + + def get_cache_timeout(self): + return self.cache_timeout + + def dispatch(self, *args, **kwargs): + response = super(CacheControlMixin, self).dispatch(*args, **kwargs) + patch_response_headers(response, self.get_cache_timeout()) + return response + + +class JitterCacheMixin(CacheControlMixin): + cache_range = [60, 120] + + def get_cache_range(self): + return self.cache_range + + def get_cache_timeout(self): + return random.randint(*self.get_cache_range()) \ No newline at end of file diff --git a/functions/form_check.py b/functions/form_check.py index 61c7cab3..e8c0954e 100644 --- a/functions/form_check.py +++ b/functions/form_check.py @@ -20,7 +20,7 @@ from slugify import slugify def translit_with_separator(string, separator='-'): - return slugify(string, to_lower=True) + #return slugify(string) """ Trsanslit string and replace "bad" symbols for separator diff --git a/functions/model_mixin.py b/functions/model_mixin.py index 7f5950c6..36b120b4 100644 --- a/functions/model_mixin.py +++ b/functions/model_mixin.py @@ -77,8 +77,9 @@ class EventMixin(object): def get_services(self): - ids = [item for item, bool in self.country.services if bool==True] - ##sasa + country_ids = [item for item, bool in self.country.services if bool==True] + ids = [item for item, bool in self.services if bool==True and item in country_ids] + return list(Service.objects.language().filter(url__in=ids).order_by('sort')) def duration_days(self, month=None): diff --git a/functions/models_methods.py b/functions/models_methods.py index 4edde8d0..004bf58f 100644 --- a/functions/models_methods.py +++ b/functions/models_methods.py @@ -1,6 +1,9 @@ + from django.utils.translation import get_language +from django.db.models import Q from hvad.models import TranslationManager + class ExpoManager(TranslationManager): def all(self, lang=None): if lang: @@ -15,6 +18,21 @@ class ExpoManager(TranslationManager): except: return None +class CityManager(TranslationManager): + def all(self): + lang = get_language() + qs = super(CityManager, self).select_related('exposition_city', 'conference_city') + qs = qs.filter(Q(exposition_city__city__isnull=False) | Q(conference_city__city__isnull=False))\ + .order_by('translations__name').distinct() + + return qs + + def expo_cities(self): + from exposition.models import Exposition + cities_id = [item['city_id'] for item in Exposition.objects.values('city_id').distinct()] + return self.language().filter(id__in=cities_id) + + def hvad_to_dict(object): """ diff --git a/functions/search_forms.py b/functions/search_forms.py index 45dac942..fd9ecbce 100644 --- a/functions/search_forms.py +++ b/functions/search_forms.py @@ -239,15 +239,10 @@ class ExpositionSearchForm(AbstactSearchForm): #tg = forms.CharField(label=_(u'Теги'), required=False, widget=forms.CheckboxSelectMultiple()) area = forms.MultipleChoiceField(label=_(u'Регион'), - choices=[(item.id, item.name) for item in Area.objects.\ - select_related('country', 'country__exposition_country').\ - filter(country__exposition_country__country__isnull=False).\ - distinct()], + choices=[(item.id, item.name) for item in Area.objects.language().all()], required=False, widget=forms.CheckboxSelectMultiple()) co = forms.MultipleChoiceField(label=_(u'Страна'), required=False, widget=forms.CheckboxSelectMultiple(), - choices=[(item.id, item.name) for item in Country.objects.select_related('exposition_country')\ - .filter(exposition_country__country__isnull=False, translations__language_code=translation.get_language())\ - .order_by('translations__name').distinct()] + choices=[(item.id, item.name) for item in Country.objects.expo_countries()] ) ci = forms.MultipleChoiceField(label=_(u'Город'), required=False, widget=forms.CheckboxSelectMultiple(), @@ -334,9 +329,7 @@ class PlaceSearchForm(AbstactSearchForm): area = forms.MultipleChoiceField(label=_(u'Регион'), choices=[(item.id, item.name) for item in Area.objects.all_sorted()], required=False, widget=forms.CheckboxSelectMultiple()) co = forms.MultipleChoiceField(label=_(u'Страна'), required=False, widget=forms.CheckboxSelectMultiple(), - choices=[(item.id, item.name) for item in Country.objects.select_related('exposition_country')\ - .filter(exposition_country__country__isnull=False, translations__language_code=translation.get_language())\ - .order_by('translations__name').distinct()] + choices=[(item.id, item.name) for item in Country.objects.expo_countries()] ) ci = forms.MultipleChoiceField(label=_(u'Город'), required=False, widget=forms.CheckboxSelectMultiple(), diff --git a/functions/translate.py b/functions/translate.py index c1a154a2..a2d1a16f 100644 --- a/functions/translate.py +++ b/functions/translate.py @@ -101,20 +101,27 @@ def fill_with_signal(model, obj, data): # translated fields fields = [field.name for field in model.translations.related.editable_fields() if field.name not in bad_fields] + # translate to first language(require) # ! first save method call signal that fill require language to all translated fields if not obj.id: # new object obj.translate(all_langs[0]) # go through all fields and set value + for field in fields: - setattr(obj, field, data.get('%s_%s'%(field, all_langs[0])).strip()) + value = data.get('%s_%s'%(field, all_langs[0]), '') + if value: + setattr(obj, field, value.strip()) obj.save() else: trans_obj = model._meta.translations_model.objects.get(language_code = all_langs[0], master__id=getattr(obj, 'id')) for field in fields: - setattr(trans_obj, field, data.get('%s_%s'%(field, all_langs[0])).strip()) + + value = data.get('%s_%s'%(field, all_langs[0]), '') + if value: + setattr(trans_obj, field, value.strip()) trans_obj.save() @@ -126,7 +133,7 @@ def fill_with_signal(model, obj, data): # start from second language trans_obj = model._meta.translations_model.objects.get(language_code = code,master__id=getattr(obj, 'id')) for field in fields: - val = data.get('%s_%s'%(field, code)).strip() + val = data.get('%s_%s'%(field, code), '').strip() if val == '': # get value from require translation setattr(trans_obj, field, getattr(require_transl, field)) diff --git a/import_xls/admin.py b/import_xls/admin.py index aad23f02..a2b43cc3 100644 --- a/import_xls/admin.py +++ b/import_xls/admin.py @@ -11,7 +11,8 @@ import xlrd from import_forms import ImportEventForm, ImportThemeForm, ImportTagForm, ImportOrganiserForm,\ ImportPlaceConferenceForm, ImportPlaceExpositionForm from export_forms import ExportEventForm, ExportOrganiserForm, ExportThemeForm, ExportTagForm,\ - ExportUserForm, ExportCompanyForm, ExportPlaceConferenceForm, ExportPlaceExpositionForm, ExportBlogForm + ExportUserForm, ExportCompanyForm, ExportPlaceConferenceForm, ExportPlaceExpositionForm, ExportBlogForm,\ + ExportCityForm from django.views.generic import FormView from django.contrib import messages @@ -82,6 +83,14 @@ class ExportBlog(ExportView): form_class = ExportBlogForm success_url = '/admin/export-blog/' +class ExportBlog(ExportView): + form_class = ExportBlogForm + success_url = '/admin/export-blog/' + +class ExportCity(ExportView): + form_class = ExportCityForm + success_url = '/admin/export-city/' + from exposition.models import Exposition diff --git a/import_xls/admin_urls.py b/import_xls/admin_urls.py index 527435fb..baf65303 100644 --- a/import_xls/admin_urls.py +++ b/import_xls/admin_urls.py @@ -3,7 +3,7 @@ from django.conf.urls import patterns, url from admin import ImportTheme, ImportEvent, ImportOrganiser, ImportTag, ImportPlaceExposition, ImportPlaceConference from admin import ExportTheme, ExportEvent, ExportOrganiser, ExportTag, ExportPlaceExposition,\ - ExportPlaceConference, ExportCompany, ExportUser, ExportBlog + ExportPlaceConference, ExportCompany, ExportUser, ExportBlog, ExportCity urlpatterns = patterns('', url(r'^import-event/$', ImportEvent.as_view()), @@ -22,5 +22,6 @@ urlpatterns = patterns('', url(r'^export-user/$', ExportUser.as_view()), url(r'^export-company/$', ExportCompany.as_view()), url(r'^export-blog/$', ExportBlog.as_view()), + url(r'^export-city/$', ExportCity.as_view()), ) diff --git a/import_xls/export_forms.py b/import_xls/export_forms.py index 30a87dee..6964194b 100644 --- a/import_xls/export_forms.py +++ b/import_xls/export_forms.py @@ -4,6 +4,7 @@ from django.conf import settings from django.utils import translation from theme.models import Theme, Tag from country.models import Country +from city.models import City from organiser.models import Organiser from accounts.models import User from company.models import Company @@ -161,6 +162,15 @@ class ExportBlogForm(ExportForm): translation.activate(data['language']) return self.model.objects.blogs() +class ExportCityForm(ExportForm): + model = City + + def get_fname(self): + return 'cities.xls' + + def get_objects(self, data): + translation.activate(data['language']) + return self.model.used.all() class ExportEventForm(forms.Form): diff --git a/meta/admin.py b/meta/admin.py index ceb59ac9..5d944cd3 100644 --- a/meta/admin.py +++ b/meta/admin.py @@ -10,18 +10,7 @@ from django.contrib.auth.decorators import login_required #models and forms from models import MetaSetting from forms import MetaForm, MetaFilterForm -from theme.models import Tag -from city.models import City -from file.models import FileModel, TmpFile -from file.forms import FileModelForm, FileForm -from photologue.forms import PhotoForm -#python -import random -#custom views -from functions.custom_views import objects_list, delete_object -from functions.views_help import get_referer - -from functions.admin_views import AdminListView, AdminView, upload_photo +from functions.admin_views import AdminListView, AdminView diff --git a/place_exposition/urls.py b/place_exposition/urls.py index af64dd62..2fe9014b 100644 --- a/place_exposition/urls.py +++ b/place_exposition/urls.py @@ -20,7 +20,8 @@ urlpatterns = patterns('', url(r'(?P.*)/photo/page/(?P\d+)/$', PlacePhoto.as_view()), url(r'(?P.*)/photo/$', PlacePhoto.as_view()), #url(r'expo/(?P.*)/service/(?P.*)/$', ExpositionServiceView.as_view()), - url(r'(?P.*)/$', PlaceDetail.as_view()), url(r'page/(?P\d+)/$', PlaceList.as_view()), + url(r'(?P.*)/$', PlaceDetail.as_view()), + url(r'$', PlaceList.as_view()), ) diff --git a/place_exposition/views.py b/place_exposition/views.py index 13ceea97..fe45ca2d 100644 --- a/place_exposition/views.py +++ b/place_exposition/views.py @@ -127,8 +127,7 @@ class PlaceList(ListView): def get_queryset(self): - lang = translation.get_language() - qs = super(PlaceList, self).get_queryset().filter(language_code=lang).order_by('-rating') + qs = super(PlaceList, self).get_queryset().order_by('-rating') conf_qs = PlaceConference.objects.language().all() return list(qs)+list(conf_qs) diff --git a/proj/settings.py b/proj/settings.py index be6286d4..59e8a94b 100644 --- a/proj/settings.py +++ b/proj/settings.py @@ -27,14 +27,17 @@ DATABASES = { } } -''' + CACHES = { - 'default': { - 'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache', - 'LOCATION': '127.0.0.1:11211', + "default": { + "BACKEND": "redis_cache.cache.RedisCache", + "LOCATION": "127.0.0.1:6379:1", + "OPTIONS": { + "CLIENT_CLASS": "redis_cache.client.DefaultClient", + }, } } -''' + # Hosts/domain names that are valid for this site; required if DEBUG is False @@ -72,10 +75,10 @@ USE_I18N = True # If you set this to False, Django will not format dates, numbers and # calendars according to the current locale. -USE_L10N = True +USE_L10N = False # If you set this to False, Django will not use timezone-aware datetimes. -USE_TZ = True +USE_TZ = False MEDIA_ROOT = os.path.join(SITE_ROOT, 'media/') @@ -136,8 +139,6 @@ TEMPLATE_CONTEXT_PROCESSORS = ( MIDDLEWARE_CLASSES = ( # 'django.middleware.cache.UpdateCacheMiddleware', - - 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.middleware.common.CommonMiddleware', @@ -149,7 +150,6 @@ MIDDLEWARE_CLASSES = ( # Uncomment the next line for simple clickjacking protection: 'django.middleware.clickjacking.XFrameOptionsMiddleware', - #'debug_toolbar.middleware.DebugToolbarMiddleware', ) @@ -163,7 +163,7 @@ TEMPLATE_DIRS = ( # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. - os.path.join(SITE_ROOT, 'templates'), + # os.path.join(SITE_ROOT, 'templates/debug_toolbar'), os.path.join(SITE_ROOT, 'templates/admin'), os.path.join(SITE_ROOT, 'templates/admin/accounts'), os.path.join(SITE_ROOT, 'templates/admin/article'), @@ -191,6 +191,7 @@ TEMPLATE_DIRS = ( os.path.join(SITE_ROOT, 'templates/client/exposition'), os.path.join(SITE_ROOT, 'templates/client/photoreport'), os.path.join(SITE_ROOT, 'templates/client/includes'), + os.path.join(SITE_ROOT, 'templates'), #os.path.join(SITE_ROOT, 'templates/client/popups'), ) @@ -199,21 +200,13 @@ LOGIN_URL='/' #registration info ACCOUNT_ACTIVATION_DAYS=2 # mail settings -#EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' -#EMAIL_HOST = 'localhost' -#EMAIL_HOST_USER = '' -#EMAIL_HOST_PASSWORD = '' -#EMAIL_USE_TLS = False -#EMAIL_PORT = 25 -#test -EMAIL_USE_TLS = True -EMAIL_HOST = 'smtp.gmail.com' -EMAIL_HOST_USER = 'kotzilla' -EMAIL_HOST_USER = 'kotzillla@gmail.com' -EMAIL_HOST_PASSWORD = 'fitteR2006!!' - -EMAIL_PORT = 587 -DEFAULT_FROM_EMAIL = 'kotzillla@gmail.com' +EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' +EMAIL_HOST = 'localhost' +EMAIL_HOST_USER = '' +EMAIL_HOST_PASSWORD = '' +EMAIL_USE_TLS = False +EMAIL_PORT = 25 +DEFAULT_FROM_EMAIL = "expomap.ru" AUTHENTICATION_BACKENDS = ( @@ -324,17 +317,11 @@ INSTALLED_APPS = ( 'pytils', 'pymorphy', 'password_reset', - #'social_auth', + 'django_crontab', 'social.apps.django_app.default', - # 'south', - #'debug_toolbar', ) -INTERNAL_IPS = ('176.121.5.82',) -DEBUG_TOOLBAR_PATCH_SETTINGS = False -#DEBUG_TOOLBAR_PANELS = ( - # 'debug_toolbar.panels.profiling.ProfilingPanel', -#) + PYMORPHY_DICTS = { 'ru': { 'dir': os.path.join(SITE_ROOT, 'settings/russian_dicts')} #'/home/www/proj/settings/russian_dicts' }, } @@ -379,7 +366,17 @@ LOGGING = { } } -THUMBNAIL_DEBUG = True + +CRONJOBS = [ + ('0 */1 * * *', 'django.core.management.call_command', ['update_index conference --age=1']), + ('0 */1 * * *', 'django.core.management.call_command', ['update_index exposition --age=1']), + ('0 */12 * * *', 'django.core.management.call_command', ['update_index place_exposition --age=12']), + ('0 */24 * * *', 'django.core.management.call_command', ['update_index company --age=24']), + ('0 */24 * * *', 'django.core.management.call_command', ['update_index theme --age=24']), + ('0 */24 * * *', 'django.core.management.call_command', ['update_index tag --age=24']), +] + +THUMBNAIL_DEBUG = DEBUG CALLBACK_EMAIL = 'kotzilla@ukr.net' @@ -407,3 +404,39 @@ try: from local import * except ImportError, e: pass + + +# debug_toolbar settings +""" +if DEBUG: + DEBUG_TOOLBAR_PATCH_SETTINGS = False + INTERNAL_IPS = ('127.0.0.1','176.121.5.82', '176.121.11.162', '77.123.47.46') + + MIDDLEWARE_CLASSES += ( + 'debug_toolbar.middleware.DebugToolbarMiddleware', + ) + + INSTALLED_APPS += ( + 'debug_toolbar', + ) + JQUERY_URL = os.path.join(SITE_ROOT, 'static/client/js/jquery-ui-1.10.4.custom.min.js'), + DEBUG_TOOLBAR_PANELS = [ + #'debug_toolbar.panels.versions.VersionsPanel', + #'debug_toolbar.panels.timer.TimerPanel', + #'debug_toolbar.panels.settings.SettingsPanel', + #'debug_toolbar.panels.headers.HeadersPanel', + #'debug_toolbar.panels.request.RequestPanel', + 'debug_toolbar.panels.sql.SQLPanel', + #'debug_toolbar.panels.staticfiles.StaticFilesPanel', + #'debug_toolbar.panels.templates.TemplatesPanel', + #'debug_toolbar.panels.cache.CachePanel', + #'debug_toolbar.panels.signals.SignalsPanel', + #'debug_toolbar.panels.logging.LoggingPanel', + #'debug_toolbar.panels.redirects.RedirectsPanel', +] + + #DEBUG_TOOLBAR_CONFIG = { + # 'INTERCEPT_REDIRECTS': False, + #} + +""" \ No newline at end of file diff --git a/proj/urls.py b/proj/urls.py index 030dd567..637e5328 100644 --- a/proj/urls.py +++ b/proj/urls.py @@ -5,13 +5,14 @@ from core.views import PlaceListView, PlacePhotoView, EventSearchView from core.simple_index_view import AdvertisingView, AboutView from views import MainPageView, MainPageViewTest from place_exposition.views import PlaceSearchView - from django.http import HttpResponse +from django.contrib.sitemaps.views import sitemap - +import debug_toolbar urlpatterns = patterns('', + #url(r'^__debug__/', include(debug_toolbar.urls)), url(r'^admin/', include('proj.admin_urls')), url(r'^$', MainPageView.as_view()), url(r'^main_page/$', MainPageViewTest.as_view()), @@ -20,6 +21,7 @@ urlpatterns = patterns('', url(r'^', include('accounts.urls')), url(r'^', include('exposition.urls')), + url(r'^', include('settings.conference_old_urls')), # conference redirects from old version url(r'^', include('conference.urls')), url(r'^', include('seminar.urls')), url(r'^', include('webinar.urls')), @@ -30,76 +32,26 @@ urlpatterns = patterns('', url(r'^city/', include('city.urls')), url(r'^organiser/', include('organiser.urls')), url(r'^gallery/', include('photologue.client_urls')), - - url(r'^', include('file.urls')), url(r'^', include('django_messages.expomap_urls')), url(r'^messages/', include('django_messages.urls')), - url(r'^advertising/$', AdvertisingView.as_view()), url(r'^about/$', AboutView.as_view()), url(r'^partners/$', AboutView.as_view()), url(r'^contacts/$', AboutView.as_view()), - #url(r'^events/search/$', EventSearchView.as_view()), - #url(r'^places/search/$', PlaceSearchView.as_view()), - #url(r'^places/(?P.*)/photo/(?P\d+)/$', PlacePhotoView.as_view()), - #url(r'^places/(?P.*)/photo/$', PlacePhotoView.as_view()), - #url(r'^places/(?P.*)/(?P\d+)/$', PlaceListView.as_view()), - #url(r'^places/(?P\d+)/$', PlaceListView.as_view()), - #url(r'^places/(?P.*)/$', PlaceListView.as_view()), - #url(r'^places/$', PlaceListView.as_view()), url(r'^social/', include('social.apps.django_app.urls', namespace='social')), url(r'^login/', 'registration.backends.default.views.LoginView'), url(r'^logout/', 'registration.backends.default.views.LogoutView'), - #url(r'^profile/$', 'accounts.views.profile'), url(r'^accounts/', include('registration.backends.default.urls')), - #url(r'^places/$', 'place_exposition.views.catalog'), - #url(r'^places/(?P.*)/(?Pphoto)', 'place_exposition.views.place'), - #url(r'^places/(?P.*)', 'place_exposition.views.place'), - #url(r'^company/(?P.*)', 'core.views.company'), url(r'^', include('password_reset.urls')), url(r'^i18n/', include('django.conf.urls.i18n')), #url(r'^social/', include('social_auth.urls')), - - # admin part + #url(r'^', include('settings.old_urls')), url(r'^search/', include('haystack.urls')), - url(r'^', include('service.urls')), - ) -# test urls -from accounts.models import User -def delete_user(request): - request.user.delete() - #User.objects.filter(email='kotzillla@gmail.com').delete() - return HttpResponse('deleted') - -def delete_user_info(request): - user = request.user - user.url = '' - user.company = None - user.position = '' - user.save() - pr = user.profile - pr.city = None - pr.country = None - pr.about_company = '' - pr.phone = None - pr.web_page = '' - pr.about = '' - pr.facebook = '' - pr.vk = '' - pr.twitter = '' - pr.linkedin = '' - pr.save() - return HttpResponse('info deleted') - -urlpatterns += patterns('', - url(r'^delete-user/', delete_user), - url(r'^delete-user-info/', delete_user_info), - ) # ajax urls urlpatterns += patterns('', @@ -113,14 +65,14 @@ urlpatterns += patterns('', url(r'^search-form/autosearch/exposition/$', 'settings.views.expo_autosearch'), url(r'^search-form/autosearch/place/$', 'settings.views.place_autosearch'), url(r'^search-form/autosearch/company/$', 'settings.views.company_autosearch'), + url(r'^', include('settings.old_urls')), url(r'^', include('accounts.user_catalog_urls')), ) -""" + if settings.DEBUG: import debug_toolbar urlpatterns += patterns('', url(r'^__debug__/', include(debug_toolbar.urls)), - ) -""" \ No newline at end of file + ) \ No newline at end of file diff --git a/service/forms.py b/service/forms.py index 1f3febd7..1431a76e 100644 --- a/service/forms.py +++ b/service/forms.py @@ -28,16 +28,15 @@ class ServiceForm(forms.Form): url = forms.CharField(label='url', required=False) price = forms.IntegerField(label='Цена', required=False, widget=forms.TextInput(attrs={'placeholder':'Валюта'})) + #price = forms.CharField(label='Цена', required=False, # widget=forms.TextInput(attrs={'placeholder':'Валюта'})) currency_list = [('USD','USD'), ('EUR','EUR'), ('RUB','RUB')] currency = forms.ChoiceField(choices=currency_list) - + type = forms.MultipleChoiceField(label='Тип', choices=[('expo', 'expo'), ('conference', 'conference')]) service_id = forms.CharField(required=False, widget=forms.HiddenInput()) - - def __init__(self, *args, **kwargs): super(ServiceForm, self).__init__(*args, **kwargs) # creates translated form fields, example: name_ru, name_en @@ -76,6 +75,8 @@ class ServiceForm(forms.Form): service.price = data['price'] service.currency = data['currency'] + #data['type'] + fill_with_signal(Service, service, data) diff --git a/service/models.py b/service/models.py index 0553d370..7eba79b1 100644 --- a/service/models.py +++ b/service/models.py @@ -2,6 +2,7 @@ from django.db import models from hvad.models import TranslatableModel, TranslatedFields, TranslationManager from functions.custom_fields import EnumField +from bitfield import BitField CURENCIES = ('', 'USD', 'RUB', 'EUR') @@ -12,12 +13,12 @@ CURENCIES = ('', 'USD', 'RUB', 'EUR') class Service(TranslatableModel): - url = models.SlugField(unique=True) currency = EnumField(values=CURENCIES, blank=True, default='USD') price = models.PositiveIntegerField(blank=True, null=True) params = models.CharField(max_length=255, blank=True) template = models.CharField(max_length=255, blank=True) + type = BitField(flags=['expo', 'conference']) #translated fields translations = TranslatedFields( name = models.CharField(max_length=50), @@ -78,6 +79,8 @@ class AbstractOrder(models.Model): class Catalog(AbstractOrder): pass +class BuildStand(AbstractOrder): + pass class Tickets(AbstractOrder): days = models.SmallIntegerField() diff --git a/service/order_forms.py b/service/order_forms.py index d5f69b79..59f00609 100644 --- a/service/order_forms.py +++ b/service/order_forms.py @@ -2,7 +2,7 @@ from django import forms from django.utils.translation import ugettext as _ from accounts.models import User -from models import Catalog, Tickets, Remote, Participation, Translation, Visit, CURENCIES, Advertising, CallBack +from models import Catalog, Tickets, Remote, Participation, Translation, Visit, CURENCIES, Advertising, CallBack, BuildStand from exposition.models import Exposition from conference.models import Conference from seminar.models import Seminar @@ -89,6 +89,10 @@ class CatalogForm(AbstractOrderForm): class Meta: model = Catalog +class BuildStandForm(AbstractOrderForm): + class Meta: + model = BuildStand + class TicketsForm(AbstractOrderForm): class Meta: diff --git a/service/views.py b/service/views.py index 949c27ac..65a570a9 100644 --- a/service/views.py +++ b/service/views.py @@ -7,13 +7,14 @@ from haystack.query import EmptySearchQuerySet from django.shortcuts import get_object_or_404 from django.http import Http404 import json -from functions.search_forms import CompanySearchForm +#from functions.search_forms import CompanySearchForm -from order_forms import TranslationForm, CatalogForm, VisitForm, RemoteForm, ParticipationForm, TicketsForm, AdvertiseForm +from order_forms import TranslationForm, CatalogForm, VisitForm, RemoteForm, ParticipationForm, TicketsForm,\ + AdvertiseForm, BuildStandForm order_forms = {'translator': TranslationForm, 'catalog': CatalogForm, 'participation': ParticipationForm, - 'remote': RemoteForm, 'tickets': TicketsForm, 'visit': VisitForm} + 'remote': RemoteForm, 'tickets': TicketsForm, 'visit': VisitForm, 'buildstand': BuildStandForm} class ServiceView(FormView): diff --git a/settings/conference_old_urls.py b/settings/conference_old_urls.py new file mode 100644 index 00000000..fa50b3d2 --- /dev/null +++ b/settings/conference_old_urls.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +from django.conf.urls import patterns, include, url +from django.http import HttpResponse +from django.views.decorators.cache import cache_page +from redirect_views import old_redirect, old_profile + + +urlpatterns = patterns('', + url(r'/rubricator.php?result_type=conference$', old_redirect, {'redirect_url': '/conference/'}), #??? + # city + url(r'^conference/city-(?P.*)/year-(?P\d+)/month-(?P.*)$', old_redirect, {'redirect_url': '/conference/city/{city}/{year}/{month}/'}), + url(r'^conference/city-(?P.*)/year-(?P\d+)/$', old_redirect, {'redirect_url': '/conference/city/{city}/{year}/'}), + url(r'^conference/city-(?P.*)/$', old_redirect, {'redirect_url': '/conference/city/{city}/'}), + #url(r'^conference/(?P.*)/$', old_redirect, {'redirect_url': '/conference/city/{city}/'}), # перенести + # country + url(r'^conference/country-(?P.*)/year-(?P\d+)/month-(?P.*)$', old_redirect, {'redirect_url': '/conference/country/{country}/{year}/{month}/'}), + url(r'^conference/country-(?P.*)/year-(?P\d+)/$', old_redirect, {'redirect_url': '/conference/country/{country}/{year}/'}), + url(r'^conference/country-(?P.*)/$', old_redirect, {'redirect_url': '/conference/country/{country}/'}), + #url(r'/conference/(?P.*)/$', old_redirect, {'redirect_url': '/conference/country/{country}/'}), # перенести + # theme + url(r'^conference/theme-(?P.*)/year-(?P\d+)/month-(?P.*)/$', old_redirect, {'redirect_url': '/conference/theme/{theme}/{year}/{month}/'}), + url(r'^conference/theme-(?P.*)/year-(?P\d+)/$', old_redirect, {'redirect_url': '/conference/theme/{theme}/{year}/'}), + url(r'^conference/theme-(?P.*)/city-(?P.*)/year-(?P\d+)/month-/$', old_redirect, {'redirect_url': '/conference/theme/{theme}/city/{city}/{year}/'}), + url(r'^conference/theme-(?P.*)/city-(?P.*)/year-(?P\d+)/$', old_redirect, {'redirect_url': '/conference/theme/{theme}/city/{city}/{year}/'}), + url(r'^conference/theme-(?P.*)/city-(?P.*)/$', old_redirect, {'redirect_url': '/conference/theme/{theme}/city/{city}/'}), + #url(r'^conference/theme/(?P.*)/$', old_redirect, {'redirect_url': '/conference/theme/{theme}/'}), # перенести + url(r'^conference/theme-(?P.*)/$', old_redirect, {'redirect_url': '/conference/theme/{theme}/'}), + ) diff --git a/settings/management/__init__.py b/settings/management/__init__.py new file mode 100644 index 00000000..3ed9fd0f --- /dev/null +++ b/settings/management/__init__.py @@ -0,0 +1 @@ +__author__ = 'root' diff --git a/settings/management/commands/__init__.py b/settings/management/commands/__init__.py new file mode 100644 index 00000000..3ed9fd0f --- /dev/null +++ b/settings/management/commands/__init__.py @@ -0,0 +1 @@ +__author__ = 'root' diff --git a/settings/management/commands/update_views_cache.py b/settings/management/commands/update_views_cache.py new file mode 100644 index 00000000..9f2452ac --- /dev/null +++ b/settings/management/commands/update_views_cache.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +from django.core.management.base import BaseCommand, CommandError +from django.test.client import RequestFactory +from django.utils import translation +from django.conf import settings +from exposition.views import ExpositionByCity + + + + +class Command(BaseCommand): + def handle(self, *args, **options): + langs = [code for code, name in settings.LANGUAGES] + + print(langs) + + #request = RequestFactory().get('/expo/city/') + #view = ExpositionByCity.as_view() + #response = view(request, name='bob') + + + print('success') diff --git a/settings/old_urls.py b/settings/old_urls.py new file mode 100644 index 00000000..dcbbec2c --- /dev/null +++ b/settings/old_urls.py @@ -0,0 +1,79 @@ +# -*- coding: utf-8 -*- +from django.conf.urls import patterns, include, url +from django.http import HttpResponse +from django.views.decorators.cache import cache_page +from redirect_views import old_redirect, old_profile +def test(request): + return HttpResponse('test') + + +urlpatterns = patterns('', + # service + url(r'^rubricator.php/?result_type=expo$', old_redirect, {'redirect_url': '/expo/'}), #??? + url(r'^serv-zaoch-info.php$', old_redirect, {'redirect_url': '/service/remote/'}), + url(r'^serv-visit-info.php$', old_redirect, {'redirect_url': '/service/visit/'}), + url(r'^serv-bilet-info.php$', old_redirect, {'redirect_url': '/service/tickets/'}), + url(r'^serv-translator-info.php$', old_redirect, {'redirect_url': '/service/translator/'}), + url(r'^(?P.*)/(?P.*)/buildstand.html$', old_redirect, {'redirect_url': '{event_catalog}{event_url}/service/buildstand/'}), + url(r'^(?P.*)/(?P.*)/bilet.html$', old_redirect, {'redirect_url': '{event_catalog}{event_url}/service/tickets/'}), + url(r'^(?P.*)/(?P.*)/zaoch.html$', old_redirect, {'redirect_url': '{event_catalog}{event_url}/service/remote/'}), + url(r'^(?P.*)/(?P.*)/translator.html$', old_redirect, {'redirect_url': '{event_catalog}{event_url}/service/translator/'}), + url(r'^(?P.*)/(?P.*)/visit.html$', old_redirect, {'redirect_url': '{event_catalog}{event_url}/service/visit/'}), + url(r'^(?P.*)/(?P.*)/uchastie.html$', old_redirect, {'redirect_url': '{event_catalog}{event_url}/service/participation/'}), + # company + url(r'^company/(?P.*)$', old_redirect, {'redirect_url': '/members/{company}/'}), + # articles and news + url(r'^articles.php$', old_redirect, {'redirect_url': '/blogs/'}), + url(r'^news.php$', old_redirect, {'redirect_url': '/news/'}), + url(r'^news.php/news/archive/', old_redirect, {'redirect_url': '/news/'}), + url(r'^article_info.php/articles_id/(?P
\d+)/(?P.*)$', old_redirect, {'redirect_url': '/blogs/{article}/'}), + url(r'^news.php/news_id/(?P
\d+)/(?P.*)$', old_redirect, {'redirect_url': '/news/{article}/'}), + # users + url(r'^users/(?P.*)$', old_redirect, {'redirect_url': '/{user}/'}), + url(r'^account_edit.php$', old_profile), + url(r'^myexpo.php$', old_redirect, {'redirect_url': '/profile/calendar/'}), + url(r'^newsletter2.php?email=(?P.*)$', old_redirect, {'redirect_url': '/profile/settings/'}), + url(r'^account_password.php$', old_redirect, {'redirect_url': '/profile/settings/'}), + #url(r'^serv-personal-info.php$', old_redirect, {'redirect_url': '/service/staff/'}), + # EXPO + # city + url(r'^catalog/city-(?P)/theme-(?P.*)/year-(?P\d+)/month-/$', old_redirect, {'redirect_url': '/expo/theme/{theme}/city/{city}/{year}/'}), + url(r'^catalog/city-(?P.*)/theme-(?P.*)/year-(?P\d+)/$', old_redirect, {'redirect_url': '/expo/theme/{theme}/city/{city}/{year}/'}), + url(r'^catalog/city-(?P.*)/theme-(?P.*)/$', old_redirect, {'redirect_url': '/expo/theme/{theme}/city/{city}/'}), + url(r'^catalog/city-(?P.*)/year-(?P\d+)/month-(?P.*)/$', old_redirect, {'redirect_url': '/expo/city/{city}/{year}/{month}'}), + url(r'^catalog/city/(?P.*)/year-(?P\d+)/month-(?P.*)/$', old_redirect, {'redirect_url': '/expo/city/{city}/{year}/{month}'}), + url(r'^catalog/city-(?P.*)/year-(?P\d+)/$', old_redirect, {'redirect_url': '/expo/city/{city}/{year}'}), + url(r'^catalog/city/(?P.*)/year-(?P\d+)/$', old_redirect, {'redirect_url': '/expo/city/{city}/{year}'}), + url(r'^catalog/city-(?P.*)/$', old_redirect, {'redirect_url': '/expo/city/{city}/'}), + # country + url(r'^catalog/country-(?P)/theme-(?P.*)/year-(?P\d+)/month-/$', old_redirect, {'redirect_url': '/expo/theme/{theme}/country/{country}/{year}/'}), + url(r'^catalog/country-(?P.*)/theme-(?P.*)/year-(?P\d+)/$', old_redirect, {'redirect_url': '/expo/theme/{theme}/country/{country}/{year}/'}), + url(r'^catalog/country-(?P.*)/theme-(?P.*)/$', old_redirect, {'redirect_url': '/expo/theme/{theme}/country/{country}/'}), + url(r'^catalog/country-(?P.*)/year-(?P\d+)/month-(?P.*)/$', old_redirect, {'redirect_url': '/expo/country/{country}/{year}/{month}/'}), + url(r'^catalog/country/(?P.*)/year-(?P\d+)/month-(?P.*)/$', old_redirect, {'redirect_url': '/expo/country/{country}/{year}/{month}/'}), + url(r'^catalog/country-(?P.*)/year-(?P\d+)/$', old_redirect, {'redirect_url': '/expo/country/{country}/{year}/'}), + url(r'^catalog/country/(?P.*)/year-(?P\d+)/$', old_redirect, {'redirect_url': '/expo/country/{country}/{year}/'}), + url(r'^catalog/country/(?P.*)/$', old_redirect, {'redirect_url': '/expo/country/{country}/'}), + url(r'^catalog/country-(?P.*)/$', old_redirect, {'redirect_url': '/expo/country/{country}/'}), + url(r'^catalog/country/$', old_redirect, {'redirect_url': '/expo/country/'}), + # theme + url(r'^catalog/theme-(?P.*)/year-(?P\d+)/month-(?P.*)/$', old_redirect, {'redirect_url': '/expo/theme/{theme}/{year}/{month}/'}), + url(r'^catalog/theme-(?P.*)/year-(?P\d+)/$', old_redirect, {'redirect_url': '/expo/theme/{theme}/{year}/'}), + url(r'^catalog/theme-(?P.*)/city-(?P)/year-(?P\d+)/month-/$', old_redirect, {'redirect_url': '/expo/theme/{theme}/city/{city}/{year}/'}), + url(r'^catalog/theme-(?P.*)/city-(?P.*)/year-(?P\d+)/$', old_redirect, {'redirect_url': '/expo/theme/{theme}/city/{city}/{year}/'}), + url(r'^catalog/theme-(?P.*)/city-(?P.*)/$', old_redirect, {'redirect_url': '/expo/theme/{theme}/city/{city}/'}), + url(r'^catalog/theme-(?P.*)/country-(?P)/year-(?P\d+)/month-/$', old_redirect, {'redirect_url': '/expo/theme/{theme}/country/{country}/{year}/'}), + url(r'^catalog/theme-(?P.*)/country-(?P.*)/year-(?P\d+)/$', old_redirect, {'redirect_url': '/expo/theme/{theme}/country/{country}/{year}/'}), + url(r'^catalog/theme-(?P.*)/country-(?P.*)/$', old_redirect, {'redirect_url': '/expo/theme/{theme}/country/{country}/'}), + url(r'^catalog/theme/(?P.*)/$', old_redirect, {'redirect_url': '/expo/theme/{theme}/'}), + url(r'^catalog/theme-(?P.*)/$', old_redirect, {'redirect_url': '/expo/theme/{theme}/'}), + url(r'^catalog/theme/$', old_redirect, {'redirect_url': '/expo/theme/'}), + # tag + url(r'^tag/(?P.*)/$', old_redirect, {'redirect_url': '/expo/tag/{tag}/'}), + + url(r'^catalog/(?P.*)/$', old_redirect, {'redirect_url': '/expo/city/{city}/'}), + url(r'^catalog/$', old_redirect, {'redirect_url': '/expo/city/'}), + # tag + + url(r'^(?P.*)/(?P.*).html$', old_redirect, {'redirect_url': '{event_catalog}{event_url}/'}), +) diff --git a/settings/redirect_views.py b/settings/redirect_views.py new file mode 100644 index 00000000..99c9f2cd --- /dev/null +++ b/settings/redirect_views.py @@ -0,0 +1,97 @@ +from django.http import HttpResponseRedirect, HttpResponse, Http404, HttpResponsePermanentRedirect +from django.shortcuts import get_object_or_404 +from city.models import City +from country.models import Country +from theme.models import Theme, Tag +from exposition.models import Exposition +from conference.models import Conference +from company.models import Company +from article.models import Article +from accounts.models import User + + +class RedirectMixin(object): + model = None + + def get_object_url(self, key, value): + Model = self.model + + try: + obj = Model.objects.get(old_url=value) + except: + obj = get_object_or_404(Model, url=value) + if obj: + return {key: obj.url} + else: + raise Http404 + +class CityRedirect(RedirectMixin): + model = City + +class CountryRedirect(RedirectMixin): + model = Country + +class ThemeRedirect(RedirectMixin): + model = Theme + +class TagRedirect(RedirectMixin): + model = Tag + +class CompanyRedirect(RedirectMixin): + model = Company + + + +class EventRedirect(object): + + def get_object_url(self,key, value): + + try: + obj = Exposition.objects.get(old_url=value) + except Exposition.DoesNotExist: + obj = Exposition.objects.safe_get(url=value) + + if not obj: + try: + obj = Conference.objects.get(old_url=value) + except Conference.DoesNotExist: + obj = Conference.objects.safe_get(url=value) + if obj: + return {'event_url': obj.url, 'event_catalog': obj.catalog} + else: + raise Http404 + +class ArticleRedirect(object): + def get_object_url(self,key, value): + obj = get_object_or_404(Article, id=value) + return {key: obj.slug} + +class UserRedirect(object): + def get_object_url(self,key, value): + obj = get_object_or_404(User, url=value) + return {key: obj.url} + + +old_params = {'city': CityRedirect, 'country': CountryRedirect, 'theme': ThemeRedirect, 'tag': TagRedirect, + 'event': EventRedirect, 'company': Company, 'article': ArticleRedirect, 'user': UserRedirect} + +def old_redirect(request, *args, **kwargs): + redirect = kwargs.get('redirect_url') + params = dict(kwargs) + updates = {} + for key, value in params.iteritems(): + if key in old_params: + redirect_obj = old_params[key]() + updates.update(redirect_obj.get_object_url(key, value)) + + + params.update(updates) + redirect = redirect.format(**params) + return HttpResponsePermanentRedirect(redirect) + +def old_profile(request): + user = request.user + if user.is_authenticated(): + return HttpResponseRedirect('/%s/'%user.url) + else: + raise Http404 \ No newline at end of file diff --git a/templates/admin/service/service_add.html b/templates/admin/service/service_add.html index 8b5fa8fa..ce487c45 100644 --- a/templates/admin/service/service_add.html +++ b/templates/admin/service/service_add.html @@ -121,6 +121,45 @@ +
+
+

Управления услугами

+
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ + + +
+
+
diff --git a/templates/client/exposition/exposition_by.html b/templates/client/exposition/exposition_by.html index 00a24203..c75597c3 100644 --- a/templates/client/exposition/exposition_by.html +++ b/templates/client/exposition/exposition_by.html @@ -23,20 +23,22 @@ {% endblock %} {% block content_list %} - {% for obj in object_list %} - {% set cur_word = obj.name %} - {% if cur_word|slice:":1"|lower != prev_word|slice:":1"|lower and forloop.counter != 1 %} - - {% endif %} - {% if cur_word|slice:":1"|lower != prev_word|slice:":1"|lower %} -
    -
    {{ cur_word|slice:":1"|upper }}
    - {% endif %} -
  • - {{ obj.name }} ({{ obj.expositions_number }}) -
  • - {% set prev_word = obj.name %} - {% endfor %} + {% with objects=object_list %} + {% for obj in objects %} + {% set cur_word = obj.name %} + {% if cur_word|slice:":1"|lower != prev_word|slice:":1"|lower and forloop.counter != 1 %} +
+ {% endif %} + {% if cur_word|slice:":1"|lower != prev_word|slice:":1"|lower %} +
    +
    {{ cur_word|slice:":1"|upper }}
    + {% endif %} +
  • + {{ obj.name }} ({{ obj.expositions_number }}) +
  • + {% set prev_word = obj.name %} + {% endfor %} + {% endwith %} {% endblock %} diff --git a/templates/client/includes/conference/conference_object.html b/templates/client/includes/conference/conference_object.html index b864e3fd..79a6dee3 100644 --- a/templates/client/includes/conference/conference_object.html +++ b/templates/client/includes/conference/conference_object.html @@ -118,7 +118,7 @@
- {% include 'client/includes/exposition/exposition_services.html' %} + {% include 'client/includes/conference/conference_services.html' with event=event %} {% include 'includes/event_steps.html' with event=event %} @@ -127,7 +127,7 @@
- + - + {% if place.total_year_action %}
{% trans 'Ежегодно проводится' %}
- {{ place.total_year_action }} - {% trans 'событий' %} -
+ {% if place.total_year_action.isdigit %} + {% ifequal LANGUAGE_CODE 'ru' %} + {% load pymorphy_tags %} + {{ place.total_year_action }} + {{ "событие"|plural:place.total_year_action }} + {% else %} + {{ place.total_year_action }} + {% trans 'событий' %} + {% endifequal %} + {% else %} + {{ place.total_year_action }} + {% endif %} +
+ {% endif %} {% if place.foundation_year %}
diff --git a/templates/client/service/build_stand.html b/templates/client/service/build_stand.html new file mode 100644 index 00000000..25e3889d --- /dev/null +++ b/templates/client/service/build_stand.html @@ -0,0 +1,199 @@ +{% extends 'base_catalog.html' %} +{% load static %} +{% load i18n %} + +{% block bread_scrumbs %} + +{% endblock %} + + + +{% block page_title %} +
+

{% if meta %}{{ meta.h1 }}{% else %}{% trans 'Строительство стенда' %} {% if object %}{% trans 'на' %} {{ object.name }} {% endif %}{% endif %}

+
+{% endblock %} + +{% block page_body %} + +
+ +
+ +
+ +
+ + +
+

{% trans 'Предлагаем Вам заказать печатный каталог выставки' %}{% if object %} {{ object.name }} {% endif %}

+ +
+
    +
  • {% trans 'вся информация о выставке' %}
  • +
  • {% trans 'экономия времени' %}
  • +
  • {% trans 'все потенциальные контакты' %}
  • +
+ +
    +
  • {% trans 'вся информация о выставке' %}
  • +
  • {% trans 'экономия времени' %}
  • +
  • {% trans 'все потенциальные контакты' %}
  • +
+
+ +
+
+ +
+
{% csrf_token %} + +
+ +
+ +
{% trans 'Ваши контактные данные' %}
+ +
+
+ {{ form.person_inf }} +
+
+
+
+ {{ form.person_inf.errors }} +
+
+ +
+
+ {{ form.country }} + +
+ +
+ {{ form.city }} +
+
+
+
+ {{ form.country.errors }} +
+
+ {{ form.city.errors }} +
+
+ +
+
+ {{ form.phone }} +
+ +
+ {{ form.person }} +
+
+
+
+ {{ form.phone.errors }} +
+
+ {{ form.person.errors }} +
+
+ +
+ +
+ +
+ +
+
+
{{ service.price }} {{ service.currency }} + {% trans 'стоимость каталога' %}
+
+ {% if service.price %} + + {% endif %} + + {% if service.price %} + + {% endif %} + +
+
+
+
{% trans 'Стоимость каталога оплачивается c учетом доставки, которую обозначают организаторы выставки (в среднем от 0 до 50 евро).' %}
+ +
+ +
+
+ +
+ +
+
+
{{ service.price }} {{ service.currency }} + {% trans 'стоимость каталога' %}
+ +
+
+
{% trans 'Стоимость каталога оплачивается c учетом доставки, которую обозначают организаторы выставки (в среднем от 0 до 50 евро).' %}
+ +
+ {% if messages %} +
+
    + {% for message in messages %} + + {{ message }} + + {% endfor %} +
+ +
+ {% endif %} +
+
+ {% trans '

Внимание! Мы не можем гарантировать то, что все организаторы предоставляют возможность заказа печатного каталога выставки. Получая Ваш запрос, мы персонально связываемся с организатором конкретного события и уточняем информацию об условиях приобретения. Только после этого мы подтверждаем Вам возможность заказа.

' %} +
+ +
+ + + +
+{% endblock %} \ No newline at end of file diff --git a/templates/debug_toolbar/base.html b/templates/debug_toolbar/base.html new file mode 100644 index 00000000..c6462835 --- /dev/null +++ b/templates/debug_toolbar/base.html @@ -0,0 +1,70 @@ +{% load i18n %}{% load static from staticfiles %}{% load url from future %} + + +{% if toolbar.config.JQUERY_URL %} + + + + +{% else %} + +{% endif %} + + diff --git a/templates/debug_toolbar/panels/cache.html b/templates/debug_toolbar/panels/cache.html new file mode 100644 index 00000000..527306cf --- /dev/null +++ b/templates/debug_toolbar/panels/cache.html @@ -0,0 +1,69 @@ +{% load i18n %} +

{% trans "Summary" %}

+ + + + + + + + + + + + + + + + + +
{% trans "Total calls" %}{% trans "Total time" %}{% trans "Cache hits" %}{% trans "Cache misses" %}
{{ total_calls }}{{ total_time }} ms{{ hits }}{{ misses }}
+

{% trans "Commands" %}

+ + + + {% for name in counts.keys %} + + {% endfor %} + + + + + {% for value in counts.values %} + + {% endfor %} + + +
{{ name }}
{{ value }}
+{% if calls %} +

{% trans "Calls" %}

+ + + + + + + + + + + + {% for call in calls %} + + + + + + + + + + + + + {% endfor %} + +
{% trans "Time (ms)" %}{% trans "Type" %}{% trans "Arguments" %}{% trans "Keyword arguments" %}{% trans "Backend" %}
+ + + {{ call.time|floatformat:"4" }}{{ call.name|escape }}{{ call.args|escape }}{{ call.kwargs|escape }}{{ call.backend }}
{{ call.trace }}
+{% endif %} diff --git a/templates/debug_toolbar/panels/headers.html b/templates/debug_toolbar/panels/headers.html new file mode 100644 index 00000000..6b43e94a --- /dev/null +++ b/templates/debug_toolbar/panels/headers.html @@ -0,0 +1,60 @@ +{% load i18n %} + +

{% trans "Request headers" %}

+ + + + + + + + + + {% for key, value in request_headers.items %} + + + + + {% endfor %} + +
{% trans "Key" %}{% trans "Value" %}
{{ key|escape }}{{ value|escape }}
+ +

{% trans "Response headers" %}

+ + + + + + + + + + {% for key, value in response_headers.items %} + + + + + {% endfor %} + +
{% trans "Key" %}{% trans "Value" %}
{{ key|escape }}{{ value|escape }}
+ +

{% trans "WSGI environ" %}

+ +

{% trans "Since the WSGI environ inherits the environment of the server, only a significant subset is shown below." %}

+ + + + + + + + + + {% for key, value in environ.items %} + + + + + {% endfor %} + +
{% trans "Key" %}{% trans "Value" %}
{{ key|escape }}{{ value|escape }}
diff --git a/templates/debug_toolbar/panels/logging.html b/templates/debug_toolbar/panels/logging.html new file mode 100644 index 00000000..3908f4fe --- /dev/null +++ b/templates/debug_toolbar/panels/logging.html @@ -0,0 +1,28 @@ +{% load i18n %} +{% if records %} + + + + + + + + + + + + {% for record in records %} + + + + + + + + {% endfor %} + +
{% trans "Level" %}{% trans "Time" %}{% trans "Channel" %}{% trans "Message" %}{% trans "Location" %}
{{ record.level }}{{ record.time|date:"h:i:s m/d/Y" }}{{ record.channel|default:"-" }}{{ record.message|linebreaksbr }}{{ record.file }}:{{ record.line }}
+{% else %} +

{% trans "No messages logged" %}.

+{% endif %} + diff --git a/templates/debug_toolbar/panels/profiling.html b/templates/debug_toolbar/panels/profiling.html new file mode 100644 index 00000000..0cd1f975 --- /dev/null +++ b/templates/debug_toolbar/panels/profiling.html @@ -0,0 +1,37 @@ +{% load i18n %}{% load static from staticfiles %} + + + + + + + + + + + + + {% for call in func_list %} + + + + + + + + + + {% endfor %} + +
{% trans "Call" %}{% trans "CumTime" %}{% trans "Per" %}{% trans "TotTime" %}{% trans "Per" %}{% trans "Count" %}
+
+ {% if call.has_subfuncs %} + - + {% else %} + + {% endif %} + {{ call.func_std_string }} +
+
{{ call.cumtime|floatformat:3 }}{{ call.cumtime_per_call|floatformat:3 }}{{ call.tottime|floatformat:3 }}{{ call.tottime_per_call|floatformat:3 }}{{ call.count }}
+ + diff --git a/templates/debug_toolbar/panels/request.html b/templates/debug_toolbar/panels/request.html new file mode 100644 index 00000000..c3c8d58c --- /dev/null +++ b/templates/debug_toolbar/panels/request.html @@ -0,0 +1,124 @@ +{% load i18n %} + +

{% trans "View information" %}

+ + + + + + + + + + + + + + + + + +
{% trans "View function" %}{% trans "Arguments" %}{% trans "Keyword arguments" %}{% trans "URL name" %}
{{ view_func }}{{ view_args|pprint }}{{ view_kwargs|pprint }}{{ view_urlname }}
+ +{% if cookies %} +

{% trans "Cookies" %}

+ + + + + + + + + + + + + {% for key, value in cookies %} + + + + + {% endfor %} + +
{% trans "Variable" %}{% trans "Value" %}
{{ key|pprint }}{{ value|pprint }}
+{% else %} +

{% trans "No cookies" %}

+{% endif %} + +{% if session %} +

{% trans "Session data" %}

+ + + + + + + + + + + + + {% for key, value in session %} + + + + + {% endfor %} + +
{% trans "Variable" %}{% trans "Value" %}
{{ key|pprint }}{{ value|pprint }}
+{% else %} +

{% trans "No session data" %}

+{% endif %} + +{% if get %} +

{% trans "GET data" %}

+ + + + + + + + + + + + + {% for key, value in get %} + + + + + {% endfor %} + +
{% trans "Variable" %}{% trans "Value" %}
{{ key|pprint }}{{ value|pprint }}
+{% else %} +

{% trans "No GET data" %}

+{% endif %} + +{% if post %} +

{% trans "POST data" %}

+ + + + + + + + + + + {% for key, value in post %} + + + + + {% endfor %} + +
{% trans "Variable" %}{% trans "Value" %}
{{ key|pprint }}{{ value|pprint }}
+{% else %} +

{% trans "No POST data" %}

+{% endif %} diff --git a/templates/debug_toolbar/panels/settings.html b/templates/debug_toolbar/panels/settings.html new file mode 100644 index 00000000..f6b5afe8 --- /dev/null +++ b/templates/debug_toolbar/panels/settings.html @@ -0,0 +1,17 @@ +{% load i18n %} + + + + + + + + + {% for name, value in settings.items %} + + + + + {% endfor %} + +
{% trans "Setting" %}{% trans "Value" %}
{{ name }}{{ value|pprint }}
diff --git a/templates/debug_toolbar/panels/signals.html b/templates/debug_toolbar/panels/signals.html new file mode 100644 index 00000000..ac32f373 --- /dev/null +++ b/templates/debug_toolbar/panels/signals.html @@ -0,0 +1,19 @@ +{% load i18n %} + + + + + + + + + + {% for name, signal, receivers in signals %} + + + + + + {% endfor %} + +
{% trans "Signal" %}{% trans "Providing" %}{% trans "Receivers" %}
{{ name|escape }}{{ signal.providing_args|join:", " }}{{ receivers|join:", " }}
diff --git a/templates/debug_toolbar/panels/sql.html b/templates/debug_toolbar/panels/sql.html new file mode 100644 index 00000000..8c6725d8 --- /dev/null +++ b/templates/debug_toolbar/panels/sql.html @@ -0,0 +1,95 @@ +{% load i18n l10n %}{% load static from staticfiles %}{% load url from future %} +
+
    + {% for alias, info in databases %} +
  • +   {{ alias }} + {{ info.time_spent|floatformat:"2" }} ms ({% blocktrans count info.num_queries as num %}{{ num }} query{% plural %}{{ num }} queries{% endblocktrans %}) +
  • + {% endfor %} +
+
+ +{% if queries %} + + + + + + + + + + + + {% for query in queries %} + + + + + + + + + + + + + {% endfor %} + +
 {% trans "Query" %}{% trans "Timeline" %}{% trans "Time (ms)" %}{% trans "Action" %}
  + + + +
+
{{ query.sql|safe }}
+
+
+
{{ query.width_ratio }}%
+
+ {{ query.duration|floatformat:"2" }} + + + {% if query.params %} + {% if query.is_select %} +
+ {{ query.form }} + + + + + {% if query.vendor == 'mysql' %} + + {% endif %} +
+ {% endif %} + {% endif %} +
+
+

{% trans "Connection:" %} {{ query.alias }}

+ {% if query.iso_level %} +

{% trans "Isolation level:" %} {{ query.iso_level }}

+ {% endif %} + {% if query.trans_status %} +

{% trans "Transaction status:" %} {{ query.trans_status }}

+ {% endif %} + {% if query.stacktrace %} +
{{ query.stacktrace }}
+ {% endif %} + {% if query.template_info %} + + {% for line in query.template_info.context %} + + + + + {% endfor %} +
{{ line.num }}{{ line.content }}
+

{{ query.template_info.name|default:_("(unknown)") }}

+ {% endif %} +
+
+{% else %} +

{% trans "No SQL queries were recorded during this request." %}

+{% endif %} + + diff --git a/templates/debug_toolbar/panels/sql_explain.html b/templates/debug_toolbar/panels/sql_explain.html new file mode 100644 index 00000000..0fa30ab7 --- /dev/null +++ b/templates/debug_toolbar/panels/sql_explain.html @@ -0,0 +1,37 @@ +{% load i18n %}{% load static from staticfiles %} +
+ +

{% trans "SQL explained" %}

+
+
+
+
+
{% trans "Executed SQL" %}
+
{{ sql|safe }}
+
{% trans "Time" %}
+
{{ duration }} ms
+
{% trans "Database" %}
+
{{ alias }}
+
+ + + + {% for h in headers %} + + {% endfor %} + + + + {% for row in result %} + + {% for column in row %} + + {% endfor %} + + {% endfor %} + +
{{ h|upper }}
{{ column|escape }}
+
+
+ + diff --git a/templates/debug_toolbar/panels/sql_profile.html b/templates/debug_toolbar/panels/sql_profile.html new file mode 100644 index 00000000..e5813c6c --- /dev/null +++ b/templates/debug_toolbar/panels/sql_profile.html @@ -0,0 +1,44 @@ +{% load i18n %}{% load static from staticfiles %} +
+ +

{% trans "SQL profiled" %}

+
+
+
+ {% if result %} +
+
{% trans "Executed SQL" %}
+
{{ sql|safe }}
+
{% trans "Time" %}
+
{{ duration }} ms
+
{% trans "Database" %}
+
{{ alias }}
+
+ + + + {% for h in headers %} + + {% endfor %} + + + + {% for row in result %} + + {% for column in row %} + + {% endfor %} + + {% endfor %} + +
{{ h|upper }}
{{ column|escape }}
+ {% else %} +
+
{% trans "Error" %}
+
{{ result_error }}
+
+ {% endif %} +
+
+ + diff --git a/templates/debug_toolbar/panels/sql_select.html b/templates/debug_toolbar/panels/sql_select.html new file mode 100644 index 00000000..50cd0b1c --- /dev/null +++ b/templates/debug_toolbar/panels/sql_select.html @@ -0,0 +1,41 @@ +{% load i18n %}{% load static from staticfiles %} +
+ +

{% trans "SQL selected" %}

+
+
+
+
+
{% trans "Executed SQL" %}
+
{{ sql|safe }}
+
{% trans "Time" %}
+
{{ duration }} ms
+
{% trans "Database" %}
+
{{ alias }}
+
+ {% if result %} + + + + {% for h in headers %} + + {% endfor %} + + + + {% for row in result %} + + {% for column in row %} + + {% endfor %} + + {% endfor %} + +
{{ h|upper }}
{{ column|escape }}
+ {% else %} +

{% trans "Empty set" %}

+ {% endif %} +
+
+ + diff --git a/templates/debug_toolbar/panels/staticfiles.html b/templates/debug_toolbar/panels/staticfiles.html new file mode 100644 index 00000000..95c9ec87 --- /dev/null +++ b/templates/debug_toolbar/panels/staticfiles.html @@ -0,0 +1,57 @@ +{% load i18n %} +{% load static from staticfiles%} + +

{% blocktrans count staticfiles_dirs|length as dirs_count %}Static file path{% plural %}Static file paths{% endblocktrans %}

+{% if staticfiles_dirs %} +
    + {% for prefix, staticfiles_dir in staticfiles_dirs %} +
  1. {{ staticfiles_dir }}{% if prefix %} {% blocktrans %}(prefix {{ prefix }}){% endblocktrans %}{% endif %}
  2. + {% endfor %} +
+{% else %} +

{% trans "None" %}

+{% endif %} + +

{% blocktrans count staticfiles_apps|length as apps_count %}Static file app{% plural %}Static file apps{% endblocktrans %}

+{% if staticfiles_apps %} +
    + {% for static_app in staticfiles_apps %} +
  1. {{ static_app }}
  2. + {% endfor %} +
+{% else %} +

{% trans "None" %}

+{% endif %} + +

{% blocktrans count staticfiles|length as staticfiles_count %}Static file{% plural %}Static files{% endblocktrans %}

+{% if staticfiles %} +
+{% for staticfile in staticfiles %} +
{{ staticfile }}
+
{{ staticfile.real_path }}
+{% endfor %} +
+{% else %} +

{% trans "None" %}

+{% endif %} + + +{% for finder, payload in staticfiles_finders.items %} +

{{ finder }} ({% blocktrans count payload|length as payload_count %}{{ payload_count }} file{% plural %}{{ payload_count }} files{% endblocktrans %})

+ + + + + + + + + {% for path, real_path in payload %} + + + + + {% endfor %} + +
{% trans 'Path' %}{% trans 'Location' %}
{{ path }}{{ real_path }}
+{% endfor %} diff --git a/templates/debug_toolbar/panels/template_source.html b/templates/debug_toolbar/panels/template_source.html new file mode 100644 index 00000000..7914f2ed --- /dev/null +++ b/templates/debug_toolbar/panels/template_source.html @@ -0,0 +1,14 @@ +{% load i18n %} +
+ +

{% trans "Template source:" %} {{ template_name }}

+
+
+
+ {% if not source.pygmentized %} + {{ source }} + {% else %} + {{ source }} + {% endif %} +
+
diff --git a/templates/debug_toolbar/panels/templates.html b/templates/debug_toolbar/panels/templates.html new file mode 100644 index 00000000..644b4d64 --- /dev/null +++ b/templates/debug_toolbar/panels/templates.html @@ -0,0 +1,46 @@ +{% load i18n %}{% load static from staticfiles %}{% load url from future %} +

{% blocktrans count template_dirs|length as template_count %}Template path{% plural %}Template paths{% endblocktrans %}

+{% if template_dirs %} +
    + {% for template in template_dirs %} +
  1. {{ template }}
  2. + {% endfor %} +
+{% else %} +

{% trans "None" %}

+{% endif %} + +

{% blocktrans count templates|length as template_count %}Template{% plural %}Templates{% endblocktrans %}

+{% if templates %} +
+{% for template in templates %} +
{{ template.template.name|addslashes }}
+
{{ template.template.origin_name|addslashes }}
+ {% if template.context %} +
+ + +
+ {% endif %} +{% endfor %} +
+{% else %} +

{% trans "None" %}

+{% endif %} + +

{% blocktrans count context_processors|length as context_processors_count %}Context processor{% plural %}Context processors{% endblocktrans %}

+{% if context_processors %} +
+{% for key, value in context_processors.items %} +
{{ key|escape }}
+
+ + +
+{% endfor %} +
+{% else %} +

{% trans "None" %}

+{% endif %} + + diff --git a/templates/debug_toolbar/panels/timer.html b/templates/debug_toolbar/panels/timer.html new file mode 100644 index 00000000..988c7156 --- /dev/null +++ b/templates/debug_toolbar/panels/timer.html @@ -0,0 +1,44 @@ +{% load i18n %}{% load static from staticfiles %} +

{% trans "Resource usage" %}

+ + + + + + + + + + + + + {% for key, value in rows %} + + + + + {% endfor %} + +
{% trans "Resource" %}{% trans "Value" %}
{{ key|escape }}{{ value|escape }}
+ + + + diff --git a/templates/debug_toolbar/panels/versions.html b/templates/debug_toolbar/panels/versions.html new file mode 100644 index 00000000..2c614f11 --- /dev/null +++ b/templates/debug_toolbar/panels/versions.html @@ -0,0 +1,17 @@ +{% load i18n %} + + + + + + + + + {% for package, version in versions.items %} + + + + + {% endfor %} + +
{% trans "Name" %}{% trans "Version" %}
{{ package }}{{ version }}
diff --git a/templates/debug_toolbar/redirect.html b/templates/debug_toolbar/redirect.html new file mode 100644 index 00000000..365fb482 --- /dev/null +++ b/templates/debug_toolbar/redirect.html @@ -0,0 +1,16 @@ +{% load i18n %} + + + + + +

{{ status_line }}

+

{% trans "Location:" %} {{ redirect_to }}

+

+ {% trans "The Django Debug Toolbar has intercepted a redirect to the above URL for debug viewing purposes. You can click the above link to continue with the redirect as normal." %} +

+ + + diff --git a/templates/registration/activation_complete.html b/templates/registration/activation_complete.html index 9e86484b..4f99685e 100644 --- a/templates/registration/activation_complete.html +++ b/templates/registration/activation_complete.html @@ -1,7 +1,7 @@ {% extends "base_catalog.html" %} {% load i18n %} -{% block title %}Activation complete{% endblock %} +{% block title %}{% trans 'Активация завершена' %}{% endblock %} {% block page_title %} {% endblock %} {% block content_list %} diff --git a/templates/registration/activation_email_subject.txt b/templates/registration/activation_email_subject.txt index 2d146b83..6019400e 100644 --- a/templates/registration/activation_email_subject.txt +++ b/templates/registration/activation_email_subject.txt @@ -1 +1,2 @@ -Activate your {{ site }} account - you have {{ expiration_days }} days! +{% load i18n %} +{% trans 'Активируйте ваш' %} {{ site }} {% trans 'акаунт - вы имеете' %} {{ expiration_days }} {% trans 'дня' %} diff --git a/theme/management/commands/old_urls.py b/theme/management/commands/old_urls.py new file mode 100644 index 00000000..bc9c5dbf --- /dev/null +++ b/theme/management/commands/old_urls.py @@ -0,0 +1,52 @@ +from django.core.management.base import BaseCommand +from theme.models import Tag, Theme + +import MySQLdb +from MySQLdb.cursors import DictCursor + +class Command(BaseCommand): + def handle(self, *args, **options): + db = MySQLdb.connect(host="localhost", + user="expomap", + passwd="7FbLtAGjse", + db="old_db", + charset='utf8', + cursorclass=DictCursor) + + cursor = db.cursor() + # id 3732 duplicate tag with bad name(2 spaces) + sql_tag = "SELECT id, title, url FROM tags WHERE id != 3732" + + sql_theme = "SELECT categories_id as id, url FROM categories_description;" + + cursor.execute(sql_theme) + res = cursor.fetchall() + """ + # themes + for item in res: + id = item['id'] + old_url = item['url'] + theme = Theme.objects.get(id=id) + theme.old_url = old_url + theme.save() + print(theme) + """ + + # tags + cursor.execute(sql_tag) + res = cursor.fetchall() + updated_tags = [] + for item in res: + id = item['id'] + old_url = item['url'] + title = item['title'] + #print(id) + print(title.encode('utf8')) + try: + tag = Tag.objects.get(id=id, translations__name=title, translations__language_code='ru') + tag.old_url = old_url + updated_tags.append(id) + tag.save() + except Tag.DoesNotExist: + Tag.objects.exclude(id__in=updated_tags).filter(translations__name=title).update(old_url=old_url) + print(len(updated_tags)) diff --git a/theme/models.py b/theme/models.py index cbcc0742..c347c514 100644 --- a/theme/models.py +++ b/theme/models.py @@ -58,6 +58,7 @@ class Theme(TranslatableModel): ('webinar', 'Вебинар'), ) url = models.SlugField(unique=True, max_length=255) + old_url = models.SlugField(unique=True, max_length=255) types = BitField([k for k, v in FLAGS]) #translated fields translations = TranslatedFields( @@ -71,6 +72,7 @@ class Theme(TranslatableModel): ) main_page = models.PositiveIntegerField(default=0, db_index=True) + inflect = models.CharField(max_length=255, blank=True) def __unicode__(self): return self.lazy_translation_getter('name', unicode(self.pk)) @@ -161,6 +163,7 @@ class Tag(TranslatableModel): active = TagActiveManager() url = models.SlugField(unique=True, max_length=255) + old_url = models.SlugField(unique=True, max_length=255) theme = models.ForeignKey(Theme, on_delete=models.PROTECT, related_name='tags') #translated fields @@ -174,6 +177,7 @@ class Tag(TranslatableModel): keywords = models.CharField(max_length=250, blank=True), ) + inflect = models.CharField(max_length=255, blank=True) #fields saves information about creating and changing model #created = models.DateTimeField(auto_now_add=True) #modified = models.DateTimeField(auto_now=True)