commit
0a97d52be9
354 changed files with 24802 additions and 10667 deletions
@ -1,10 +1,22 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
from django.conf.urls import patterns, url |
from django.conf.urls import patterns, url |
||||||
from views import BlogList, NewsList, BlogDetail, NewsDetail |
from views import BlogList, NewsList, BlogDetail, NewsDetail, NewsTagCatalog, BlogsTagCatalog |
||||||
|
|
||||||
urlpatterns = patterns('', |
urlpatterns = patterns('', |
||||||
url(r'blogs/$', BlogList.as_view()), |
url(r'^blogs/tag/(?P<slug>.*)/page/(?P<page>\d+)/$', BlogsTagCatalog.as_view(), {'meta_id':75}), |
||||||
url(r'news/$', NewsList.as_view()), |
url(r'^blogs/page/(?P<page>\d+)/$', BlogList.as_view(), {'meta_id':79}), |
||||||
url(r'blogs/(?P<slug>.*)$', BlogDetail.as_view()), |
url(r'^blogs/tag/(?P<slug>.*)/$', BlogsTagCatalog.as_view(), {'meta_id':75}), |
||||||
url(r'news/(?P<slug>.*)$', NewsDetail.as_view()), |
url(r'^blogs/$', BlogList.as_view(), {'meta_id':79}), |
||||||
|
|
||||||
|
|
||||||
|
url(r'^news/tag/(?P<slug>.*)/(?P<year>\d+)/(?P<month>.*)/page/(?P<page>\d+)/$', NewsTagCatalog.as_view(), {'meta_id':77}), |
||||||
|
url(r'^news/tag/(?P<slug>.*)/(?P<year>\d+)/page/(?P<page>\d+)/$', NewsTagCatalog.as_view(), {'meta_id':76}), |
||||||
|
url(r'^news/tag/(?P<slug>.*)/page/(?P<page>\d+)/$', NewsTagCatalog.as_view(), {'meta_id':74}), |
||||||
|
url(r'^news/tag/(?P<slug>.*)/(?P<year>\d+)/(?P<month>.*)/$', NewsTagCatalog.as_view(), {'meta_id':77}), |
||||||
|
url(r'^news/tag/(?P<slug>.*)/(?P<year>\d+)/$', NewsTagCatalog.as_view(), {'meta_id':76}), |
||||||
|
url(r'^news/tag/(?P<slug>.*)/$', NewsTagCatalog.as_view(), {'meta_id':74}), |
||||||
|
url(r'^news/page/(?P<page>\d+)/$', NewsList.as_view(), {'meta_id':78}), |
||||||
|
url(r'^news/$', NewsList.as_view(), {'meta_id':78}), |
||||||
|
url(r'^blogs/(?P<slug>.*)/$', BlogDetail.as_view(), {'meta_id':19}), |
||||||
|
url(r'^news/(?P<slug>.*)/$', NewsDetail.as_view(), {'meta_id':19}), |
||||||
) |
) |
||||||
|
|||||||
@ -0,0 +1,22 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from django.core.management.base import BaseCommand, CommandError |
||||||
|
from city.models import City |
||||||
|
from country.models import Country |
||||||
|
from functions.form_check import translit_with_separator |
||||||
|
from django.db import IntegrityError |
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand): |
||||||
|
def handle(self, *args, **options): |
||||||
|
|
||||||
|
qs = City.objects.language('en').filter() |
||||||
|
for c in qs: |
||||||
|
url = translit_with_separator(c.name.encode('utf8')) |
||||||
|
c.url = url |
||||||
|
try: |
||||||
|
c.save() |
||||||
|
except IntegrityError: |
||||||
|
continue |
||||||
|
|
||||||
|
print(c.url) |
||||||
|
#print(qs.count()) |
||||||
@ -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')) |
||||||
@ -1,40 +1,42 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
from django.conf.urls import patterns, url |
from django.conf.urls import patterns, url |
||||||
from views import CompanyView, CompanySearchView, MemberDetail, MemberList, MemberTagList, MemberThemeList |
from views import CompanySearchView, MemberDetail, MemberList, MemberTagList, MemberThemeList |
||||||
from django.contrib.auth.decorators import login_required |
from django.contrib.auth.decorators import login_required |
||||||
from edit_views import * |
from edit_views import * |
||||||
|
|
||||||
|
|
||||||
urlpatterns = patterns('', |
urlpatterns = patterns('', |
||||||
|
url(r'company/create-company/$', 'company.views.create_company'), |
||||||
|
url(r'company/get-company/$', 'company.views.get_company'), |
||||||
|
# |
||||||
url(r'members/search/$', CompanySearchView.as_view()), |
url(r'members/search/$', CompanySearchView.as_view()), |
||||||
#url(r'members/(?P<params>.*)/(?P<page>\d+)/$', CompanyView.as_view()), |
#url(r'members/(?P<params>.*)/(?P<page>\d+)/$', CompanyView.as_view()), |
||||||
#url(r'members/(?P<page>\d+)/$', CompanyView.as_view()), |
#url(r'members/(?P<page>\d+)/$', CompanyView.as_view()), |
||||||
#url(r'members/(?P<params>.*)/$', CompanyView.as_view()), |
#url(r'members/(?P<params>.*)/$', CompanyView.as_view()), |
||||||
#url(r'members/$', CompanyView.as_view()), |
#url(r'members/$', CompanyView.as_view()), |
||||||
url(r'members/theme/(?P<slug>.*)/page/(?P<page>\d+)/$', MemberThemeList.as_view()), |
url(r'members/theme/(?P<slug>.*)/page/(?P<page>\d+)/$', MemberThemeList.as_view(), {'meta_id':69}), |
||||||
url(r'members/theme/(?P<slug>.*)/$', MemberThemeList.as_view()), |
url(r'members/theme/(?P<slug>.*)/$', MemberThemeList.as_view(), {'meta_id':69}), |
||||||
url(r'members/tag/(?P<slug>.*)/page/(?P<page>\d+)/$', MemberTagList.as_view()), |
url(r'members/tag/(?P<slug>.*)/page/(?P<page>\d+)/$', MemberTagList.as_view(), {'meta_id':70}), |
||||||
url(r'members/tag/(?P<slug>.*)/$', MemberTagList.as_view()), |
url(r'members/tag/(?P<slug>.*)/$', MemberTagList.as_view(), {'meta_id':70}), |
||||||
url(r'members/page/(?P<page>\d+)/$', MemberList.as_view()), |
url(r'members/page/(?P<page>\d+)/$', MemberList.as_view(), {'meta_id':67}), |
||||||
url(r'members/(?P<slug>.*)/$', MemberDetail.as_view()), |
url(r'members/(?P<slug>.*)/$', MemberDetail.as_view(), {'meta_id':68}), |
||||||
url(r'members/$', MemberList.as_view()), |
url(r'members/$', MemberList.as_view(), {'meta_id':67}), |
||||||
|
|
||||||
# |
# |
||||||
url(r'company/create-company/$', 'company.views.create_company'), |
url(r'company/update/name/(?P<slug>.*)/$', login_required(NameView.as_view())), |
||||||
url(r'company/get-company/$', 'company.views.get_company'), |
url(r'^company/update/home/(?P<slug>.*)/$', login_required(HomeView.as_view())), |
||||||
# |
url(r'^company/update/specialization/(?P<slug>.*)/$', login_required(SpecializationView.as_view())), |
||||||
url(r'company/update/name/$', login_required(NameView.as_view())), |
url(r'^company/update/phone/(?P<slug>.*)/$', login_required(PhoneView.as_view())), |
||||||
url(r'^company/update/home/$', login_required(HomeView.as_view())), |
url(r'^company/update/email/(?P<slug>.*)/$', login_required(EmailView.as_view())), |
||||||
url(r'^company/update/specialization/$', login_required(SpecializationView.as_view())), |
url(r'^company/update/web-page/(?P<slug>.*)/$', login_required(WebPageView.as_view())), |
||||||
url(r'^company/update/phone/$', login_required(PhoneView.as_view())), |
url(r'^company/update/social/(?P<slug>.*)/$', login_required(SocialView.as_view())), |
||||||
url(r'^company/update/email/$', login_required(EmailView.as_view())), |
url(r'^company/update/tag/(?P<slug>.*)/$', login_required(TagView.as_view())), |
||||||
url(r'^company/update/web-page/$', login_required(WebPageView.as_view())), |
url(r'^company/update/theme/(?P<slug>.*)/$', login_required(ThemeView.as_view())), |
||||||
url(r'^company/update/social/$', login_required(SocialView.as_view())), |
url(r'^company/update/foundation/(?P<slug>.*)/$', login_required(FoundationView.as_view())), |
||||||
url(r'^company/update/tag/$', login_required(TagView.as_view())), |
url(r'^company/update/staff/(?P<slug>.*)/$', login_required(StaffView.as_view())), |
||||||
url(r'^company/update/foundation/$', login_required(FoundationView.as_view())), |
url(r'^company/update/description/(?P<slug>.*)/$', login_required(DescriptionView.as_view())), |
||||||
url(r'^company/update/staff/$', login_required(StaffView.as_view())), |
url(r'^company/update/address/(?P<slug>.*)/$', login_required(AddressView.as_view())), |
||||||
url(r'^company/update/description/$', login_required(DescriptionView.as_view())), |
url(r'^company/update/logo/(?P<slug>.*)/$', login_required(LogoView.as_view())), |
||||||
url(r'^company/update/address/$', login_required(AddressView.as_view())), |
|
||||||
url(r'^company/update/logo/$', login_required(LogoView.as_view())), |
|
||||||
|
|
||||||
) |
) |
||||||
|
|||||||
@ -1,13 +1,15 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
from django.conf.urls import patterns, include, url |
from django.conf.urls import patterns, include, url |
||||||
from admin import ConferenceListView |
from admin import ConferenceListView, ConferenceView |
||||||
|
|
||||||
urlpatterns = patterns('conference.admin', |
urlpatterns = patterns('conference.admin', |
||||||
url(r'^add.*/$', 'conference_add'), |
url(r'^upload-photo/(?P<conf_id>.*)/$', 'upload_conference_photo'), |
||||||
url(r'^delete/(?P<url>.*)$', 'conference_delete'), |
url(r'^delete/(?P<url>.*)$', 'conference_delete'), |
||||||
url(r'^change/(?P<url>.*)/$', 'conference_change'), |
|
||||||
url(r'^copy/(?P<url>.*)/$', 'conference_copy'), |
|
||||||
url(r'^switch/(?P<url>.*)/(?P<action>.*)$', 'conference_switch'), |
|
||||||
#url(r'^all/$', 'conference_all'), |
|
||||||
url(r'^all/$', ConferenceListView.as_view()), |
url(r'^all/$', ConferenceListView.as_view()), |
||||||
|
#url(r'^change/(?P<url>.*)/$', 'conference_change'), |
||||||
|
|
||||||
|
url(r'^switch/(?P<url>.*)/(?P<action>.*)$', 'conference_switch'), |
||||||
|
|
||||||
|
url(r'^(?P<url>.*)/$', ConferenceView.as_view()), |
||||||
|
url(r'^$', ConferenceView.as_view()), |
||||||
) |
) |
||||||
@ -1,15 +1,74 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
from django.conf.urls import patterns, include, url |
from django.conf.urls import patterns, include, url |
||||||
from views import ConferenceView |
from views import ConferenceDetail, ConferenceList, ConferenceByCity, ConferenceByCountry, ConferenceByTheme,\ |
||||||
|
ConferenceCountryCatalog, ConferenceCityCatalog, ConferenceTagCatalog, ConferenceThemeCatalog, ConferenceMembers,\ |
||||||
|
ConferenceVisitors, ConferenceServiceView |
||||||
|
from exposition.views import ExpositionSearchView |
||||||
|
|
||||||
urlpatterns = patterns('', |
urlpatterns = patterns('', |
||||||
url(r'conferences/(?P<params>.*)/(?P<page>\d+)/$', ConferenceView.as_view()), |
|
||||||
url(r'conferences/(?P<page>\d+)/$', ConferenceView.as_view()), |
|
||||||
url(r'conferences/(?P<params>.*)/$', ConferenceView.as_view()), |
url(r'conference/add-note/(?P<slug>.*)/$', 'conference.views.add_note'), |
||||||
url(r'conferences/$', ConferenceView.as_view()), |
|
||||||
# |
|
||||||
url(r'conference-add-calendar/(?P<id>\d+)/$', 'conference.views.conference_add_calendar'), |
url(r'conference-add-calendar/(?P<id>\d+)/$', 'conference.views.conference_add_calendar'), |
||||||
url(r'conference-remove-calendar/(?P<id>\d+)/$', 'conference.views.conference_remove_calendar'), |
|
||||||
url(r'conference-visit/(?P<id>\d+)/$', 'conference.views.conference_visit'), |
url(r'conference-visit/(?P<id>\d+)/$', 'conference.views.conference_visit'), |
||||||
url(r'conference-unvisit/(?P<id>\d+)/$', 'conference.views.conference_unvisit'), |
# search |
||||||
|
url(r'conference/search/', ExpositionSearchView.as_view()), |
||||||
|
# country catalog |
||||||
|
url(r'conference/country/$', ConferenceByCountry.as_view(), {'meta_id':51}), |
||||||
|
url(r'conference/country/(?P<slug>.*)/(?P<year>\d+)/(?P<month>.*)/page/(?P<page>\d+)/$', ConferenceCountryCatalog.as_view(), {'meta_id':25}), |
||||||
|
url(r'conference/country/(?P<slug>.*)/(?P<year>\d+)/page/(?P<page>\d+)/$', ConferenceCountryCatalog.as_view(), {'meta_id':24}), |
||||||
|
url(r'conference/country/(?P<slug>.*)/page/(?P<page>\d+)/$', ConferenceCountryCatalog.as_view(), {'meta_id':23}), |
||||||
|
url(r'conference/country/(?P<slug>.*)/(?P<year>\d+)/(?P<month>.*)/$', ConferenceCountryCatalog.as_view(), {'meta_id':25}), |
||||||
|
url(r'conference/country/(?P<slug>.*)/(?P<year>\d+)/$', ConferenceCountryCatalog.as_view(), {'meta_id':24}), |
||||||
|
url(r'conference/country/(?P<slug>.*)/$', ConferenceCountryCatalog.as_view(), {'meta_id':23}), |
||||||
|
# city catalog |
||||||
|
url(r'conference/city/$', ConferenceByCity.as_view(), {'meta_id':52}), |
||||||
|
url(r'conference/city/(?P<slug>.*)/(?P<year>\d+)/(?P<month>.*)/page/(?P<page>\d+)/$', ConferenceCityCatalog.as_view(), {'meta_id':28}), |
||||||
|
url(r'conference/city/(?P<slug>.*)/(?P<year>\d+)/page/(?P<page>\d+)/$', ConferenceCityCatalog.as_view(), {'meta_id':27}), |
||||||
|
url(r'conference/city/(?P<slug>.*)/page/(?P<page>\d+)/$', ConferenceCityCatalog.as_view(), {'meta_id':26}), |
||||||
|
url(r'conference/city/(?P<slug>.*)/(?P<year>\d+)/(?P<month>.*)/$', ConferenceCityCatalog.as_view(), {'meta_id':28}), |
||||||
|
url(r'conference/city/(?P<slug>.*)/(?P<year>\d+)/$', ConferenceCityCatalog.as_view(), {'meta_id':27}), |
||||||
|
url(r'conference/city/(?P<slug>.*)/$', ConferenceCityCatalog.as_view(), {'meta_id':26}), |
||||||
|
# theme catalog |
||||||
|
url(r'conference/theme/$', ConferenceByTheme.as_view(), {'meta_id':50}), |
||||||
|
url(r'conference/theme/(?P<slug>.*)/country/(?P<country_slug>.*)/page/(?P<page>\d+)/$', ConferenceThemeCatalog.as_view()), |
||||||
|
url(r'conference/theme/(?P<slug>.*)/country/(?P<country_slug>.*)/$', ConferenceThemeCatalog.as_view()), |
||||||
|
url(r'conference/theme/(?P<slug>.*)/city/(?P<city_slug>.*)/page/(?P<page>\d+)/$', ConferenceThemeCatalog.as_view()), |
||||||
|
url(r'conference/theme/(?P<slug>.*)/city/(?P<city_slug>.*)/$', ConferenceThemeCatalog.as_view()), |
||||||
|
url(r'conference/theme/(?P<slug>.*)/(?P<year>\d+)/(?P<month>.*)/page/(?P<page>\d+)/$', ConferenceThemeCatalog.as_view(), {'meta_id':31}), |
||||||
|
url(r'conference/theme/(?P<slug>.*)/(?P<year>\d+)/page/(?P<page>\d+)/$', ConferenceThemeCatalog.as_view(), {'meta_id':30}), |
||||||
|
url(r'conference/theme/(?P<slug>.*)/page/(?P<page>\d+)/$', ConferenceThemeCatalog.as_view(), {'meta_id':29}), |
||||||
|
url(r'conference/theme/(?P<slug>.*)/(?P<year>\d+)/(?P<month>.*)/$', ConferenceThemeCatalog.as_view(), {'meta_id':31}), |
||||||
|
url(r'conference/theme/(?P<slug>.*)/(?P<year>\d+)/$', ConferenceThemeCatalog.as_view(), {'meta_id':30}), |
||||||
|
url(r'conference/theme/(?P<slug>.*)/$', ConferenceThemeCatalog.as_view(), {'meta_id':29}), |
||||||
|
# tag catalog |
||||||
|
url(r'conference/tag/(?P<slug>.*)/(?P<year>\d+)/(?P<month>.*)/page/(?P<page>\d+)/$', ConferenceTagCatalog.as_view(), {'meta_id':34}), |
||||||
|
url(r'conference/tag/(?P<slug>.*)/(?P<year>\d+)/page/(?P<page>\d+)/$', ConferenceTagCatalog.as_view(), {'meta_id':33}), |
||||||
|
url(r'conference/tag/(?P<slug>.*)/page/(?P<page>\d+)/$', ConferenceTagCatalog.as_view(), {'meta_id':32}), |
||||||
|
url(r'conference/tag/(?P<slug>.*)/(?P<year>\d+)/(?P<month>.*)/$', ConferenceTagCatalog.as_view(), {'meta_id':34}), |
||||||
|
url(r'conference/tag/(?P<slug>.*)/(?P<year>\d+)/$', ConferenceTagCatalog.as_view(), {'meta_id':33}), |
||||||
|
url(r'conference/tag/(?P<slug>.*)/$', ConferenceTagCatalog.as_view(), {'meta_id':32}), |
||||||
|
# conf additional pages |
||||||
|
url(r'conference/(?P<slug>.*)/visitors/page/(?P<page>\d+)/$', ConferenceVisitors.as_view()), |
||||||
|
url(r'conference/(?P<slug>.*)/visitors/$', ConferenceVisitors.as_view()), |
||||||
|
url(r'conference/(?P<slug>.*)/members/page/(?P<page>\d+)/$', ConferenceMembers.as_view()), |
||||||
|
url(r'conference/(?P<slug>.*)/members/$', ConferenceMembers.as_view()), |
||||||
|
url(r'conference/(?P<slug>.*)/service/(?P<service_url>.*)/', ConferenceServiceView.as_view()), |
||||||
|
|
||||||
|
# conf list |
||||||
|
url(r'conference/(?P<year>\d+)/(?P<month>.*)/page/(?P<page>\d+)/$', ConferenceList.as_view(), {'meta_id':22}), |
||||||
|
url(r'conference/(?P<year>\d+)/page/(?P<page>\d+)/$', ConferenceList.as_view(), {'meta_id':21}), |
||||||
|
url(r'conference/(?P<year>\d+)/(?P<month>.*)/$', ConferenceList.as_view(), {'meta_id':22}), |
||||||
|
url(r'conference/(?P<year>\d+)/$', ConferenceList.as_view(), {'meta_id':21}), |
||||||
|
url(r'conference/page/(?P<page>\d+)/$', ConferenceList.as_view(), {'meta_id':20}), |
||||||
|
# conf page |
||||||
|
url(r'conference/(?P<slug>.*)/$', ConferenceDetail.as_view(), {'meta_id':35}), |
||||||
|
url(r'conference/$', ConferenceList.as_view(), {'meta_id':20}), |
||||||
|
|
||||||
) |
) |
||||||
|
|
||||||
|
|
||||||
|
""" |
||||||
|
|
||||||
|
|
||||||
|
""" |
||||||
@ -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 |
||||||
@ -0,0 +1,105 @@ |
|||||||
|
import datetime |
||||||
|
from django.utils import translation |
||||||
|
from django.core.cache import cache |
||||||
|
from django.utils.translation import get_language as lang |
||||||
|
from hvad.models import TranslationManager |
||||||
|
|
||||||
|
|
||||||
|
class CountryManager(TranslationManager): |
||||||
|
cache_time = 600 |
||||||
|
|
||||||
|
def all(self): |
||||||
|
""" |
||||||
|
hack |
||||||
|
""" |
||||||
|
return super(TranslationManager, self).all().filter(translations__language_code=lang()).order_by('translations__name') |
||||||
|
|
||||||
|
def safe_get(self, **kwargs): |
||||||
|
model = self.model |
||||||
|
try: |
||||||
|
return model.objects.get(**kwargs) |
||||||
|
except: |
||||||
|
return None |
||||||
|
|
||||||
|
def expo_countries(self): |
||||||
|
lang = translation.get_language() |
||||||
|
key = 'used_expo_countries_%s'%lang |
||||||
|
cached_countries = cache.get(key) |
||||||
|
if cached_countries: |
||||||
|
return cached_countries |
||||||
|
else: |
||||||
|
from exposition.models import Exposition |
||||||
|
countries_id = [item['country_id'] for item in Exposition.objects.values('country_id').distinct()] |
||||||
|
countries = list(self.language().filter(id__in=countries_id)) |
||||||
|
cache.set(key, countries, self.cache_time) |
||||||
|
return countries |
||||||
|
|
||||||
|
def expo_countries_with_count(self): |
||||||
|
lang = translation.get_language() |
||||||
|
key = 'used_expo_countries_count_%s'%lang |
||||||
|
cached_countries = cache.get(key) |
||||||
|
if cached_countries: |
||||||
|
return cached_countries |
||||||
|
else: |
||||||
|
|
||||||
|
from exposition.models import Exposition |
||||||
|
sql = {'expo_count': |
||||||
|
"""SELECT COUNT(*) |
||||||
|
FROM exposition_exposition |
||||||
|
WHERE exposition_exposition.country_id = country_country.id |
||||||
|
AND exposition_exposition.data_end >= CURDATE() |
||||||
|
AND exposition_exposition.is_published = 1"""} |
||||||
|
now = datetime.datetime.now().date() |
||||||
|
# id of unique countries |
||||||
|
countries_id = [item['country_id'] for item in Exposition.objects.filter(is_published=True, data_end__gte=now).values('country_id').distinct()] |
||||||
|
countries = set(list(self.language().filter(id__in=countries_id).extra(select=sql))) |
||||||
|
countries = sorted(countries, key=lambda x: x.name) |
||||||
|
cache.set(key, countries, self.cache_time) |
||||||
|
return countries |
||||||
|
|
||||||
|
def conference_countries_with_count(self): |
||||||
|
lang = translation.get_language() |
||||||
|
key = 'used_conference_countries_count_%s'%lang |
||||||
|
cached_countries = cache.get(key) |
||||||
|
if cached_countries: |
||||||
|
return cached_countries |
||||||
|
else: |
||||||
|
|
||||||
|
from conference.models import Conference |
||||||
|
sql = {'conference_count': |
||||||
|
"""SELECT COUNT(*) |
||||||
|
FROM conference_conference |
||||||
|
WHERE conference_conference.country_id = country_country.id |
||||||
|
AND conference_conference.data_end >= CURDATE() |
||||||
|
AND conference_conference.is_published = 1"""} |
||||||
|
now = datetime.datetime.now().date() |
||||||
|
# id of unique countries |
||||||
|
countries_id = [item['country_id'] for item in Conference.objects.filter(is_published=True, data_end__gte=now).values('country_id').distinct()] |
||||||
|
countries = set(list(self.language().filter(id__in=countries_id).extra(select=sql))) |
||||||
|
countries = sorted(countries, key=lambda x: x.name) |
||||||
|
cache.set(key, countries, self.cache_time) |
||||||
|
return countries |
||||||
|
|
||||||
|
def conference_countries(self): |
||||||
|
lang = translation.get_language() |
||||||
|
key = 'used_conference_countries_%s'%lang |
||||||
|
cached_countries = cache.get(key) |
||||||
|
if cached_countries: |
||||||
|
return cached_countries |
||||||
|
else: |
||||||
|
from conference.models import Conference |
||||||
|
countries_id = [item['country_id'] for item in Conference.objects.values('country_id').distinct()] |
||||||
|
countries = list(self.language().filter(id__in=countries_id)) |
||||||
|
cache.set(key, countries, self.cache_time) |
||||||
|
return countries |
||||||
|
|
||||||
|
|
||||||
|
class AreaManager(TranslationManager): |
||||||
|
def all_sorted(self): |
||||||
|
""" |
||||||
|
return list, not queryset |
||||||
|
""" |
||||||
|
model = self.model |
||||||
|
result = list(model.objects.filter()) |
||||||
|
result.sort(key=lambda x: len(x.expos()), reverse=True) |
||||||
|
return result |
||||||
@ -0,0 +1,201 @@ |
|||||||
|
# -*- 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' |
||||||
|
|
||||||
|
import datetime |
||||||
|
from theme.models import Theme |
||||||
|
from conference.models import Conference |
||||||
|
''' |
||||||
|
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() |
||||||
|
conf_old = """ |
||||||
|
SELECT DISTINCT (products_to_categories.products_id), url as old_url |
||||||
|
FROM `products_to_categories` |
||||||
|
LEFT JOIN `products` ON products_to_categories.products_id=products.products_id |
||||||
|
LEFT JOIN `products_description` ON products_to_categories.products_id=products_description.products_id |
||||||
|
WHERE `products_status` =1 |
||||||
|
AND `conference` =0 |
||||||
|
|
||||||
|
""" |
||||||
|
|
||||||
|
|
||||||
|
find_themes = "SELECT categories_id FROM `products_to_categories` WHERE `products_id` =%d" |
||||||
|
|
||||||
|
cursor.execute(conf_old) |
||||||
|
|
||||||
|
conferences = cursor.fetchall() |
||||||
|
#for item in conferences: |
||||||
|
cursor.execute(find_themes%conferences[0]['products_id']) |
||||||
|
|
||||||
|
day = datetime.date.today() |
||||||
|
day = day.replace(month=1, day=1) |
||||||
|
|
||||||
|
for item in conferences: |
||||||
|
old_url = item['old_url'] |
||||||
|
if not old_url: |
||||||
|
continue |
||||||
|
try: |
||||||
|
expo = Exposition.objects.get(old_url=old_url) |
||||||
|
except: |
||||||
|
continue |
||||||
|
if expo.data_begin > day: |
||||||
|
continue |
||||||
|
|
||||||
|
cursor.execute(find_themes%item['products_id']) |
||||||
|
|
||||||
|
themes_id = [i['categories_id'] for i in cursor.fetchall()] |
||||||
|
theme_qs = Theme.objects.filter(id__in=themes_id) |
||||||
|
|
||||||
|
expo.theme.add(*theme_qs) |
||||||
|
print(expo) |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# if item['categories_id'] == 0: |
||||||
|
# continue |
||||||
|
# Theme.objects.get(id=item['categories_id']) |
||||||
|
#print(result) |
||||||
|
''' |
||||||
|
|
||||||
|
from haystack.query import SearchQuerySet |
||||||
|
from django.db import IntegrityError |
||||||
|
from django.utils import translation |
||||||
|
|
||||||
|
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 |
||||||
|
ORDER BY products.products_id DESC |
||||||
|
""" |
||||||
|
translation.activate('ru') |
||||||
|
expos = list(Exposition.objects.language().filter(old_url='')) |
||||||
|
find_expo = "SELECT products_name, url from products_description WHERE products_name = '%s'" |
||||||
|
|
||||||
|
for expo in expos: |
||||||
|
cursor.execute(find_expo%expo.name) |
||||||
|
result = cursor.fetchall() |
||||||
|
if result: |
||||||
|
expo.old_url = result[0]['url'] |
||||||
|
expo.save() |
||||||
|
print(expo) |
||||||
|
|
||||||
|
#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): |
||||||
|
qs = SearchQuerySet().models(Exposition).filter(name_ru=item['name']) |
||||||
|
if not item: |
||||||
|
continue |
||||||
|
if not qs.count()>0: |
||||||
|
continue |
||||||
|
expo =qs[0].object |
||||||
|
|
||||||
|
if not expo or expo.old_url: |
||||||
|
continue |
||||||
|
print(expo) |
||||||
|
expo.old_url = item['old_url'] |
||||||
|
try: |
||||||
|
expo.save() |
||||||
|
except IntegrityError: |
||||||
|
continue |
||||||
|
|
||||||
|
|
||||||
|
""" |
||||||
|
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 |
||||||
|
""" |
||||||
|
''' |
||||||
@ -0,0 +1,60 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
import xlrd |
||||||
|
from django.core.management.base import BaseCommand |
||||||
|
from django.conf import settings |
||||||
|
from functions.form_check import translit_with_separator |
||||||
|
from exposition.models import Exposition |
||||||
|
from organiser.models import Organiser |
||||||
|
|
||||||
|
|
||||||
|
CHINA_FILE = settings.MEDIA_ROOT+'/import/expo_china_ru.xlsx' |
||||||
|
GERMANY_FILE = settings.MEDIA_ROOT+'/import/expo_germany_ru.xlsx' |
||||||
|
# 391 row not imported(same url) |
||||||
|
ITALY_FILE = settings.MEDIA_ROOT+'/import/expo_italy_ru.xlsx' |
||||||
|
# moscow 3 exps |
||||||
|
F = settings.MEDIA_ROOT+'/import/exp.xlsx' |
||||||
|
|
||||||
|
LA_FILE = settings.MEDIA_ROOT+'/import/expo_la.xlsx' |
||||||
|
NA_EU_ASIA_FILE = settings.MEDIA_ROOT+'/import/expo_na_eu_ sa.xls' |
||||||
|
NA_EU_ASIA_FILE2 = settings.MEDIA_ROOT+'/import/expo_na_eu_ sa_part2.xls' |
||||||
|
RUSSIA_FILE = settings.MEDIA_ROOT+'/import/expo_russia.xls' |
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand): |
||||||
|
def handle(self, *args, **options): |
||||||
|
|
||||||
|
f = open(RUSSIA_FILE, 'r') |
||||||
|
book = xlrd.open_workbook(file_contents=f.read()) |
||||||
|
sheet = book.sheet_by_index(0) |
||||||
|
row_list = [sheet.row_values(row_number) for row_number in range(sheet.nrows)] |
||||||
|
labels = [label for label in row_list[0]] |
||||||
|
|
||||||
|
for row_number, row in enumerate(row_list[1:]): |
||||||
|
exp_url = translit_with_separator(row[2]) |
||||||
|
try: |
||||||
|
exp = Exposition.objects.get(url=exp_url) |
||||||
|
except Exposition.DoesNotExist: |
||||||
|
continue |
||||||
|
|
||||||
|
cell1 = row[11].split(';') |
||||||
|
cell2 = row[12].split(';') |
||||||
|
orgs = [item.strip() for item in cell1+cell2 if item] |
||||||
|
exp.organiser.clear() |
||||||
|
for org in orgs: |
||||||
|
url = translit_with_separator(org) |
||||||
|
try: |
||||||
|
organiser = Organiser.objects.get(url=url) |
||||||
|
except Organiser.DoesNotExist: |
||||||
|
organiser = Organiser(url=url) |
||||||
|
organiser.translate('ru') |
||||||
|
organiser.name = org |
||||||
|
organiser.save() |
||||||
|
except Organiser.MultipleObjectsReturned: |
||||||
|
continue |
||||||
|
|
||||||
|
|
||||||
|
if not exp.organiser.filter(url=organiser.url).exists(): |
||||||
|
exp.organiser.add(organiser) |
||||||
|
|
||||||
|
print(exp) |
||||||
|
|
||||||
@ -0,0 +1,77 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
import xlrd |
||||||
|
import urllib2 |
||||||
|
from django.core.management.base import BaseCommand |
||||||
|
from django.conf import settings |
||||||
|
from functions.form_check import translit_with_separator |
||||||
|
from functions.files import get_alternative_filename |
||||||
|
from exposition.models import Exposition, Statistic |
||||||
|
from organiser.models import Organiser |
||||||
|
|
||||||
|
|
||||||
|
CHINA_FILE = settings.MEDIA_ROOT+'/import/expo_china_ru.xlsx' |
||||||
|
GERMANY_FILE = settings.MEDIA_ROOT+'/import/expo_germany_ru.xlsx' |
||||||
|
# 391 row not imported(same url) |
||||||
|
ITALY_FILE = settings.MEDIA_ROOT+'/import/expo_italy_ru.xlsx' |
||||||
|
# moscow 3 exps |
||||||
|
F = settings.MEDIA_ROOT+'/import/exp.xlsx' |
||||||
|
|
||||||
|
LA_FILE = settings.MEDIA_ROOT+'/import/expo_la.xlsx' |
||||||
|
NA_EU_ASIA_FILE = settings.MEDIA_ROOT+'/import/expo_na_eu_ sa.xls' |
||||||
|
NA_EU_ASIA_FILE2 = settings.MEDIA_ROOT+'/import/expo_na_eu_ sa_part2.xls' |
||||||
|
|
||||||
|
# 44 |
||||||
|
class Command(BaseCommand): |
||||||
|
def handle(self, *args, **options): |
||||||
|
qs = Statistic.objects.language('ru').exclude(translations__countries='') |
||||||
|
comas = 0 |
||||||
|
enters = 0 |
||||||
|
main = 0 |
||||||
|
spaces = 0 |
||||||
|
word = 0 |
||||||
|
number = 0 |
||||||
|
for i in qs: |
||||||
|
if ';' in i.countries: |
||||||
|
main +=1 |
||||||
|
a = i.countries.split(';') |
||||||
|
new = [item.strip() for item in a] |
||||||
|
|
||||||
|
st = ';'.join(new) |
||||||
|
#print st.encode('utf8') |
||||||
|
i.countries = st |
||||||
|
#i.save() |
||||||
|
elif ',' in i.countries: |
||||||
|
comas += 1 |
||||||
|
|
||||||
|
|
||||||
|
elif '\n' in i.countries: |
||||||
|
enters += 1 |
||||||
|
elif ' ' in i.countries: |
||||||
|
spaces += 1 |
||||||
|
print(i.countries.encode('utf8')) |
||||||
|
if '55' in i.countries: |
||||||
|
continue |
||||||
|
|
||||||
|
|
||||||
|
elif '.' in i.countries: |
||||||
|
number += 1 |
||||||
|
#print(i.countries) |
||||||
|
#a = i.countries.split('.') |
||||||
|
#i.countries_number = int(a[0]) |
||||||
|
#i.countries = '' |
||||||
|
#i.save() |
||||||
|
|
||||||
|
else: |
||||||
|
word += 1 |
||||||
|
#print(i.countries.encode('utf8')) |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
print('all: %d'%qs.count()) |
||||||
|
print('main: %d'%main) |
||||||
|
print('comas: %d'%comas) |
||||||
|
print('enter: %d'%enters) |
||||||
|
print('spaces: %d'%spaces) |
||||||
|
print('word: %d'%word) |
||||||
|
print('number: %d'%number) |
||||||
|
|
||||||
@ -0,0 +1,89 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
import xlrd |
||||||
|
import urllib2 |
||||||
|
from django.core.management.base import BaseCommand |
||||||
|
from django.conf import settings |
||||||
|
from functions.form_check import translit_with_separator |
||||||
|
from functions.files import get_alternative_filename |
||||||
|
from exposition.models import Exposition |
||||||
|
from organiser.models import Organiser |
||||||
|
|
||||||
|
|
||||||
|
CHINA_FILE = settings.MEDIA_ROOT+'/import/expo_china_ru.xlsx' |
||||||
|
GERMANY_FILE = settings.MEDIA_ROOT+'/import/expo_germany_ru.xlsx' |
||||||
|
# 391 row not imported(same url) |
||||||
|
ITALY_FILE = settings.MEDIA_ROOT+'/import/expo_italy_ru.xlsx' |
||||||
|
# moscow 3 exps |
||||||
|
F = settings.MEDIA_ROOT+'/import/exp.xlsx' |
||||||
|
|
||||||
|
LA_FILE = settings.MEDIA_ROOT+'/import/expo_la.xlsx' |
||||||
|
NA_EU_ASIA_FILE = settings.MEDIA_ROOT+'/import/expo_na_eu_ sa.xls' |
||||||
|
NA_EU_ASIA_FILE2 = settings.MEDIA_ROOT+'/import/expo_na_eu_ sa_part2.xls' |
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand): |
||||||
|
def handle(self, *args, **options): |
||||||
|
|
||||||
|
f = open(CHINA_FILE, 'r') |
||||||
|
book = xlrd.open_workbook(file_contents=f.read()) |
||||||
|
sheet = book.sheet_by_index(0) |
||||||
|
row_list = [sheet.row_values(row_number) for row_number in range(sheet.nrows)] |
||||||
|
labels = [label for label in row_list[0]] |
||||||
|
|
||||||
|
for row_number, row in enumerate(row_list[1:]): |
||||||
|
exp_url = translit_with_separator(row[2]) |
||||||
|
try: |
||||||
|
exp = Exposition.objects.get(url=exp_url) |
||||||
|
except Exposition.DoesNotExist: |
||||||
|
continue |
||||||
|
|
||||||
|
if exp.logo or row[19] == '':# or row[16].startswith('http') or row[16].startswith('https') or not row[16].startswith('/') or row[16].startswith('../'): |
||||||
|
continue |
||||||
|
|
||||||
|
path = row[19] |
||||||
|
file_name = path.split('/')[-1] |
||||||
|
logo_path = exp.logo.field.upload_to |
||||||
|
full_path = settings.MEDIA_ROOT + logo_path |
||||||
|
|
||||||
|
try: |
||||||
|
alt_name = get_alternative_filename(full_path, file_name) |
||||||
|
except UnicodeEncodeError: |
||||||
|
continue |
||||||
|
|
||||||
|
download_to = full_path+alt_name |
||||||
|
|
||||||
|
if path.startswith('http') or path.startswith('https'): |
||||||
|
url = path |
||||||
|
elif path.startswith('/'): |
||||||
|
url = 'http://expomap.ru' + path |
||||||
|
elif path.startswith('images'): |
||||||
|
url = 'http://expomap.ru/' + path |
||||||
|
else: |
||||||
|
continue |
||||||
|
#print('------------------------------------') |
||||||
|
#print(path) |
||||||
|
#print(url) |
||||||
|
#print('------------------------------------') |
||||||
|
|
||||||
|
try: |
||||||
|
response = urllib2.urlopen(url, timeout=15) |
||||||
|
except: |
||||||
|
continue |
||||||
|
if response.code != 200: |
||||||
|
continue |
||||||
|
|
||||||
|
with open(download_to,'wb') as f: |
||||||
|
try: |
||||||
|
f.write(response.read()) |
||||||
|
f.close() |
||||||
|
except: |
||||||
|
# can be timeout |
||||||
|
continue |
||||||
|
|
||||||
|
exp.logo = logo_path + alt_name |
||||||
|
try: |
||||||
|
exp.save() |
||||||
|
print(exp) |
||||||
|
except: |
||||||
|
print('logo exception. logo: %s'%exp.logo) |
||||||
|
continue |
||||||
@ -0,0 +1,68 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
import xlrd |
||||||
|
import urllib2 |
||||||
|
from django.core.management.base import BaseCommand |
||||||
|
from django.conf import settings |
||||||
|
from functions.form_check import translit_with_separator |
||||||
|
from functions.files import get_alternative_filename |
||||||
|
from exposition.models import Exposition, Statistic |
||||||
|
from organiser.models import Organiser |
||||||
|
|
||||||
|
|
||||||
|
CHINA_FILE = settings.MEDIA_ROOT+'/import/expo_china_ru.xlsx' |
||||||
|
GERMANY_FILE = settings.MEDIA_ROOT+'/import/expo_germany_ru.xlsx' |
||||||
|
# 391 row not imported(same url) |
||||||
|
ITALY_FILE = settings.MEDIA_ROOT+'/import/expo_italy_ru.xlsx' |
||||||
|
# moscow 3 exps |
||||||
|
F = settings.MEDIA_ROOT+'/import/exp.xlsx' |
||||||
|
|
||||||
|
LA_FILE = settings.MEDIA_ROOT+'/import/expo_la.xlsx' |
||||||
|
NA_EU_ASIA_FILE = settings.MEDIA_ROOT+'/import/expo_na_eu_ sa.xls' |
||||||
|
NA_EU_ASIA_FILE2 = settings.MEDIA_ROOT+'/import/expo_na_eu_ sa_part2.xls' |
||||||
|
RUSSIA_FILE = settings.MEDIA_ROOT+'/import/expo_russia.xls' |
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand): |
||||||
|
def handle(self, *args, **options): |
||||||
|
|
||||||
|
f = open(RUSSIA_FILE, 'r') |
||||||
|
book = xlrd.open_workbook(file_contents=f.read()) |
||||||
|
sheet = book.sheet_by_index(0) |
||||||
|
row_list = [sheet.row_values(row_number) for row_number in range(sheet.nrows)] |
||||||
|
labels = [label for label in row_list[0]] |
||||||
|
|
||||||
|
for row_number, row in enumerate(row_list[1:]): |
||||||
|
exp_url = translit_with_separator(row[2]) |
||||||
|
try: |
||||||
|
exp = Exposition.objects.language('ru').get(url=exp_url) |
||||||
|
except Exposition.DoesNotExist: |
||||||
|
continue |
||||||
|
if not row[30]: |
||||||
|
continue |
||||||
|
|
||||||
|
year = int(row[30]) |
||||||
|
|
||||||
|
|
||||||
|
try: |
||||||
|
countries_number = int(exp.stat_countries) |
||||||
|
countries = '' |
||||||
|
except ValueError: |
||||||
|
countries_number = None |
||||||
|
countries = exp.stat_countries |
||||||
|
|
||||||
|
members = exp.members |
||||||
|
visitors = exp.visitors |
||||||
|
area = exp.area |
||||||
|
|
||||||
|
|
||||||
|
s = Statistic(exposition=exp, |
||||||
|
year=year, |
||||||
|
countries_number=countries_number, |
||||||
|
members=members, |
||||||
|
visitors=visitors, |
||||||
|
area=area) |
||||||
|
s.translate('ru') |
||||||
|
s.countries = countries |
||||||
|
s.save() |
||||||
|
|
||||||
|
print(exp) |
||||||
@ -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() |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -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()) |
||||||
@ -0,0 +1,57 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from django.shortcuts import render_to_response |
||||||
|
from django.http import HttpResponseRedirect, HttpResponse |
||||||
|
from django.core.context_processors import csrf |
||||||
|
from django.conf import settings |
||||||
|
from django.forms.formsets import BaseFormSet, formset_factory |
||||||
|
from django.forms.models import modelformset_factory |
||||||
|
from django.contrib.contenttypes.models import ContentType |
||||||
|
from django.contrib.auth.decorators import login_required |
||||||
|
#models and forms |
||||||
|
from models import MetaSetting |
||||||
|
from forms import MetaForm, MetaFilterForm |
||||||
|
from functions.admin_views import AdminListView, AdminView |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class MetaListView(AdminListView): |
||||||
|
template_name = 'admin/meta/meta_list.html' |
||||||
|
form_class = MetaFilterForm |
||||||
|
model = MetaSetting |
||||||
|
|
||||||
|
class MetaView(AdminView): |
||||||
|
form_class = MetaForm |
||||||
|
model = MetaSetting |
||||||
|
success_url = '/admin/meta/all/' |
||||||
|
template_name = 'admin/meta/meta_setting.html' |
||||||
|
|
||||||
|
def form_valid(self, form): |
||||||
|
self.set_obj() |
||||||
|
expo = form.save(obj=self.obj) |
||||||
|
|
||||||
|
return HttpResponseRedirect(self.success_url) |
||||||
|
|
||||||
|
def get_form(self, form_class): |
||||||
|
if self.request.POST: |
||||||
|
return super(MetaView, self).get_form(form_class) |
||||||
|
obj = self.set_obj() |
||||||
|
if obj: |
||||||
|
data = {'name':obj.name} |
||||||
|
|
||||||
|
for code, name in settings.LANGUAGES: |
||||||
|
trans_obj = self.model._meta.translations_model.objects.get(language_code = code,master__id=obj.id) #access to translated fields |
||||||
|
data['title_%s' % code] = trans_obj.title |
||||||
|
data['description_%s' % code] = trans_obj.description |
||||||
|
data['keywords_%s' % code] = trans_obj.keywords |
||||||
|
data['h1_%s' % code] = trans_obj.h1 |
||||||
|
|
||||||
|
form =form_class(initial=data) |
||||||
|
return form |
||||||
|
else: |
||||||
|
return form_class() |
||||||
|
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs): |
||||||
|
context = super(MetaView, self).get_context_data(**kwargs) |
||||||
|
obj = self.set_obj() |
||||||
|
return context |
||||||
@ -0,0 +1,11 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from django.conf.urls import patterns, include, url |
||||||
|
from admin import MetaListView, MetaView |
||||||
|
|
||||||
|
urlpatterns = patterns('conference.admin', |
||||||
|
|
||||||
|
url(r'^all/$', MetaListView.as_view()), |
||||||
|
#url(r'^change/(?P<url>.*)/$', 'conference_change'), |
||||||
|
url(r'^(?P<id>.*)/$', MetaView.as_view()), |
||||||
|
url(r'^$', MetaView.as_view()), |
||||||
|
) |
||||||
@ -0,0 +1,23 @@ |
|||||||
|
from meta.views import Meta |
||||||
|
|
||||||
|
def add_meta(view): |
||||||
|
def wrapper(request, *args, **kwargs): |
||||||
|
""" |
||||||
|
meta = Meta( |
||||||
|
title=title, |
||||||
|
description=description, |
||||||
|
keywords=keywords, |
||||||
|
meta_extras = { |
||||||
|
'viewport': 'width=device-width, initial-scale=1.0, minimum-scale=1.0' |
||||||
|
} |
||||||
|
'extra_custom_props': [ |
||||||
|
('http-equiv', 'Content-Type', 'text/html; charset=UTF-8'), |
||||||
|
] |
||||||
|
) |
||||||
|
""" |
||||||
|
|
||||||
|
|
||||||
|
r = view(request, *args, **kwargs) |
||||||
|
r.context_data = {'foo': 'bar'} |
||||||
|
return r.render() |
||||||
|
return wrapper |
||||||
@ -0,0 +1,48 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from django import forms |
||||||
|
from django.conf import settings |
||||||
|
from models import MetaSetting |
||||||
|
from functions.translate import fill_with_signal |
||||||
|
from functions.admin_forms import AdminFilterForm |
||||||
|
|
||||||
|
|
||||||
|
class MetaForm(forms.Form): |
||||||
|
name = forms.CharField(label=u'Название страницы') |
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs): |
||||||
|
""" |
||||||
|
create dynamical translated fields fields |
||||||
|
""" |
||||||
|
super(MetaForm, self).__init__(*args, **kwargs) |
||||||
|
#creates translated forms example: name_ru, name_en |
||||||
|
# len(10) is a hack for detect if settings.LANGUAGES is not configured it return all langs |
||||||
|
if len(settings.LANGUAGES) in range(10): |
||||||
|
for lid, (code, name) in enumerate(settings.LANGUAGES): |
||||||
|
# uses enumerate for detect iteration number |
||||||
|
# first iteration is a default lang so it required fields |
||||||
|
required = True if lid == 0 else False |
||||||
|
self.fields['title_%s' % code] = forms.CharField(label=u'Title', required=required, |
||||||
|
widget=forms.TextInput(attrs={'style':'width: 550px'})) |
||||||
|
self.fields['description_%s' % code] = forms.CharField(label=u'Description', required=required, |
||||||
|
widget=forms.TextInput(attrs={'style':'width: 550px'})) |
||||||
|
self.fields['keywords_%s' % code] = forms.CharField(label=u'Keywords', required=False, |
||||||
|
widget=forms.TextInput(attrs={'style':'width: 550px'})) |
||||||
|
self.fields['h1_%s' % code] = forms.CharField(label=u'H1', required=False, |
||||||
|
widget=forms.TextInput(attrs={'style':'width: 550px'})) |
||||||
|
|
||||||
|
def save(self, obj=None): |
||||||
|
data = self.cleaned_data |
||||||
|
if not obj: |
||||||
|
meta = MetaSetting() |
||||||
|
else: |
||||||
|
meta = obj |
||||||
|
|
||||||
|
meta.name = data['name'] |
||||||
|
|
||||||
|
|
||||||
|
# fill translated fields and save object |
||||||
|
fill_with_signal(MetaSetting, meta, data) |
||||||
|
meta.save() |
||||||
|
|
||||||
|
class MetaFilterForm(AdminFilterForm): |
||||||
|
model = MetaSetting |
||||||
@ -0,0 +1,114 @@ |
|||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
||||||
|
"http://www.w3.org/TR/html4/loose.dtd"> |
||||||
|
<html style="margin: 0; padding: 0; height: 100%;"> |
||||||
|
<head> |
||||||
|
<title></title> |
||||||
|
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> |
||||||
|
</head> |
||||||
|
<body style="margin: 0; padding: 0; min-height: 100%; background: #f4f2ee;"> |
||||||
|
<table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%" bgcolor="#f4f2ee" style="font-family: Arial, sans-serif; background: #f4f2ee;"> |
||||||
|
<tr> |
||||||
|
<td align="center" style="padding: 50px 0"> |
||||||
|
|
||||||
|
<table cellpadding="0" cellspacing="0" border="0" width="600" style="width: 600px;"> |
||||||
|
<tr> |
||||||
|
<td style="vertical-align: top;"> |
||||||
|
<div class="logo"> |
||||||
|
<a style="text-decoration: none; color: #a2a2a2; font-size: 12px;" href="#"> |
||||||
|
<img src="cid:logo" alt="Expomap.ru" /> |
||||||
|
<b style="display: block; padding-left: 67px; margin-top: -5px;">Выставки, конференции, семинары</b> |
||||||
|
</a> |
||||||
|
</div> |
||||||
|
</td> |
||||||
|
<td style="vertical-align: top; padding-top: 22px;"> |
||||||
|
<ul class="t-links" style="margin: 0 0 15px; padding: 0; list-style: none; text-align: right; font-size: 16px; line-height: 17px; font-weight: bold;"> |
||||||
|
<li style="display: inline-block;"><a style="text-decoration: none; color: #ff6600" href="#">СОБЫТИЯ</a></li> |
||||||
|
<li style="display: inline-block; margin-left: 20px;"><a style="text-decoration: none; color: #ff6600" href="#">МЕСТА</a></li> |
||||||
|
<li style="display: inline-block; margin-left: 20px;"><a style="text-decoration: none; color: #ff6600" href="#">УЧАСТНИКИ</a></li> |
||||||
|
</ul> |
||||||
|
|
||||||
|
<ul class="soc-media-buttons" style="margin: 0; padding: 0; list-style: none; text-align: right;"> |
||||||
|
<li style="display: inline-block;"><a href="#"><img src="cid:rss" title="RSS" alt="RSS" /></a></li> |
||||||
|
<li style="display: inline-block; margin-left: 5px;"><a href="#"><img src="cid:fb" title="Facebook" alt="Facebook" /></a></li> |
||||||
|
<li style="display: inline-block; margin-left: 5px;"><a href="#"><img src="cid:linkedin" title="LinkedIn" alt="LinkedIn" /></a></li> |
||||||
|
<li style="display: inline-block; margin-left: 5px;"><a href="#"><img src="cid:vk" title="В контакте" alt="В контакте" /></a></li> |
||||||
|
<li style="display: inline-block; margin-left: 5px;"><a href="#"><img src="cid:twit" title="Twitter" alt="Twitter" /></a></li> |
||||||
|
</ul> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
|
||||||
|
<table cellpadding="0" cellspacing="0" border="0" width="600" style="width: 600px; margin-bottom: 10px;"> |
||||||
|
<tr> |
||||||
|
<td style="padding: 20px 0 0;"><p style="display: block; padding: 25px 30px; text-decoration: none; background: #ff6600; color: #ffffff; font-size: 20px; line-height: 26px; margin-bottom: 0;" >Воостановление пароля на портале <a href="http://expomap.ru/" style="color: #ffffff;text-decoration: none;border-bottom: 1px dashed #ee3824;">Expomap</a></p></td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td style="padding: 10px 30px 15px; background: #faf9f7;"> |
||||||
|
|
||||||
|
<table cellpadding="0" cellspacing="0" border="0" width="540" style="margin-bottom: 15px;"> |
||||||
|
|
||||||
|
<tr valign="top"> |
||||||
|
<td style="padding: 15px 0 36px 0;"> |
||||||
|
<p style="font-weight: bold;color: #003e79;margin: 0;">Добрый день, {{ user.first_name }}!</p> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<tr valign="top"> |
||||||
|
<td style="padding: 0 0 23px 0;"> |
||||||
|
Вы или кто-то еще сделал запрос на сброс пароля на сайте <a href="{{ domain }}" style="text-decoration: none;border-bottom: 1px dashed #ee3824;color: #645a5a;">{{ domain }}</a> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<tr valign="top"> |
||||||
|
<td style="padding: 0 0 32px 0;"> |
||||||
|
Вы можете восстановить доступ, нажав на кнопку ниже и указав новый пароль: |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<tr valign="top"> |
||||||
|
<td style="padding: 0 0 32px 0; text-align: center;"> |
||||||
|
<a class="button" style="display: inline-block; padding: 4px 10px 3px; text-decoration: none; color: #2592c5; font-size: 14px; font-weight: bold; line-height: 14px; border: 1px solid #90c7e0; text-transform: uppercase; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; width: 336px;" href="http{% if secure %}s{% endif %}://{{ site.domain }}{% url "password_reset_reset" token %}">востановить пароль</a> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<tr valign="top"> |
||||||
|
<td style="padding: 0 0 20px 0; text-align: left; "> |
||||||
|
Если вы не хотите сбрасывать пароль, просто <span style="border-bottom: 1px dashed #ee3824;">проигнорируйте</span> это сообщение |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
|
||||||
|
</table> |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
|
||||||
|
<table cellpadding="0" cellspacing="0" border="0" width="600" style="width: 600px; border-bottom: 1px dotted #cccccc;"> |
||||||
|
<tr> |
||||||
|
<td style="vertical-align: top; padding: 15px 0 10px;"> |
||||||
|
<div class="logo"> |
||||||
|
<a style="text-decoration: none; color: #a2a2a2; font-size: 12px;" href="#"> |
||||||
|
<img src="cid:logo2" alt="Expomap.ru" /> |
||||||
|
</a> |
||||||
|
</div> |
||||||
|
</td> |
||||||
|
<td style="vertical-align: top; padding: 25px 0 5px;"> |
||||||
|
<ul class="t-links" style="margin: 0 0 15px; padding: 0; list-style: none; text-align: right; font-size: 14px; line-height: 15px; font-weight: bold;"> |
||||||
|
<li style="display: inline-block;"><a style="text-decoration: none; color: #ff6600" href="#">СОБЫТИЯ</a></li> |
||||||
|
<li style="display: inline-block; margin-left: 20px;"><a style="text-decoration: none; color: #ff6600" href="#">МЕСТА</a></li> |
||||||
|
<li style="display: inline-block; margin-left: 20px;"><a style="text-decoration: none; color: #ff6600" href="#">УЧАСТНИКИ</a></li> |
||||||
|
</ul> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
<table cellpadding="0" cellspacing="0" border="0" width="600" style="width: 600px; font-size: 12px; line-height: 15px;"> |
||||||
|
<tr> |
||||||
|
<td style="vertical-align: top; padding: 15px 0 15px; color: #a2a2a2; text-align: right;"> |
||||||
|
© 2018 — 2013 <a style="color: #a2a2a2; text-decoration: none;" href="#">Expomap.ru</a> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
|
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
</body> |
||||||
|
</html> |
||||||
@ -1,99 +1,114 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
from django.core.management.base import BaseCommand, CommandError |
from django.core.management.base import BaseCommand, CommandError |
||||||
|
import xlrd |
||||||
from place_exposition.models import PlaceExposition |
from place_exposition.models import PlaceExposition |
||||||
import xlrd, xlwt |
|
||||||
from import_xls.excel_settings import import_settings, place_exp_sett |
from import_xls.excel_settings import import_settings, place_exp_sett |
||||||
from django.conf import settings |
from django.conf import settings |
||||||
from import_xls.import_forms import google_address |
|
||||||
|
PLACE_FILE = settings.MEDIA_ROOT+'import/places_ru.xls' |
||||||
|
|
||||||
class Command(BaseCommand): |
class Command(BaseCommand): |
||||||
def handle(self, *args, **options): |
def handle(self, *args, **options): |
||||||
|
|
||||||
f = open(settings.MEDIA_ROOT+'/import/places_ru.xlsx', 'r') |
f = open(PLACE_FILE, 'r') |
||||||
book = xlrd.open_workbook(file_contents=f.read()) |
book = xlrd.open_workbook(file_contents=f.read()) |
||||||
sheet = book.sheet_by_index(0) |
sheet = book.sheet_by_index(0) |
||||||
row_list = [sheet.row_values(row_number) for row_number in range(sheet.nrows)] |
row_list = [sheet.row_values(row_number) for row_number in range(sheet.nrows)] |
||||||
labels = [label for label in row_list[0]] |
labels = [label for label in row_list[0]] |
||||||
for row_number, row in enumerate(row_list): |
existing = 0 |
||||||
|
|
||||||
|
for row_number, row in enumerate(row_list[1:]): |
||||||
|
new = 0 |
||||||
# go through all rows in file |
# go through all rows in file |
||||||
if row_number > 0: |
if row[0] != '': |
||||||
# first field is label |
# in first column ids |
||||||
if row[0] != '': |
|
||||||
# in first column ids |
|
||||||
|
|
||||||
try: |
try: |
||||||
object = PlaceExposition.objects.language('ru').get(id=int(row[0])) |
object = PlaceExposition.objects.language('ru').get(id=int(row[0])) |
||||||
except ValueError: |
existing += 1 |
||||||
object = PlaceExposition() |
except ValueError: |
||||||
object.translate('ru') |
object = PlaceExposition() |
||||||
|
|
||||||
except PlaceExposition.DoesNotExist: |
|
||||||
object = PlaceExposition(id= int(row[0])) |
|
||||||
object.translate('ru') |
|
||||||
else: |
|
||||||
# if id blank - its a new place |
|
||||||
object = PlaceExposition |
|
||||||
object.translate('ru') |
object.translate('ru') |
||||||
methods = [] |
new = 1 |
||||||
for col_number, cell in enumerate(row): |
|
||||||
# go through row cells |
|
||||||
# field name current cell |
|
||||||
label = labels[col_number] |
|
||||||
setting = place_exp_sett.get(label) |
|
||||||
|
|
||||||
if setting is None: |
|
||||||
continue |
|
||||||
|
|
||||||
if setting.get('method'): |
except PlaceExposition.DoesNotExist: |
||||||
if cell != "": |
object = PlaceExposition(id= int(row[0])) |
||||||
methods.append({'func': setting['func'], 'value': cell, 'purpose': setting.get('purpose')}) |
object.translate('ru') |
||||||
continue |
existing += 1 |
||||||
|
new = 1 |
||||||
|
else: |
||||||
|
# if id blank - its a new place |
||||||
|
object = PlaceExposition |
||||||
|
object.translate('ru') |
||||||
|
|
||||||
field_name = setting['field'] |
|
||||||
|
|
||||||
|
|
||||||
func = setting.get('func') |
|
||||||
if func is not None: |
|
||||||
extra_value = setting.get('extra_values') |
|
||||||
if extra_value is not None: |
|
||||||
# if setting has extra value then |
|
||||||
# it is some field like city, theme, tag |
|
||||||
# that has relation and can be created |
|
||||||
|
|
||||||
# in function we add language(need for relation fields) |
|
||||||
# and extra value from object (like for city need country) |
|
||||||
value = func(cell, 'ru', getattr(object, extra_value)) |
|
||||||
else: |
|
||||||
value = func(cell) |
|
||||||
#if field_name =='adress': |
|
||||||
# setattr(object, 'address', google_address(value)) |
|
||||||
setattr(object, field_name, value) |
|
||||||
|
|
||||||
object.save() |
|
||||||
print('post save %s'% str(object)) |
|
||||||
""" |
|
||||||
try: |
|
||||||
print(object) |
|
||||||
#object.save() |
|
||||||
|
|
||||||
except IntegrityError: |
methods = [] |
||||||
|
for col_number, cell in enumerate(row): |
||||||
|
# go through row cells |
||||||
|
# field name current cell |
||||||
|
label = labels[col_number] |
||||||
|
setting = place_exp_sett.get(label) |
||||||
|
|
||||||
|
if setting is None: |
||||||
continue |
continue |
||||||
#url = object.url + translit_with_separator(object.city.name) |
|
||||||
#object.url = url |
if setting.get('method'): |
||||||
#object.save() |
if cell != "": |
||||||
""" |
methods.append({'func': setting['func'], 'value': cell, 'purpose': setting.get('purpose')}) |
||||||
|
continue |
||||||
for method in methods: |
|
||||||
func = method['func'] |
field_name = setting['field'] |
||||||
if method.get('purpose'): |
func = setting.get('func') |
||||||
try: |
|
||||||
func(object, method['value'], method['purpose']) |
if func is not None: |
||||||
except: |
extra_value = setting.get('extra_values') |
||||||
continue |
if extra_value is not None: |
||||||
|
# if setting has extra value then |
||||||
|
# it is some field like city, theme, tag |
||||||
|
# that has relation and can be created |
||||||
|
|
||||||
|
# in function we add language(need for relation fields) |
||||||
|
# and extra value from object (like for city need country) |
||||||
|
value = func(cell, 'ru', getattr(object, extra_value)) |
||||||
|
|
||||||
|
|
||||||
|
else: |
||||||
|
value = func(cell) |
||||||
|
#if field_name =='adress': |
||||||
|
# setattr(object, 'address', google_address(value)) |
||||||
|
if field_name == 'city' and new == 0: |
||||||
|
pass |
||||||
else: |
else: |
||||||
try: |
try: |
||||||
func(object, method['value']) |
setattr(object, field_name, value) |
||||||
except: |
except ValueError, e: |
||||||
continue |
print(value, field_name) |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
object.save() |
||||||
|
print('post save %s'% str(object)) |
||||||
|
""" |
||||||
|
try: |
||||||
|
print(object) |
||||||
|
#object.save() |
||||||
|
|
||||||
|
except IntegrityError: |
||||||
|
continue |
||||||
|
#url = object.url + translit_with_separator(object.city.name) |
||||||
|
#object.url = url |
||||||
|
#object.save() |
||||||
|
""" |
||||||
|
|
||||||
|
for method in methods: |
||||||
|
func = method['func'] |
||||||
|
if method.get('purpose'): |
||||||
|
try: |
||||||
|
func(object, method['value'], method['purpose']) |
||||||
|
except: |
||||||
|
continue |
||||||
|
else: |
||||||
|
try: |
||||||
|
func(object, method['value']) |
||||||
|
except: |
||||||
|
continue |
||||||
@ -0,0 +1,141 @@ |
|||||||
|
import datetime |
||||||
|
from django.contrib.sitemaps import Sitemap |
||||||
|
from exposition.models import Exposition |
||||||
|
from conference.models import Conference |
||||||
|
from city.models import City |
||||||
|
from country.models import Country |
||||||
|
from theme.models import Theme, Tag |
||||||
|
from article.models import Article |
||||||
|
from django.core.urlresolvers import reverse |
||||||
|
from django.core.paginator import Paginator |
||||||
|
|
||||||
|
|
||||||
|
class Abstract(Sitemap): |
||||||
|
changefreq = 'weekly' |
||||||
|
priority = 0.8 |
||||||
|
|
||||||
|
def lastmod(self, obj): |
||||||
|
return datetime.date.today() |
||||||
|
|
||||||
|
|
||||||
|
class ExpoCard(Abstract): |
||||||
|
changefreq = 'weekly' |
||||||
|
priority = 0.8 |
||||||
|
|
||||||
|
def items(self): |
||||||
|
return Exposition.enable.upcoming() |
||||||
|
|
||||||
|
def lastmod(self, obj): |
||||||
|
return obj.modified |
||||||
|
|
||||||
|
class ExpoCity(Abstract): |
||||||
|
|
||||||
|
def items(self): |
||||||
|
return City.used.expo_cities() |
||||||
|
|
||||||
|
def location(self, obj): |
||||||
|
return "/expo/city/%s/" % obj.url |
||||||
|
|
||||||
|
class ExpoCountry(Abstract): |
||||||
|
def items(self): |
||||||
|
return Country.objects.expo_countries() |
||||||
|
|
||||||
|
def location(self, obj): |
||||||
|
return "/expo/country/%s/" % obj.url |
||||||
|
|
||||||
|
class ExpoTheme(Abstract): |
||||||
|
def items(self): |
||||||
|
return Theme.active.expo_themes() |
||||||
|
|
||||||
|
def location(self, obj): |
||||||
|
return "/expo/theme/%s/" % obj.url |
||||||
|
|
||||||
|
class ExpoTag(Abstract): |
||||||
|
def items(self): |
||||||
|
return Tag.active.expo_tag() |
||||||
|
|
||||||
|
def location(self, obj): |
||||||
|
return "/expo/tag/%s/" % obj.url |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class ConfCard(Sitemap): |
||||||
|
changefreq = 'weekly' |
||||||
|
priority = 0.8 |
||||||
|
|
||||||
|
def items(self): |
||||||
|
return Conference.enable.upcoming() |
||||||
|
|
||||||
|
def lastmod(self, obj): |
||||||
|
return obj.modified |
||||||
|
|
||||||
|
def location(self, obj): |
||||||
|
return "/conference/%s/" % obj.url |
||||||
|
|
||||||
|
|
||||||
|
class ConfCity(Abstract): |
||||||
|
|
||||||
|
def items(self): |
||||||
|
return City.used.conference_cities() |
||||||
|
|
||||||
|
def location(self, obj): |
||||||
|
return "/conference/city/%s/" % obj.url |
||||||
|
|
||||||
|
class ConfCountry(Abstract): |
||||||
|
def items(self): |
||||||
|
return Country.objects.conference_countries() |
||||||
|
|
||||||
|
def location(self, obj): |
||||||
|
return "/conference/country/%s/" % obj.url |
||||||
|
|
||||||
|
class ConfTheme(Abstract): |
||||||
|
def items(self): |
||||||
|
return Theme.active.conference_themes_with_count() |
||||||
|
|
||||||
|
def location(self, obj): |
||||||
|
return "/conference/theme/%s/" % obj.url |
||||||
|
|
||||||
|
class ConfTag(Abstract): |
||||||
|
def items(self): |
||||||
|
return Tag.active.conference_tags() |
||||||
|
|
||||||
|
def location(self, obj): |
||||||
|
return "/conference/tag/%s/" % obj.url |
||||||
|
|
||||||
|
|
||||||
|
class NewsSiteMap(Abstract): |
||||||
|
priority = 0.5 |
||||||
|
def items(self): |
||||||
|
return Article.objects.news().filter(publish_date__isnull=False) |
||||||
|
|
||||||
|
def location(self, obj): |
||||||
|
return "/news/%s/" % obj.slug |
||||||
|
|
||||||
|
class BlogsSiteMap(Abstract): |
||||||
|
priority = 0.5 |
||||||
|
def items(self): |
||||||
|
return Article.objects.blogs().filter(publish_date__isnull=False) |
||||||
|
|
||||||
|
def location(self, obj): |
||||||
|
return "/blogs/%s/" % obj.slug |
||||||
|
|
||||||
|
|
||||||
|
class SimpleAbstract(Sitemap): |
||||||
|
priority = 0.5 |
||||||
|
|
||||||
|
def location(self, item): |
||||||
|
return item |
||||||
|
|
||||||
|
|
||||||
|
class Important(SimpleAbstract): |
||||||
|
priority = 1 |
||||||
|
|
||||||
|
def items(self): |
||||||
|
return ['', '/expo/', '/conference/', '/conference/country/', '/conference/city/', '/conference/theme/', |
||||||
|
'/expo/theme/', '/expo/country/', '/expo/city/'] |
||||||
|
|
||||||
|
class Additional(SimpleAbstract): |
||||||
|
priority = 0.5 |
||||||
|
|
||||||
|
def items(self): |
||||||
|
return ['/blogs/', '/news/', '/partners/', '/about/', '/advertising/', '/contacts/'] |
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue