Ejemplo n.º 1
0
def handle_file_creation(obj, event):
    if obj.portal_type == 'Image':
        return
    qi = getToolByName(obj, 'portal_quickinstaller', None)
    if not qi:
        return
    if not qi.isProductInstalled('collective.documentviewer'):
        return
    if getRequest().get('plone.app.contenttypes_migration_running', False):
        """Don't migrate while running a plone.app.contenttypes migration.
        """
        return

    site = getPortal(obj)
    gsettings = GlobalSettings(site)

    if not allowedDocumentType(obj, gsettings.auto_layout_file_types):
        return

    auto_layout = gsettings.auto_select_layout
    if auto_layout and obj.getLayout() != 'documentviewer':
        obj.setLayout('documentviewer')

    if obj.getLayout() == 'documentviewer' and gsettings.auto_convert:
        queueJob(obj)
Ejemplo n.º 2
0
    def __call__(self):
        self.site = getPortal(self.context)
        self.settings = Settings(self.context)
        self.global_settings = GlobalSettings(self.site)

        self.portal_url = getMultiAdapter(
            (self.context, self.request),
            name="plone_portal_state").portal_url()
        self.dvstatic = "%s/++resource++dv.resources" % (self.portal_url)
        resource_url = self.global_settings.override_base_resource_url
        rel_url = storage.getResourceRelURL(gsettings=self.global_settings,
                                            settings=self.settings)
        if resource_url:
            self.dvpdffiles = '%s/%s' % (resource_url.rstrip('/'), rel_url)
        else:
            self.dvpdffiles = '%s/%s' % (self.portal_url, rel_url)

        utils = getToolByName(self.context, 'plone_utils')
        msg = None
        self.enabled = True

        if allowedDocumentType(self.context,
                               self.global_settings.auto_layout_file_types):
            if not self.installed:
                msg = _(
                    "Since you do not have docsplit installed on this "
                    "system, we can not render the pages of this document.")
            if self.settings.converting is not None and \
                    self.settings.converting:
                if self.settings.successfully_converted:
                    # there is a version that is already converted, show it.
                    self.enabled = True
                else:
                    msg = _("The document is currently being converted to the "
                            "Document Viewer view.")
                    self.enabled = False
            elif self.settings.successfully_converted is not None and \
                    not self.settings.successfully_converted:
                msg = _("There was an error trying to convert the document. "
                        "Maybe the document is encrypted, corrupt or "
                        "malformed? Check log for details.")
                self.enabled = False
            elif self.settings.successfully_converted is None:
                # must have just switched to this view
                msg = _("This document is not yet converted to document "
                        "viewer. Please click the `Document Viewer Convert` "
                        "button in the actions menu to convert.")
                self.enabled = False
        else:
            self.enabled = False
            msg = _("The file is not a supported document type. "
                    "Your type may be supported. Check out the document "
                    "viewer configuration settings.")
        mtool = getToolByName(self.context, 'portal_membership')
        self.can_modify = mtool.checkPermission('cmf.ModifyPortalContent',
                                                self.context)
        if msg and self.can_modify:
            utils.addPortalMessage(_(msg))

        return self.index()
Ejemplo n.º 3
0
def generate_previews(obj, event=None):
    """ Generate the previews for a content type. We need our own subscriber as
    c.dv insists on checking for its custom layout. Also we want our own async
    mechanism, it is using this method.

    :param obj: The Plone content object to get preview URLs for
    :type obj: A Plone content object
    :return: Does not return anything.
    :rtype: None
    """
    site = getPortal(obj)
    gsettings = GlobalSettings(site)
    html_types = api.portal.get_registry_record(
        'ploneintranet.docconv.html_types',
        default=[],
    )

    if obj.portal_type in html_types:
        generate_pdf(obj, event=event)

    if not allowedDocumentType(obj, gsettings.auto_layout_file_types):
        log.info('Object type is not in available file types for conversion.')
        return

    if gsettings.auto_convert:
        converter = Converter(obj)
        if not converter.can_convert:
            return
        converter()
Ejemplo n.º 4
0
def convert_all(context):
    catalog = getToolByName(context, 'portal_catalog')
    portal = getSite()
    gsettings = GlobalSettings(portal)
    for brain in catalog(object_provides=IFileContent.__identifier__):
        file = brain.getObject()

        if not allowedDocumentType(file,
                gsettings.auto_layout_file_types):
            continue

        # let's not switch to the document viewer view
        # until the document is converted. The conversion
        # process will check if the layout is set correctly.
        if file.getLayout() != 'documentviewer':
            settings = Settings(file)
            settings.last_updated = DateTime('1999/01/01').ISO8601()
            queueJob(file)
        else:
            settings = Settings(file)
            # also convert if there was an error.
            if settings.successfully_converted == False:
                settings.last_updated = DateTime('1999/01/01').ISO8601()
                settings.filehash = ''
                queueJob(file)
Ejemplo n.º 5
0
def convert_all(context):
    catalog = getToolByName(context, 'portal_catalog')
    portal = getSite()
    gsettings = GlobalSettings(portal)
    for brain in catalog(object_provides=OBJECT_PROVIDES):
        file_item = brain.getObject()

        if not allowedDocumentType(file_item,
                                   gsettings.auto_layout_file_types):
            continue

        # let's not switch to the document viewer view
        # until the document is converted. The conversion
        # process will check if the layout is set correctly.
        if file_item.getLayout() != 'documentviewer':
            settings = Settings(file_item)
            settings.last_updated = DateTime('1999/01/01').ISO8601()
            queueJob(file_item)
        else:
            settings = Settings(file_item)
            # also convert if there was an error.
            if settings.successfully_converted == False:
                settings.last_updated = DateTime('1999/01/01').ISO8601()
                settings.filehash = ''
                queueJob(file_item)
    def __call__(self):
        self.site = getPortal(self.context)
        self.settings = Settings(self.context)
        self.global_settings = GlobalSettings(self.site)

        self.portal_url = getMultiAdapter((self.context, self.request),
            name="plone_portal_state").portal_url()
        self.dvstatic = "%s/++resource++dv.resources" % (
            self.portal_url)
        resource_url = self.global_settings.override_base_resource_url
        rel_url = storage.getResourceRelURL(gsettings=self.global_settings,
                                            settings=self.settings)
        if resource_url:
            self.dvpdffiles = '%s/%s' % (resource_url.rstrip('/'), rel_url)
        else:
            self.dvpdffiles = '%s/%s' % (self.portal_url, rel_url)

        utils = getToolByName(self.context, 'plone_utils')
        msg = None

        if allowedDocumentType(self.context,
                self.global_settings.auto_layout_file_types):
            if not self.installed:
                msg = "Since you do not have docsplit installed on this " + \
                      "system, we can not render the pages of this document."
            elif self.settings.converting is not None and \
                    self.settings.converting:
                if self.settings.successfully_converted:
                    # there is a version that is already converted, show it.
                    self.enabled = True
                else:
                    msg = "The document is currently being converted to the " + \
                          "Document Viewer view."
                    self.enabled = False
            elif self.settings.successfully_converted is not None and \
                    not self.settings.successfully_converted:
                msg = "There was an error trying to convert the document. " +\
                      "Maybe the document is encrypted, corrupt or " +\
                      "malformed? Check log for details."
                self.enabled = False
            elif self.settings.successfully_converted is None:
                # must have just switched to this view
                msg = "This document is not yet converted to document " +\
                      "viewer. Please click the `Document Viewer Convert` " +\
                      "button in the actions menu to convert."
                self.enabled = False
        else:
            self.enabled = False
            msg = "The file is not a supported document type. " + \
                  "Your type may be supported. Check out the document " + \
                  "viewer configuration settings."
        mtool = getToolByName(self.context, 'portal_membership')
        self.can_modify = mtool.checkPermission('cmf.ModifyPortalContent',
                                                self.context)
        if msg and self.can_modify:
            utils.addPortalMessage(msg)

        return self.index()
Ejemplo n.º 7
0
 def enabled(self):
     try:
         fw = IFileWrapper(self.context)
         if fw.has_enclosure:
             if self.context.getLayout() == 'documentviewer':
                 return True
             else:
                 settings = GlobalSettings(api.portal.get())
                 return allowedDocumentType(self.context,
                                            settings.auto_layout_file_types)
         else:
             return False
     except Exception:
         return False
Ejemplo n.º 8
0
 def enabled(self):
     try:
         if IFileContent.providedBy(self.context):
             if self.context.getLayout() == 'documentviewer':
                 return True
             else:
                 return allowedDocumentType(
                     self.context,
                     GlobalSettings(getPortal(
                         self.context)).auto_layout_file_types)
         else:
             return False
     except:
         return False
Ejemplo n.º 9
0
 def enabled(self):
     try:
         fw = IFileWrapper(self.context)
         if fw.has_enclosure:
             if self.context.getLayout() == 'documentviewer':
                 return True
             else:
                 return allowedDocumentType(self.context,
                     GlobalSettings(
                         getPortal(self.context)).auto_layout_file_types)
         else:
             return False
     except:
         return False
Ejemplo n.º 10
0
def handle_file_creation(object, event):
    qi = getToolByName(object, 'portal_quickinstaller')
    if not qi.isProductInstalled('collective.documentviewer'):
        return

    site = getPortal(object)
    gsettings = GlobalSettings(site)

    if not allowedDocumentType(object, gsettings.auto_layout_file_types):
        return

    auto_layout = gsettings.auto_select_layout
    if auto_layout and object.getLayout() != 'documentviewer':
        object.setLayout('documentviewer')

    if object.getLayout() == 'documentviewer' and gsettings.auto_convert:
        queueJob(object)
Ejemplo n.º 11
0
def convert_all(only_unconverted=True):
    """Convert all files.
    Defaults to convert only files, which haven't been converted yet.
    """
    site = getSite()

    qi = getToolByName(site, 'portal_quickinstaller', None)
    if not qi:
        return
    if not qi.isProductInstalled('collective.documentviewer'):
        return
    if getRequest().get('plone.app.contenttypes_migration_running', False):
        """Don't migrate while running a plone.app.contenttypes migration.
        """
        return

    cat = getToolByName(site, 'portal_catalog')
    res = cat(portal_type='File')
    length = len(res)

    async_enabled = celeryInstalled()

    for cnt, item in enumerate(res, 1):

        logger.info('processing %s/%s', cnt, length)

        obj = item.getObject()

        settings = Settings(obj)
        if only_unconverted and settings.successfully_converted:
            continue

        gsettings = GlobalSettings(site)

        if not allowedDocumentType(obj, gsettings.auto_layout_file_types):
            continue

        auto_layout = gsettings.auto_select_layout
        if auto_layout and obj.getLayout() != 'documentviewer':
            obj.setLayout('documentviewer')

        if obj.getLayout() == 'documentviewer' and gsettings.auto_convert:
            queueJob(obj)
            if not async_enabled:
                # conversion lasts an eternity. commit the results immediately.
                transaction.commit()
Ejemplo n.º 12
0
def is_allowed_document_type(obj):
    """ Check if object can actually be converted

    :param obj: The Plone object to get previews for
    :type obj: A Plone content object
    :return: True if object can be converted
    :rtype: boolean
    """
    site = getPortal(obj)
    gsettings = GlobalSettings(site)
    try:
        return allowedDocumentType(obj, gsettings.auto_layout_file_types)
    except MimeTypeException as e:
        log.warning(
            'Mimetype issue for %r: %s',
            obj,
            e,
        )
        return False
def handle_file_creation(obj, event):
    if _should_skip_handler(obj):
        return

    req = getRequest()
    if req is not None and not ILayer.providedBy(req):
        return

    gsettings = GlobalSettings(api.portal.get())

    if not allowedDocumentType(obj, gsettings.auto_layout_file_types):
        return

    auto_layout = gsettings.auto_select_layout
    if auto_layout and obj.getLayout() != 'documentviewer':
        obj.setLayout('documentviewer')

    if obj.getLayout() == 'documentviewer' and gsettings.auto_convert:
        queueJob(obj)
def handle_file_creation(obj, event):
    if _should_skip_handler(obj):
        return
    qi = getToolByName(obj, 'portal_quickinstaller', None)
    if not qi:
        return
    if not qi.isProductInstalled('collective.documentviewer'):
        return

    gsettings = GlobalSettings(api.portal.get())

    if not allowedDocumentType(obj, gsettings.auto_layout_file_types):
        return

    auto_layout = gsettings.auto_select_layout
    if auto_layout and obj.getLayout() != 'documentviewer':
        obj.setLayout('documentviewer')

    if obj.getLayout() == 'documentviewer' and gsettings.auto_convert:
        queueJob(obj)
Ejemplo n.º 15
0
def generate_previews(obj, event=None):
    """ Generate the previews for a content type. We need our own subscriber as
    c.dv insists on checking for its custom layout. Also we want our own async
    mechanism, it is using this method.

    :param obj: The Plone content object to get preview URLs for
    :type obj: A Plone content object
    :return: Does not return anything.
    :rtype: None
    """
    site = getPortal(obj)
    gsettings = GlobalSettings(site)

    if not allowedDocumentType(obj, gsettings.auto_layout_file_types):
        return

    if gsettings.auto_convert:
        # ASYNC HERE
        converter = Converter(obj)
        if not converter.can_convert:
            return
        converter()
Ejemplo n.º 16
0
    def get_previews(self, obj):
        if IImage.providedBy(obj):
            return {
                'class': '',
                'url': '{}/@@images/image'.format(obj.absolute_url()),
                'page_count': 1,
                'has_preview': True,
            }
        portal = api.portal.get()
        gsettings = GlobalSettings(portal)

        preview_details = {'class': 'not-generated', 'has_preview': False}
        if not allowedDocumentType(obj, gsettings.auto_layout_file_types):
            preview_details['class'] = 'not-possible'
        elif previews.has_previews(obj):
            preview_urls = previews.get_preview_urls(obj)
            if preview_urls:
                preview_details = {
                    'class': '',
                    'url': preview_urls[0],
                    'page_count': len(preview_urls),
                    'has_preview': True,
                }
        return preview_details