예제 #1
0
    def dv_data(self):
        dump_path = DUMP_FILENAME.rsplit('.', 1)[0]

        if self.global_settings.show_contributor:
            if self.global_settings.override_contributor:
                contributor = self.global_settings.override_contributor
            else:
                contributor = self.context.Creator()

                mtool = getToolByName(self.context, 'portal_membership')
                contributor_user = mtool.getMemberById(contributor)
                if contributor_user is not None:
                    contributor = contributor_user.getProperty('fullname', None) \
                        or contributor

            if self.global_settings.override_organization:
                organization = self.global_settings.override_organization
            else:
                organization = self.site.title
        else:
            contributor = organization = ''

        image_format = self.settings.pdf_image_format
        if not image_format:
            # oops, this wasn't set like it should have been
            # on alpha release. We'll default back to global
            # setting.
            image_format = self.global_settings.pdf_image_format

        return {
            'access': 'public',
            'annotations': self.annotations(),
            'sections': list(self.sections()),
            'canonical_url': self.context.absolute_url() + '/view',
            'created_at': DateTime(self.context.CreationDate()).aCommonZ(),
            'data': {},
            'description': self.context.Description(),
            'id': self.context.UID(),
            'pages': self.settings.num_pages,
            'updated_at': DateTime(self.context.ModificationDate()).aCommonZ(),
            'title': self.context.Title(),
            'source': '',
            "contributor": contributor,
            "contributor_organization": organization,
            'resources': {
                'page': {
                    'image': '%s/{size}/%s_{page}.%s' % (
                        self.dvpdffiles, dump_path,
                        image_format),
                    'text': '%s/%s/%s_{page}.txt' % (
                        self.dvpdffiles, TEXT_REL_PATHNAME, dump_path)
                },
                'pdf': self.context.absolute_url(),
                'thumbnail': '%s/small/%s_1.%s' % (
                    self.dvpdffiles, dump_path,
                    image_format),
                'search': '%s/dv-search.json?q={query}' % (
                    self.context.absolute_url())
            }
        }
예제 #2
0
    def dv_data(self):
        dump_path = DUMP_FILENAME.rsplit('.', 1)[0]

        if self.global_settings.show_contributor:
            if self.global_settings.override_contributor:
                contributor = self.global_settings.override_contributor
            else:
                contributor = self.context.Creator()

                mtool = getToolByName(self.context, 'portal_membership')
                contributor_user = mtool.getMemberById(contributor)
                if contributor_user is not None:
                    contributor = contributor_user.getProperty('fullname', None) \
                        or contributor

            if self.global_settings.override_organization:
                organization = self.global_settings.override_organization
            else:
                organization = self.site.title
        else:
            contributor = organization = ''

        image_format = self.settings.pdf_image_format
        if not image_format:
            # oops, this wasn't set like it should have been
            # on alpha release. We'll default back to global
            # setting.
            image_format = self.global_settings.pdf_image_format

        return {
            'annotations': [],
            'sections': [],
            'access': 'public',
            'canonical_url': self.context.absolute_url() + '/view',
            'created_at': DateTime(self.context.CreationDate()).aCommonZ(),
            'data': {},
            'description': self.context.Description(),
            'id': self.context.UID(),
            'pages': self.settings.num_pages,
            'updated_at': DateTime(self.context.ModificationDate()).aCommonZ(),
            'title': self.context.Title(),
            'source': '',
            "contributor": contributor,
            "contributor_organization": organization,
            'resources': {
                'page': {
                    'image': '%s/{size}/%s_{page}.%s' % (
                        self.dvpdffiles, dump_path,
                        image_format),
                    'text': '%s/%s/%s_{page}.txt' % (
                        self.dvpdffiles, TEXT_REL_PATHNAME, dump_path)
                },
                'pdf': self.context.absolute_url(),
                'thumbnail': '%s/small/%s_1.%s' % (
                    self.dvpdffiles, dump_path,
                    image_format),
                'search': '%s/dv-search.json?q={query}' % (
                    self.context.absolute_url())
            }
        }
예제 #3
0
    def __call__(self):
        self.site = getPortal(self.context)
        self.global_settings = GlobalSettings(self.site)
        self.search_enabled = self.global_settings.show_search_on_group_view

        self.portal_url = getMultiAdapter((self.context, self.request),
            name="plone_portal_state").portal_url()
        self.static_url = '%s/++resource++dv.resources' % (self.portal_url)
        self.resource_url = self.global_settings.override_base_resource_url
        self.dump_path = DUMP_FILENAME.rsplit('.', 1)[0]
        return super(GroupView, self).__call__()
예제 #4
0
    def __call__(self):
        self.site = getPortal(self.context)
        self.global_settings = GlobalSettings(self.site)
        self.search_enabled = self.global_settings.show_search_on_group_view

        self.portal_url = getMultiAdapter((self.context, self.request),
            name="plone_portal_state").portal_url()
        self.static_url = '%s/++resource++dv.resources' % (self.portal_url)
        self.resource_url = self.global_settings.override_base_resource_url
        self.dump_path = DUMP_FILENAME.rsplit('.', 1)[0]
        return super(GroupView, self).__call__()
예제 #5
0
def get_thumbnail_url_by_uid(uid, relative=False):
    site = getSite()
    portal_url = site.portal_url()
    global_settings = GlobalSettings(site)
    resource_url = global_settings.override_base_resource_url
    rel_url = _resource_url_by_uid(uid)
    if resource_url:
        dvpdffiles = '%s/%s' % (resource_url.rstrip('/'),
                                rel_url)
    else:
        dvpdffiles = '%s/%s' % (portal_url, rel_url)
    dump_path = DUMP_FILENAME.rsplit('.', 1)[0]
    image_format = global_settings.pdf_image_format
    thumbnail_url = '%s/small/%s_1.%s' % (
                    dvpdffiles, dump_path,
                    image_format)
    if relative:
        portal = api.portal.get()
        thumbnail_url = thumbnail_url.replace(portal.absolute_url(),
                                              portal.absolute_url(1))
    return thumbnail_url
예제 #6
0
def _get_dv_data(obj):
    """ Access the collective.documentviewer settings of an object and
    return metadata that can be used to retrieve or access a preview
    image.

    :param obj: The Plone content object that has a preview
    :type obj: A Plone content object
    :return: Metadata consisting of canonical_url, number of pages and
    resource urls to preview images and thumbnails.
    :rtype: mapping
    """
    site = getSite()
    global_settings = GlobalSettings(site)
    settings = Settings(obj)
    portal_url = site.portal_url()

    try:
        canonical_url = obj.absolute_url()
    except AttributeError:
        canonical_url = ''  # XXX construct a url to an attachment

    if not hasattr(obj, 'UID') or not settings.successfully_converted:
        # Can't have previews on objects without a UID. Return a
        # minimal datastructure
        return {
            'canonical_url': canonical_url + '/view',
            'pages': settings.num_pages,
            'resources': {
                'page': {
                    'image': fallback_image_url(obj),
                    'text': ''
                },
                'pdf': canonical_url,
                'thumbnail': fallback_image_url(obj),
            }
        }

    resource_url = global_settings.override_base_resource_url
    rel_url = storage.getResourceRelURL(gsettings=global_settings,
                                        settings=settings)
    if resource_url:
        dvpdffiles = '%s/%s' % (resource_url.rstrip('/'),
                                rel_url)
    else:
        dvpdffiles = '%s/%s' % (portal_url, rel_url)
    dump_path = DUMP_FILENAME.rsplit('.', 1)[0]

    image_format = settings.pdf_image_format or \
        global_settings.pdf_image_format

    return {
        'canonical_url': canonical_url + '/view',
        'pages': settings.num_pages,
        'resources': {
            'page': {
                'image': '%s/{size}/%s_{page}.%s' % (
                    dvpdffiles, dump_path,
                    image_format),
                'text': '%s/%s/%s_{page}.txt' % (
                    dvpdffiles, TEXT_REL_PATHNAME, dump_path)
            },
            'pdf': canonical_url,
            'thumbnail': '%s/small/%s_1.%s' % (
                dvpdffiles, dump_path,
                image_format),
        }
    }
예제 #7
0
def _get_dv_data(obj):
    """ Access the collective.documentviewer settings of an object and
    return metadata that can be used to retrieve or access a preview
    image.

    :param obj: The Plone content object that has a preview
    :type obj: A Plone content object
    :return: Metadata consisting of canonical_url, number of pages and
    resource urls to preview images and thumbnails.
    :rtype: mapping
    """
    site = getSite()
    global_settings = GlobalSettings(site)
    settings = Settings(obj)
    portal_url = site.portal_url()

    try:
        canonical_url = obj.absolute_url()
    except AttributeError:
        canonical_url = ''  # XXX construct a url to an attachment

    if not hasattr(obj, 'UID') or not settings.successfully_converted:
        # Can't have previews on objects without a UID. Return a
        # minimal datastructure
        return {
            'canonical_url': canonical_url + '/view',
            'pages': settings.num_pages,
            'resources': {
                'page': {
                    'image': fallback_image_url(obj),
                    'text': ''
                },
                'pdf': canonical_url,
                'thumbnail': fallback_image_url(obj),
            }
        }

    resource_url = global_settings.override_base_resource_url
    rel_url = storage.getResourceRelURL(gsettings=global_settings,
                                        settings=settings)
    if resource_url:
        dvpdffiles = '%s/%s' % (resource_url.rstrip('/'),
                                rel_url)
    else:
        dvpdffiles = '%s/%s' % (portal_url, rel_url)
    dump_path = DUMP_FILENAME.rsplit('.', 1)[0]

    image_format = settings.pdf_image_format or \
        global_settings.pdf_image_format

    return {
        'canonical_url': canonical_url + '/view',
        'pages': settings.num_pages,
        'resources': {
            'page': {
                'image': '%s/{size}/%s_{page}.%s' % (
                    dvpdffiles, dump_path,
                    image_format),
                'text': '%s/%s/%s_{page}.txt' % (
                    dvpdffiles, TEXT_REL_PATHNAME, dump_path)
            },
            'pdf': canonical_url,
            'thumbnail': '%s/small/%s_1.%s' % (
                dvpdffiles, dump_path,
                image_format),
        }
    }