parent
e1b5ceba82
commit
c7c1cc147b
24 changed files with 401 additions and 8515 deletions
@ -1 +0,0 @@ |
|||||||
__author__ = 'kotzilla' |
|
||||||
@ -1 +0,0 @@ |
|||||||
__author__ = 'kotzilla' |
|
||||||
File diff suppressed because it is too large
Load Diff
@ -1,128 +0,0 @@ |
|||||||
from django.core.management.base import BaseCommand, CommandError |
|
||||||
import urllib2, base64, json |
|
||||||
|
|
||||||
from country.models import Country |
|
||||||
from city.models import City |
|
||||||
from functions.form_check import translit_with_separator |
|
||||||
import string, random |
|
||||||
|
|
||||||
def random_url(): |
|
||||||
salt = 'randomurl-' |
|
||||||
r = ''.join(random.choice(string.ascii_lowercase) for _ in range(8)) |
|
||||||
return salt+r |
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand): |
|
||||||
# booking data |
|
||||||
b_username = 'expomap' |
|
||||||
b_password = '33xp00m33p' |
|
||||||
|
|
||||||
def fill_city(self, d): |
|
||||||
lang = d['languagecode'] |
|
||||||
id = d['city_id'] |
|
||||||
country_code = d['countrycode'] |
|
||||||
name = d['name'] |
|
||||||
|
|
||||||
country = Country.objects.filter(country_code=country_code)[0] |
|
||||||
|
|
||||||
try: |
|
||||||
|
|
||||||
city = City.objects.get(id=id) |
|
||||||
except City.DoesNotExist: |
|
||||||
try: |
|
||||||
url = translit_with_separator(name)+'-%s'%country_code |
|
||||||
except: |
|
||||||
url = random_url() |
|
||||||
|
|
||||||
city = City(country=country, id=id, url=url) |
|
||||||
city.translate(lang) |
|
||||||
city.name = name |
|
||||||
try: |
|
||||||
city.save() |
|
||||||
except Exception, e: |
|
||||||
with open('/home/kotzilla/Documents/qwer/proj/city/management/commands/errors.txt', 'a') as f: |
|
||||||
f.write('error: %s\n city: %s\n'%(str(e), str(d))) |
|
||||||
return |
|
||||||
|
|
||||||
|
|
||||||
try: |
|
||||||
url = translit_with_separator(name)+'-%s'%country_code |
|
||||||
except: |
|
||||||
url = random_url() |
|
||||||
|
|
||||||
city.url = url |
|
||||||
try: |
|
||||||
city.save() |
|
||||||
|
|
||||||
except Exception, e: |
|
||||||
with open('/home/kotzilla/Documents/qwer/proj/city/management/commands/errors.txt', 'a') as f: |
|
||||||
f.write('error: %s\n city: %s\n'%(str(e), str(d))) |
|
||||||
return |
|
||||||
|
|
||||||
try: |
|
||||||
tr = City._meta.translations_model.objects.get(language_code=lang,master__id=getattr(city, 'id')) |
|
||||||
except: |
|
||||||
city.translate(lang) |
|
||||||
city.name = name |
|
||||||
try: |
|
||||||
city.save() |
|
||||||
return |
|
||||||
except Exception, e: |
|
||||||
with open('/home/kotzilla/Documents/qwer/proj/city/management/commands/errors.txt', 'a') as f: |
|
||||||
f.write('error: %s\n city: %s\n'%(str(e), str(d))) |
|
||||||
return |
|
||||||
|
|
||||||
tr.name = name |
|
||||||
tr.save() |
|
||||||
return |
|
||||||
|
|
||||||
|
|
||||||
def handle(self, *args, **options): |
|
||||||
ROWS = 1000 |
|
||||||
|
|
||||||
qs = Country.objects.filter() |
|
||||||
codes = [country.country_code for country in qs] |
|
||||||
#print(codes[86:]) |
|
||||||
|
|
||||||
|
|
||||||
for code in codes[86:]:# start from 7 cause previous already filled(delete this) |
|
||||||
offset= 0 |
|
||||||
run = True |
|
||||||
while(run): |
|
||||||
url = 'https://distribution-xml.booking.com/json/bookings.getCities?countrycodes=%s&rows=%s&offset=%s&lanuagecodes=ru,en'%(code ,ROWS, offset) |
|
||||||
request = urllib2.Request(url) |
|
||||||
base64string = base64.encodestring('%s:%s' % (self.b_username, self.b_password)).replace('\n', '') |
|
||||||
request.add_header("Authorization", "Basic %s" % base64string) |
|
||||||
try: |
|
||||||
response = urllib2.urlopen(request) |
|
||||||
except urllib2.HTTPError, e: |
|
||||||
continue |
|
||||||
#raise CommandError('request failed. code error: %s'%code) |
|
||||||
except urllib2.URLError, e: |
|
||||||
continue |
|
||||||
#raise CommandError('request failed. code error: %s'%code) |
|
||||||
if response: |
|
||||||
try: |
|
||||||
json_list = response.read() |
|
||||||
except Exception, e: |
|
||||||
with open('/home/kotzilla/Documents/qwer/proj/city/management/commands/errors.txt', 'a') as f: |
|
||||||
f.write('error: %s\n'%str(e)) |
|
||||||
continue |
|
||||||
else: |
|
||||||
with open('/home/kotzilla/Documents/qwer/proj/city/management/commands/errors.txt', 'a') as f: |
|
||||||
f.write('error: bad request\n') |
|
||||||
continue |
|
||||||
try: |
|
||||||
cities = json.loads(json_list) |
|
||||||
except: |
|
||||||
continue |
|
||||||
|
|
||||||
for city in cities: |
|
||||||
if isinstance(city, dict): |
|
||||||
self.fill_city(city) |
|
||||||
print('city: %s, country: %s, language: %s'%(city.get('name'), city.get('countrycode'), city.get('languagecode'))) |
|
||||||
|
|
||||||
if len(cities) < ROWS: |
|
||||||
run = False |
|
||||||
else: |
|
||||||
offset += ROWS |
|
||||||
@ -1,129 +0,0 @@ |
|||||||
from django.core.management.base import BaseCommand, CommandError |
|
||||||
import urllib2, base64, json |
|
||||||
|
|
||||||
from country.models import Country |
|
||||||
from city.models import City |
|
||||||
from functions.form_check import translit_with_separator |
|
||||||
import string, random |
|
||||||
|
|
||||||
def random_url(): |
|
||||||
salt = 'randomurl-' |
|
||||||
r = ''.join(random.choice(string.ascii_lowercase) for _ in range(8)) |
|
||||||
return salt+r |
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand): |
|
||||||
# booking data |
|
||||||
b_username = 'expomap' |
|
||||||
b_password = '33xp00m33p' |
|
||||||
|
|
||||||
def fill_city(self, d): |
|
||||||
lang = d['languagecode'] |
|
||||||
id = d['city_id'] |
|
||||||
country_code = d['countrycode'] |
|
||||||
name = d['name'] |
|
||||||
|
|
||||||
country = Country.objects.filter(country_code=country_code)[0] |
|
||||||
|
|
||||||
try: |
|
||||||
|
|
||||||
city = City.objects.get(id=id) |
|
||||||
except City.DoesNotExist: |
|
||||||
try: |
|
||||||
url = translit_with_separator(name)+'-%s'%country_code |
|
||||||
except: |
|
||||||
url = random_url() |
|
||||||
|
|
||||||
city = City(country=country, id=id, url=url) |
|
||||||
city.translate(lang) |
|
||||||
city.name = name |
|
||||||
try: |
|
||||||
city.save() |
|
||||||
except Exception, e: |
|
||||||
with open('/home/kotzilla/Documents/qwer/proj/city/management/commands/errors.txt', 'a') as f: |
|
||||||
f.write('error: %s\n city: %s\n'%(str(e), str(d))) |
|
||||||
return |
|
||||||
|
|
||||||
|
|
||||||
try: |
|
||||||
url = translit_with_separator(name)+'-%s'%country_code |
|
||||||
except: |
|
||||||
url = random_url() |
|
||||||
|
|
||||||
city.url = url |
|
||||||
try: |
|
||||||
city.save() |
|
||||||
|
|
||||||
except Exception, e: |
|
||||||
with open('/home/kotzilla/Documents/qwer/proj/city/management/commands/errors.txt', 'a') as f: |
|
||||||
f.write('error: %s\n city: %s\n'%(str(e), str(d))) |
|
||||||
return |
|
||||||
|
|
||||||
try: |
|
||||||
tr = City._meta.translations_model.objects.get(language_code=lang,master__id=getattr(city, 'id')) |
|
||||||
except: |
|
||||||
city.translate(lang) |
|
||||||
city.name = name |
|
||||||
try: |
|
||||||
city.save() |
|
||||||
return |
|
||||||
except Exception, e: |
|
||||||
with open('/home/kotzilla/Documents/qwer/proj/city/management/commands/errors.txt', 'a') as f: |
|
||||||
f.write('error: %s\n city: %s\n'%(str(e), str(d))) |
|
||||||
return |
|
||||||
|
|
||||||
tr.name = name |
|
||||||
tr.save() |
|
||||||
return |
|
||||||
|
|
||||||
|
|
||||||
def handle(self, *args, **options): |
|
||||||
ROWS = 1000 |
|
||||||
|
|
||||||
qs = Country.objects.filter() |
|
||||||
codes = [country.country_code for country in qs] |
|
||||||
|
|
||||||
#print(sorted(codes, reverse=True)) |
|
||||||
|
|
||||||
|
|
||||||
for code in sorted(codes, reverse=True): |
|
||||||
offset= 0 |
|
||||||
run = True |
|
||||||
while(run): |
|
||||||
url = 'https://distribution-xml.booking.com/json/bookings.getCities?countrycodes=%s&rows=%s&offset=%s&lanuagecodes=ru,en'%(code ,ROWS, offset) |
|
||||||
request = urllib2.Request(url) |
|
||||||
base64string = base64.encodestring('%s:%s' % (self.b_username, self.b_password)).replace('\n', '') |
|
||||||
request.add_header("Authorization", "Basic %s" % base64string) |
|
||||||
try: |
|
||||||
response = urllib2.urlopen(request) |
|
||||||
except urllib2.HTTPError, e: |
|
||||||
continue |
|
||||||
#raise CommandError('request failed. code error: %s'%code) |
|
||||||
except urllib2.URLError, e: |
|
||||||
continue |
|
||||||
#raise CommandError('request failed. code error: %s'%code) |
|
||||||
if response: |
|
||||||
try: |
|
||||||
json_list = response.read() |
|
||||||
except Exception, e: |
|
||||||
with open('/home/kotzilla/Documents/qwer/proj/city/management/commands/errors.txt', 'a') as f: |
|
||||||
f.write('error: %s\n'%str(e)) |
|
||||||
continue |
|
||||||
else: |
|
||||||
with open('/home/kotzilla/Documents/qwer/proj/city/management/commands/errors.txt', 'a') as f: |
|
||||||
f.write('error: bad request\n') |
|
||||||
continue |
|
||||||
try: |
|
||||||
cities = json.loads(json_list) |
|
||||||
except: |
|
||||||
continue |
|
||||||
|
|
||||||
for city in cities: |
|
||||||
if isinstance(city, dict): |
|
||||||
self.fill_city(city) |
|
||||||
print('city: %s, country: %s, language: %s'%(city.get('name'), city.get('countrycode'), city.get('languagecode'))) |
|
||||||
|
|
||||||
if len(cities) < ROWS: |
|
||||||
run = False |
|
||||||
else: |
|
||||||
offset += ROWS |
|
||||||
@ -1,12 +1,18 @@ |
|||||||
from haystack import indexes |
from haystack import indexes |
||||||
from models import City |
from models import City |
||||||
|
|
||||||
|
""" |
||||||
class CityIndex(indexes.SearchIndex, indexes.Indexable): |
class CityIndex(indexes.SearchIndex, indexes.Indexable): |
||||||
text = indexes.CharField(document=True) |
text = indexes.CharField(document=True, use_template=True) |
||||||
name = indexes.CharField(model_attr='name') |
translations = indexes.MultiValueField() |
||||||
|
#name = indexes.CharField(model_attr='translations__name') |
||||||
|
|
||||||
|
def prepare_translations(self, obj): |
||||||
|
return [tr.name for tr in obj.translations.all()] |
||||||
|
|
||||||
def get_model(self): |
def get_model(self): |
||||||
return City |
return City |
||||||
|
|
||||||
def index_queryset(self, using=None): |
def index_queryset(self, using=None): |
||||||
return self.get_model().objects.all() |
return self.get_model().objects.filter() |
||||||
|
""" |
||||||
|
|||||||
@ -0,0 +1,26 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from django import forms |
||||||
|
from place_exposition.models import PlaceExposition |
||||||
|
from place_conference.models import PlaceConference |
||||||
|
from django.utils.translation import ugettext_lazy as _ |
||||||
|
from haystack.query import SearchQuerySet, EmptySearchQuerySet |
||||||
|
|
||||||
|
class PlaceSearchForm(forms.Form): |
||||||
|
q = forms.CharField(label=_(u'Поиск'), required=False) |
||||||
|
w = forms.CharField(label=_(u'Где'), required=False) |
||||||
|
|
||||||
|
def search(self): |
||||||
|
q = self.cleaned_data.get('q') |
||||||
|
w = self.cleaned_data.get('w') |
||||||
|
|
||||||
|
if not q and not w: |
||||||
|
return EmptySearchQuerySet() |
||||||
|
|
||||||
|
sqs = SearchQuerySet().models(PlaceExposition, PlaceConference) |
||||||
|
|
||||||
|
if q: |
||||||
|
sqs = sqs.auto_query(q) |
||||||
|
if w: |
||||||
|
sqs = sqs.filter(where__contains=w) |
||||||
|
|
||||||
|
return sqs |
||||||
@ -0,0 +1,31 @@ |
|||||||
|
from haystack import indexes |
||||||
|
from models import PlaceExposition |
||||||
|
from django.conf import settings |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class PlaceExpositionIndex(indexes.SearchIndex, indexes.Indexable): |
||||||
|
text = indexes.CharField(document=True, use_template=True) |
||||||
|
where = indexes.MultiValueField() |
||||||
|
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()] |
||||||
|
|
||||||
|
return country + city |
||||||
|
|
||||||
|
""" |
||||||
|
translations = indexes.MultiValueField() |
||||||
|
|
||||||
|
def prepare_translations(self, obj): |
||||||
|
|
||||||
|
return [tr.name for tr in obj.translations.all()] |
||||||
|
""" |
||||||
|
|
||||||
|
def get_model(self): |
||||||
|
return PlaceExposition |
||||||
|
|
||||||
|
def index_queryset(self, using=None): |
||||||
|
|
||||||
|
return self.get_model().objects.filter() |
||||||
|
|
||||||
@ -0,0 +1,59 @@ |
|||||||
|
{% load static %} |
||||||
|
{% load i18n %} |
||||||
|
{% load template_filters %} |
||||||
|
|
||||||
|
<ul class="cat-list cl-places"> |
||||||
|
{% for result in query %} |
||||||
|
<li class="cl-item"> |
||||||
|
<div class="cl-item-wrap clearfix"> |
||||||
|
<a href="/{{ result.object.get_permanent_url }}"> |
||||||
|
<div class="cli-pict"> |
||||||
|
{% with obj=result.object %} |
||||||
|
{% include 'client/includes/show_logo.html' %} |
||||||
|
{% endwith %} |
||||||
|
</div> |
||||||
|
</a> |
||||||
|
<div class="cli-info"> |
||||||
|
<div class="cli-top clearfix"> |
||||||
|
<div class="cli-approved"> |
||||||
|
{% if result.object.approved %} |
||||||
|
<img src="{% static 'clint/img/approved-logo.png' %}" alt="" title="Approved Event" /> |
||||||
|
{% endif %} |
||||||
|
</div> |
||||||
|
<header> |
||||||
|
<div class="cli-title"><a href="{{ result.object.get_permanent_url }}"> |
||||||
|
{{ result.object.name|safe }}</a></div> |
||||||
|
</header> |
||||||
|
|
||||||
|
<div class="cli-descr">{{ result.object.get_type }}</div> |
||||||
|
</div> |
||||||
|
|
||||||
|
<div class="cli-bot clearfix"> |
||||||
|
{% if result.object.total_area %} |
||||||
|
<div class="cli-dim">{{ result.object.total_area }} м2</div> |
||||||
|
{% endif %} |
||||||
|
<div class="cli-place"><a href="#">{{ result.object.country }}</a>, <a href="#">{{ result.object.city }}</a>, <a href="{{ result.object.get_permanent_url }}">{{ result.object.adress }}</a></div> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
|
||||||
|
<div class="cli-buttons clearfix"> |
||||||
|
<div class="cli-m-buttons"> |
||||||
|
<a class="button icon-info" href="{{ result.object.get_permanent_url }}">{% trans 'описание' %}</a> |
||||||
|
{% if result.object.get_events_number %} |
||||||
|
<a class="button green icon-list" href="#">{% trans 'события' %} ({{ result.object.get_events_number }})</a> |
||||||
|
{% endif %} |
||||||
|
{% if result.object.get_photos %} |
||||||
|
<a class="button blue icon-photo" href="{{ result.object.get_permanent_url }}/photo/">{% trans 'фото' %}</a> |
||||||
|
{% endif %} |
||||||
|
</div> |
||||||
|
<!-- |
||||||
|
<div class="cli-s-buttons"> |
||||||
|
<a class="button blue2 lc" href="#">{% trans 'Найти отели поблизости' %}</a> |
||||||
|
</div> |
||||||
|
--> |
||||||
|
</div> |
||||||
|
|
||||||
|
</div> |
||||||
|
</li> |
||||||
|
{% endfor %} |
||||||
|
</ul> |
||||||
@ -0,0 +1,70 @@ |
|||||||
|
{% extends 'base_catalog.html' %} |
||||||
|
{% load i18n %} |
||||||
|
{% load template_filters %} |
||||||
|
|
||||||
|
{% block bread_scrumbs %} |
||||||
|
<div class="bread-crumbs"> |
||||||
|
<a href="/">{% trans 'Главная страница' %}</a> |
||||||
|
<a href="/places/">{% trans 'Места' %}</a> |
||||||
|
<strong>{% trans 'Поиск' %}</strong> |
||||||
|
</div> |
||||||
|
{% endblock %} |
||||||
|
|
||||||
|
{% block page_title %} |
||||||
|
<div class="page-title"> |
||||||
|
<h1>{% trans 'Поиск' %}:</h1> |
||||||
|
</div> |
||||||
|
{% endblock %} |
||||||
|
|
||||||
|
{% block content_list %} |
||||||
|
|
||||||
|
{% with query=object_list %} |
||||||
|
{% include 'includes/place/search_result.html' %} |
||||||
|
{% endwith %} |
||||||
|
{% endblock %} |
||||||
|
|
||||||
|
{% block paginator %} |
||||||
|
|
||||||
|
{% if page_obj.paginator.num_pages > 1 %} |
||||||
|
<div class="pagination clearfix"> |
||||||
|
<div class="pg-info"> Показано {{ page_obj.start_index }} - {{ page_obj.end_index }} <i>(всего {{ page_obj.paginator.count }} позиций)</i></div> |
||||||
|
<div class="pg-body"> |
||||||
|
{% if page_obj.has_previous %} |
||||||
|
<a class="pg-prev" href="?page={{ page_obj.previous_page_number }}&{{ queries.urlencode }}">Предыдущая</a> |
||||||
|
{% else %} |
||||||
|
<a class="pg-prev disabled" href="#">Предыдущая</a> |
||||||
|
{% endif %} |
||||||
|
|
||||||
|
<ul> |
||||||
|
{% if page_obj.number > 2 %} |
||||||
|
<li><a href="?page={{ 1 }}&{{ queries.urlencode }} ">{{ 1 }}</a></li> |
||||||
|
{% if page_obj.number > 3 %} |
||||||
|
<li>...</li> |
||||||
|
{% endif %} |
||||||
|
{% endif %} |
||||||
|
{% if page_obj.has_previous %} |
||||||
|
<li><a href="?page={{ page_obj.previous_page_number }}&{{ queries.urlencode }}">{{ page_obj.previous_page_number }}</a></li> |
||||||
|
{% endif %} |
||||||
|
|
||||||
|
<li><b>{{ page_obj.number }}</b></li> |
||||||
|
|
||||||
|
{% if page_obj.has_next %} |
||||||
|
<li><a href="?page={{ page_obj.next_page_number }}&{{ queries.urlencode }}">{{ page_obj.next_page_number }}</a></li> |
||||||
|
{% endif %} |
||||||
|
{% if page_obj.paginator.num_pages|subtract:page_obj.number > 1 %} |
||||||
|
{% if page_obj.paginator.num_pages|subtract:page_obj.number > 2 %} |
||||||
|
<li>...</li> |
||||||
|
{% endif %} |
||||||
|
<li><a href="?page={{ page_obj.paginator.num_pages }}&{{ queries.urlencode }}">{{ page_obj.paginator.num_pages }}</a></li> |
||||||
|
{% endif %} |
||||||
|
</ul> |
||||||
|
{% if page_obj.has_next %} |
||||||
|
<a class="pg-next" href="?page={{ page_obj.next_page_number }}&{{ queries.urlencode }}">Следующая</a> |
||||||
|
{% else %} |
||||||
|
<a class="pg-next disabled" href="#">Следующая</a> |
||||||
|
{% endif %} |
||||||
|
|
||||||
|
</div> |
||||||
|
</div> |
||||||
|
{% endif %} |
||||||
|
{% endblock %} |
||||||
@ -0,0 +1,3 @@ |
|||||||
|
{{ object.first_name }} |
||||||
|
{{ object.last_name }} |
||||||
|
{{ object.email }} |
||||||
@ -0,0 +1 @@ |
|||||||
|
{{ object.name }} |
||||||
@ -0,0 +1,4 @@ |
|||||||
|
{% for text in object.get_index_text %} |
||||||
|
{{ text }} |
||||||
|
{% endfor %} |
||||||
|
|
||||||
Loading…
Reference in new issue