t85: попытка оптимизировать экспорт событий в админке

remotes/origin/t79_search_places_modal
Slava Kyrachevsky 9 years ago
parent f2c7c9e9c3
commit d7462c1b62
  1. 22
      apps/import_xls/admin.py
  2. 1
      apps/import_xls/excel_settings.py
  3. 19
      apps/import_xls/export_forms.py
  4. 18
      requirements.txt

@ -45,7 +45,7 @@ class ExportView(FormView):
def form_valid(self, form): def form_valid(self, form):
workbook = form.export() workbook = form.export()
if workbook: if workbook is not None:
f_name = form.get_fname() f_name = form.get_fname()
else: else:
messages.error(self.request, _('No objects found')) messages.error(self.request, _('No objects found'))
@ -55,32 +55,32 @@ class ExportView(FormView):
class ExportTheme(ExportView): class ExportTheme(ExportView):
form_class = ExportThemeForm form_class = ExportThemeForm
success_url = '/admin/export-theme' success_url = '/admin/export-theme/'
class ExportTag(ExportView): class ExportTag(ExportView):
form_class = ExportTagForm form_class = ExportTagForm
success_url = '/admin/export-tag' success_url = '/admin/export-tag/'
class ExportUser(ExportView): class ExportUser(ExportView):
form_class = ExportUserForm form_class = ExportUserForm
success_url = '/admin/export-user' success_url = '/admin/export-user/'
class ExportCompany(ExportView): class ExportCompany(ExportView):
form_class = ExportCompanyForm form_class = ExportCompanyForm
success_url = '/admin/export-company' success_url = '/admin/export-company/'
class ExportPlaceConference(ExportView): class ExportPlaceConference(ExportView):
form_class = ExportPlaceConferenceForm form_class = ExportPlaceConferenceForm
success_url = '/admin/export-place_conference' success_url = '/admin/export-place_conference/'
class ExportPlaceExposition(ExportView): class ExportPlaceExposition(ExportView):
form_class = ExportPlaceExpositionForm form_class = ExportPlaceExpositionForm
success_url = '/admin/export-place_exposition' success_url = '/admin/export-place_exposition/'
class ExportBlog(ExportView): class ExportBlog(ExportView):
@ -120,7 +120,7 @@ class ImportPlaceExposition(FormView):
class ImportPlaceConference(ImportView): class ImportPlaceConference(ImportView):
form_class = ImportPlaceConferenceForm form_class = ImportPlaceConferenceForm
success_url = '/admin/import-place_conference' success_url = '/admin/import-place_conference/'
def form_valid(self, form): def form_valid(self, form):
errors = form.save_file_debug() errors = form.save_file_debug()
@ -129,12 +129,12 @@ class ImportPlaceConference(ImportView):
class ImportTheme(ImportView): class ImportTheme(ImportView):
form_class = ImportThemeForm form_class = ImportThemeForm
success_url = '/admin/import-theme' success_url = '/admin/import-theme/'
class ImportTag(ImportView): class ImportTag(ImportView):
form_class = ImportTagForm form_class = ImportTagForm
success_url = '/admin/import-tag' success_url = '/admin/import-tag/'
@ -143,7 +143,7 @@ class ImportTag(ImportView):
class ExportEvent(ExportView): class ExportEvent(ExportView):
form_class = ExportEventForm form_class = ExportEventForm
template_name = 'export_event.html' template_name = 'export_event.html'
success_url = '/admin/export-event' success_url = '/admin/export-event/'
class LogList(ListView): class LogList(ListView):

@ -59,6 +59,7 @@ def get_periodic(value):
def get_quality(value, field): def get_quality(value, field):
# print value, field
flags = {u'UFI': 'ufi', u'РСВЯ': 'rsva', u'EXPORATING': 'exporating'} flags = {u'UFI': 'ufi', u'РСВЯ': 'rsva', u'EXPORATING': 'exporating'}
v = flags.get(field) v = flags.get(field)
if v: if v:

@ -174,8 +174,8 @@ class ExportEventForm(forms.Form):
language = forms.ChoiceField(label=_(u'Выберите язык'), choices=languages) language = forms.ChoiceField(label=_(u'Выберите язык'), choices=languages)
date_from = forms.DateField(label=_(u'С'), input_formats=settings.CLIENT_DATE_FORMAT) date_from = forms.DateField(label=_(u'С'), input_formats=settings.CLIENT_DATE_FORMAT)
date_to = forms.DateField(label=_(u'До'), input_formats=settings.CLIENT_DATE_FORMAT) date_to = forms.DateField(label=_(u'До'), input_formats=settings.CLIENT_DATE_FORMAT)
theme = forms.ModelMultipleChoiceField(label=_(u'Направление'), queryset=Theme.objects.all(), required=False) theme = forms.ModelMultipleChoiceField(label=_(u'Направление'), queryset=Theme.objects.language().all(), required=False)
country = forms.ModelMultipleChoiceField(label=_(u'Страны'), queryset=Country.objects.all(), required=False) country = forms.ModelMultipleChoiceField(label=_(u'Страны'), queryset=Country.objects.language().all(), required=False)
def export(self): def export(self):
data = self.cleaned_data data = self.cleaned_data
@ -185,20 +185,17 @@ class ExportEventForm(forms.Form):
lang, date_from, date_to, co, th = data['language'], data['date_from'], data['date_to'], data['country'], data['theme'] lang, date_from, date_to, co, th = data['language'], data['date_from'], data['date_to'], data['country'], data['theme']
# get objects # get objects
qs = model.objects.language(lang).filter(data_begin__range=[date_from, date_to]) qs = model.objects.language(lang).filter(data_begin__gte=date_from, data_begin__lte=date_to).select_related('place', 'country', 'city').prefetch_related('theme', 'tag', 'organiser', 'audience').distinct()
if co: if co:
qs = qs.filter(country__in=co) qs = qs.filter(country__in=co)
if th: if th:
qs = qs.filter(theme__in=th) qs = qs.filter(theme__in=th)
objects = list(qs.distinct()) if not qs.exists():
# not found any objects
if not objects:
# not found any objects
return None return None
workbook = xlwt.Workbook(encoding='utf8')
workbook = xlwt.Workbook(encoding = 'utf8')
# new tab # new tab
worksheet = workbook.add_sheet('My Worksheet') worksheet = workbook.add_sheet('My Worksheet')
@ -210,7 +207,7 @@ class ExportEventForm(forms.Form):
# Create the Style # Create the Style
style.font = font style.font = font
for row, object in enumerate(objects): for row, object in enumerate(qs):
# column number # column number
col = 0 col = 0
@ -222,7 +219,7 @@ class ExportEventForm(forms.Form):
continue continue
if row == 0: if row == 0:
# first iteration. set names. set columns width # first iteration. set names. set columns width
worksheet.write(0, col, field.get('verbose_name', 'default'), style) worksheet.write(0, col, field.get('verbose_name', 'default'), style)
worksheet.col(col).width = field.get('width', 3333) worksheet.col(col).width = field.get('width', 3333)
if field['name'] != 'quality_label': if field['name'] != 'quality_label':

@ -1,6 +1,6 @@
awesome-slugify==1.6 awesome-slugify==1.6.5
BeautifulSoup==3.2.1 BeautifulSoup==3.2.1
beautifulsoup4==4.4.0 beautifulsoup4==4.6.0
chainmap==1.0.2 chainmap==1.0.2
chardet==2.3.0 chardet==2.3.0
contextlib2==0.5.4 contextlib2==0.5.4
@ -14,7 +14,7 @@ django-debug-toolbar==1.2.1
django-haystack==2.3.2 django-haystack==2.3.2
django-hvad==1.2.2 django-hvad==1.2.2
django-model-utils==2.2 django-model-utils==2.2
django-modeltranslation==0.12 django-modeltranslation==0.12.1
django-recaptcha==1.2.1 django-recaptcha==1.2.1
django-redis==4.0.0 django-redis==4.0.0
django-redis-cache==0.13.1 django-redis-cache==0.13.1
@ -50,9 +50,9 @@ python-memcached==1.48
python-openid==2.2.5 python-openid==2.2.5
python-social-auth==0.1.23 python-social-auth==0.1.23
pytils==0.3 pytils==0.3
pytz==2016.10 pytz==2017.2
raven==5.32.0 raven==6.1.0
redis==2.10.1 redis==2.10.5
redis-collections==0.4.2 redis-collections==0.4.2
regex==2014.11.14 regex==2014.11.14
requests==2.2.1 requests==2.2.1
@ -66,8 +66,8 @@ South==1.0.2
sqlparse==0.1.11 sqlparse==0.1.11
suds==0.4 suds==0.4
Unidecode==0.4.16 Unidecode==0.4.16
uWSGI==2.0.14 uWSGI==2.0.15
vobject==0.8.2 vobject==0.8.2
wstools==0.4.3 wstools==0.4.3
xlrd==0.9.2 xlrd==1.0.0
xlwt==0.7.5 xlwt==1.2.0

Loading…
Cancel
Save