def forms_valid(self, forms): uploaded_file = self.source.get_upload_file_object( forms['source_form'].cleaned_data) shared_uploaded_file = SharedUploadedFile.objects.create( file=uploaded_file.file) try: self.source.clean_up_upload_file(uploaded_file) except Exception as exception: messages.error(self.request, exception) if not self.request.user.is_anonymous(): user_id = self.request.user.pk else: user_id = None task_upload_new_version.apply_async(kwargs=dict( shared_uploaded_file_id=shared_uploaded_file.pk, document_id=self.document.pk, user_id=user_id, comment=forms['document_form'].cleaned_data.get('comment'))) messages.success( self.request, _('New document version queued for uploaded and will be ' 'available shortly.')) return HttpResponseRedirect( reverse('documents:document_version_list', args=(self.document.pk, )))
def forms_valid(self, forms): try: uploaded_file = self.source.get_upload_file_object( forms['source_form'].cleaned_data ) except SourceException as exception: messages.error(self.request, exception) else: shared_uploaded_file = SharedUploadedFile.objects.create( file=uploaded_file.file ) try: self.source.clean_up_upload_file(uploaded_file) except Exception as exception: messages.error(self.request, exception) if not self.request.user.is_anonymous: user_id = self.request.user.pk else: user_id = None task_upload_new_version.apply_async(kwargs=dict( shared_uploaded_file_id=shared_uploaded_file.pk, document_id=self.document.pk, user_id=user_id, comment=forms['document_form'].cleaned_data.get('comment') )) messages.success( self.request, _( 'New document version queued for uploaded and will be ' 'available shortly.' ) ) return HttpResponseRedirect( reverse( 'documents:document_version_list', args=(self.document.pk,) ) )