Example #1
0
    def trigger_pdf_conversion(self):
        if not self.get_property('archival_file_conversion_enabled'):
            return

        docs = api.content.find(self.context, object_provides=[IBaseDocument])
        for doc in docs:
            ArchivalFileConverter(doc.getObject()).trigger_conversion()
    def test_archival_file_management_view_listing(self, browser):
        self.login(self.manager, browser)
        subdossier = create(
            Builder('dossier').within(
                self.expired_dossier).titled(u"Subdossier"))
        subdocument = create(
            Builder('document').within(subdossier).with_dummy_content().titled(
                u"subdocument"))
        document = create(
            Builder('document').within(
                self.expired_dossier).with_dummy_content().titled(
                    u"Another document"))

        ArchivalFileConverter(subdocument).store_file('TEST DATA')
        IDocumentMetadata(self.expired_document
                          ).archival_file_state = STATE_FAILED_TEMPORARILY

        # make sure that document with no archival file is handled by the view
        self.assertIsNone(IDocumentMetadata(document).archival_file)

        browser.open(self.expired_dossier, view="archival_file_management")
        table = browser.css('table').first
        expected = [[
            'Path', 'Filetype', 'Has archival PDF', 'Archival file state'
        ],
                    [
                        self.expired_document.absolute_url_path(), '.doc',
                        'True', "STATE_FAILED_TEMPORARILY"
                    ], [document.absolute_url_path(), '.doc', 'False', ''],
                    [
                        subdocument.absolute_url_path(), '.doc', 'True',
                        "STATE_CONVERTED"
                    ]]
        self.assertEqual(expected, table.lists())
Example #3
0
    def trigger_pdf_conversion(self):
        if not self.get_property('archival_file_conversion_enabled'):
            return

        path = '/'.join(self.context.getPhysicalPath())
        docs = self.catalog.unrestrictedSearchResults(
            path=path, object_provides=IBaseDocument.__identifier__)
        for doc in docs:
            ArchivalFileConverter(doc.getObject()).trigger_conversion()
    def test_trigger_conversion_skip_files_in_manually_state(self):
        document = create(
            Builder('document').titled(
                u'\xdcberpr\xfcfung XY').with_dummy_content().having(
                    archival_file_state=STATE_MANUALLY_PROVIDED))

        ArchivalFileConverter(self.document).trigger_conversion()

        self.assertEquals(STATE_MANUALLY_PROVIDED,
                          IDocumentMetadata(document).archival_file_state)
Example #5
0
def set_archival_file_state(context, event):
    # Because every filewidget is always marked as changed, in the event
    # descriptions, even when no file has changed, we have to check the request
    request = context.REQUEST

    if request.get('ACTUAL_URL').endswith('edit_archival_file'):
        field_name = 'archival_file'
    else:
        field_name = 'IDocumentMetadata.archival_file'

    fileupload = request.get('form.widgets.{}'.format(field_name))
    action = request.get('form.widgets.{}.action'.format(field_name), '')

    if bool(fileupload):
        ArchivalFileConverter(context).handle_manual_file_upload()

    file_removed = action == u'remove'
    file_removed_in_archival_form = isinstance(action,
                                               list) and u'remove' in action

    if file_removed or file_removed_in_archival_form:
        ArchivalFileConverter(context).remove_state()
    def test_store_file_decodes_unicode_contenttypes(self):
        ArchivalFileConverter(self.document).store_file(
            'TEST DATA', mimetype=u'application/pdf')

        archival_file = IDocumentMetadata(self.document).archival_file
        self.assertTrue(isinstance(archival_file.contentType, str))
 def test_store_file_sets_state_to_converted(self):
     ArchivalFileConverter(self.document).store_file('TEST DATA')
     self.assertEquals(STATE_CONVERTED,
                       IDocumentMetadata(self.document).archival_file_state)
 def test_trigger_conversion_sets_state_to_converting(self):
     ArchivalFileConverter(self.document).trigger_conversion()
     self.assertEquals(STATE_CONVERTING,
                       IDocumentMetadata(self.document).archival_file_state)
 def test_file_name_is_file_filename_with_pdf_extension(self):
     self.assertEquals('uberprufung-xy.pdf',
                       ArchivalFileConverter(self.document).get_file_name())
Example #10
0
    def test_file_name_is_file_filename_with_pdf_extension(self):
        self.login(self.regular_user)

        self.assertEquals(
            u'Die Buergschaft.pdf',
            ArchivalFileConverter(self.test_document).get_file_name())
Example #11
0
 def handle_skipped(self):
     ArchivalFileConverter(
         self.context).handle_permanent_conversion_failure()
Example #12
0
 def handle_error(self):
     ArchivalFileConverter(
         self.context).handle_temporary_conversion_failure()
Example #13
0
 def handle_success(self, mimetype, file_data):
     ArchivalFileConverter(self.context).store_file(file_data, mimetype)