refactored structure of XML-document
This commit is contained in:
parent
963e0597dc
commit
75e4077917
|
|
@ -242,7 +242,7 @@ class SendExportBase:
|
|||
def get_emails_to(self):
|
||||
return [
|
||||
# 'a.feteleu@spider.ru',
|
||||
'kuzmenko.da@gmail.com',
|
||||
# 'kuzmenko.da@gmail.com',
|
||||
# 'sinapsit@yandex.ru'
|
||||
]
|
||||
|
||||
|
|
@ -550,9 +550,7 @@ class SendGuideExport(SendExportBase):
|
|||
if row.pop("node_name") == "WineNode":
|
||||
product = ET.SubElement(products, 'product')
|
||||
for key, value in row.items():
|
||||
prop = ET.SubElement(product, 'prop')
|
||||
prop.set('name', key)
|
||||
prop.text = str(value)
|
||||
product.set(key, str(value)) if value else None
|
||||
|
||||
# create a new XML file with the results
|
||||
tree = ET.ElementTree(data)
|
||||
|
|
@ -562,9 +560,7 @@ class SendGuideExport(SendExportBase):
|
|||
|
||||
elif self.guide.guide_type in [self.guide.ARTISAN, self.guide.RESTAURANT]:
|
||||
# establishment
|
||||
# create the file structure
|
||||
data = ET.Element('data')
|
||||
items = ET.SubElement(data, 'cities')
|
||||
objects = []
|
||||
city = None
|
||||
ad_number_of_pages = None
|
||||
ad_right_pages = None
|
||||
|
|
@ -578,18 +574,29 @@ class SendGuideExport(SendExportBase):
|
|||
row['ad_number_of_pages'] = ad_number_of_pages
|
||||
row['ad_right_pages'] = ad_right_pages
|
||||
|
||||
row_city = row.get('city_name')
|
||||
row_city = row.pop('city_name')
|
||||
if row_city:
|
||||
city = row_city
|
||||
else:
|
||||
row['city_name'] = city
|
||||
objects.append({'city': city, 'establishments': []})
|
||||
|
||||
if row.pop("node_name") == "EstablishmentNode":
|
||||
item = ET.SubElement(items, 'city')
|
||||
for key, value in row.items():
|
||||
prop = ET.SubElement(item, 'prop')
|
||||
prop.set('name', key)
|
||||
prop.text = str(value)
|
||||
city_index = [i for i, obj in enumerate(objects)
|
||||
if obj['city'] == city][0]
|
||||
establishments = objects[city_index].get('establishments')
|
||||
establishments.append(row)
|
||||
|
||||
# create xml-structure
|
||||
data = ET.Element('data')
|
||||
cities_element = ET.SubElement(data, 'cities')
|
||||
|
||||
for city in objects:
|
||||
city_element = ET.SubElement(cities_element, 'city', attrib={'name': city.get('city')})
|
||||
|
||||
establishments_element = ET.SubElement(city_element, 'establishments')
|
||||
for establishment in city.get('establishments'):
|
||||
establishment_element = ET.SubElement(establishments_element, 'establishment')
|
||||
for key, value in establishment.items():
|
||||
establishment_element.set(key, str(value)) if value else None
|
||||
|
||||
# create a new XML file with the results
|
||||
tree = ET.ElementTree(data)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user