parent
3a23d56b40
commit
30abcf8da6
15 changed files with 286 additions and 90 deletions
@ -0,0 +1,57 @@ |
|||||||
|
# -*- 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' |
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand): |
||||||
|
def handle(self, *args, **options): |
||||||
|
|
||||||
|
f = open(GERMANY_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() |
||||||
|
|
||||||
|
|
||||||
|
if not exp.organiser.filter(url=organiser.url).exists(): |
||||||
|
exp.organiser.add(organiser) |
||||||
|
|
||||||
|
print(exp) |
||||||
|
|
||||||
@ -0,0 +1,74 @@ |
|||||||
|
# -*- 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(NA_EU_ASIA_FILE2, '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 row[16] =='' or row[16].startswith('http') or row[16].startswith('https') or row[16].startswith('/') or row[16].startswith('../'): |
||||||
|
continue |
||||||
|
|
||||||
|
path = row[16] |
||||||
|
|
||||||
|
|
||||||
|
file_name = path.split('/')[-1] |
||||||
|
logo_path = exp.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 |
||||||
|
url = 'http://expomap.ru/' + path |
||||||
|
try: |
||||||
|
response = urllib2.urlopen(url, timeout=15) |
||||||
|
except: |
||||||
|
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,38 @@ |
|||||||
|
{% load i18n %} |
||||||
|
{% load template_filters %} |
||||||
|
{% get_current_language as LANGUAGE_CODE %} |
||||||
|
{% load pytils_dt %} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{% if obj.data_begin|timesince_exp:obj.data_end %} |
||||||
|
|
||||||
|
{{ obj.data_begin|date:"F" }} |
||||||
|
|
||||||
|
{% else %} |
||||||
|
{% if obj.data_begin|timesince:obj.data_end < "1 day" %} |
||||||
|
{% ifequal LANGUAGE_CODE 'ru' %} |
||||||
|
{{ obj.data_begin|ru_strftime:"%d %B %Y" }} |
||||||
|
{% else %} |
||||||
|
{{ obj.data_begin }} |
||||||
|
{% endifequal %} |
||||||
|
|
||||||
|
{% else %} |
||||||
|
|
||||||
|
{% if obj.data_end %} |
||||||
|
{% trans 'с' %} |
||||||
|
{% ifnotequal obj.data_begin|date:"F" obj.data_end|date:"F" %} |
||||||
|
{% ifequal LANGUAGE_CODE 'ru' %} |
||||||
|
{{ obj.data_begin|ru_strftime:"%d %B" }} |
||||||
|
{% else %} |
||||||
|
{{ obj.data_begin|date:"F j" }} |
||||||
|
{% endifequal %} |
||||||
|
{% else %} |
||||||
|
{{ obj.data_begin|date:"j" }}{% endifnotequal %} {% trans 'по' %} {{ obj.data_end|date:"j E Y" }} {% trans 'года' %} |
||||||
|
{% else %} |
||||||
|
{{ obj.data_begin }} |
||||||
|
{% endif %} |
||||||
|
|
||||||
|
{% endif %} |
||||||
|
{% endif %} |
||||||
|
|
||||||
@ -0,0 +1,64 @@ |
|||||||
|
{% load thumbnail %} |
||||||
|
{% load i18n %} |
||||||
|
{% load template_filters %} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="mcl"> |
||||||
|
|
||||||
|
<div id="mp-recent-expo" class="recent-expo swiper-container"> |
||||||
|
<ul class="swiper-wrapper"> |
||||||
|
{% for event in events %} |
||||||
|
<li class="swiper-slide"> |
||||||
|
<div class="re-pict pict-over" > |
||||||
|
{% if event.logo %} |
||||||
|
<a href="{{ event.get_permanent_url }}"> |
||||||
|
<!--<img src="{{ event.logo.url }}">--> |
||||||
|
|
||||||
|
{% thumbnail event.get_preview "220x220" as im %} |
||||||
|
<img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}"> |
||||||
|
{% endthumbnail %} |
||||||
|
|
||||||
|
</a> |
||||||
|
{% endif %} |
||||||
|
</div> |
||||||
|
<div class="re-body"> |
||||||
|
<div class="re-info"> |
||||||
|
<a href="{{ event.get_permanent_url }}"> |
||||||
|
<div class="re-title">{{ event.name|safe }}</div> |
||||||
|
<div class="re-date"> |
||||||
|
{% include 'client/includes/index/main_date_block.html' with obj=event %} |
||||||
|
</div> |
||||||
|
<div class="re-descr" title="{{ event.main_title|safe }}">{{ event.main_title|safe }}</div> |
||||||
|
</a> |
||||||
|
</div> |
||||||
|
<footer> |
||||||
|
<div class="re-buttons"> |
||||||
|
<a class="button blue icon-calendar {% if event|in_calendar:request.user %}removecalendar {% else %}addcalendar {% endif %}" href="{{ event.get_calendar_url }}">{% if event|in_calendar:request.user %}{% trans 'Убрать из календаря' %}{% else %}{% trans 'добавить в календарь' %}{% endif %}</a> |
||||||
|
<div class="main-page {% if request.user.is_authenticated%}note-wrap{% else %}note-wrap-disabled{% endif %}"> |
||||||
|
<a class="button green icon-note {% if note %}active{% endif %} note-button" href="/expo/add-note/{{ event.url }}/">{% trans 'заметка' %}</a> |
||||||
|
<div class="note-overlay"> |
||||||
|
<form action=""> |
||||||
|
<textarea name="note_text" class="note-text"> {{ note }}</textarea> |
||||||
|
</form> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<div class="re-tags"> |
||||||
|
{% with tags=event.tag.all %} |
||||||
|
{% for tag in tags %} |
||||||
|
<a href="{{ event.get_catalog_url }}tag/{{ tag.url }}">{{ tag }}</a>{% if forloop.counter < tags|length %},{% endif %} |
||||||
|
{% endfor %} |
||||||
|
{% endwith %} |
||||||
|
</div> |
||||||
|
</footer> |
||||||
|
</div> |
||||||
|
</li> |
||||||
|
{% endfor %} |
||||||
|
</ul> |
||||||
|
<div class="re-controls"> |
||||||
|
<a class="prev" href="#"><</a> |
||||||
|
<a class="next" href="#">></a> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</div> |
||||||
Loading…
Reference in new issue