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


Python DocumentFactory.get_metadata方法代码示例

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


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

示例1: test_all_revisions_document_download

# 需要导入模块: from documents.factories import DocumentFactory [as 别名]
# 或者: from documents.factories.DocumentFactory import get_metadata [as 别名]
    def test_all_revisions_document_download(self):
        """
        Tests that download returns a zip file of all revisions
        of a document.
        """
        document = DocumentFactory(
            category=self.category,
        )
        sample_path = b'documents/tests/'
        native_doc = b'sample_doc_native.docx'
        pdf_doc = b'sample_doc_pdf.pdf'

        MetadataRevisionFactory(
            metadata=document.get_metadata(),
            revision=2,
            native_file=SimpleUploadedFile(native_doc, sample_path + native_doc),
            pdf_file=SimpleUploadedFile(pdf_doc, sample_path + pdf_doc),
        )
        MetadataRevisionFactory(
            metadata=document.get_metadata(),
            revision=3,
            native_file=SimpleUploadedFile(native_doc, sample_path + native_doc),
            pdf_file=SimpleUploadedFile(pdf_doc, sample_path + pdf_doc),
        )
        r = self.client.post(document.category.get_download_url(), {
            'document_ids': document.id,
            'revisions': 'all',
            'format': 'both',
        })
        self.assertEqual(r.status_code, 200)

        zipfile = BytesIO(r.content)
        filelist = ZipFile(zipfile).namelist()
        self.assertEqual(len(filelist), 4)
开发者ID:andyjia,项目名称:phase,代码行数:36,代码来源:test_views.py

示例2: generate_random_documents

# 需要导入模块: from documents.factories import DocumentFactory [as 别名]
# 或者: from documents.factories.DocumentFactory import get_metadata [as 别名]
def generate_random_documents(nb_of_docs, category):
    """Generate a bunch of random documents.

    This function is useful for testing purpose.

    """
    if category.category_template.metadata_model.model_class() != DemoMetadata:
        error_message = ('This function is only useful for testing purpose. '
                         'The category you pass as an argument can only host '
                         'documents of the DemoMetadata type.')
        raise Exception(error_message)

    for i in range(nb_of_docs):
        document = DocumentFactory(
            category=category,
        )
        metadata = document.get_metadata()
        max_revision = choice(list(range(1, 5)))
        for revision_number in range(2, max_revision):
            MetadataRevisionFactory(
                revision=revision_number,
                revision_date='{year}-{month:0>2}-{day:0>2}'.format(
                    year=2008 + revision_number,
                    month=choice(list(range(1, 13))),
                    day=choice(list(range(1, 29))),
                ),
                metadata=metadata
            )
开发者ID:Talengi,项目名称:phase,代码行数:30,代码来源:utils.py

示例3: setUp

# 需要导入模块: from documents.factories import DocumentFactory [as 别名]
# 或者: from documents.factories.DocumentFactory import get_metadata [as 别名]
    def setUp(self):
        self.tmpdir = tempfile.mkdtemp(prefix='phasetest_', suffix='_trs')
        self.incoming = join(self.tmpdir, 'incoming')
        self.tobechecked = join(self.tmpdir, 'tobechecked')
        self.accepted = join(self.tmpdir, 'accepted')
        self.rejected = join(self.tmpdir, 'rejected')

        os.mkdir(self.accepted)
        os.mkdir(self.rejected)
        os.mkdir(self.tobechecked)

        doc = DocumentFactory(
            document_key='FAC10005-CTR-CLT-TRS-00001',
            metadata_factory_class=TransmittalFactory,
            revision_factory_class=TransmittalRevisionFactory,
            metadata={
                'status': 'tobechecked',
                'tobechecked_dir': self.tobechecked,
                'accepted_dir': self.accepted,
                'rejected_dir': self.rejected,
                'contractor': 'test'
            }
        )
        self.transmittal = doc.get_metadata()
        os.mkdir(self.transmittal.full_tobechecked_name)
开发者ID:Talengi,项目名称:phase,代码行数:27,代码来源:test_models.py

示例4: test_new_revision_can_update_document_key

# 需要导入模块: from documents.factories import DocumentFactory [as 别名]
# 或者: from documents.factories.DocumentFactory import get_metadata [as 别名]
    def test_new_revision_can_update_document_key(self):
        doc = DocumentFactory(
            category=self.category,
            document_key='FAC09001-FWF-000-HSE-REP-0004',
            revision={
                'status': 'STD',
            }
        )
        url = reverse('document_revise', args=[
            self.category.organisation.slug,
            self.category.slug,
            doc.document_key
        ])
        self.client.post(url, {
            'document_number': 'Another Document Number',
            'title': doc.metadata.title,
            'status': 'SPD',
            'docclass': 1,
            'created_on': '2015-10-10',
            'revision_date': '2015-10-10',
            'received_date': '2015-10-10',
        }, follow=True)

        doc.refresh_from_db()
        self.assertEqual(doc.document_number, 'Another Document Number')
        self.assertEqual(doc.document_key, 'ANOTHER-DOCUMENT-NUMBER')

        metadata = doc.get_metadata()
        self.assertEqual(metadata.document_number, 'Another Document Number')
        self.assertEqual(metadata.document_key, 'ANOTHER-DOCUMENT-NUMBER')
开发者ID:Talengi,项目名称:phase,代码行数:32,代码来源:test_forms.py

示例5: test_edition_updates_document_key

# 需要导入模块: from documents.factories import DocumentFactory [as 别名]
# 或者: from documents.factories.DocumentFactory import get_metadata [as 别名]
    def test_edition_updates_document_key(self):
        doc = DocumentFactory(
            category=self.category,
            document_key='FAC09001-FWF-000-HSE-REP-0004',
            metadata={
                'title': 'HAZOP related 1',
            },
            revision={
                'status': 'STD',
            }
        )
        c = self.client
        c.post(doc.get_edit_url(), {
            'document_number': 'New Document Number',
            'title': 'a new title',
            'docclass': 1,
            'created_on': '2015-10-10',
            'received_date': '2015-10-10',
            'save-view': 'View',
        }, follow=True)

        doc.refresh_from_db()
        self.assertEqual(doc.document_number, 'New Document Number')
        self.assertEqual(doc.document_key, 'NEW-DOCUMENT-NUMBER')

        metadata = doc.get_metadata()
        self.assertEqual(metadata.document_number, 'New Document Number')
        self.assertEqual(metadata.document_key, 'NEW-DOCUMENT-NUMBER')
开发者ID:Talengi,项目名称:phase,代码行数:30,代码来源:test_forms.py

示例6: test_command

# 需要导入模块: from documents.factories import DocumentFactory [as 别名]
# 或者: from documents.factories.DocumentFactory import get_metadata [as 别名]
    def test_command(self):
        document = DocumentFactory(
            category=self.category,
        )
        native_doc = 'sample_doc_native.docx'
        pdf_doc = 'sample_doc_pdf.pdf'

        MetadataRevisionFactory(
            metadata=document.get_metadata(),
            revision=2,
            native_file=SimpleUploadedFile(native_doc, b'content'),
            pdf_file=SimpleUploadedFile(pdf_doc, b'content'),
        )
        # Document without files
        DocumentFactory(
            category=self.category,
        )
        rev = document.get_latest_revision()
        filepath = rev.pdf_file.path
        # check file is on disk after doc deletion
        document.delete()
        self.assertTrue(os.path.exists(filepath))

        call_command('clearmedia')
        # command has deleted file
        self.assertFalse(os.path.exists(filepath))
开发者ID:Talengi,项目名称:phase,代码行数:28,代码来源:test_command.py

示例7: create_doc

# 需要导入模块: from documents.factories import DocumentFactory [as 别名]
# 或者: from documents.factories.DocumentFactory import get_metadata [as 别名]
 def create_doc(self, nb_revisions=1):
     doc = DocumentFactory(category=self.category)
     meta = doc.get_metadata()
     for rev in range(2, nb_revisions + 1):
         MetadataRevisionFactory(
             metadata=meta,
             revision=rev
         )
     url = reverse('document_revision_delete', args=[
         self.category.organisation.slug,
         self.category.slug,
         doc.document_key
     ])
     return doc, url
开发者ID:providenz,项目名称:phase,代码行数:16,代码来源:test_views.py


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