def post(self, request, *args, **kwargs): upload = request.FILES.get('bulk_upload_file') if not upload: messages.error(request, _('no file uploaded')) return self.get(request, *args, **kwargs) if not args: messages.error(request, _('no domain specified')) return self.get(request, *args, **kwargs) if upload.content_type != 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': messages.error(request, _("Invalid file-format. Please upload a valid xlsx file.")) return self.get(request, *args, **kwargs) domain = args[0] ref = self._cache_file(request, domain, upload) if not isinstance(ref, LocationImportView.Ref): # ref is HTTP response: lock could not be acquired return ref file_ref = ref.value task = import_locations_async.delay(domain, file_ref.download_id, request.couch_user.user_id) file_ref.set_task(task) return HttpResponseRedirect( reverse( LocationImportStatusView.urlname, args=[domain, file_ref.download_id] ) )
def post(self, request, *args, **kwargs): upload = request.FILES.get('bulk_upload_file') if not upload: messages.error(request, _('no file uploaded')) return self.get(request, *args, **kwargs) if not args: messages.error(request, _('no domain specified')) return self.get(request, *args, **kwargs) if upload.content_type != 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': messages.error( request, _("Invalid file-format. Please upload a valid xlsx file.")) return self.get(request, *args, **kwargs) domain = args[0] ref = self._cache_file(request, domain, upload) if not isinstance(ref, LocationImportView.Ref): # ref is HTTP response: lock could not be acquired return ref file_ref = ref.value task = import_locations_async.delay(domain, file_ref.download_id, request.couch_user.user_id) file_ref.set_task(task) return HttpResponseRedirect( reverse(LocationImportStatusView.urlname, args=[domain, file_ref.download_id]))
def post(self, request, *args, **kwargs): upload = request.FILES.get('bulk_upload_file') if not upload: messages.error(request, _('no file uploaded')) return self.get(request, *args, **kwargs) if not args: messages.error(request, _('no domain specified')) return self.get(request, *args, **kwargs) if not upload.name.endswith('.xlsx'): messages.error(request, _("Invalid file-format. Please upload a valid xlsx file.")) return self.get(request, *args, **kwargs) try: get_workbook(upload) except WorkbookJSONError as e: messages.error(request, e) return self.get(request, *args, **kwargs) domain = args[0] ref = self._cache_file(request, domain, upload) if not isinstance(ref, LocationImportView.Ref): # ref is HTTP response: lock could not be acquired return ref file_ref = ref.value task = import_locations_async.delay(domain, file_ref.download_id, request.couch_user.user_id) file_ref.set_task(task) return HttpResponseRedirect( reverse( LocationImportStatusView.urlname, args=[domain, file_ref.download_id] ) )