Search bug. Cities and countries import

remotes/origin/1203
Назар Котюк 11 years ago
parent 85326c7079
commit 531c85fe6f
  1. 1
      article/management/__init__.py
  2. 1
      article/management/commands/__init__.py
  3. 22
      article/management/commands/articles_from_old.py
  4. 30
      city/management/commands/city_update_from_old.py
  5. 3
      city/models.py
  6. 39
      country/management/commands/country_update_from_old.py
  7. 4
      country/models.py
  8. 7
      exposition/urls.py
  9. 66
      exposition/views.py
  10. 11
      functions/custom_views.py
  11. 2
      functions/search_forms.py
  12. 3
      settings/templatetags/tempalte_tags.py
  13. 65
      templates/client/exposition/catalog_theme.html
  14. 3
      templates/client/includes/catalog_search.html
  15. 12
      templates/client/includes/exposition/exposition_object.html

@ -0,0 +1 @@
__author__ = 'root'

@ -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"""

@ -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'))

@ -33,6 +33,9 @@ class City(TranslatableModel):
services = BitField(flags=flags) services = BitField(flags=flags)
url = models.SlugField(unique=True) url = models.SlugField(unique=True)
#
old_url = models.CharField(max_length=55)
inflect = models.CharField(max_length=255, blank=True)
#relations #relations
country = models.ForeignKey('country.Country', null=True, on_delete=models.PROTECT, related_name='cities') country = models.ForeignKey('country.Country', null=True, on_delete=models.PROTECT, related_name='cities')
code_IATA = models.ForeignKey(Iata, blank=True, null=True) code_IATA = models.ForeignKey(Iata, blank=True, null=True)

@ -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

@ -93,6 +93,10 @@ class Country(TranslatableModel):
services = BitField(flags=flags) services = BitField(flags=flags)
url = models.SlugField(unique=True) url = models.SlugField(unique=True)
#
old_url = models.CharField(unique=True, max_length=55)
inflect = models.CharField(max_length=255, blank=True)
# relations # relations
area = models.ForeignKey(Area) area = models.ForeignKey(Area)
big_cities = models.ManyToManyField(City, blank=True, null=True, related_name='cities') big_cities = models.ManyToManyField(City, blank=True, null=True, related_name='cities')

@ -16,6 +16,7 @@ urlpatterns = patterns('',
url(r'exposition-visit/(?P<id>\d+)/$', 'exposition.views.exposition_visit'), url(r'exposition-visit/(?P<id>\d+)/$', 'exposition.views.exposition_visit'),
# search # search
url(r'expo/search/', ExpositionSearchView.as_view()), url(r'expo/search/', ExpositionSearchView.as_view()),
#url(r'expo/search/', 'exposition.views.search_test'),
# country catalog # country catalog
@ -36,6 +37,12 @@ urlpatterns = patterns('',
url(r'expo/city/(?P<slug>.*)/$', ExpoCityCatalog.as_view()), url(r'expo/city/(?P<slug>.*)/$', ExpoCityCatalog.as_view()),
# theme catalog # theme catalog
url(r'expo/theme/$', ExpositionByTheme.as_view()), url(r'expo/theme/$', ExpositionByTheme.as_view()),
url(r'expo/theme/(?P<slug>.*)/country/(?P<country_slug>.*)/page/(?P<page>\d+)/$', ExpoThemeCatalog.as_view()),
url(r'expo/theme/(?P<slug>.*)/country/(?P<country_slug>.*)/$', ExpoThemeCatalog.as_view()),
url(r'expo/theme/(?P<slug>.*)/city/(?P<city_slug>.*)/page/(?P<page>\d+)/$', ExpoThemeCatalog.as_view()),
url(r'expo/theme/(?P<slug>.*)/city/(?P<city_slug>.*)/$', ExpoThemeCatalog.as_view()),
url(r'expo/theme/(?P<slug>.*)/(?P<year>\d+)/(?P<month>.*)/page/(?P<page>\d+)/$', ExpoThemeCatalog.as_view()), url(r'expo/theme/(?P<slug>.*)/(?P<year>\d+)/(?P<month>.*)/page/(?P<page>\d+)/$', ExpoThemeCatalog.as_view()),
url(r'expo/theme/(?P<slug>.*)/(?P<year>\d+)/page/(?P<page>\d+)/$', ExpoThemeCatalog.as_view()), url(r'expo/theme/(?P<slug>.*)/(?P<year>\d+)/page/(?P<page>\d+)/$', ExpoThemeCatalog.as_view()),
url(r'expo/theme/(?P<slug>.*)/page/(?P<page>\d+)/$', ExpoThemeCatalog.as_view()), url(r'expo/theme/(?P<slug>.*)/page/(?P<page>\d+)/$', ExpoThemeCatalog.as_view()),

@ -7,7 +7,7 @@ from django.contrib.contenttypes.models import ContentType
from django.conf import settings from django.conf import settings
from django.views.generic import ListView, DetailView from django.views.generic import ListView, DetailView
from django.utils.translation import ugettext as _ 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.http import Http404
from django.utils import translation from django.utils import translation
#models #models
@ -19,7 +19,6 @@ from country.models import Country
from city.models import City from city.models import City
from theme.models import Theme, Tag from theme.models import Theme, Tag
from note.models import Note from note.models import Note
from functions.custom_views import ExpoSearchView
from functions.search_forms import ExpositionSearchForm from functions.search_forms import ExpositionSearchForm
from functions.custom_views import ExpoSearchView from functions.custom_views import ExpoSearchView
@ -82,10 +81,24 @@ class ExpositionByCity(ExpositionBy):
class ExpositionSearchView(ExpoSearchView): class ExpositionSearchView(ExpoSearchView):
#paginate_by = 10 #paginate_by = 10
template_name = 'exposition/search.html' template_name = 'client/exposition/search.html'
search_form = ExpositionSearchForm search_form = ExpositionSearchForm
model = Exposition 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): def exposition_add_calendar(request, id):
args = {'success': False} args = {'success': False}
@ -270,6 +283,8 @@ class ExpoCatalog(ListView):
filter_object = None filter_object = None
year = None year = None
month = None month = None
country = None
city = None
def get_filtered_qs(self): def get_filtered_qs(self):
# diferent for views # diferent for views
@ -282,7 +297,16 @@ class ExpoCatalog(ListView):
if year: if year:
qs = qs.filter(data_begin__year=year) qs = qs.filter(data_begin__year=year)
# info for breadscrumbs # 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') month = self.kwargs.get('month')
@ -294,7 +318,14 @@ class ExpoCatalog(ListView):
'nov': {'value': 11, 'name': _(u'Ноябрь')}, 'dec': {'value': 12, 'name': _(u'Декабрь')}} 'nov': {'value': 11, 'name': _(u'Ноябрь')}, 'dec': {'value': 12, 'name': _(u'Декабрь')}}
if month and monthes.get(month): if month and monthes.get(month):
qs = qs.filter(data_begin__month=monthes[month]['value']) 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') return qs.order_by('data_begin')
@ -330,15 +361,40 @@ class ExpoCityCatalog(ExpoCatalog):
class ExpoThemeCatalog(ExpoCatalog): class ExpoThemeCatalog(ExpoCatalog):
template_name = 'exposition/catalog_theme.html'
catalog_url = '/expo/theme/' catalog_url = '/expo/theme/'
country = None
city = None
def get_filtered_qs(self): def get_filtered_qs(self):
#this method used in parent get_queryset #this method used in parent get_queryset
slug = self.kwargs.get('slug') 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) theme = get_object_or_404(Theme, url=slug)
qs = self.model.enable.filter(theme=theme) 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 self.filter_object = theme
return qs 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): class ExpoTagCatalog(ExpoCatalog):
catalog_url = '/expo/tag/' catalog_url = '/expo/tag/'

@ -325,12 +325,11 @@ class ExpoSearchView(ListView):
search_form = None search_form = None
model = None model = None
def get_queryset(self):
def get_queryset(self):
if self.request.GET: if self.request.GET:
form = self.search_form(self.request.GET) form = self.search_form(self.request.GET)
if form.is_valid(): if form.is_valid():
return form.search() return form.search()
else: else:
return EmptySearchQuerySet() return EmptySearchQuerySet()
@ -340,10 +339,15 @@ class ExpoSearchView(ListView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(ExpoSearchView, self).get_context_data(**kwargs) context = super(ExpoSearchView, self).get_context_data(**kwargs)
form = self.search_form(self.request.GET)
if self.request.GET: if self.request.GET:
form = self.search_form(self.request.GET)
if form.is_valid(): if form.is_valid():
form.data_with_parents = form.get_form_data() 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 context['search_form'] = form
@ -352,4 +356,5 @@ class ExpoSearchView(ListView):
del queries['page'] del queries['page']
context['queries'] = queries context['queries'] = queries
return context return context

@ -99,6 +99,8 @@ class AbstactSearchForm(forms.Form):
return result return result
def get_places_display(self): def get_places_display(self):
if self.is_valid(): if self.is_valid():
area = self.cleaned_data['area'] area = self.cleaned_data['area']

@ -12,7 +12,8 @@ register = template.Library()
class Date(template.Node): class Date(template.Node):
def __init__(self): def __init__(self):
self.now = datetime.datetime.today() date = datetime.datetime.today().replace(day=1)
self.now = date
def render(self, context): def render(self, context):

@ -0,0 +1,65 @@
{% extends 'base_catalog.html' %}
{% load template_filters %}
{% load i18n %}
{% block bread_scrumbs %}
<div class="bread-crumbs">
<a href="/">{% trans 'Главная страница' %}</a>
<a href="{{ catalog_url }}">{% trans 'Выставки' %}</a>
{% if month %}
<a href="{{ catalog_url }}{{ filter_object.url }}/">{{ filter_object.name }}</a>
{% if country %}
<a href="{{ catalog_url }}{{ filter_object.url }}/country/{{ country.url }}">{{ country.name }}</a>
{% endif %}
{% if city %}
<a href="{{ catalog_url }}{{ filter_object.url }}/city/{{ city.url }}">{{ city.name }}</a>
{% endif %}
<a href="{{ year.link }}">{{ year.text }}</a>
<strong>{{ month.text }}</strong>
{% else %}
{% if year %}
<a href="{{ catalog_url }}{{ filter_object.url }}/">{{ filter_object.name }}</a>
{% if country %}
<a href="{{ catalog_url }}{{ filter_object.url }}/country/{{ country.url }}">{{ country.name }}</a>
{% endif %}
{% if city %}
<a href="{{ catalog_url }}{{ filter_object.url }}/city/{{ city.url }}">{{ city.name }}</a>
{% endif %}
<strong>{{ year.text }}</strong>
{% else %}
{% if country %}
<a href="{{ catalog_url }}{{ filter_object.url }}/">{{ filter_object.name }}</a>
<strong>{{ country.name }}</strong>
{% else %}
{% if city %}
<a href="{{ catalog_url }}{{ filter_object.url }}/">{{ filter_object.name }}</a>
<strong>{{ city.name }}</strong>
{% else %}
<strong>{{ filter_object.name }}</strong>
{% endif %}
{% endif %}
{% endif %}
{% endif %}
</div>
{% endblock %}
{% block page_title %}
<div class="page-title">
<h1>{% trans 'Выставки' %}: <strong>{{ filter_object.name }}</strong></h1>
</div>
{% 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 %}

@ -104,10 +104,11 @@
<script src="{% static 'client/js/plugins/inputmask/jquery.inputmask.js' %}"></script> <script src="{% static 'client/js/plugins/inputmask/jquery.inputmask.js' %}"></script>
<script src="{% static 'client/js' %}{% if debug %}/{% else %}_min/{% endif %}_modules/block.search{% if debug %}{% else %}.min{% endif %}.js"></script> <script src="{% static 'client/js' %}{% if debug %}/{% else %}_min/{% endif %}_modules/block.search{% if debug %}{% else %}.min{% endif %}.js"></script>
<script> <script>
EXPO.searchBlock.init({ EXPO.searchBlock.init({
formId: 'search-block-form', formId: 'search-block-form',
modalTriggerClass:'search-modal-open', modalTriggerClass:'search-modal-open',
searchData:'{{ search_form.data_with_parents|safe }}', searchData:'{{ form_data_with_parents|safe }}',
closerText: "{% trans ' и еще _ позиции' %}", closerText: "{% trans ' и еще _ позиции' %}",
closerTextSingle:"{% trans ' и еще _ позиция' %}", closerTextSingle:"{% trans ' и еще _ позиция' %}",
place:{ place:{

@ -368,14 +368,10 @@
--> -->
<div class="e-cat look-also"> <div class="e-cat look-also">
<div class="sect-title">{% trans 'Смотрите также:' %}</div> <div class="sect-title">{% trans 'Смотрите также:' %}</div>
<a href="{{ exposition.catalog }}city/{{ exposition.city.url }}/">{% trans "Выставки:" %} {{ exposition.city.name }}</a>
<a href="">Выставки: Автомобильная электроника (3)</a> <a href="{{ exposition.catalog }}country/{{ exposition.country.url }}/">{% trans "Выставки:" %} {{ exposition.country.name }}</a>
<a href="">Выставки: Классические автомобили (2)</a> <a href="{{ exposition.catalog }}theme/{{ exposition.theme.all.0.url }}/country/{{ exposition.country.url }}/">{% trans "Выставки по тематике " %}"{{ exposition.theme.all.0.name|lower }}" {% trans "в" %} {{ exposition.country.name }}</a>
<a href="">Выставки: Транспортная промышленность (28)</a> <a href="{{ exposition.catalog }}theme/{{ exposition.theme.all.0.url }}/city/{{ exposition.city.url }}/">{% trans "Выставки по тематике " %}"{{ exposition.theme.all.0.name|lower }}" {% trans "в" %} {{ exposition.city.name }}</a>
<a href="">Выставки: Лес, деревообработка, бумага (8)</a>
<a href="">Выставки: Мода, одежда, обувь, аксессуары (3)</a>
<a href="">Выставки: Полиграфия, издательское дело (14)</a>
</div> </div>
{% endblock %} {% endblock %}

Loading…
Cancel
Save