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 %}
{% include 'includes/article_tags.html' with obj=object %}
Смартфоны, планшеты, программные решения и аксессуары заполнили каждый свободный метр экспоцентра Барселоны в надежде стать лидером продаж в своем сегменте. За день до официального старта восьмой выставки-конгресса Mobile World Congress глава GSMA Джон Хоффман торжественно отметил новую точку отсчета в богатой истории мероприятия: два монумента, которые появились у входа в экспоцентр, кажется, навсегда закрепили за Барселоной статус столицы мобильной индустрии.
+ {{ object.created|date:"d E Y" }}{% if object.get_event %}{{ object.get_event.name }}{% endif %}
-
- С 16 по 18 мая в Выставочном центре «АККО Интернешнл», на территории парка им. А.С. Пушкина, состоится Выставка- -фестиваль семейного досуга Baby Active' 2014 («Активный ребенок»).
- 28 апреля 2014РИФ-2014 + {% include 'includes/show_logo.html' with obj=news %} +{{ news.preview }}
+ {{ news.created|date:"d E Y" }}{% if news.get_event %}{{ news.get_event.name }}<{% endif %}/strong>
{{ blog.main_title }}
{{ blog.preview }}
- {{ blog.publish_date }}Евгения Булавина + {{ blog.created|date:"d E Y" }}Евгения Булавина