def export_offer(self, request, permanence_id, permanence=None): wb = export_offer(permanence=permanence, wb=None) if wb is not None: response = HttpResponse( content_type= "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ) response[ "Content-Disposition"] = "attachment; filename={0}-{1}.xlsx".format( _("Preview report"), permanence) wb.save(response) return response else: return HttpResponseRedirect(self.get_redirect_to_change_list_url())
def export_xlsx_offer(self, request, queryset): permanence = queryset.first() if permanence.status not in [PERMANENCE_PLANNED, PERMANENCE_OPENED]: user_message = _("The status of %(permanence)s prohibit you to perform this action.") % { 'permanence': permanence} user_message_level = messages.ERROR self.message_user(request, user_message, user_message_level) return wb = export_offer(permanence=permanence, wb=None) if wb is not None: response = HttpResponse(content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') response['Content-Disposition'] = "attachment; filename={0}-{1}.xlsx".format( _("Preview report"), permanence ) wb.save(response) return response else: return
def export_xlsx_offer(self, request, queryset): permanence = queryset.first() if permanence is None or permanence.status not in [ PERMANENCE_PLANNED, PERMANENCE_OPENED ]: user_message = _("Action canceled by the system.") user_message_level = messages.ERROR self.message_user(request, user_message, user_message_level) return wb = export_offer(permanence=permanence, wb=None) if wb is not None: response = HttpResponse( content_type= 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ) response[ 'Content-Disposition'] = "attachment; filename={0}-{1}.xlsx".format( slugify(_("Preview report")), slugify(permanence)) wb.save(response) return response else: return