コード例 #1
0
ファイル: views.py プロジェクト: keyzf/Mayan-EDMS
    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(message=exception, request=self.request)
        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(message=exception, request=self.request)

            if not self.request.user.is_anonymous:
                user = self.request.user
                user_id = self.request.user.pk
            else:
                user = None
                user_id = None

            try:
                DocumentVersion.execute_pre_create_hooks(
                    kwargs={
                        'document': self.document,
                        'shared_uploaded_file': shared_uploaded_file,
                        'user': user
                    })

                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')))
            except Exception as exception:
                message = _('Error executing document version upload task; '
                            '%(exception)s') % {
                                'exception': exception,
                            }
                logger.critical(msg=message, exc_info=True)
                if self.request.is_ajax():
                    return JsonResponse(data={'error': force_text(message)},
                                        status=500)
                else:
                    raise type(exception)(message)
            else:
                messages.success(message=_(
                    'New document version queued for upload and will be '
                    'available shortly.'),
                                 request=self.request)

        return HttpResponseRedirect(
            redirect_to=reverse(viewname='documents:document_version_list',
                                kwargs={'document_id': self.document.pk}))
コード例 #2
0
ファイル: views.py プロジェクト: keyzf/Mayan-EDMS
    def forms_valid(self, forms):
        if self.source.can_compress:
            if self.source.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK:
                expand = forms['source_form'].cleaned_data.get('expand')
            else:
                if self.source.uncompress == SOURCE_UNCOMPRESS_CHOICE_Y:
                    expand = True
                else:
                    expand = False
        else:
            expand = False

        try:
            uploaded_file = self.source.get_upload_file_object(
                forms['source_form'].cleaned_data)
        except SourceException as exception:
            messages.error(message=exception, request=self.request)
        else:
            shared_uploaded_file = SharedUploadedFile.objects.create(
                file=uploaded_file.file)

            if not self.request.user.is_anonymous:
                user = self.request.user
                user_id = self.request.user.pk
            else:
                user = None
                user_id = None

            try:
                self.source.clean_up_upload_file(uploaded_file)
            except Exception as exception:
                messages.error(message=exception, request=self.request)

            querystring = self.request.GET.copy()
            querystring.update(self.request.POST)

            try:
                Document.execute_pre_create_hooks(kwargs={
                    'document_type': self.document_type,
                    'user': user
                })

                DocumentVersion.execute_pre_create_hooks(
                    kwargs={
                        'document_type': self.document_type,
                        'shared_uploaded_file': shared_uploaded_file,
                        'user': user
                    })

                task_source_handle_upload.apply_async(kwargs=dict(
                    description=forms['document_form'].cleaned_data.get(
                        'description'),
                    document_type_id=self.document_type.pk,
                    expand=expand,
                    label=forms['document_form'].get_final_label(
                        filename=force_text(shared_uploaded_file)),
                    language=forms['document_form'].cleaned_data.get(
                        'language'),
                    querystring=querystring.urlencode(),
                    shared_uploaded_file_id=shared_uploaded_file.pk,
                    source_id=self.source.pk,
                    user_id=user_id,
                ))
            except Exception as exception:
                message = _('Error executing document upload task; '
                            '%(exception)s') % {
                                'exception': exception,
                            }
                logger.critical(msg=message, exc_info=True)
                raise type(exception)(message)
            else:
                messages.success(message=_(
                    'New document queued for upload and will be available '
                    'shortly.'),
                                 request=self.request)

        return HttpResponseRedirect(redirect_to='{}?{}'.format(
            reverse(viewname=self.request.resolver_match.view_name,
                    kwargs=self.request.resolver_match.kwargs),
            self.request.META['QUERY_STRING']), )
コード例 #3
0
ファイル: quota_backends.py プロジェクト: addaxagent/agent96
 def _initialize(cls):
     DocumentVersion.register_pre_create_hook(
         func=hook_factory_document_version_check_quota(klass=cls)
     )