From aa01b8273c935c27b0606f77276e9c7454e2a089 Mon Sep 17 00:00:00 2001 From: Ivan Kovalkovskyi Date: Wed, 23 Sep 2015 15:45:12 +0300 Subject: [PATCH] calendar indexOutOfRange bug fixed --- core/views.py | 69 +++++++++++++------------ templates/client/accounts/calendar.html | 7 ++- 2 files changed, 42 insertions(+), 34 deletions(-) diff --git a/core/views.py b/core/views.py index 03e01142..0ec0cb16 100644 --- a/core/views.py +++ b/core/views.py @@ -265,36 +265,39 @@ from django.core.urlresolvers import reverse def download_workbook(request): lang = get_language() data = request.GET - qs = [] - for i,obj in enumerate(data): - if data.get('data[%i][name]'%i) == 'expo': - qs.append(Exposition.objects.language(lang).get(id=data['data[%i][value]'%i])) - elif data.get('data[%i][name]'%i) == 'conf': - qs.append(Conference.objects.language(lang).get(id=data['data[%i][value]'%i])) - - earliest_event = qs[0].data_begin - for i, obj in enumerate(qs, start=1): - if obj.data_begin < earliest_event: - earliest_event = obj.data_begin - setattr(obj, 'number', i) - setattr(obj, 'dates', u'%s - %s'%(obj.data_begin.strftime('%d %B %Y'),obj.data_end.strftime('%d %B %Y'))) - setattr(obj, 'full_place', u'%s, %s, %s' % (obj.country, obj.city, getattr(obj.place, 'name', ''))) - try: - setattr(obj, 'link', u'http://www.expomap.ru%s)'%obj.get_absolute_url()) - except: - setattr(obj, 'link', u'http://www.expomap.ru%s)'%obj.get_permanent_url()) - - columns = ( - 'number', - 'name', - 'dates', - 'main_title', - 'full_place', - 'participation_note', - 'link') - - workbook = queryset_to_workbook(qs, columns, earliest_event) - response = HttpResponse(content_type='application/vnd.ms-excel') - response['Content-Disposition'] = 'attachment; filename="My calendar.xls"' - workbook.save(response) - return response + if data: + qs = [] + for i,obj in enumerate(data): + if data.get('data[%i][name]'%i) == 'expo': + qs.append(Exposition.objects.language(lang).get(id=data['data[%i][value]'%i])) + elif data.get('data[%i][name]'%i) == 'conf': + qs.append(Conference.objects.language(lang).get(id=data['data[%i][value]'%i])) + + earliest_event = qs[0].data_begin + for i, obj in enumerate(qs, start=1): + if obj.data_begin < earliest_event: + earliest_event = obj.data_begin + setattr(obj, 'number', i) + setattr(obj, 'dates', u'%s - %s'%(obj.data_begin.strftime('%d %B %Y'),obj.data_end.strftime('%d %B %Y'))) + setattr(obj, 'full_place', u'%s, %s, %s' % (obj.country, obj.city, getattr(obj.place, 'name', ''))) + try: + setattr(obj, 'link', u'http://www.expomap.ru%s)'%obj.get_absolute_url()) + except: + setattr(obj, 'link', u'http://www.expomap.ru%s)'%obj.get_permanent_url()) + + columns = ( + 'number', + 'name', + 'dates', + 'main_title', + 'full_place', + 'participation_note', + 'link') + + workbook = queryset_to_workbook(qs, columns, earliest_event) + response = HttpResponse(content_type='application/vnd.ms-excel') + response['Content-Disposition'] = 'attachment; filename="My calendar.xls"' + workbook.save(response) + return response + else: + return HttpResponseRedirect(request.META.get('HTTP_REFERER'), "/profile/calendar/") diff --git a/templates/client/accounts/calendar.html b/templates/client/accounts/calendar.html index ad9766c6..d49542e5 100644 --- a/templates/client/accounts/calendar.html +++ b/templates/client/accounts/calendar.html @@ -65,7 +65,12 @@ } console.log(clear_list); var query = $.param({data:clear_list}); - window.location.href = "/profile/calendar/export/?" + query; + if(clear_list.Length > 0){ + window.location.href = "/profile/calendar/export/?" + query; + } + else{ + alert({% trans "Не выбрано ни одного события!" %}) + } }); })