@ -1,12 +1,12 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
from django.conf.urls import patterns, url |
from django.conf.urls import patterns, url |
||||||
|
from admin import UserListView |
||||||
|
|
||||||
urlpatterns = patterns('', |
urlpatterns = patterns('', |
||||||
#url(r'^registration/$', 'accounts.admin.registration'), |
#url(r'^registration/$', 'accounts.admin.registration'), |
||||||
#url(r'^create_admin/$', 'accounts.admin.create_admin'), |
#url(r'^create_admin/$', 'accounts.admin.create_admin'), |
||||||
#url(r'^create_md5user/$', 'accounts.admin.create_md5'), |
#url(r'^create_md5user/$', 'accounts.admin.create_md5'), |
||||||
url(r'^change/(.*)/$', 'accounts.admin.user_change'), |
url(r'^change/(.*)/$', 'accounts.admin.user_change'), |
||||||
# url(r'^change/(?P<user_id>\d+).*/$', 'accounts.views.user_change'), |
url(r'^all/$', UserListView.as_view()), |
||||||
url(r'^all/$', 'accounts.admin.user_all'), |
|
||||||
url(r'^reset_password_email/$', 'accounts.admin.reset_password_email'), |
url(r'^reset_password_email/$', 'accounts.admin.reset_password_email'), |
||||||
) |
) |
||||||
@ -1 +0,0 @@ |
|||||||
|
|
||||||
@ -1,11 +1,16 @@ |
|||||||
# -*- 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 CompanyListView |
from admin import CompanyListView, CompanyView |
||||||
|
|
||||||
urlpatterns = patterns('company.admin', |
urlpatterns = patterns('company.admin', |
||||||
url(r'^add.*/$', 'company_add'), |
|
||||||
url(r'^delete/(?P<url>.*)/$', 'company_delete'), |
|
||||||
url(r'^change/(?P<url>.*).*/$', 'company_change'), |
|
||||||
#url(r'^all/$', 'company_all'), |
|
||||||
url(r'^all/$', CompanyListView.as_view()), |
url(r'^all/$', CompanyListView.as_view()), |
||||||
|
url(r'^$', CompanyView.as_view()), |
||||||
|
url(r'^(?P<url>.*)/$', CompanyView.as_view()), |
||||||
|
|
||||||
|
#url(r'^add.*/$', 'company_add'), |
||||||
|
#url(r'^delete/(?P<url>.*)/$', 'company_delete'), |
||||||
|
#url(r'^change/(?P<url>.*).*/$', 'company_change'), |
||||||
|
#url(r'^all/$', 'company_all'), |
||||||
|
#url(r'^all/$', CompanyListView.as_view()), |
||||||
|
|
||||||
) |
) |
||||||
@ -0,0 +1,65 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from haystack import indexes |
||||||
|
|
||||||
|
class ExpoSearchMixin(object): |
||||||
|
""" |
||||||
|
|
||||||
|
""" |
||||||
|
|
||||||
|
def prepare_where(self, obj): |
||||||
|
if obj.country: |
||||||
|
country = [tr.name for tr in obj.country.translations.all()] |
||||||
|
else: |
||||||
|
country = '' |
||||||
|
if obj.city: |
||||||
|
city = [tr.name for tr in obj.city.translations.all()] |
||||||
|
else: |
||||||
|
city = '' |
||||||
|
|
||||||
|
return country + city |
||||||
|
|
||||||
|
def prepare_content_auto(self, obj): |
||||||
|
""" |
||||||
|
object must have get_index_text method which generate text for searching |
||||||
|
""" |
||||||
|
return obj.get_index_text() |
||||||
|
|
||||||
|
|
||||||
|
def prepare_area_id(self, obj): |
||||||
|
if obj.country: |
||||||
|
return obj.country.area.id |
||||||
|
return None |
||||||
|
|
||||||
|
def prepare_country_id(self, obj): |
||||||
|
if obj.country: |
||||||
|
return obj.country.id |
||||||
|
return None |
||||||
|
|
||||||
|
def prepare_city_id(self, obj): |
||||||
|
if obj.city: |
||||||
|
return obj.city.id |
||||||
|
return None |
||||||
|
|
||||||
|
def prepare_theme(self, obj): |
||||||
|
return [th.id for th in obj.theme.filter()] |
||||||
|
|
||||||
|
def prepare_tag(self, obj): |
||||||
|
return [th.id for th in obj.tag.filter()] |
||||||
|
|
||||||
|
|
||||||
|
def prepare_url(self, obj): |
||||||
|
return obj.get_permanent_url() |
||||||
|
|
||||||
|
def prepare_name_en(self, obj): |
||||||
|
try: |
||||||
|
return obj.translations.get(language_code = 'en').name |
||||||
|
except: |
||||||
|
return '' |
||||||
|
|
||||||
|
def prepare_name_ru(self, obj): |
||||||
|
try: |
||||||
|
return obj.translations.get(language_code = 'ru').name |
||||||
|
except: |
||||||
|
return '' |
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,22 @@ |
|||||||
|
from hvad.models import TranslationManager |
||||||
|
|
||||||
|
|
||||||
|
class ExpoImportManager(TranslationManager): |
||||||
|
def create_by_dict(self, d): |
||||||
|
model = self.model |
||||||
|
id = d['id'] |
||||||
|
lang = d['lang'] |
||||||
|
if id: |
||||||
|
expo = self.language(lang).get(id=id) |
||||||
|
else: |
||||||
|
expo = model() |
||||||
|
expo.translate(lang) |
||||||
|
|
||||||
|
|
||||||
|
aaaa |
||||||
|
|
||||||
|
# save simple values |
||||||
|
# save relations |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,172 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
import urllib2 |
||||||
|
import time, xlrd |
||||||
|
from django.conf import settings |
||||||
|
from django.utils import translation |
||||||
|
from hvad.utils import get_translation_aware_manager |
||||||
|
from bitfield import BitHandler |
||||||
|
from place_exposition.models import PlaceExposition |
||||||
|
from exposition.models import Exposition |
||||||
|
from country.models import Country |
||||||
|
from city.models import City |
||||||
|
from theme.models import Theme, Tag |
||||||
|
from functions.files import get_alternative_filename |
||||||
|
from exposition.models import BIT_AUDIENCE |
||||||
|
|
||||||
|
|
||||||
|
def to_int(val): |
||||||
|
""" |
||||||
|
Reverse function to get_int |
||||||
|
return None if value isnt integer |
||||||
|
""" |
||||||
|
try: |
||||||
|
return int(val) |
||||||
|
except ValueError: |
||||||
|
return None |
||||||
|
|
||||||
|
def to_date(value): |
||||||
|
if not value: |
||||||
|
return None |
||||||
|
|
||||||
|
if isinstance(value, unicode) or isinstance(value, str): |
||||||
|
|
||||||
|
t = time.strptime(value, "%d.%m.%Y") |
||||||
|
if isinstance(value, float): |
||||||
|
t = xlrd.xldate_as_tuple(value, 0)+(0,0,0) |
||||||
|
return time.strftime("%Y-%m-%d", t) |
||||||
|
|
||||||
|
def to_country(value): |
||||||
|
try: |
||||||
|
query = get_translation_aware_manager(Country) |
||||||
|
country = query.filter(name=value)[0] |
||||||
|
return country |
||||||
|
except IndexError: |
||||||
|
return None |
||||||
|
|
||||||
|
def to_city(value, lang, country): |
||||||
|
try: |
||||||
|
# get city by name |
||||||
|
#objects = get_translation_aware_manager(City) |
||||||
|
# except IndexError if no found |
||||||
|
city = City.objects.filter(translations__name=value, country=country)[0] |
||||||
|
# print(city) |
||||||
|
return city |
||||||
|
except IndexError: |
||||||
|
# print('---------------------') |
||||||
|
# print(value.encode('utf8')) |
||||||
|
# print('---------------------') |
||||||
|
return None |
||||||
|
|
||||||
|
|
||||||
|
def to_theme(obj, value): |
||||||
|
|
||||||
|
if isinstance(value, float) or isinstance(value, int): |
||||||
|
if (value - int(value) > 0): |
||||||
|
value = str(value) |
||||||
|
else: |
||||||
|
value = str(int(value)) |
||||||
|
theme_ids = value.split('.') |
||||||
|
else: |
||||||
|
theme_ids = value.split(',') |
||||||
|
|
||||||
|
obj.theme.add(*Theme.objects.filter(id__in=theme_ids)) |
||||||
|
|
||||||
|
def to_tag(obj,value): |
||||||
|
if value == [""]: |
||||||
|
return None |
||||||
|
names = value.split(',') |
||||||
|
translation.activate('en') |
||||||
|
if names: |
||||||
|
obj.tag.add(*Tag.objects.filter(translations__name__in=names, theme__in=obj.theme.all())) |
||||||
|
else: |
||||||
|
return |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def to_place(value): |
||||||
|
try: |
||||||
|
place = PlaceExposition.objects.get(url=value) |
||||||
|
return place |
||||||
|
except PlaceExposition.DoesNotExist: |
||||||
|
return None |
||||||
|
|
||||||
|
|
||||||
|
def to_periodic(value): |
||||||
|
periodic = {'': 0, u'Ежегодно': 1.0, u'2 раза в год': 2.0, u'3 раза в год': 3.0, |
||||||
|
u'4 раза в год': 4.0, u'5 раз в год': 5.0, u'Раз в 2 года': 0.5, |
||||||
|
u'Раз в 3 года': 0.33, u'Раз в 4 года': 0.25} |
||||||
|
|
||||||
|
return periodic.get(value, 0) |
||||||
|
|
||||||
|
|
||||||
|
def to_audience(value, model=Exposition): |
||||||
|
if value: |
||||||
|
l = value.split(', ') |
||||||
|
if l: |
||||||
|
new_list = [] |
||||||
|
for value in l: |
||||||
|
for item1, item2 in BIT_AUDIENCE: |
||||||
|
if value == item2: |
||||||
|
new_list.append(item1) |
||||||
|
if new_list: |
||||||
|
return reduce(lambda x,y: x|y, (getattr(model.audience, item) for item in new_list)) |
||||||
|
return 0 |
||||||
|
|
||||||
|
def get_audience(value): |
||||||
|
if isinstance(value, BitHandler): |
||||||
|
l = [k for k, v in value.iteritems() if v] |
||||||
|
if l: |
||||||
|
new_list = [] |
||||||
|
for value in l: |
||||||
|
for item1, item2 in BIT_AUDIENCE: |
||||||
|
if value == item1: |
||||||
|
new_list.append(item2) |
||||||
|
|
||||||
|
return ', '.join(new_list) |
||||||
|
return |
||||||
|
|
||||||
|
|
||||||
|
def save_logo(obj, path): |
||||||
|
if not path: |
||||||
|
return None |
||||||
|
file_name = path.split('/')[-1] |
||||||
|
logo_path = obj.logo.field.upload_to |
||||||
|
full_path = settings.MEDIA_ROOT + logo_path |
||||||
|
|
||||||
|
|
||||||
|
alt_name = get_alternative_filename(full_path, file_name) |
||||||
|
|
||||||
|
download_to = full_path+alt_name |
||||||
|
|
||||||
|
if path.startswith('http://') or path.startswith('https://'): |
||||||
|
|
||||||
|
url = path |
||||||
|
else: |
||||||
|
url = 'http://expomap.ru' + path |
||||||
|
|
||||||
|
try: |
||||||
|
response = urllib2.urlopen(url, timeout=10) |
||||||
|
except: |
||||||
|
return None |
||||||
|
|
||||||
|
with open(download_to,'wb') as f: |
||||||
|
try: |
||||||
|
f.write(response.read()) |
||||||
|
f.close() |
||||||
|
except: |
||||||
|
# can be timeout |
||||||
|
return None |
||||||
|
|
||||||
|
obj.logo = logo_path + alt_name |
||||||
|
obj.save() |
||||||
|
|
||||||
|
|
||||||
|
def check_quality_label(obj, value, label): |
||||||
|
bit = obj.quality_label |
||||||
|
try: |
||||||
|
value = int(value) |
||||||
|
except: |
||||||
|
return bit |
||||||
|
if value: |
||||||
|
setattr(bit, label, True) |
||||||
|
return bit |
||||||
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 7.5 KiB |
|
Before Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 7.5 KiB |
|
Before Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 6.2 KiB |
|
Before Width: | Height: | Size: 4.6 KiB |
|
Before Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 39 KiB |
|
Before Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 7.5 KiB |
|
Before Width: | Height: | Size: 4.4 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 6.5 KiB |
|
Before Width: | Height: | Size: 8.4 KiB |
|
Before Width: | Height: | Size: 6.2 KiB |
|
Before Width: | Height: | Size: 9.8 KiB |
|
Before Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 8.6 KiB |
|
Before Width: | Height: | Size: 7.8 KiB |
|
Before Width: | Height: | Size: 7.7 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 7.3 KiB |
|
Before Width: | Height: | Size: 6.8 KiB |
|
Before Width: | Height: | Size: 7.0 KiB |
|
Before Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 6.9 KiB |
|
Before Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 5.0 KiB |
|
Before Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 6.1 KiB |
|
Before Width: | Height: | Size: 4.5 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 4.1 KiB |
|
Before Width: | Height: | Size: 4.1 KiB |
|
Before Width: | Height: | Size: 1.9 KiB |