This commit is contained in:
Dmitriy Kuzmenko 2019-12-27 17:57:16 +03:00
parent f42f571053
commit d09776c8fa
3 changed files with 38 additions and 6 deletions

View File

@ -185,6 +185,14 @@ class GuideElementExportXMLView(generics.ListAPIView):
serializer_class = serializers.GuideElementBaseSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
def get(self, request, *args, **kwargs):
"""Overridden get_queryset method."""
guide = get_object_or_404(
models.Guide.objects.all(), pk=self.kwargs.get('pk'))
tasks.export_guide(guide_id=guide.id, user_id=request.user.id, file_type='xml')
return Response({"success": _('The file will be sent to your email.')},
status=status.HTTP_200_OK)
class GuideElementExportDOCView(generics.ListAPIView):
"""Guide element export doc view."""

View File

@ -9,9 +9,9 @@ import docx
import xlsxwriter
from django.conf import settings
from django.core.mail import EmailMultiAlternatives
from docx.blkcntnr import BlockItemContainer
from timetable.models import Timetable
from docx.shared import RGBColor, Pt
import xml.etree.ElementTree as ET
from utils.methods import section_name_into_index_name
logging.basicConfig(format='[%(levelname)s] %(message)s', level=logging.INFO)
@ -232,8 +232,8 @@ class SendExportBase:
@abc.abstractmethod
def get_emails_to(self):
return [
'a.feteleu@spider.ru',
# 'kuzmenko.da@gmail.com',
# 'a.feteleu@spider.ru',
'kuzmenko.da@gmail.com',
# 'sinapsit@yandex.ru'
]
@ -432,3 +432,27 @@ class SendGuideExport(SendExportBase):
if row.pop("node_name") == "EstablishmentNode":
file_writer.writerow(row.values())
def make_xml_file(self):
# create the file structure
data = ET.Element('data')
items = ET.SubElement(data, 'items')
city = None
for row in self.get_data():
row_city = row.get('city_name')
if row_city:
city = row_city
else:
row['city_name'] = city
if row.pop("node_name") == "EstablishmentNode":
for key, value in row.items():
item1 = ET.SubElement(items, 'item')
item1.set('name', key)
item1.text = str(value)
# create a new XML file with the results
tree = ET.ElementTree(data)
with open(self.file_path, 'bw') as f:
tree.write(f)
self.success = True

View File

@ -102,8 +102,8 @@ ELASTICSEARCH_DSL = {
ELASTICSEARCH_INDEX_NAMES = {
# 'search_indexes.documents.news': 'local_news',
'search_indexes.documents.establishment': 'local_establishment',
'search_indexes.documents.product': 'local_product',
'search_indexes.documents.establishment': 'local_establishment',
'search_indexes.documents.product': 'local_product',
'search_indexes.documents.tag_category': 'local_tag_category',
}
ELASTICSEARCH_DSL_AUTOSYNC = False