@ -1,18 +1,36 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from django.utils import translation |
||||||
from haystack import indexes |
from haystack import indexes |
||||||
from models import City |
from models import City |
||||||
|
from functions.search_mixin import ExpoSearchMixin |
||||||
|
|
||||||
""" |
|
||||||
class CityIndex(indexes.SearchIndex, indexes.Indexable): |
class CountryIndex(indexes.SearchIndex, indexes.Indexable, ExpoSearchMixin): |
||||||
text = indexes.CharField(document=True, use_template=True) |
text = indexes.CharField(document=True, use_template=True) |
||||||
translations = indexes.MultiValueField() |
url = indexes.CharField() |
||||||
#name = indexes.CharField(model_attr='translations__name') |
content_auto = indexes.EdgeNgramField() |
||||||
|
form_name = indexes.CharField() |
||||||
|
# translated fields |
||||||
|
name_en = indexes.CharField() |
||||||
|
name_ru = indexes.CharField() |
||||||
|
catalog_name_en = indexes.CharField() |
||||||
|
catalog_name_ru = indexes.CharField() |
||||||
|
|
||||||
|
def prepare_form_name(self, obj): |
||||||
|
return 'ci' |
||||||
|
|
||||||
|
def prepare_catalog_name_en(self, obj): |
||||||
|
return u'Cities' |
||||||
|
|
||||||
def prepare_translations(self, obj): |
def prepare_catalog_name_ru(self, obj): |
||||||
return [tr.name for tr in obj.translations.all()] |
return u'Города' |
||||||
|
|
||||||
def get_model(self): |
def get_model(self): |
||||||
return City |
return City |
||||||
|
|
||||||
def index_queryset(self, using=None): |
def index_queryset(self, using=None): |
||||||
return self.get_model().objects.filter() |
|
||||||
""" |
return self.get_model().used.all() |
||||||
|
|
||||||
|
def get_updated_field(self): |
||||||
|
return 'modified' |
||||||
@ -0,0 +1,62 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from django.utils import translation |
||||||
|
from haystack import indexes |
||||||
|
from models import Country, Area |
||||||
|
from functions.search_mixin import ExpoSearchMixin |
||||||
|
|
||||||
|
|
||||||
|
class CountryIndex(indexes.SearchIndex, indexes.Indexable, ExpoSearchMixin): |
||||||
|
text = indexes.CharField(document=True, use_template=True) |
||||||
|
url = indexes.CharField() |
||||||
|
content_auto = indexes.EdgeNgramField() |
||||||
|
form_name = indexes.CharField() |
||||||
|
# translated fields |
||||||
|
name_en = indexes.CharField() |
||||||
|
name_ru = indexes.CharField() |
||||||
|
catalog_name_en = indexes.CharField() |
||||||
|
catalog_name_ru = indexes.CharField() |
||||||
|
|
||||||
|
def prepare_form_name(self, obj): |
||||||
|
return 'co' |
||||||
|
|
||||||
|
def prepare_catalog_name_en(self, obj): |
||||||
|
return u'Countries' |
||||||
|
|
||||||
|
def prepare_catalog_name_ru(self, obj): |
||||||
|
return u'Страны' |
||||||
|
|
||||||
|
def get_model(self): |
||||||
|
return Country |
||||||
|
|
||||||
|
def index_queryset(self, using=None): |
||||||
|
|
||||||
|
return self.get_model().objects.countries_for_search() |
||||||
|
|
||||||
|
def get_updated_field(self): |
||||||
|
return 'modified' |
||||||
|
|
||||||
|
class AreaIndex(indexes.SearchIndex, indexes.Indexable, ExpoSearchMixin): |
||||||
|
text = indexes.CharField(document=True, use_template=True) |
||||||
|
content_auto = indexes.EdgeNgramField() |
||||||
|
form_name = indexes.CharField() |
||||||
|
# translated fields |
||||||
|
name_en = indexes.CharField() |
||||||
|
name_ru = indexes.CharField() |
||||||
|
catalog_name_en = indexes.CharField() |
||||||
|
catalog_name_ru = indexes.CharField() |
||||||
|
|
||||||
|
def prepare_form_name(self, obj): |
||||||
|
return 'area' |
||||||
|
|
||||||
|
def prepare_catalog_name_en(self, obj): |
||||||
|
return u'Areas' |
||||||
|
|
||||||
|
def prepare_catalog_name_ru(self, obj): |
||||||
|
return u'Регионы' |
||||||
|
|
||||||
|
def get_model(self): |
||||||
|
return Area |
||||||
|
|
||||||
|
def index_queryset(self, using=None): |
||||||
|
|
||||||
|
return self.get_model().objects.filter() |
||||||
@ -0,0 +1,77 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from django.db import models |
||||||
|
from django.conf import settings |
||||||
|
from django.db.models.fields.files import FieldFile |
||||||
|
from django.db.models.signals import pre_delete |
||||||
|
|
||||||
|
def get_doc_dir(instance, filename): |
||||||
|
from pytils import translit |
||||||
|
return u'import_xls/import/%s' %translit.translify(filename) |
||||||
|
|
||||||
|
|
||||||
|
def file_cleanup(sender, instance, *args, **kwargs): |
||||||
|
''' |
||||||
|
Deletes the file(s) associated with a model instance. The model |
||||||
|
is not saved after deletion of the file(s) since this is meant |
||||||
|
to be used with the pre_delete signal. |
||||||
|
''' |
||||||
|
for field_name, _ in instance.__dict__.iteritems(): |
||||||
|
field = getattr(instance, field_name) |
||||||
|
if issubclass(field.__class__, FieldFile) and field.name: |
||||||
|
field.delete(save=False) |
||||||
|
|
||||||
|
class LogManager(models.Manager): |
||||||
|
def create_log(self, work_file, errors): |
||||||
|
""" |
||||||
|
|
||||||
|
:param work_file: executing file |
||||||
|
:param errors: list of errors ([{'event name':['err1', 'err2']}]) |
||||||
|
:return: object log |
||||||
|
""" |
||||||
|
LOG_DIRECTORY = settings.MEDIA_ROOT+'import_xls/logs/' |
||||||
|
name= '111.txt' |
||||||
|
filename = LOG_DIRECTORY + name |
||||||
|
|
||||||
|
log_file = open(filename, "w") |
||||||
|
for error in errors: |
||||||
|
event_name = ';'.join(error.keys()) |
||||||
|
errs = '' |
||||||
|
for err in error.values(): |
||||||
|
errs += '; '.join(err) |
||||||
|
errs += ';' |
||||||
|
|
||||||
|
log_file.write('%s: %s\n'%(event_name, errs)) |
||||||
|
|
||||||
|
log_file.close() |
||||||
|
#update.log_file.name = 'updates/'+name |
||||||
|
log = Log(work_file=work_file) |
||||||
|
log.log.name = 'import_xls/logs/' + name |
||||||
|
#log = Log.objects.create(work_file=work_file, log=log_file) |
||||||
|
log.save() |
||||||
|
return log |
||||||
|
|
||||||
|
def create_log_name(self, work_file): |
||||||
|
log = Log.objects.create(work_file=work_file) |
||||||
|
LOG_DIRECTORY = settings.MEDIA_ROOT+'import_xls/logs/' |
||||||
|
name= 'log_%d.log'%log.id |
||||||
|
filename = LOG_DIRECTORY + name |
||||||
|
log_file = open(filename, "w").close() |
||||||
|
log.log.name = 'import_xls/logs/' + name |
||||||
|
log.save() |
||||||
|
return log |
||||||
|
|
||||||
|
|
||||||
|
class Log(models.Model): |
||||||
|
work_file = models.FileField(upload_to=get_doc_dir) |
||||||
|
log = models.FileField(upload_to='import_xls/logs/', blank=True) |
||||||
|
type = models.CharField(max_length=10, default='IMPORT') |
||||||
|
created = models.DateTimeField(auto_now_add=True) |
||||||
|
|
||||||
|
objects = models.Manager() |
||||||
|
custom = LogManager() |
||||||
|
|
||||||
|
class Meta: |
||||||
|
ordering = ['-created'] |
||||||
|
|
||||||
|
pre_delete.connect(file_cleanup, sender=Log) |
||||||
|
|
||||||
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 65 KiB |
|
After Width: | Height: | Size: 47 KiB |
@ -0,0 +1,46 @@ |
|||||||
|
{% extends 'base.html' %} |
||||||
|
{% load static %} |
||||||
|
|
||||||
|
|
||||||
|
{% block body %} |
||||||
|
{% comment %} |
||||||
|
Displays lists of all cities in the table |
||||||
|
and creating buttons which can change each city |
||||||
|
{% endcomment %} |
||||||
|
|
||||||
|
<div class="box span8"> |
||||||
|
<div class="box-header well"> |
||||||
|
<h2><i class="icon-arrow-down"></i>Логи импорта</h2> |
||||||
|
</div> |
||||||
|
<div class="box-content"> |
||||||
|
|
||||||
|
<table class="table table-hover"> |
||||||
|
<thead> |
||||||
|
<tr> |
||||||
|
<th>Время импорта</th> |
||||||
|
<th>Робочий файл</th> |
||||||
|
<th>Лог</th> |
||||||
|
<th> </th> |
||||||
|
</tr> |
||||||
|
</thead> |
||||||
|
<tbody> |
||||||
|
{% for item in object_list %} |
||||||
|
<tr> |
||||||
|
<td>{{ item.created|date:"Y-m-d H:m:s" }}</td> |
||||||
|
<td><a href="/admin/log/work_file/{{ item.id }}/">скачать</a></td> |
||||||
|
<td><a href="/admin/log/log/{{ item.id }}/">скачать</a></td> |
||||||
|
<td class="center sorting_1"> |
||||||
|
<a class="btn btn-danger delete" href="/admin/import/log/delete/{{ item.id }}/"> |
||||||
|
<i class="icon-trash icon-white"></i> Удалить |
||||||
|
</a> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
{% endfor %} |
||||||
|
</tbody> |
||||||
|
</table> |
||||||
|
</div> |
||||||
|
|
||||||
|
{% include 'admin/includes/admin_pagination.html' with page_obj=objects %} |
||||||
|
|
||||||
|
</div> |
||||||
|
{% endblock %} |
||||||
@ -0,0 +1,15 @@ |
|||||||
|
{% extends 'base.html' %} |
||||||
|
|
||||||
|
{% block body %} |
||||||
|
|
||||||
|
<form action="" method="post"> {% csrf_token %} |
||||||
|
|
||||||
|
<div class="alert alert-danger"> |
||||||
|
<p>Вы действительно хотите удалить <b>{{ object }}</b>?</p> |
||||||
|
</div> |
||||||
|
<input type="submit" class="btn-primary" value="Да"> |
||||||
|
<a class="btn" href="/admin/import/log/">Нет</a> |
||||||
|
</form> |
||||||
|
|
||||||
|
|
||||||
|
{% endblock %} |
||||||
@ -0,0 +1,8 @@ |
|||||||
|
<div id="expo-ad-popup" data-rdr="51" class="popup-window" style="width:800px;"> |
||||||
|
<header class="clearfix"> |
||||||
|
<div class="pw-title"></div> |
||||||
|
</header> |
||||||
|
<div class="pw-body clearfix"> |
||||||
|
<a href="/redirect/redirect/51/"><img src="/static/client/img/expo_b/mims15.gif"/></a> |
||||||
|
</div> |
||||||
|
</div> |
||||||
@ -0,0 +1,23 @@ |
|||||||
|
<div id="expo-ad-popup" data-rdr="52" class="popup-window" style="width:500px;"> |
||||||
|
<header class="clearfix"> |
||||||
|
<div class="pw-title">Вы планируете посещение MIMS Automechanika Moscow в Экспоцентре?</div> |
||||||
|
</header> |
||||||
|
<div class="pw-body clearfix"> |
||||||
|
<form id="expo-form-popup" class="pw-form simple-validate" action="/redirect/redirect/52/"> |
||||||
|
<div class="pwf-line"> |
||||||
|
С 24 по 27 августа 2015 г. в Экспоцентре будут представлены лучшие предложения производителей и поставщиков автозапчастей, оборудования и товаров для технического обслуживания автомобилей. |
||||||
|
</div> |
||||||
|
<div class="pwf-line"> |
||||||
|
<a href="/redirect/redirect/52/"> |
||||||
|
<img src="/static/client/img/expo_b/mims.png"> |
||||||
|
</a> |
||||||
|
</div> |
||||||
|
<button>Узнать подробнее</button> |
||||||
|
</form> |
||||||
|
|
||||||
|
|
||||||
|
</div> |
||||||
|
|
||||||
|
</div> |
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,8 @@ |
|||||||
|
<div id="expo-ad-popup" data-rdr="49" class="popup-window" style="width:800px;"> |
||||||
|
<header class="clearfix"> |
||||||
|
<div class="pw-title"></div> |
||||||
|
</header> |
||||||
|
<div class="pw-body clearfix"> |
||||||
|
<a href="/redirect/redirect/49/"><img src="/static/client/img/expo_b/cemat15.gif"/></a> |
||||||
|
</div> |
||||||
|
</div> |
||||||
@ -0,0 +1,8 @@ |
|||||||
|
<div id="expo-ad-popup" data-rdr="50" class="popup-window" style="width:800px;"> |
||||||
|
<header class="clearfix"> |
||||||
|
<div class="pw-title"></div> |
||||||
|
</header> |
||||||
|
<div class="pw-body clearfix"> |
||||||
|
<a href="/redirect/redirect/50/"><img src="/static/client/img/expo_b/cemat15_v2.gif"/></a> |
||||||
|
</div> |
||||||
|
</div> |
||||||
@ -0,0 +1,24 @@ |
|||||||
|
|
||||||
|
<div id="expo-ad-popup" data-rdr="53" class="popup-window"> |
||||||
|
<header class="clearfix"> |
||||||
|
<div class="pw-title">Ваш логист пойдет на выставку CEMAT?</div> |
||||||
|
</header> |
||||||
|
<div class="pw-body clearfix"> |
||||||
|
<form id="expo-form-popup" class="pw-form simple-validate" action="/redirect/redirect/53/"> |
||||||
|
<div class="pwf-line"> |
||||||
|
С 22 по 25 сентября 2015 г. в Крокус Экспо производители складского оборудования и техники представят свои выгодные предложения. |
||||||
|
</div> |
||||||
|
<div class="pwf-line"> |
||||||
|
<a href="/redirect/redirect/53/"> |
||||||
|
<img src="/static/client/img/expo_b/cemat_modal1.png"> |
||||||
|
</a> |
||||||
|
<a href="/redirect/redirect/53. /" style="margin-left: 10px;"> |
||||||
|
<img src="/static/client/img/expo_b/cemat_modal2.png"> |
||||||
|
</a> |
||||||
|
</div> |
||||||
|
<button >Узнать подробнее</button> |
||||||
|
</form> |
||||||
|
|
||||||
|
</div> |
||||||
|
|
||||||
|
</div> |
||||||
@ -1 +1 @@ |
|||||||
{{ object.name }} |
{{ object.get_index_text }} |
||||||
@ -0,0 +1 @@ |
|||||||
|
{{ object.get_index_text }} |
||||||
@ -0,0 +1 @@ |
|||||||
|
{{ object.get_index_text }} |
||||||
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 65 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 8.3 KiB |
|
After Width: | Height: | Size: 8.4 KiB |
|
After Width: | Height: | Size: 47 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 65 KiB |
|
After Width: | Height: | Size: 47 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 125 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 4.8 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 2.4 KiB |