def test_content_category_changed_default_values(self):
        """While content_category is changed on an element, the default values for fields
           to_print/confidential/to_sign/signed are reapplied with new content_category
           default values if it was still the default vlue of the original content_category."""
        category_group = self.portal.config['group-1']
        category_group.to_be_printed_activated = True
        category_group.confidentiality_activated = True
        category_group.signed_activated = True
        category11 = self.portal.config['group-1']['category-1-1']
        category11_id = calculate_category_id(category11)
        obj = api.content.create(
            id='file2',
            type='File',
            file=self.file,
            container=self.portal,
            content_category=category11_id)
        self.assertFalse(obj.confidential)
        self.assertFalse(obj.to_sign)
        self.assertFalse(obj.signed)
        self.assertIsNone(obj.to_print)
        # now enable everything on category-1-2 and use it
        category12 = self.portal.config['group-1']['category-1-2']
        category12.to_print = False
        category12.confidential = True
        category12.to_sign = True
        category12.signed = True
        category12_id = calculate_category_id(category12)
        adapted_obj = IconifiedCategorization(obj)
        setattr(adapted_obj, 'content_category', category12_id)
        notify(ObjectModifiedEvent(obj))

        # changed to True on obj an in parent's categorized_elements
        parent_cat_elements = obj.aq_parent.categorized_elements[obj.UID()]
        self.assertTrue(obj.confidential)
        self.assertTrue(parent_cat_elements['confidential'])
        self.assertTrue(obj.to_sign)
        self.assertTrue(parent_cat_elements['to_sign'])
        self.assertTrue(obj.signed)
        self.assertTrue(parent_cat_elements['signed'])
        # to_print could not be set to False because not printable
        self.assertIsNone(obj.to_print)
        self.assertIsNone(parent_cat_elements['to_print'])

        # enable conversion and back to category11
        category11.to_print = True
        gsettings = GlobalSettings(self.portal)
        gsettings.auto_layout_file_types = CONVERTABLE_TYPES.keys()
        # set to_print to False, aka the default value of category12
        obj.to_print = False
        setattr(adapted_obj, 'content_category', category11_id)
        notify(ObjectModifiedEvent(obj))
        self.assertTrue(obj.to_print)
        self.assertTrue(parent_cat_elements['to_print'])

        # if original content_category does not exist, it does not fail
        # but default values are not reapplied
        obj.content_category = 'unkown_content_category'
        setattr(adapted_obj, 'content_category', category12_id)
        notify(ObjectModifiedEvent(obj))
        self.assertEqual(obj.content_category, category12_id)
    def test_set_values(self):
        obj = self.portal['file']
        view = obj.restrictedTraverse('@@iconified-print')

        # works only if functionnality enabled and user have Modify portal content
        category = utils.get_category_object(obj, obj.content_category)
        group = category.get_category_group()

        # fails if one of 2 conditions is not fullfilled
        self.assertTrue(api.user.has_permission(ModifyPortalContent, obj=obj))
        group.to_be_printed_activated = False
        self.assertRaises(Unauthorized, view.set_values, {'to_print': True})
        group.to_be_printed_activated = True

        obj.manage_permission(ModifyPortalContent, roles=[])
        self.assertRaises(Unauthorized, view.set_values, {'to_print': True})
        obj.manage_permission(ModifyPortalContent, roles=['Manager'])

        # set to None when format not managed by collective.documentviewer
        self.assertFalse(obj.to_print, obj.aq_parent.categorized_elements[obj.UID()]['to_print'])
        view.set_values({'to_print': True})
        self.assertIsNone(obj.to_print, obj.aq_parent.categorized_elements[obj.UID()]['to_print'])

        # will be correctly set if format is managed
        gsettings = GlobalSettings(self.portal)
        gsettings.auto_layout_file_types = CONVERTABLE_TYPES.keys()
        view.set_values({'to_print': True})
        self.assertTrue(obj.to_print, obj.aq_parent.categorized_elements[obj.UID()]['to_print'])
        view.set_values({'to_print': False})
        self.assertFalse(obj.to_print, obj.aq_parent.categorized_elements[obj.UID()]['to_print'])
    def test_content_category_to_print_on_creation(self):
        """ """
        category_group = self.portal.config['group-1']
        category = self.portal.config['group-1']['category-1-1']
        content_category_id = calculate_category_id(category)
        category_group.to_be_printed_activated = True
        # enable conversion
        gsettings = GlobalSettings(self.portal)
        gsettings.auto_layout_file_types = CONVERTABLE_TYPES.keys()

        # set to False
        category.to_print = False
        file2 = api.content.create(
            id='file2',
            type='File',
            file=self.file,
            container=self.portal,
            content_category=content_category_id)
        self.assertFalse(file2.to_print)

        # set to True
        category.to_print = True
        file3 = api.content.create(
            id='file3',
            type='File',
            file=self.file,
            container=self.portal,
            content_category=content_category_id)
        self.assertTrue(file3.to_print)
Esempio n. 4
0
def apply_patches():

    # Set default convertible types
    from collective.documentviewer.interfaces import IGlobalDocumentViewerSettings
    from collective.documentviewer.config import CONVERTABLE_TYPES
    IGlobalDocumentViewerSettings['auto_layout_file_types'].default = (
        CONVERTABLE_TYPES.keys()
    )
    patch_documentviewer_mimetype()
Esempio n. 5
0
 def _documentViewerPrintableExtensions(self):
     """
       Compute file extensions that will be considered as printable.
     """
     from collective.documentviewer.config import CONVERTABLE_TYPES
     printableExtensions = []
     for convertable_type in CONVERTABLE_TYPES.iteritems():
         printableExtensions.extend(convertable_type[1].extensions)
     return printableExtensions
    def test_PrintColumn(self):
        table = self.portal.restrictedTraverse('@@iconifiedcategory')
        brain = CategorizedContent(self.portal.portal_catalog(UID=self.portal['file'].UID())[0],
                                   self.portal)
        obj = brain.real_object()
        column = PrintColumn(self.portal, self.portal.REQUEST, table)
        # not convertible by default as c.documentviewer not enabled
        self.assertEqual(
            column.renderCell(brain),
            u'<a href="#" '
            u'class="iconified-action deactivated" '
            u'alt="Not convertible to a printable format" '
            u'title="Not convertible to a printable format"></a>')
        self.assertIsNone(brain.to_print)
        self.assertIsNone(obj.to_print)

        # enable collective.documentviewer so document is convertible
        gsettings = GlobalSettings(self.portal)
        gsettings.auto_layout_file_types = CONVERTABLE_TYPES.keys()
        # enable to_print management in configuration
        category = utils.get_category_object(obj, obj.content_category)
        category_group = category.get_category_group(category)
        category_group.to_be_printed_activated = True
        category.to_print = False
        notify(ObjectModifiedEvent(obj))
        brain = CategorizedContent(self.portal.portal_catalog(UID=self.portal['file'].UID())[0],
                                   self.portal)
        self.assertEqual(brain.to_print, False)
        self.assertFalse(obj.to_print)
        self.assertEqual(
            column.renderCell(brain),
            u'<a href="http://nohost/plone/file/@@iconified-print" '
            u'class="iconified-action editable" '
            u'alt="Should not be printed" '
            u'title="Should not be printed"></a>')

        # set to_print to True
        obj.to_print = True
        notify(ObjectModifiedEvent(obj))
        brain = CategorizedContent(self.portal.portal_catalog(UID=self.portal['file'].UID())[0],
                                   self.portal)
        self.assertTrue(brain.to_print, False)
        self.assertTrue(obj.to_print)
        self.assertEqual(
            column.renderCell(brain),
            u'<a href="http://nohost/plone/file/@@iconified-print" '
            u'class="iconified-action active editable" '
            u'alt="Must be printed" '
            u'title="Must be printed"></a>')

        # if element is not editable, the 'editable' CSS class is not there
        obj.manage_permission(ModifyPortalContent, roles=[])
        notify(ObjectModifiedEvent(obj))
        self.assertEqual(column.renderCell(brain),
                         u'<a href="http://nohost/plone/file/@@iconified-print" '
                         u'class="iconified-action active" '
                         u'alt="Must be printed" title="Must be printed"></a>')
Esempio n. 7
0
def configure(context):
    """

    """
    if context.readDataFile('ploneintranet.docconv_default.txt') is None:
        return
    log.info("document conversion configuration")

    global_settings = GlobalSettings(getSite())
    global_settings.enable_indexation = False
    global_settings.auto_select_layout = False
    global_settings.auto_layout_file_types = CONVERTABLE_TYPES.keys()
    commit()
    log.info("document conversion configuration: done.")
    def test_table_render_when_preview_enabled(self):
        # enable collective.documentviewer so document is convertible
        gsettings = GlobalSettings(self.portal)
        gsettings.auto_layout_file_types = CONVERTABLE_TYPES.keys()
        # initialize collective.documentviewer annotations on file
        file_obj = self.portal['file']
        image_obj = self.portal['image']
        notify(ObjectModifiedEvent(file_obj))
        notify(ObjectModifiedEvent(image_obj))

        view = self.portal.restrictedTraverse('@@iconifiedcategory')
        result = view()
        # by default, images are not handled by collective.documentviewer
        self.assertTrue('<a href="http://nohost/plone/image" ' in result)
        self.assertTrue('<a href="http://nohost/plone/file/documentviewer#document/p1" ' in result)
    def test_is_convertible(self):
        obj = self.portal['file']

        preview_adapter = adapter.CategorizedObjectPreviewAdapter(obj)

        # convertible relies on the fact that contentType is managed
        # by collective.documentviewer gsettings.auto_layout_file_types
        gsettings = GlobalSettings(self.portal)
        self.assertEqual(gsettings.auto_layout_file_types, ['pdf'])

        obj.file.contentType = 'application/pdf'
        self.assertTrue(preview_adapter.is_convertible())

        obj.file.contentType = 'application/rtf'
        self.assertFalse(preview_adapter.is_convertible())

        # right enable every file_types in collective.documentviewer
        gsettings.auto_layout_file_types = CONVERTABLE_TYPES.keys()

        convertables = (
            'application/msword',
            'application/pdf',
            'application/rtf',
            'application/vnd.oasis.opendocument.spreadsheet',
            'application/vnd.oasis.opendocument.text',
            # xlsx
            'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
            'image/png',
            'image/jpeg',
            'text/html',
        )
        for convertable in convertables:
            obj.file.contentType = convertable
            self.assertTrue(preview_adapter.is_convertible())

        not_convertables = ('application/octet-stream',
                            'text/x-python')
        for not_convertable in not_convertables:
            obj.file.contentType = not_convertable
            self.assertFalse(preview_adapter.is_convertible())
    def test_content_category_to_print_only_set_if_convertible_when_conversion_enabled(self):
        """ """
        category_group = self.portal.config['group-1']
        category = self.portal.config['group-1']['category-1-1']
        content_category_id = calculate_category_id(category)
        category_group.to_be_printed_activated = True

        # set to True
        category.to_print = True
        file2 = api.content.create(
            id='file2',
            type='File',
            file=self.file,
            container=self.portal,
            content_category=content_category_id)
        # enable conversion
        gsettings = GlobalSettings(self.portal)
        gsettings.auto_layout_file_types = CONVERTABLE_TYPES.keys()
        file2.file.contentType = 'text/unknown'

        notify(ObjectModifiedEvent(file2))
        self.assertIsNone(file2.to_print)
    def test_status(self):
        obj = self.portal['file']

        preview_adapter = adapter.CategorizedObjectPreviewAdapter(obj)

        gsettings = GlobalSettings(self.portal)
        self.assertEqual(gsettings.auto_layout_file_types, ['pdf'])

        obj.file.contentType = 'application/rtf'
        self.assertEqual(preview_adapter.status, 'not_convertable')
        self.assertFalse(preview_adapter.converted)

        obj.file.contentType = 'application/pdf'
        self.assertEqual(preview_adapter.status, 'not_converted')
        self.assertFalse(preview_adapter.converted)

        ann = IAnnotations(obj)['collective.documentviewer']
        ann['filehash'] = '--foobar--'
        obj.file.contentType = 'application/pdf'
        self.assertEqual(preview_adapter.status, 'in_progress')
        self.assertFalse(preview_adapter.converted)

        queueJob(obj)
        # not a real PDF actually...
        self.assertEqual(preview_adapter.status, 'conversion_error')
        self.assertFalse(preview_adapter.converted)

        # enable every supported types including txt
        gsettings.auto_layout_file_types = CONVERTABLE_TYPES.keys()
        obj.file.contentType = 'text/plain'
        # collective.documentviewer checks if element was modified
        # or it does not convert again
        sleep(1)
        obj.notifyModified()
        queueJob(obj)
        self.assertEqual(preview_adapter.status, 'converted')
        self.assertTrue(preview_adapter.converted)
try:
    # older versions of zope.schema do not support defaultFactory
    schema.Int(title=u"", defaultFactory=lambda x: 5)
    SUPPORT_DEFAULT_FACTORY = True
except TypeError:
    SUPPORT_DEFAULT_FACTORY = False


class ILayer(Interface):
    """
    layer class
    """

FILE_TYPES_VOCAB = []

for id, doc in CONVERTABLE_TYPES.items():
    FILE_TYPES_VOCAB.append(SimpleTerm(id, id, doc.name))


class IGlobalDocumentViewerSettings(Interface):
    large_size = schema.Int(
        title=_("Large Image Size"),
        default=1000)
    normal_size = schema.Int(
        title=_("Normal Image Size"),
        default=700)
    thumb_size = schema.Int(
        title=_("Thumb Image Size"),
        default=180)
    storage_type = schema.Choice(
        title=_("Storage Type"),
Esempio n. 13
0
 def _enableAutoConvert(self, enable=True):
     """Enable collective.documentviewer auto_convert."""
     gsettings = GlobalSettings(self.portal)
     gsettings.auto_convert = enable
     gsettings.auto_layout_file_types = CONVERTABLE_TYPES.keys()
     return gsettings
from zope.interface import Attribute
from zope import schema
from zope.component.interfaces import IObjectEvent
from collective.documentviewer.config import CONVERTABLE_TYPES
from OFS.interfaces import IItem


class ILayer(Interface):
    """
    layer class
    """


FILE_TYPES_VOCAB = []

for id, doc in CONVERTABLE_TYPES.items():
    FILE_TYPES_VOCAB.append(SimpleTerm(id, id, doc.name))


class IGlobalDocumentViewerSettings(Interface):
    large_size = schema.Int(title=u"Large Image Size", default=1000)
    normal_size = schema.Int(title=u"Normal Image Size", default=700)
    thumb_size = schema.Int(title=u"Thumb Image Size", default=180)
    storage_type = schema.Choice(
        title=u"Storage Type",
        description=u"Blob storage using the normal ZODB blob mechanism. "
        u"File storage is for just storage the files on the "
        u"file system with no hard reference on write to the "
        u"ZODB. This allows you to easily push the files to "
        u"be served off-site.",
        default='Blob',
 def setUp(self):
     super(TestCategorizedObjectPrintableAdapter, self).setUp()
     gsettings = GlobalSettings(self.portal)
     gsettings.auto_layout_file_types = CONVERTABLE_TYPES.keys()
try:
    # older versions of zope.schema do not support defaultFactory
    schema.Int(title=u"", defaultFactory=lambda x: 5)
    SUPPORT_DEFAULT_FACTORY = True
except TypeError:
    SUPPORT_DEFAULT_FACTORY = False


class ILayer(Interface):
    """
    layer class
    """

FILE_TYPES_VOCAB = []

for type_id, doc in CONVERTABLE_TYPES.items():
    FILE_TYPES_VOCAB.append(SimpleTerm(type_id, type_id, doc.name))


class IGlobalDocumentViewerSettings(Interface):
    large_size = schema.Int(
        title=_("Large Image Size"),
        default=1000)
    normal_size = schema.Int(
        title=_("Normal Image Size"),
        default=700)
    thumb_size = schema.Int(
        title=_("Thumb Image Size"),
        default=180)
    storage_type = schema.Choice(
        title=_("Storage Type"),
    from plone.app.contenttypes.interfaces import IFile

    class IPACPossibleDocumentViewerMarker(IFile):
        pass
except ImportError:
    pass


class ILayer(Interface):
    """
    layer class
    """

FILE_TYPES_VOCAB = []

for type_id, doc in CONVERTABLE_TYPES.items():
    FILE_TYPES_VOCAB.append(SimpleTerm(type_id, type_id, doc.name))


class IGlobalDocumentViewerSettings(Interface):
    large_size = schema.Int(
        title=_("Large Image Size"),
        default=1000)
    normal_size = schema.Int(
        title=_("Normal Image Size"),
        default=700)
    thumb_size = schema.Int(
        title=_("Thumb Image Size"),
        default=180)
    storage_type = schema.Choice(
        title=_("Storage Type"),