diff --git a/article/management/__init__.py b/article/management/__init__.py new file mode 100644 index 00000000..3ed9fd0f --- /dev/null +++ b/article/management/__init__.py @@ -0,0 +1 @@ +__author__ = 'root' diff --git a/article/management/commands/__init__.py b/article/management/commands/__init__.py new file mode 100644 index 00000000..3ed9fd0f --- /dev/null +++ b/article/management/commands/__init__.py @@ -0,0 +1 @@ +__author__ = 'root' diff --git a/article/management/commands/articles_from_old.py b/article/management/commands/articles_from_old.py new file mode 100644 index 00000000..51bbda1f --- /dev/null +++ b/article/management/commands/articles_from_old.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +import MySQLdb +from MySQLdb.cursors import DictCursor +from django.core.management.base import BaseCommand, CommandError +from functions.translate import fill_with_signal +from article.models import Article + + +class Command(BaseCommand): + def handle(self, *args, **options): + db = MySQLdb.connect(host="localhost", + user="kotzilla", + passwd="qazedc", + db="old_expomap", + charset='utf8', + cursorclass=DictCursor) + cursor = db.cursor() + sql = """SELECT articles_description.articles_id as id , articles_description.articles_name as name, articles_description.articles_description as description, articles_description.articles_head_title_tag as title, articles_description.articles_head_desc_tag as descriptions, articles_description.articles_head_keywords_tag as keywords, articles_description.articles_intro as main_title, articles.articles_date_added as created, articles.articles_last_modified as modified + FROM `articles_description` + JOIN articles + ON articles_description.articles_id=articles.articles_id""" + diff --git a/city/management/commands/city_update_from_old.py b/city/management/commands/city_update_from_old.py new file mode 100644 index 00000000..465d0930 --- /dev/null +++ b/city/management/commands/city_update_from_old.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +import MySQLdb +from MySQLdb.cursors import DictCursor +from django.core.management.base import BaseCommand, CommandError +from django.utils import translation +from country.models import City + + +class Command(BaseCommand): + def handle(self, *args, **options): + db = MySQLdb.connect(host="localhost", + user="kotzilla", + passwd="qazedc", + db="test2", + charset='utf8', + cursorclass=DictCursor) + cursor = db.cursor() + sql = """SELECT title, url, inflect + FROM old_expomap.products_places + WHERE parent_id > 0 """ + + + cursor.execute(sql) + result = cursor.fetchall() + for res in result: + name = res['title'] + url = res['url'] + inflect = res['inflect'] + City.objects.filter(translations__name=name).update(inflect=inflect, old_url=url) + print(name.encode('utf-8')) \ No newline at end of file diff --git a/city/models.py b/city/models.py index f2e312bf..c4f07298 100644 --- a/city/models.py +++ b/city/models.py @@ -33,6 +33,9 @@ class City(TranslatableModel): services = BitField(flags=flags) url = models.SlugField(unique=True) + # + old_url = models.CharField(max_length=55) + inflect = models.CharField(max_length=255, blank=True) #relations country = models.ForeignKey('country.Country', null=True, on_delete=models.PROTECT, related_name='cities') code_IATA = models.ForeignKey(Iata, blank=True, null=True) diff --git a/country/management/commands/country_update_from_old.py b/country/management/commands/country_update_from_old.py new file mode 100644 index 00000000..5c70e1f9 --- /dev/null +++ b/country/management/commands/country_update_from_old.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +import MySQLdb +from MySQLdb.cursors import DictCursor +from django.core.management.base import BaseCommand, CommandError +from django.utils import translation +from country.models import Country + + +def get_from_old(country): + db = MySQLdb.connect(host="localhost", + user="kotzilla", + passwd="qazedc", + db="test2", + charset='utf8', + cursorclass=DictCursor) + cursor = db.cursor() + sql = """SELECT url, inflect FROM old_expomap.products_places WHERE title="%(name)s" """%{'name': country.name.encode('utf-8')} + #print(country.name.encode('utf-8')) +# print(sql) + cursor.execute(sql) + result = cursor.fetchone() + + return result + + +class Command(BaseCommand): + def handle(self, *args, **options): + translation.activate('ru') + for country in Country.objects.all(): + old_data = get_from_old(country) + if old_data is None: + continue + country.old_url = old_data['url'] + country.inflect = old_data['inflect'] + try: + country.save() + print(country) + except: + continue \ No newline at end of file diff --git a/country/models.py b/country/models.py index 6e954537..9af02d61 100644 --- a/country/models.py +++ b/country/models.py @@ -93,6 +93,10 @@ class Country(TranslatableModel): services = BitField(flags=flags) url = models.SlugField(unique=True) + # + old_url = models.CharField(unique=True, max_length=55) + inflect = models.CharField(max_length=255, blank=True) + # relations area = models.ForeignKey(Area) big_cities = models.ManyToManyField(City, blank=True, null=True, related_name='cities') diff --git a/exposition/urls.py b/exposition/urls.py index 02c4b8af..b0f74175 100644 --- a/exposition/urls.py +++ b/exposition/urls.py @@ -16,6 +16,7 @@ urlpatterns = patterns('', url(r'exposition-visit/(?P\d+)/$', 'exposition.views.exposition_visit'), # search url(r'expo/search/', ExpositionSearchView.as_view()), + #url(r'expo/search/', 'exposition.views.search_test'), # country catalog @@ -36,6 +37,12 @@ urlpatterns = patterns('', url(r'expo/city/(?P.*)/$', ExpoCityCatalog.as_view()), # theme catalog url(r'expo/theme/$', ExpositionByTheme.as_view()), + + url(r'expo/theme/(?P.*)/country/(?P.*)/page/(?P\d+)/$', ExpoThemeCatalog.as_view()), + url(r'expo/theme/(?P.*)/country/(?P.*)/$', ExpoThemeCatalog.as_view()), + url(r'expo/theme/(?P.*)/city/(?P.*)/page/(?P\d+)/$', ExpoThemeCatalog.as_view()), + url(r'expo/theme/(?P.*)/city/(?P.*)/$', ExpoThemeCatalog.as_view()), + url(r'expo/theme/(?P.*)/(?P\d+)/(?P.*)/page/(?P\d+)/$', ExpoThemeCatalog.as_view()), url(r'expo/theme/(?P.*)/(?P\d+)/page/(?P\d+)/$', ExpoThemeCatalog.as_view()), url(r'expo/theme/(?P.*)/page/(?P\d+)/$', ExpoThemeCatalog.as_view()), diff --git a/exposition/views.py b/exposition/views.py index 9f5bcb93..1e709f0a 100644 --- a/exposition/views.py +++ b/exposition/views.py @@ -7,7 +7,7 @@ from django.contrib.contenttypes.models import ContentType from django.conf import settings from django.views.generic import ListView, DetailView from django.utils.translation import ugettext as _ -from django.shortcuts import get_object_or_404 +from django.shortcuts import get_object_or_404, render_to_response from django.http import Http404 from django.utils import translation #models @@ -19,7 +19,6 @@ from country.models import Country from city.models import City from theme.models import Theme, Tag from note.models import Note -from functions.custom_views import ExpoSearchView from functions.search_forms import ExpositionSearchForm from functions.custom_views import ExpoSearchView @@ -82,10 +81,24 @@ class ExpositionByCity(ExpositionBy): class ExpositionSearchView(ExpoSearchView): #paginate_by = 10 - template_name = 'exposition/search.html' + template_name = 'client/exposition/search.html' search_form = ExpositionSearchForm model = Exposition +""" +def search_test(request): + if request.GET: + form = ExpositionSearchForm(request.GET) + if form.is_valid(): + form.data_with_parents = form.get_form_data() + object_list = form.search() + + context = {} + context['object_list'] = object_list + context['search_form'] = form + return render_to_response('client/exposition/search.html', context) +""" + def exposition_add_calendar(request, id): args = {'success': False} @@ -270,6 +283,8 @@ class ExpoCatalog(ListView): filter_object = None year = None month = None + country = None + city = None def get_filtered_qs(self): # diferent for views @@ -282,7 +297,16 @@ class ExpoCatalog(ListView): if year: qs = qs.filter(data_begin__year=year) # info for breadscrumbs - self.year = {'text': year, 'link': '%s%s/%s/'%(self.catalog_url, self.filter_object.url, year)} + if self.country: + self.year = {'text': year, 'link': '%s%s/country/%s/%s/'% + (self.catalog_url, self.filter_object.url, self.country.url, year) + } + elif self.city: + self.year = {'text': year, 'link': '%s%s/city/%s/%s/'% + (self.catalog_url, self.filter_object.url, self.city.url, year) + } + else: + self.year = {'text': year, 'link': '%s%s/%s/'%(self.catalog_url, self.filter_object.url, year)} month = self.kwargs.get('month') @@ -294,7 +318,14 @@ class ExpoCatalog(ListView): 'nov': {'value': 11, 'name': _(u'Ноябрь')}, 'dec': {'value': 12, 'name': _(u'Декабрь')}} if month and monthes.get(month): qs = qs.filter(data_begin__month=monthes[month]['value']) - self.month = {'text': monthes[month]['name'], 'link': '%s%s/%s/%s/'%(self.catalog_url, self.filter_object.url, year, month)} + if self.country: + self.month = {'text': monthes[month]['name'], 'link': '%s%s/country/%s/%s/%s/'% + (self.catalog_url, self.filter_object.url, self.country.url, year, month)} + elif self.city: + self.month = {'text': monthes[month]['name'], 'link': '%s%s/city/%s/%s/%s/'% + (self.catalog_url, self.filter_object.url, self.city.url, year, month)} + else: + self.month = {'text': monthes[month]['name'], 'link': '%s%s/%s/%s/'%(self.catalog_url, self.filter_object.url, year, month)} return qs.order_by('data_begin') @@ -330,15 +361,40 @@ class ExpoCityCatalog(ExpoCatalog): class ExpoThemeCatalog(ExpoCatalog): + template_name = 'exposition/catalog_theme.html' catalog_url = '/expo/theme/' + country = None + city = None + def get_filtered_qs(self): #this method used in parent get_queryset slug = self.kwargs.get('slug') + country_slug = self.kwargs.get('country_slug') + city_slug = self.kwargs.get('city_slug') theme = get_object_or_404(Theme, url=slug) + qs = self.model.enable.filter(theme=theme) + if country_slug: + country = get_object_or_404(Country, url=country_slug) + self.country = country + qs = qs.filter(country=country) + + if city_slug: + city = get_object_or_404(City, url=city_slug) + self.city = city + qs = qs.filter(city=city) + self.filter_object = theme return qs + def get_context_data(self, **kwargs): + context = super(ExpoThemeCatalog, self).get_context_data(**kwargs) + if self.country: + context['country'] = self.country + if self.city: + context['city'] = self.city + return context + class ExpoTagCatalog(ExpoCatalog): catalog_url = '/expo/tag/' diff --git a/functions/custom_views.py b/functions/custom_views.py index cce1e3f4..9cfff4a9 100644 --- a/functions/custom_views.py +++ b/functions/custom_views.py @@ -325,12 +325,11 @@ class ExpoSearchView(ListView): search_form = None model = None - def get_queryset(self): + def get_queryset(self): if self.request.GET: form = self.search_form(self.request.GET) if form.is_valid(): - return form.search() else: return EmptySearchQuerySet() @@ -340,10 +339,15 @@ class ExpoSearchView(ListView): def get_context_data(self, **kwargs): context = super(ExpoSearchView, self).get_context_data(**kwargs) - form = self.search_form(self.request.GET) + if self.request.GET: + form = self.search_form(self.request.GET) if form.is_valid(): form.data_with_parents = form.get_form_data() + context['form_data_with_parents'] = form.data_with_parents + + else: + form = self.search_form() context['search_form'] = form @@ -352,4 +356,5 @@ class ExpoSearchView(ListView): del queries['page'] context['queries'] = queries + return context \ No newline at end of file diff --git a/functions/search_forms.py b/functions/search_forms.py index ed0c58e8..7f1af9a0 100644 --- a/functions/search_forms.py +++ b/functions/search_forms.py @@ -99,6 +99,8 @@ class AbstactSearchForm(forms.Form): return result + + def get_places_display(self): if self.is_valid(): area = self.cleaned_data['area'] diff --git a/settings/templatetags/tempalte_tags.py b/settings/templatetags/tempalte_tags.py index 5061e270..4f866ce5 100644 --- a/settings/templatetags/tempalte_tags.py +++ b/settings/templatetags/tempalte_tags.py @@ -12,7 +12,8 @@ register = template.Library() class Date(template.Node): def __init__(self): - self.now = datetime.datetime.today() + date = datetime.datetime.today().replace(day=1) + self.now = date def render(self, context): diff --git a/templates/client/exposition/catalog_theme.html b/templates/client/exposition/catalog_theme.html new file mode 100644 index 00000000..7a727431 --- /dev/null +++ b/templates/client/exposition/catalog_theme.html @@ -0,0 +1,65 @@ +{% extends 'base_catalog.html' %} +{% load template_filters %} +{% load i18n %} + +{% block bread_scrumbs %} + +{% endblock %} + + +{% block page_title %} +
+

{% trans 'Выставки' %}: {{ filter_object.name }}

+
+ + {% include 'includes/exposition/catalog_filter_period.html' %} + +{% endblock %} + +{% block content_list %} + {% include 'includes/exposition/exposition_list.html' with object_list=object_list %} +{% endblock %} + +{% block paginator %} + {% include 'includes/catalog_paginator.html' with page_obj=page_obj %} +{% endblock %} \ No newline at end of file diff --git a/templates/client/includes/catalog_search.html b/templates/client/includes/catalog_search.html index dbfd94df..0f08c7a8 100644 --- a/templates/client/includes/catalog_search.html +++ b/templates/client/includes/catalog_search.html @@ -104,10 +104,11 @@