diff --git a/article/forms.py b/article/forms.py index 44fcdad8..72315264 100644 --- a/article/forms.py +++ b/article/forms.py @@ -4,6 +4,7 @@ from django.conf import settings from ckeditor.widgets import CKEditorWidget from django.core.exceptions import ValidationError from django.forms.util import ErrorList +from django.utils.translation import ugettext as _ #functions from functions.translate import fill_with_signal from functions.files import check_tmp_files @@ -226,4 +227,9 @@ class BlogForm(forms.ModelForm): widget=forms.TextInput(attrs={'style':'width: 550px'})) self.fields['descriptions_%s' % code] = forms.CharField(label='Кейвордс', required=False, max_length=255, widget=forms.TextInput(attrs={'style':'width: 550px'})) -""" \ No newline at end of file +""" + +class ArticleFilterForm(forms.Form): + theme = forms.MultipleChoiceField(label=_(u'Тематика:'), required=False, + choices=[(item.id, item.name) for item in Theme.objects.language().all()]) + tag = forms.CharField(label=_(u'Теги:'), widget=forms.HiddenInput(), required=False) \ No newline at end of file diff --git a/article/management/commands/news_from_old.py b/article/management/commands/news_from_old.py index 6a975707..a1971cf8 100644 --- a/article/management/commands/news_from_old.py +++ b/article/management/commands/news_from_old.py @@ -5,7 +5,7 @@ from django.core.management.base import BaseCommand, CommandError from functions.translate import fill_with_signal from article.models import Article from accounts.models import User - +from django.db import IntegrityError class Command(BaseCommand): def handle(self, *args, **options): @@ -22,14 +22,15 @@ class Command(BaseCommand): cid as author, date_added as created - FROM `latest_news`""" + FROM `latest_news` order by created DESC""" cursor.execute(sql) result = cursor.fetchall() user = User.objects.get(id=1) - c = 0 + Article.objects.news().delete() + for a in result: if len(a['main_title'])>255 or not a['main_title']: continue @@ -49,11 +50,13 @@ class Command(BaseCommand): article.translate('ru') article.main_title = a['main_title'] article.description = a['description'] - article.save() - print(article) + try: + article.save() + print(article) + except : + print ('error. id:%d'%a['id']) - #print(a['main_title']) - + #print(a['main_title']) diff --git a/article/management/commands/news_generate_file.py b/article/management/commands/news_generate_file.py new file mode 100644 index 00000000..57af5a16 --- /dev/null +++ b/article/management/commands/news_generate_file.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +import MySQLdb +from MySQLdb.cursors import DictCursor +from django.core.management.base import BaseCommand, CommandError +from functions.translate import fill_with_signal +from article.models import Article +from accounts.models import User +from django.db import IntegrityError +import xlwt +from django.utils import translation +from django.conf import settings + +class Command(BaseCommand): + def handle(self, *args, **options): + translation.activate('en') + + workbook = xlwt.Workbook(encoding = 'utf8') + worksheet = workbook.add_sheet('My Worksheet') + + font = xlwt.Font() + font.name = 'Times New Roman' + font.bold = True + + style = xlwt.XFStyle() + # Create the Style + style.font = font + + qs = Article.objects.news() + worksheet.write(0, 0, 'id') + worksheet.write(0, 1, 'url') + worksheet.write(0, 2, 'title') + + row = 1 + for a in qs: + print a.id + url = a.slug + id = a.id + name = a.main_title + + worksheet.write(row, 0, id) + worksheet.write(row, 1, url) + worksheet.write(row, 2, name) + + row += 1 + workbook.save(settings.MEDIA_ROOT+'/import/exported_news.xls') \ No newline at end of file diff --git a/article/models.py b/article/models.py index 5f8c2eae..2ee840ca 100644 --- a/article/models.py +++ b/article/models.py @@ -8,6 +8,7 @@ from django.utils.html import strip_tags from sorl.thumbnail import ImageField from functions.url_utils import slugify, unique_slug from functions.model_utils import base_concrete_model +from functions.form_check import translit_with_separator class ArticleManager(TranslationManager): @@ -73,10 +74,10 @@ class Article(TranslatableModel): gen_description = models.BooleanField(_("Generate description"), help_text=_("If checked, the description will be automatically " "generated from content. Uncheck if you want to manually " - "set a custom description."), default=True) + "set a custom description."), default=False) # published = models. - created = models.DateTimeField(auto_now_add=True) + created = models.DateTimeField() modified = models.DateTimeField(auto_now=True) #translated fields @@ -140,7 +141,9 @@ class Article(TranslatableModel): # slug lookup. concrete_model = base_concrete_model(Article, self) slug_qs = concrete_model.objects.exclude(id=self.id) - return unique_slug(slug_qs, "slug", self.get_slug()) + slug = unique_slug(slug_qs, "slug", self.get_slug()) + slug = translit_with_separator(slug) + return slug def get_slug(self): """ diff --git a/article/views.py b/article/views.py index 3bce10e5..63ed81ca 100644 --- a/article/views.py +++ b/article/views.py @@ -1,6 +1,9 @@ from django.views.generic import DetailView, ListView from django.http import HttpResponse from models import Article +from forms import ArticleFilterForm + + class NewsList(ListView): model = Article @@ -22,6 +25,18 @@ class NewsList(ListView): else: return self.model.objects.news() + def get_context_data(self, **kwargs): + context = super(NewsList, self).get_context_data(object_list=self.object_list) + if self.request.GET: + filter_form = ArticleFilterForm(self.request.GET) + else: + filter_form = ArticleFilterForm() + + context['article_filter_form'] = filter_form + return context + + + class NewsDetail(DetailView): model = Article slug_field = 'slug' @@ -49,6 +64,16 @@ class BlogList(ListView): else: return self.model.objects.blogs() + def get_context_data(self, **kwargs): + context = super(BlogList, self).get_context_data(object_list=self.object_list) + if self.request.GET: + filter_form = ArticleFilterForm(self.request.GET) + else: + filter_form = ArticleFilterForm() + + context['article_filter_form'] = filter_form + return context + class BlogDetail(DetailView): diff --git a/city/management/commands/city_slug.py b/city/management/commands/city_slug.py new file mode 100644 index 00000000..d60006a9 --- /dev/null +++ b/city/management/commands/city_slug.py @@ -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()) \ No newline at end of file diff --git a/exposition/management/commands/expo_organiser.py b/exposition/management/commands/expo_organiser.py index 12e62f0b..c0596fe1 100644 --- a/exposition/management/commands/expo_organiser.py +++ b/exposition/management/commands/expo_organiser.py @@ -17,12 +17,13 @@ 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(GERMANY_FILE, 'r') + 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)] @@ -48,6 +49,8 @@ class Command(BaseCommand): organiser.translate('ru') organiser.name = org organiser.save() + except Organiser.MultipleObjectsReturned: + continue if not exp.organiser.filter(url=organiser.url).exists(): diff --git a/exposition/management/commands/expo_test.py b/exposition/management/commands/expo_test.py index 8f4197d0..4eb39b4e 100644 --- a/exposition/management/commands/expo_test.py +++ b/exposition/management/commands/expo_test.py @@ -37,7 +37,7 @@ class Command(BaseCommand): new = [item.strip() for item in a] st = ';'.join(new) - print st.encode('utf8') + #print st.encode('utf8') i.countries = st #i.save() elif ',' in i.countries: @@ -48,12 +48,14 @@ class Command(BaseCommand): 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 = '' @@ -61,6 +63,7 @@ class Command(BaseCommand): else: word += 1 + #print(i.countries.encode('utf8')) diff --git a/exposition/management/commands/exposition_load.py b/exposition/management/commands/exposition_load.py index 7a755020..8cef995e 100644 --- a/exposition/management/commands/exposition_load.py +++ b/exposition/management/commands/exposition_load.py @@ -4,6 +4,7 @@ from django.core.management.base import BaseCommand from django.conf import settings from exposition.models import Exposition from import_xls.excel_settings import event_sett +from django.db import IntegrityError CHINA_FILE = settings.MEDIA_ROOT+'/import/expo_china_ru.xlsx' GERMANY_FILE = settings.MEDIA_ROOT+'/import/expo_germany_ru.xlsx' @@ -15,31 +16,35 @@ 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(NA_EU_ASIA_FILE2, 'r') + 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:]): + existing = 0 + for row_number, row in enumerate(row_list[1246:]): #print(row_number) if row[0] != '': # in first column ids try: object = Exposition.objects.language('ru').get(id=int(row[0])) + existing += 1 except ValueError: object = Exposition() object.translate('ru') + except Exposition.DoesNotExist: object = Exposition(id= int(row[0])) object.translate('ru') + existing += 1 else: # if id blank - its a new place object = Exposition() @@ -78,11 +83,15 @@ class Command(BaseCommand): pass else: setattr(object, field_name, value) - - object.save() + try: + object.save() + except IntegrityError: + continue print('post save %s'% str(object)) + + for method in methods: func = method['func'] if method.get('purpose'): diff --git a/exposition/management/commands/imp_stat.py b/exposition/management/commands/imp_stat.py index c62854a3..2a97a158 100644 --- a/exposition/management/commands/imp_stat.py +++ b/exposition/management/commands/imp_stat.py @@ -19,12 +19,13 @@ 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(NA_EU_ASIA_FILE, 'r') + 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)] @@ -40,6 +41,8 @@ class Command(BaseCommand): continue year = int(row[30]) + + try: countries_number = int(exp.stat_countries) countries = '' @@ -62,4 +65,4 @@ class Command(BaseCommand): s.countries = countries s.save() - print(exp) \ No newline at end of file + print(exp) diff --git a/import_xls/utils.py b/import_xls/utils.py index b2c29481..8c010760 100644 --- a/import_xls/utils.py +++ b/import_xls/utils.py @@ -53,7 +53,7 @@ def to_city(value, lang, country): # except IndexError if no found city = City.objects.filter(translations__name=value, country=country)[0] # print(city) - return city + return city.id except IndexError: print('---------city error------------') print(value.encode('utf8')) @@ -142,16 +142,23 @@ def save_logo(obj, path): logo_path = obj.logo.field.upload_to full_path = settings.MEDIA_ROOT + logo_path - - alt_name = get_alternative_filename(full_path, file_name) + try: + alt_name = get_alternative_filename(full_path, file_name) + except UnicodeEncodeError: + return None download_to = full_path+alt_name if path.startswith('http://') or path.startswith('https://'): url = path - else: + elif path.startswith('/'): + url = 'http://expomap.ru' + path + elif path.startswith('images'): + url = 'http://expomap.ru/' + path + else: + return None try: response = urllib2.urlopen(url, timeout=15) diff --git a/templates/client/article/article.html b/templates/client/article/article.html index 534673d0..8e266887 100644 --- a/templates/client/article/article.html +++ b/templates/client/article/article.html @@ -19,7 +19,7 @@ {% include 'includes/article/article_logo.html' with obj=object %}

{{ object.main_title }}

- {{ object.created }}{{ object.author.get_full_name }} + {{ object.created|date:"d E Y" }}{{ object.author.get_full_name }} {{ object.description|safe }}
@@ -29,14 +29,17 @@ {% include 'includes/show_logo.html' with obj=object.author %}

{{ object.author.get_full_name }}

- zherdneva + {% if object.author.profile.fb %} + {{ object.author.get_full_name }} + {% endif %} + {% if object.tag.all.exists %}
- {% include 'includes/article_tags.html' with obj=object %}
+ {% endif %}
@@ -46,7 +49,7 @@
- +
{% for blog in object.similars %}
@@ -54,7 +57,7 @@ {% include 'includes/show_logo.html' with obj=blog %}

{{ blog.main_title }}

{{ blog.preview }}

- {{ blog.publish_date }}Евгения Булавина + {{ blog.created|date:"d E Y" }}Евгения Булавина
{% endfor %} diff --git a/templates/client/article/blog_list.html b/templates/client/article/blog_list.html index 892bd30e..e3a9a947 100644 --- a/templates/client/article/blog_list.html +++ b/templates/client/article/blog_list.html @@ -21,77 +21,17 @@
-
- -
-
-
-
-
-
    -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
-
-
-
- -
+ + {{ article_filter_form.theme }}
-
- -
-
-
-
-
-
    -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
-
-
-
+ + {{ article_filter_form.tag.label }} -
-
diff --git a/templates/client/article/news.html b/templates/client/article/news.html index 98d8f78d..8b8eb7c5 100644 --- a/templates/client/article/news.html +++ b/templates/client/article/news.html @@ -17,38 +17,35 @@
- {% include 'includes/show_logo.html' with obj=object %} + + {% include 'includes/article/article_logo.html' with obj=object %}

{{ object.main_title }}

- {{ object.publish_date }}{{ object.get_event.name }} -

Смартфоны, планшеты, программные решения и аксессуары заполнили каждый свободный метр экспоцентра Барселоны в надежде стать лидером продаж в своем сегменте. За день до официального старта восьмой выставки-конгресса Mobile World Congress глава GSMA Джон Хоффман торжественно отметил новую точку отсчета в богатой истории мероприятия: два монумента, которые появились у входа в экспоцентр, кажется, навсегда закрепили за Барселоной статус столицы мобильной индустрии.

+ {{ object.created|date:"d E Y" }}{% if object.get_event %}{{ object.get_event.name }}{% endif %}
- {{ object.description }} + {{ object.description|safe }}
- Источник: {{ object.author }} - {% include 'includes/article_tags.html' with obj=object %} + {% trans 'Источник' %}: {{ object.author }} + {% if object.tag.all.exists %} + {% include 'includes/article_tags.html' with obj=object %} + {% endif %}
-
- -
-
- +
{% for news in object.similar %}
- -

Самое интересное на Baby Active' 2014

-

С 16 по 18 мая в Выставочном центре «АККО Интернешнл», на территории парка им. А.С. Пушкина, состоится Выставка- -фестиваль семейного досуга Baby Active' 2014 («Активный ребенок»).

- 28 апреля 2014РИФ-2014 + {% include 'includes/show_logo.html' with obj=news %} +

{{ news.main_title }}

+

{{ news.preview }}

+ {{ news.created|date:"d E Y" }}{% if news.get_event %}{{ news.get_event.name }}<{% endif %}/strong>
{% endfor %} diff --git a/templates/client/article/news_list.html b/templates/client/article/news_list.html index 9c3a577d..6d982fc9 100644 --- a/templates/client/article/news_list.html +++ b/templates/client/article/news_list.html @@ -23,71 +23,14 @@
- -
-
-
-
-
-
    -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
-
-
-
- -
+ + {{ article_filter_form.theme }}
- -
-
-
-
-
-
    -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
-
-
-
+ + {{ article_filter_form.tag.label }} -
diff --git a/templates/client/includes/place/place_object.html b/templates/client/includes/place/place_object.html index 46497fc1..b26b471b 100644 --- a/templates/client/includes/place/place_object.html +++ b/templates/client/includes/place/place_object.html @@ -68,7 +68,7 @@
  • {% trans 'Конгресс-центр' %}
  • {% endif %} {% if place.business_centre %} -
  • {% trans 'Бизнес центр' %}
  • +
  • {% trans 'Бизнес-центр' %}
  • {% endif %} {% if place.online_registration %}
  • {% trans 'Онлайн-регистрация' %}
  • diff --git a/theme/forms.py b/theme/forms.py index 8805193d..54632b75 100644 --- a/theme/forms.py +++ b/theme/forms.py @@ -53,7 +53,7 @@ class ThemeForm(forms.Form): #generates bitfield flag = reduce(lambda x,y: x|y, (getattr(Theme.types, item) for item in data['types'])) theme.types = flag - theme.save() + #theme.save() fill_with_signal(Theme, theme, data) diff --git a/translator/management/__init__.py b/translator/management/__init__.py new file mode 100644 index 00000000..3ed9fd0f --- /dev/null +++ b/translator/management/__init__.py @@ -0,0 +1 @@ +__author__ = 'root' diff --git a/translator/management/commands/__init__.py b/translator/management/commands/__init__.py new file mode 100644 index 00000000..3ed9fd0f --- /dev/null +++ b/translator/management/commands/__init__.py @@ -0,0 +1 @@ +__author__ = 'root' diff --git a/translator/management/commands/translator_from_crm.py b/translator/management/commands/translator_from_crm.py new file mode 100644 index 00000000..9ad4259f --- /dev/null +++ b/translator/management/commands/translator_from_crm.py @@ -0,0 +1,186 @@ +# -*- coding: utf-8 -*- +import MySQLdb +import datetime +from MySQLdb.cursors import DictCursor +from django.core.management.base import BaseCommand, CommandError +from functions.translate import fill_with_signal +from translator.models import Translator +from accounts.models import User, Profile +from country.models import Country +from city.models import City +from functions.form_check import is_positive_integer + + + +def to_phone(phone): + + if not phone: + return None + + deduct = ('-','(',')','.',' ', '+') + for elem in deduct: + phone = phone.replace(elem, '') + if phone.isdigit(): + return int(phone) + else: + return None + + +def get_country_name(id): + db = MySQLdb.connect(host="localhost", + user="kotzilla", + passwd="qazedc", + db="crm", + charset='utf8', + cursorclass=DictCursor) + sql =""" + SELECT country_name as name + FROM `country` + WHERE `country_id` =%d"""%id + + cursor = db.cursor() + cursor.execute(sql) + result = cursor.fetchone() + return result['name'] + + +def get_city_name(id): + db = MySQLdb.connect(host="localhost", + user="kotzilla", + passwd="qazedc", + db="crm", + charset='utf8', + cursorclass=DictCursor) + sql =""" + SELECT city_name as name + FROM `city` + WHERE `city_id` =%d"""%id + cursor = db.cursor() + cursor.execute(sql) + result = cursor.fetchone() + return result['name'] + +class Command(BaseCommand): + def handle(self, *args, **options): + db = MySQLdb.connect(host="localhost", + user="kotzilla", + passwd="qazedc", + db="crm", + charset='utf8', + cursorclass=DictCursor) + cursor = db.cursor() + sql = """SELECT * + FROM `interpreter_table` """ + + cursor.execute(sql) + result = cursor.fetchall() + + + + for data in result: + email = data['email'] + print(email.encode('utf8')) + + if email: + try: + user = User.objects.select_related('translator').get(username=email) + + except User.DoesNotExist: + user = None + if user: + # add information to user + profile = user.profile + if data['phone1']: + phone = to_phone(data['phone1']) + if len(str(phone))<15: + profile.phone = phone + if data['skype']: + + profile.skype = data['skype'] + if data['country_id']: + name = get_country_name(data['country_id']) + country_qs = Country.objects.filter(translations__name=name) + if country_qs.exists(): + country = country_qs[0] + else: + country = None + profile.country = country + + if profile.country and data['city_id']: + name = get_city_name(data['city_id']) + city_qs = City.objects.filter(translations__name=name, country=profile.country) + if city_qs.exists(): + city = city_qs[0] + else: + city = None + profile.city = city + + profile.save() + + + else: + # create new user + user = User.objects.create_user(email, data['fam'], data['name'], data['pass']) + user.is_active = True + user.save() + profile = user.profile + #user.url = 'id%s'%str(self.id) + if data['phone1']: + phone = to_phone(data['phone1']) + if len(str(phone))<15: + profile.phone = phone + if data['skype']: + profile.skype = data['skype'] + if data['country_id']: + name = get_country_name(data['country_id']) + country_qs = Country.objects.filter(translations__name=name) + if country_qs.exists(): + country = country_qs[0] + else: + country = None + profile.country = country + + if profile.country and data['city_id']: + name = get_city_name(data['city_id']) + city_qs = City.objects.filter(translations__name=name, country=profile.country) + if city_qs.exists(): + city = city_qs[0] + else: + city = None + profile.city = city + + profile.save() + + user.save() + + # fill translator + if user.translator: + translator_id = user.translator_id + translator = Translator.objects.language('ru').get(id=translator_id) + new = 0 + else: + translator = Translator() + new = 1 + + gender = data['gender'] + if gender == u'мужской': + gender = 'male' + elif gender == u'женский': + gender = 'female' + else: + gender = 'male' + translator.gender = gender + + translator.birth = data['born'] + if data['automobile'] == u'да': + translator.car = 1 + if new: + translator.translate('ru') + + translator.education = data['education'] + translator.specialization = data['spec'] + translator.languages = ', '.join([data['selfLang'], data['selfLang2']]) + translator.save() + user.translator = translator + + user.save() \ No newline at end of file