|
|
|
|
@ -2,10 +2,6 @@ |
|
|
|
|
|
|
|
|
|
import xlwt |
|
|
|
|
import datetime |
|
|
|
|
|
|
|
|
|
from exposition.models import Exposition |
|
|
|
|
from conference.models import Conference |
|
|
|
|
|
|
|
|
|
from django.core.exceptions import ObjectDoesNotExist |
|
|
|
|
|
|
|
|
|
HEADER_STYLE = xlwt.easyxf('font: bold on') |
|
|
|
|
@ -42,11 +38,13 @@ def get_column_cell(obj, name): |
|
|
|
|
return ', '.join(unicode(x).strip() for x in attr.all()) |
|
|
|
|
return attr |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def queryset_to_workbook(queryset, columns, header_style=None, default_style=None, cell_style_map=None): |
|
|
|
|
workbook = xlwt.Workbook() |
|
|
|
|
report_date = datetime.date.today() |
|
|
|
|
sheet_name = 'Export {0}'.format(report_date.strftime('%Y-%m-%d')) |
|
|
|
|
sheet_name = u'My calendar {0}'.format(report_date.strftime('%Y-%m-%d')) |
|
|
|
|
sheet = workbook.add_sheet(sheet_name) |
|
|
|
|
sheet.insert_bitmap('') |
|
|
|
|
|
|
|
|
|
if not header_style: |
|
|
|
|
header_style = HEADER_STYLE |
|
|
|
|
@ -57,14 +55,13 @@ def queryset_to_workbook(queryset, columns, header_style=None, default_style=Non |
|
|
|
|
|
|
|
|
|
obj = queryset[0] |
|
|
|
|
|
|
|
|
|
for y, column in enumerate(columns): |
|
|
|
|
header_list=[u'Название события',u'Страна',u'Город',u'Место проведения', u'Дата начала', u'Дата окончания'] |
|
|
|
|
|
|
|
|
|
sheet.write(0, y, header_list[y], header_style) |
|
|
|
|
for i, column in enumerate(columns): |
|
|
|
|
header_list=[u'#', u'Название события',u'Даты',u'Краткое описание',u'Место проведения', u'Заметка', u'Ссылка на событие'] |
|
|
|
|
sheet.write(0, i, header_list[i], header_style) |
|
|
|
|
|
|
|
|
|
for x, obj in enumerate(queryset, start=1): |
|
|
|
|
for y, column in enumerate(columns): |
|
|
|
|
value = get_column_cell(obj, column) |
|
|
|
|
value = getattr(obj, column) |
|
|
|
|
style = default_style |
|
|
|
|
for value_type, cell_style in cell_style_map: |
|
|
|
|
if isinstance(value, value_type): |
|
|
|
|
|