remotes/origin/1203
Ivan 11 years ago
commit 8f0adcdcb5
  1. 7
      accounts/models.py
  2. 10
      import_xls/admin.py
  3. 2
      import_xls/excel_settings.py
  4. 155
      import_xls/import_forms.py
  5. 9
      import_xls/utils.py
  6. 1
      proj/urls.py
  7. 6
      settings/old_urls.py
  8. 27
      settings/redirect_views.py
  9. BIN
      static/seminar_lending/img/reporter3.png
  10. 21
      templates/admin/import templates/import.html
  11. 21
      templates/client/accounts/translators/translators_list.html
  12. 56
      templates/client/includes/accounts/translators.html
  13. BIN
      templates/client/static_client/img/fancybox/blank.gif
  14. BIN
      templates/client/static_client/img/fancybox/fancybox_loading.gif
  15. BIN
      templates/client/static_client/img/fancybox/fancybox_loading@2x.gif
  16. BIN
      templates/client/static_client/img/fancybox/fancybox_overlay.png
  17. BIN
      templates/client/static_client/img/fancybox/fancybox_sprite.png
  18. BIN
      templates/client/static_client/img/fancybox/fancybox_sprite@2x.png
  19. 13
      translator/urls.py
  20. 30
      translator/views.py

@ -140,6 +140,9 @@ class User(AbstractBaseUser, PermissionsMixin):
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['first_name', 'last_name']
class Meta:
ordering=['-rating']
def get_full_name(self):
"""
Returns the first_name plus the last_name, with a space in between.
@ -196,9 +199,9 @@ class User(AbstractBaseUser, PermissionsMixin):
def get_permanent_url(self):
if self.url:
return '/%s'%self.url
return '/%s/'%self.url
#return self.catalog+self.url+'/'
return '/%d'%self.id
return '/%d/'%self.id
#return self.catalog+str(self.id)+'/'
def get_expos(self):

@ -27,13 +27,17 @@ class ImportView(FormView):
"""
abstract class
"""
template_name = 'import.html'
template_name = 'admin/import templates/import.html'
def form_valid(self, form):
form.save_file()
errors = form.save_file()
messages.success(self.request, 'Success')
context = self.get_context_data()
context['import_errors'] = errors
context['form'] = form
return render_to_response(self.template_name, context)
return super(ImportView, self).form_valid(form)
class ExportView(FormView):

@ -280,7 +280,7 @@ place_exp_sett = {
u'Тип':{u'field': u'type', u'func': to_type},
u'Краткое описание':{u'field': u'main_title', u'func': unicode},
u'Страна':{u'field': u'country', u'func': to_country},
u'Город':{u'field': u'city', u'func': to_city, 'extra_values': 'country'},
u'Город':{u'field': u'city_id', u'func': to_city, 'extra_values': 'country'},
u'Описание':{u'field': u'description', u'func': unicode},
u'Адрес':{u'field': u'adress', u'func': unicode},
u'Тел.':{u'field': u'phone', u'func': to_phone},

@ -106,6 +106,7 @@ def google_address(address):
response = {'address' : results[0].get('formatted_address'),
'lat' : results[0]['geometry']['location']['lat'],
'lng' : results[0]['geometry']['location']['lng']}
#return response
return json.dumps(response)
else:
return ''
@ -113,11 +114,11 @@ def google_address(address):
from djutils.decorators import async
from djutils.queue.decorators import queue_command
# place
class ImportPlaceExpositionForm(ImportForm):
model = PlaceExposition
settings = place_exp_sett
#@async
def save_file(self):
data = self.cleaned_data
lang = data['language']
@ -125,86 +126,113 @@ class ImportPlaceExpositionForm(ImportForm):
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)]
model = self.model
labels = [label for label in row_list[0]]
errors = []
for row_number, row in enumerate(row_list):
if row_number == 0:
continue
if row[0] != '':
# in first column id
try:
obj = self.model.objects.language(lang).get(id=int(row[0]))
except ValueError:
obj = self.model()
obj.translate(lang)
except self.model.DoesNotExist:
obj = self.model(id= int(row[0]))
obj.translate(lang)
else:
# if id blank - its a new event
obj = model()
obj.translate(lang)
# ----------------
# go through all rows in file
if row_number > 0:
# first field is label
if row[0] != '':
# in first column ids
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
if setting.get('method'):
if cell != "":
methods.append({'func': setting['func'], 'value': cell, 'purpose': setting.get('purpose')})
continue
field_name = setting['field']
func = setting.get('func')
if func is None:
continue
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)
try:
object = self.model.objects.language(lang).get(id=int(row[0]))
except ValueError:
object = self.model()
object.translate(lang)
extra = getattr(obj, extra_value)
except Exception:
continue
value = func(cell, 'ru', extra)
except self.model.DoesNotExist:
object = self.model(id= int(row[0]))
object.translate(lang)
else:
# if id blank - its a new event
object = self.model()
object.translate(lang)
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)
value = func(cell)
if setting is None:
continue
try:
setattr(obj, field_name, value)
except ValueError, e:
continue
if setting.get('method'):
if cell != "":
methods.append({'func': setting['func'], 'value': cell, 'purpose': setting.get('purpose')})
if field_name !='adress':
try:
setattr(obj, field_name, value)
except ValueError:
continue
field_name = setting['field']
else:
#gaddress = google_address(value)
setattr(obj, 'address', google_address(value))
if not obj.url:
obj.url = translit_with_separator(obj.name)
try:
obj.save()
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
except IntegrityError, e:
# in function we add language(need for relation fields)
# and extra value from object (like for city need country)
value = func(cell, lang, getattr(object, extra_value))
else:
value = func(cell)
if field_name =='adress':
setattr(object, 'address', google_address(value))
setattr(object, field_name, value)
error = str(e)
if typical_errors.get(error):
error = typical_errors[error]
if error.startswith('(1062, "Duplicate entry') and error.endswith('for key \'url\'")'):
error = u'Место с таким названием или урлом уже существует'
errors.append([obj.name, error])
continue
try:
object.save()
for method in methods:
func = method['func']
if method.get('purpose'):
try:
func(obj, method['value'], method['purpose'])
except Exception, e:
continue
else:
func(obj, method['value'])
return errors
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
class ImportPlaceConferenceForm(ImportForm):
@ -217,6 +245,7 @@ typical_errors = {'(1048, "Column \'city_id\' cannot be null")':u'Неправи
'(1048, "Column \'data_end\' cannot be null")':u'НЕправильный формат или не заполнена дата окончания',
'(1048, "Column \'data_end\' cannot be null")':u'НЕправильный формат или не заполнена дата начала'}
# event
class ImportEventForm(ImportForm):
"""
extended form for importing one type of event

@ -62,12 +62,12 @@ def to_country(value):
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.id
except IndexError:
print('---------city error------------')
@ -154,14 +154,19 @@ def get_audience(value):
return ', '.join(new_list)
return ''
import types
def save_logo(obj, path):
if not path:
return None
file_name = path.split('/')[-1]
logo_path = obj.logo.field.upload_to
if isinstance(logo_path, types.FunctionType):
logo_path = logo_path(obj, obj.url)
logo_path = '/'.join(logo_path.split('/')[:-1])
full_path = settings.MEDIA_ROOT + logo_path
try:
alt_name = get_alternative_filename(full_path, file_name)
except UnicodeEncodeError:

@ -38,6 +38,7 @@ urlpatterns = patterns('',
url(r'^page/', include('core.simple_urls')),
url(r'^theme/', include('theme.urls')),
url(r'^places/', include('place_exposition.urls')),
url(r'^translators/', include('translator.urls')),
url(r'^', include('accounts.urls')),
url(r'^', include('exposition.urls')),
url(r'^', include('settings.conference_old_urls')), # conference redirects from old version

@ -13,9 +13,9 @@ urlpatterns = patterns('',
url(r'^serv-zaoch-info.php$', old_redirect, {'redirect_url': '/service/remote/'}),
url(r'^serv-visit-info.php$', old_redirect, {'redirect_url': '/service/visit/'}),
url(r'^serv-bilet-info.php$', old_redirect, {'redirect_url': '/service/tickets/'}),
url(r'^serv-translator-info.php$', old_redirect, {'redirect_url': '/service/translator/'}),
url(r'^content.php/coID/(?P<some>.*)/perevodchiki-(?P<some1>.*)/$', old_redirect, {'redirect_url': '/service/translator/'}),
url(r'^content.php/coID/(?P<some>.*)/perevodchiki-(?P<some1>.*)$', old_redirect, {'redirect_url': '/service/translator/'}),
url(r'^serv-translator-info.php$', old_redirect, {'redirect_url': '/translators/'}),
url(r'^content.php/coID/(?P<some>.*)/perevodchiki-(?P<country_or_city>.*)/$', old_redirect, {'redirect_url': '/translators/{country_or_city}/'}),
url(r'^content.php/coID/(?P<some>.*)/perevodchik-(?P<country_or_city>.*)/$', old_redirect, {'redirect_url': '/translators/{country_or_city}/'}),
url(r'^(?P<some>.*)/(?P<event>.*)/buildstand.html$', old_redirect, {'redirect_url': '{event_catalog}{event_url}/service/participation/'}),
url(r'^(?P<some>.*)/(?P<event>.*)/bilet.html$', old_redirect, {'redirect_url': '{event_catalog}{event_url}/service/tickets/'}),

@ -106,11 +106,36 @@ class News_p(object):
obj = get_object_or_404(Article, old_id=value)
return {key: obj.slug}
class Country_or_City(object):
def get_object_url(self,key, value):
try:
obj = Country.objects.get(old_url=value)
except Country.DoesNotExist:
try:
obj = Country.objects.filter(url=value)[0]
except IndexError:
obj = None
if not obj:
try:
obj = City.objects.get(old_url=value)
except City.DoesNotExist:
obj = get_object_or_404(City, url=value)
except City.MultipleObjectsReturned:
obj = City.objects.filter(old_url=value)[0]
if not obj:
raise Http404
if isinstance(obj, Country):
result = 'country/%s'%obj.url
elif isinstance(obj, City):
result = 'city/%s'%obj.url
return {key: result}
old_params = {'city': CityRedirect, 'country': CountryRedirect, 'theme': ThemeRedirect, 'tag': TagRedirect,
'event': EventRedirect, 'company': Company, 'article': ArticleRedirect, 'user': UserRedirect,
'page': PageRedirect, 'news_p': News_p}
'page': PageRedirect, 'news_p': News_p, 'country_or_city': Country_or_City}
def old_redirect(request, *args, **kwargs):

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

@ -62,6 +62,26 @@
{% endfor %}
{% endif %}
{% if import_errors %}
<div id="import_errors">
<table class="table table-hover">
<thead>
<tr>
<th>Событие</th>
<th>Ошибка</th>
</tr>
</thead>
<tbody>
{% for error in import_errors %}
<tr>
<td>{{ error.0 }}</td>
<td>{{ error.1 }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
<script>
$(document).ready(function(){
setTimeout(function(){
@ -70,4 +90,5 @@
});
</script>
{% endblock %}

@ -0,0 +1,21 @@
{% extends 'base_catalog.html' %}
{% load i18n %}
{% block bread_scrumbs %}
{% endblock %}
{% block page_title %}
<div class="page-title">
<h1>{% if meta %}{{ meta.h1 }}{% else %}{% trans 'Переводчики' %}{% endif %}</h1>
</div>
{% endblock %}
{% block content_list %}
{% include 'client/includes/accounts/translators.html' with object_list=object_list %}
{% endblock %}
{% block paginator %}
{% include 'includes/catalog_paginator.html' with page_obj=page_obj %}
{% endblock %}

@ -0,0 +1,56 @@
{% load static %}
{% load i18n %}
{% load template_filters %}
<ul class="cat-list cl-visitors">
{% for user in object_list %}
<li class="cl-item">
<div class="cl-item-wrap clearfix">
<a href="{{ user.get_permanent_url }}">
<div class="cli-pict">
{% with obj=user %}
{% include 'includes/show_logo.html' %}
{% endwith %}
</div>
</a>
<div class="cli-info">
<div class="cli-top clearfix">
<header>
<div class="cli-title">
<a href="{{ user.get_permanent_url }}">{{ user.get_full_name }}</a>
</div>
</header>
</div>
<div class="cli-bot clearfix">
<div class="cli-position">{{ user.translator.languages }}</div>
{% if user.profile.country %}
<div class="cli-place"><a href="/translators/country/{{ user.profile.country.url }}/">{{ user.profile.country }}</a>{% if user.profile.city %}, <a href="/translators/city/{{ user.profile.city.url }}/">{{ user.profile.city }}</a>{% endif %}</div>
{% endif %}
</div>
</div>
<div class="cli-buttons clearfix">
<div class="cli-m-buttons">
<a class="button icon-info" href="{{ user.get_permanent_url }}">{% trans 'информация' %}</a>
</div>
{% comment %}
<div class="cli-s-buttons">
{% if user.is_authenticated %}
<a class="button icon-msg" href="#">{% trans 'отправить сообщение' %}</a>
{% endif %}
</div>
{% endcomment %}
</div>
</div>
{% comment %}
<footer class="clearfix">
<div class="cli-tags">
</div>
</footer>
{% endcomment %}
</li>
{% endfor %}
</ul>

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1003 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
from django.conf.urls import patterns, include, url
from translator.views import TranslatorList
urlpatterns = patterns('',
url(r'^city/(?P<city>.*)/page/(?P<page>\d+)/$', TranslatorList.as_view(), {'meta_id':88}),
url(r'^city/(?P<city>.*)/$', TranslatorList.as_view(), {'meta_id':88}),
url(r'^country/(?P<country>.*)/page/(?P<page>\d+)/$', TranslatorList.as_view(), {'meta_id':87}),
url(r'^country/(?P<country>.*)/$', TranslatorList.as_view(), {'meta_id':87}),
url(r'^page/(?P<page>\d+)/$', TranslatorList.as_view() , {'meta_id':86}),
url(r'^', TranslatorList.as_view() , {'meta_id':86}),
)

@ -0,0 +1,30 @@
from django.views.generic import ListView
from django.shortcuts import get_object_or_404
from django.conf import settings
from functions.cache_mixin import JitterCacheMixin, CacheMixin
from meta.views import MetadataMixin
from accounts.models import User
from country.models import Country
from city.models import City
from translator.models import Translator
class TranslatorList(JitterCacheMixin, MetadataMixin, ListView):
model = User
template_name = 'client/accounts/translators/translators_list.html'
paginate_by = settings.CLIENT_PAGINATION
def get_queryset(self):
# all users with translator profile
qs = self.model.objects.select_related('profile', 'country', 'city').filter(translator__isnull=False)
if self.kwargs.get('city'):
city_slug = self.kwargs.get('city')
city = get_object_or_404(City, url=city_slug)
self.kwargs['city'] = city
qs = qs.filter(profile__city=city)
if self.kwargs.get('country'):
country_slug = self.kwargs.get('country')
country = get_object_or_404(Country, url=country_slug)
self.kwargs['country'] = country
qs = qs.filter(profile__country=country)
return qs
Loading…
Cancel
Save