当前位置: 首页>>代码示例>>Python>>正文


Python Document.add_as_recent_document_for_user方法代码示例

本文整理汇总了Python中documents.models.Document.add_as_recent_document_for_user方法的典型用法代码示例。如果您正苦于以下问题:Python Document.add_as_recent_document_for_user方法的具体用法?Python Document.add_as_recent_document_for_user怎么用?Python Document.add_as_recent_document_for_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在documents.models.Document的用法示例。


在下文中一共展示了Document.add_as_recent_document_for_user方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: upload_single_file

# 需要导入模块: from documents.models import Document [as 别名]
# 或者: from documents.models.Document import add_as_recent_document_for_user [as 别名]
    def upload_single_file(self, file_object, filename=None, use_file_name=False, document_type=None, metadata_dict_list=None, user=None, document=None, new_version_data=None):
        if not document:
            document = Document()
            if document_type:
                document.document_type = document_type
            document.save()            

            if metadata_dict_list:
                save_metadata_list(metadata_dict_list, document, create=True)
            warnings = update_indexes(document)

            if user:
                document.add_as_recent_document_for_user(user)
                create_history(HISTORY_DOCUMENT_CREATED, document, {'user': user})
            else:
                create_history(HISTORY_DOCUMENT_CREATED, document)
        else:
            if use_file_name:
                filename = None
            else:
                filename = filename if filename else document.latest_version.filename

        if not new_version_data:
            new_version_data = {}
            
        new_version = document.new_version(file=file_object, **new_version_data)
        if filename:
            new_version.filename = filename
            new_version.save()

        transformations, errors = self.get_transformation_list()

        new_version.apply_default_transformations(transformations)
开发者ID:mabroor,项目名称:mayan,代码行数:35,代码来源:models.py

示例2: upload_document

# 需要导入模块: from documents.models import Document [as 别名]
# 或者: from documents.models.Document import add_as_recent_document_for_user [as 别名]
    def upload_document(self, file_object, document_type, description=None, label=None, language=None, metadata_dict_list=None, metadata_dictionary=None, tag_ids=None, user=None):
        """
        Upload an individual document
        """
        try:
            with transaction.atomic():
                document = Document(
                    description=description or '', document_type=document_type,
                    label=label or file_object.name,
                    language=language or setting_language.value
                )
                document.save(_user=user)
        except Exception as exception:
            logger.critical(
                'Unexpected exception while trying to create new document '
                '"%s" from source "%s"; %s',
                label or file_object.name, self, exception
            )
            raise
        else:
            try:
                document_version = document.new_version(
                    file_object=file_object, _user=user,
                )

                if user:
                    document.add_as_recent_document_for_user(user)

                Transformation.objects.copy(
                    source=self, targets=document_version.pages.all()
                )

                if metadata_dict_list:
                    save_metadata_list(
                        metadata_dict_list, document, create=True
                    )

                if metadata_dictionary:
                    set_bulk_metadata(
                        document=document,
                        metadata_dictionary=metadata_dictionary
                    )

                if tag_ids:
                    for tag in Tag.objects.filter(pk__in=tag_ids):
                        tag.documents.add(document)
            except Exception as exception:
                logger.critical(
                    'Unexpected exception while trying to create version for '
                    'new document "%s" from source "%s"; %s',
                    label or file_object.name, self, exception
                )
                document.delete(to_trash=False)
                raise
开发者ID:jorik041,项目名称:open-paperless,代码行数:56,代码来源:models.py

示例3: upload_single_file

# 需要导入模块: from documents.models import Document [as 别名]
# 或者: from documents.models.Document import add_as_recent_document_for_user [as 别名]
    def upload_single_file(self, file_object, filename=None, use_file_name=False, document_type=None, metadata_dict_list=None, user=None, document=None, new_version_data=None, description=None):
        new_document = not document

        if not document:
            document = Document()
            if document_type:
                document.document_type = document_type

            if description:
                document.description = description

            document.save()

            apply_default_acls(document, user)

            if user:
                document.add_as_recent_document_for_user(user)
                create_history(HISTORY_DOCUMENT_CREATED, document, {'user': user})
            else:
                create_history(HISTORY_DOCUMENT_CREATED, document)
        else:
            if use_file_name:
                filename = None
            else:
                filename = filename if filename else document.latest_version.filename

            if description:
                document.description = description
                document.save()

        if not new_version_data:
            new_version_data = {}

        new_version = document.new_version(file=file_object, user=user, **new_version_data)

        if filename:
            document.rename(filename)

        transformations, errors = self.get_transformation_list()

        new_version.apply_default_transformations(transformations)
        # TODO: new HISTORY for version updates

        if metadata_dict_list and new_document:
            # Only do for new documents
            save_metadata_list(metadata_dict_list, document, create=True)
            warnings = update_indexes(document)
开发者ID:EmlynC,项目名称:mayan-edms,代码行数:49,代码来源:models.py

示例4: upload_document

# 需要导入模块: from documents.models import Document [as 别名]
# 或者: from documents.models.Document import add_as_recent_document_for_user [as 别名]
    def upload_document(self, file_object, document_type, description=None, label=None, language=None, querystring=None, user=None):
        """
        Upload an individual document
        """
        try:
            with transaction.atomic():
                document = Document(
                    description=description or '', document_type=document_type,
                    label=label or file_object.name,
                    language=language or setting_language.value
                )
                document.save(_user=user)
        except Exception as exception:
            logger.critical(
                'Unexpected exception while trying to create new document '
                '"%s" from source "%s"; %s',
                label or file_object.name, self, exception
            )
            raise
        else:
            try:
                document_version = document.new_version(
                    file_object=file_object, _user=user,
                )

                if user:
                    document.add_as_recent_document_for_user(user)

                Transformation.objects.copy(
                    source=self, targets=document_version.pages.all()
                )

            except Exception as exception:
                logger.critical(
                    'Unexpected exception while trying to create version for '
                    'new document "%s" from source "%s"; %s',
                    label or file_object.name, self, exception, exc_info=True
                )
                document.delete(to_trash=False)
                raise
            else:
                WizardStep.post_upload_process(
                    document=document, querystring=querystring
                )
                return document
开发者ID:mayan-edms,项目名称:mayan-edms,代码行数:47,代码来源:models.py

示例5: upload_single_file

# 需要导入模块: from documents.models import Document [as 别名]
# 或者: from documents.models.Document import add_as_recent_document_for_user [as 别名]
    def upload_single_file(self, file_object, filename=None, document_type=None, metadata_dict_list=None, user=None):
        transformations, errors = self.get_transformation_list()
        document = Document(file=file_object)
        if document_type:
            document.document_type = document_type
        document.save()
        if filename:
            document.file_filename = filename
            document.save()    

        document.apply_default_transformations(transformations)

        if metadata_dict_list:
            save_metadata_list(metadata_dict_list, document, create=True)
        warnings = update_indexes(document)

        if user:
            document.add_as_recent_document_for_user(user)
            create_history(HISTORY_DOCUMENT_CREATED, document, {'user': user})
        else:
            create_history(HISTORY_DOCUMENT_CREATED, document)
开发者ID:IHLeanne,项目名称:mayan,代码行数:23,代码来源:models.py


注:本文中的documents.models.Document.add_as_recent_document_for_user方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。