def show_parent(self):
     """ Do not show parent if you are on navigationroot.
     """
     if IPloneSiteRoot.providedBy(self.context):
         return False
     elif self.is_default_page and IPloneSiteRoot.providedBy(aq_parent(aq_inner(self.context))):
         return False
     return True
Beispiel #2
0
 def show_parent(self):
     """ Do not show parent if you are on navigationroot.
     """
     if IPloneSiteRoot.providedBy(self.context):
         return False
     elif self.is_default_page and \
             IPloneSiteRoot.providedBy(aq_parent(aq_inner(self.context))):
         return False
     return True
def listPloneSites(context):
    out = []
    for item in context.values():
        if IPloneSiteRoot.providedBy(item):
            out.append(item)
        if IFolder.providedBy(item):
            for site in item.values():
                if IPloneSiteRoot.providedBy(site):
                    out.append(site)
    return out
Beispiel #4
0
    def __call__(self, expand=False):
        root_interface = self.get_root_interface()
        content_interfaces = self.get_content_interfaces()

        if self.request.form.get('include_root'):
            content_interfaces.append(root_interface)

        context = self.context

        if root_interface not in content_interfaces:
            while (not root_interface.providedBy(context)
                   and not IPloneSiteRoot.providedBy(context)):
                context = aq_parent(context)
        else:
            # This happens i.e. on lookup a dossier tree from a subdossier.
            #
            # The current context is the subdossier which is also
            # providing the root_interface. We have to get sure, that we return
            # the most upper object providing the given root_interface if
            # the root_interface is within `content_interfaces`
            current = context
            while (not IPloneSiteRoot.providedBy(current)):
                if root_interface.providedBy(current):
                    context = current
                current = aq_parent(current)

        if root_interface.providedBy(context):
            root = context
        else:
            roots = api.content.find(
                object_provides=root_interface.__identifier__)
            if roots:
                root = roots[0].getObject()
            else:
                root = None

        result = {
            'navigation': {
                '@id': '{}/@navigation'.format(root.absolute_url()),
            },
        }
        if not expand:
            return result

        items = api.content.find(
            object_provides=content_interfaces,
            path='/'.join(root.getPhysicalPath()),
            sort_on='sortable_title',
        )

        nodes = map(self.brain_to_node, items)
        result['navigation']['tree'] = make_tree_by_url(nodes)

        return result
Beispiel #5
0
    def __call__(self, expand=False):
        root_interface = self.get_root_interface()
        content_interfaces = self.get_content_interfaces()

        if self.request.form.get('include_root'):
            content_interfaces.append(root_interface)

        context = self.context

        if root_interface not in content_interfaces:
            while (not root_interface.providedBy(context)
                   and not IPloneSiteRoot.providedBy(context)):
                context = aq_parent(context)
        else:
            # This happens i.e. on lookup a dossier tree from a subdossier.
            #
            # The current context is the subdossier which is also
            # providing the root_interface. We have to get sure, that we return
            # the most upper object providing the given root_interface if
            # the root_interface is within `content_interfaces`
            current = context
            while (not IPloneSiteRoot.providedBy(current)):
                if root_interface.providedBy(current):
                    context = current
                current = aq_parent(current)

        if root_interface.providedBy(context):
            root = context
        else:
            roots = api.content.find(
                object_provides=root_interface.__identifier__)
            if roots:
                root = roots[0].getObject()
            else:
                root = None

        result = {
            'navigation': {
                '@id': '{}/@navigation'.format(root.absolute_url()),
            },
        }
        if not expand:
            return result

        items = api.content.find(
            object_provides=content_interfaces,
            path='/'.join(root.getPhysicalPath()),
            sort_on='sortable_title',
        )

        nodes = map(self.brain_to_node, items)
        result['navigation']['tree'] = make_tree_by_url(nodes)

        return result
Beispiel #6
0
def find_parent_dossier(content):
    """Returns the first parent dossier relative to the current context.
    """

    if IPloneSiteRoot.providedBy(content):
        raise ValueError('Site root passed as argument.')

    while content and not IDossierMarker.providedBy(content):
        content = aq_parent(aq_inner(content))
        if IPloneSiteRoot.providedBy(content):
            raise ValueError('Site root reached while searching '
                             'parent dossier.')
    return content
Beispiel #7
0
def find_parent_dossier(content):
    """Returns the first parent dossier relative to the current context.
    """

    if IPloneSiteRoot.providedBy(content):
        raise ValueError('Site root passed as argument.')

    while content and not IDossierMarker.providedBy(content):
        content = aq_parent(aq_inner(content))
        if IPloneSiteRoot.providedBy(content):
            raise ValueError('Site root reached while searching '
                             'parent dossier.')
    return content
Beispiel #8
0
def find_context(context, viewname=None, iface=None,
                 as_url=False, append_view=True):
    """Find the next context with a given view name or interface, up in the
    content tree, starting from the given context. This might not be the
    IPloneSiteRoot, but another subsite.

    :param context: The context to start the search from.
    :param viewname: (optional) The name of a view which a context should have
                     configured as defaultView.
    :param iface: (optional) The interface, the context to search for should
                  implement.
    :param as_url: (optional) Return the URL of the context found.
    :param append_view: (optional) In case of a given viewname and called with
                        as_url, append the viewname to the url, if the context
                        hasn't configured it as defaultView. Otherwise ignore
                        this parameter.
    :returns: A context with the given view name, inteface or ISite root.
    """
    context = aq_inner(context)
    ret = None
    if viewname and context.defaultView() == viewname\
       or iface and iface.providedBy(context)\
       or IPloneSiteRoot.providedBy(context):
        # Search for viewname or interface but stop at IPloneSiteRoot
        ret = context
    else:
        ret = find_context(aq_parent(context), viewname=viewname, iface=iface,
                           as_url=False, append_view=False)
    if as_url:
        url = ret.absolute_url()
        if viewname and append_view and ret.defaultView() != viewname:
            url = '%s/%s' % (url, viewname)
        return url
    return ret
Beispiel #9
0
    def __init__(self, context, interfaces=[IGallerySettings]):
        """
        The interfaces argument allows you to customize which
        interface these settings implemenet.
        """
        self.context = context

        self._interfaces = interfaces
        if type(self._interfaces) not in (list, tuple):
            self._interfaces = [self._interfaces]
        self._interfaces = list(self._interfaces)
        if IGallerySettings not in self._interfaces:
            self._interfaces.append(IGallerySettings)
        if None in self._interfaces:
            self._interfaces.remove(None)

        from collective.plonetruegallery.utils import convertMeasurementToInt
        self._inline_conversions = {
            'nivoslider_width': convertMeasurementToInt,
            'nivoslider_height': convertMeasurementToInt
        }

        self.storage = AnnotationStorage(context)
        if not IPloneSiteRoot.providedBy(context):
            site = getToolByName(context, 'portal_url').getPortalObject()
            self.default_settings = GallerySettings(site,
                interfaces=interfaces)
        else:
            self.default_settings = None
Beispiel #10
0
 def getOrdering(self):
     if IPloneSiteRoot.providedBy(self.context):
         return self.context
     if getattr(self.context, "getOrdering", None):
         ordering = self.context.getOrdering()
         if IExplicitOrdering.providedBy(ordering):
             return ordering
def _supports_explicit_ordering(context):
    if IPloneSiteRoot.providedBy(context):
        return True
    if not IOrderableFolder.providedBy(context):
        return False
    ordering = context.getOrdering()
    return IExplicitOrdering.providedBy(ordering)
    def __init__(self, context, interfaces=[IGallerySettings]):
        """
        The interfaces argument allows you to customize which
        interface these settings implemenet.
        """
        self.context = context

        self._interfaces = interfaces
        if type(self._interfaces) not in (list, tuple):
            self._interfaces = [self._interfaces]
        self._interfaces = list(self._interfaces)
        if IGallerySettings not in self._interfaces:
            self._interfaces.append(IGallerySettings)
        if None in self._interfaces:
            self._interfaces.remove(None)

        from collective.plonetruegallery.utils import convertMeasurementToInt
        self._inline_conversions = {
            'nivoslider_width': convertMeasurementToInt,
            'nivoslider_height': convertMeasurementToInt
        }

        self.storage = AnnotationStorage(context)
        if not IPloneSiteRoot.providedBy(context):
            site = getToolByName(context, 'portal_url').getPortalObject()
            self.default_settings = GallerySettings(site,
                                                    interfaces=interfaces)
        else:
            self.default_settings = None
Beispiel #13
0
    def replace_interactive_user(self, principal):
        """Replaces interactive users in the principal.
        """

        if principal == 'responsible':
            # find the dossier
            dossier = self.context
            while not IDossierMarker.providedBy(dossier):
                if IPloneSiteRoot.providedBy(dossier):
                    raise ValueError('Could not find dossier')
                dossier = aq_parent(aq_inner(dossier))
            # get the responsible of the dossier
            wrapped_dossier = IDossier(dossier)
            return wrapped_dossier.responsible

        elif principal == 'current_user':
            # get the current user
            mtool = getToolByName(self.context, 'portal_membership')
            member = mtool.getAuthenticatedMember()
            if not member:
                raise Unauthorized()
            return member.getId()

        else:
            return principal
Beispiel #14
0
    def collection(self):
        context = None
        portal_state = getMultiAdapter((self.context, self.request),
                                       name=u'plone_portal_state')
        portal = portal_state.portal()
        
        if (IPloneSiteRoot.providedBy(self.context) or
            IATTopic.providedBy(self.context)):
            self.kind = 'all'
            collection = 'todas-las-noticias'
            context = portal

        if INITF.providedBy(self.context):
            self.kind = 'section'
            normalizer = getUtility(IIDNormalizer)
            collection = normalizer.normalize(self.context.section)
            context = portal.get('noticias', None)

        if not context:
            return None

        result = context.get(collection, None)

        if result is not None:
            sm = getSecurityManager()
            if not sm.checkPermission('View', result):
                result = None

        return result
def get_site(zopeapp=None):
    # if 'PROJECT_ID' in os.environ:
    #     plone_path = os.environ['PROJECT_ID']
    #     conf_path = '/home/imio/imio-website/parts/instance/etc/zope.conf'
    # else:
    #     args = parser.parse_args()
    #     plone_path = args.plone_path
    #     conf_path = 'parts/instance/etc/zope.conf'
    # if not plone_path:
    #     return
    # if not zopeapp:
    #     configure(conf_path)
    #     zopeapp = Zope2.app()
    zopeapp = makerequest.makerequest(app)  # noqa
    zopeapp.REQUEST['PARENTS'] = [app]  # noqa
    setRequest(zopeapp.REQUEST)
    # newSecurityManager(None, user)
    user = app.acl_users.getUser('admin')  # noqa
    newSecurityManager(None, user.__of__(app.acl_users)) # noqa
    portal = None
    for oid in app.objectIds():  # noqa
        obj = app[oid] # noqa
        if IPloneSiteRoot.providedBy(obj):
            portal = obj
    if not portal:
        raise('Do not find portal')
    return portal
Beispiel #16
0
    def __call__(self, context):
        types_tool = api.portal.get_tool('portal_types')

        types_to_check = types_tool.objectIds()

        licence_config = None
        parent = context
        while not IPloneSiteRoot.providedBy(parent):
            parent = parent.aq_parent
            if ILicenceConfig.providedBy(parent):
                licence_config = parent

        # make sure to only return types allowed for this EventConfig licence
        if licence_config:
            for type_definition in types_tool.objectValues():
                if type_definition.id.lower() == licence_config.id:
                    types_to_check = [
                        t for t in types_to_check
                        if t in type_definition.allowed_content_types
                    ]
                    break

        terms = []
        for type_id in types_to_check:
            klass = get_portal_type_class(type_id)
            if klass and issubclass(klass, UrbanEvent):
                terms.append(SimpleTerm(type_id, type_id, _(type_id)))

        vocabulary = SimpleVocabulary(terms)
        return vocabulary
Beispiel #17
0
    def header(self):
        self.disabled = None
        self.enabled = None

        parent = aq_inner(self.context)
        while True:
            try:
                if not self.enabled and not self.disabled and IAnnotations(parent).get(ANNOTATIONS_KEY_DISABLED, False):
                    self.disabled = parent
                if not self.disabled and not self.enabled and IAnnotations(parent).get(ANNOTATIONS_KEY_ENABLED, False):
                    self.enabled = parent
            except:
                pass
            brain = self.catalog(object_provides=IHeader.__identifier__,
                                 path={'query': '/'.join(parent.getPhysicalPath()),'depth': 1})
            if len(brain) or IPloneSiteRoot.providedBy(parent) or not self.props.getProperty('header_allow_inheritance', True):
                break
            else:
                parent = aq_parent(parent)
        if not len(brain):
            return
        
        """take the first header-element
        """
        return brain[0]
Beispiel #18
0
    def __call__(self, context):
        """ gets main-dossier path and put it to the navigation_tree_query """
        dossier_path = ''
        parent = context
        while not IPloneSiteRoot.providedBy(parent) and \
                parent.portal_type != 'opengever.repository.repositoryfolder':
            dossier_path = '/'.join(parent.getPhysicalPath())
            parent = aq_parent(aq_inner(parent))
        if not self.navigation_tree_query:
            self.navigation_tree_query = {}

        self.navigation_tree_query['path'] = {'query': dossier_path}

        # Extend path in selectable_filter, to make sure only objects
        # inside the current dossier are selectable.
        self.selectable_filter.criteria['path'] = {'query': dossier_path}

        source = self.path_source(
            context,
            selectable_filter=self.selectable_filter,
            navigation_tree_query=self.navigation_tree_query)

        # The path source bases on the navtree strategy, which adds a
        # portal_type query option, which disables all types not-to-list
        # in the navigation. This is not a navigation - so remove this
        # limitation.
        del source.navigation_tree_query['portal_type']

        return source
Beispiel #19
0
    def __call__(self, context):
        """ gets main-dossier path and put it to the navigation_tree_query """
        dossier_path = ''
        parent = context
        while not IPloneSiteRoot.providedBy(parent) and \
                parent.portal_type != 'opengever.repository.repositoryfolder':
            dossier_path = '/'.join(parent.getPhysicalPath())
            parent = aq_parent(aq_inner(parent))
        if not self.navigation_tree_query:
            self.navigation_tree_query = {}

        self.navigation_tree_query['path'] = {'query': dossier_path}

        # Extend path in selectable_filter, to make sure only objects
        # inside the current dossier are selectable.
        self.selectable_filter.criteria['path'] = {'query': dossier_path}

        source = self.path_source(
            context,
            selectable_filter=self.selectable_filter,
            navigation_tree_query=self.navigation_tree_query)

        # The path source bases on the navtree strategy, which adds a
        # portal_type query option, which disables all types not-to-list
        # in the navigation. This is not a navigation - so remove this
        # limitation.
        del source.navigation_tree_query['portal_type']

        return source
Beispiel #20
0
def get_containing_dossier(obj):
    while not IPloneSiteRoot.providedBy(obj):
        if IDossierMarker.providedBy(obj) or IInbox.providedBy(obj):
            return obj
        obj = aq_parent(aq_inner(obj))

    return None
Beispiel #21
0
def get_specific_parent(startobj, criteria):
    """Finds a specific parent for the startobj

    Criteria is a callable. For example:
    >>> criteria = lambda o: ISpecification.providedBy(o)

    If nothing is found, raise ValueError
    """

    parent = startobj
    find = None
    while not criteria(parent):
        try:
            parent = aq_parent(aq_inner(parent))
        except AttributeError:
            raise ValueError
        if IPloneSiteRoot.providedBy(parent):
            raise ValueError

    if criteria(parent):  #doublecheck just to make sure
        find = parent

    if find is None:
        raise ValueError

    return find
Beispiel #22
0
    def page_title(self):
        if IPloneSiteRoot.providedBy(self.context):
            return {
                'search' : 'Search'
            }.get(self.template, u'')

        return super(TitleViewlet, self).page_title
Beispiel #23
0
    def update(self):

        # Assign image URL and mime type
        image_url = image_mime_type = ''

        # Look up through the acquisition chain until we hit a Plone site
        for _ in self.context.aq_chain:
            if IPloneSiteRoot.providedBy(_):
                break

            (image_url, image_mime_type) = self.get_image_info(_)

            if image_url:
                break

        # Fallback
        if not image_url:
            image_url = "%s/++resource++agsci.common/assets/images/social-media-site-graphic.png" % self.context.portal_url()

        (self.fb_image, self.link_mime_type) = (image_url, image_mime_type)

        self.link_metadata_image = self.fb_image

        # FB Titles
        titles = self.site_title_data

        if len(titles) == 3:
            self.fb_site_name = u'%s (%s)' % tuple(titles[1:3])
            self.fb_title = u'%s (%s)' % tuple(titles[0:2])

        elif len(titles) == 2:
            self.fb_title = self.fb_site_name = u'%s (%s)' % tuple(titles[0:2])

        else:
            self.fb_title = self.fb_site_name = titles[0]
Beispiel #24
0
    def collection(self):
        context = None
        portal_state = getMultiAdapter((self.context, self.request),
                                       name=u'plone_portal_state')
        portal = portal_state.portal()

        if (IPloneSiteRoot.providedBy(self.context)
                or IATTopic.providedBy(self.context)):
            self.kind = 'all'
            collection = 'todas-las-noticias'
            context = portal

        if INITF.providedBy(self.context):
            self.kind = 'section'
            normalizer = getUtility(IIDNormalizer)
            collection = normalizer.normalize(self.context.section)
            context = portal.get('noticias', None)

        if not context:
            return None

        result = context.get(collection, None)

        if result is not None:
            sm = getSecurityManager()
            if not sm.checkPermission('View', result):
                result = None

        return result
Beispiel #25
0
def find_context(context, viewname=None, iface=None,
                 as_url=False, append_view=True):
    """Find the next context with a given view name or interface, up in the
    content tree, starting from the given context. This might not be the
    IPloneSiteRoot, but another subsite.

    :param context: The context to start the search from.
    :param viewname: (optional) The name of a view which a context should have
                     configured as defaultView.
    :param iface: (optional) The interface, the context to search for should
                  implement.
    :param as_url: (optional) Return the URL of the context found.
    :param append_view: (optional) In case of a given viewname and called with
                        as_url, append the viewname to the url, if the context
                        hasn't configured it as defaultView. Otherwise ignore
                        this parameter.
    :returns: A context with the given view name, inteface or ISite root.
    """
    context = aq_inner(context)
    ret = None
    if viewname and context.defaultView() == viewname\
       or iface and iface.providedBy(context)\
       or IPloneSiteRoot.providedBy(context):
        # Search for viewname or interface but stop at IPloneSiteRoot
        ret = context
    else:
        ret = find_context(aq_parent(context), viewname=viewname, iface=iface,
                           as_url=False, append_view=False)
    if as_url:
        url = ret.absolute_url()
        if viewname and append_view and ret.defaultView() != viewname:
            url = '%s/%s' % (url, viewname)
        return url
    return ret
 def find_endpoint(self, obj, lang, types_to_list):
     if not (IFolder.providedBy(obj) or IPloneSiteRoot.providedBy(obj)):
         return obj
     contents = obj.contentIds()
     # TODO: make list reversable
     for cid in contents:
         child = obj[cid]
         # try to get translation if LinguaPlone is installed, child
         # is translatable and child language does not match lang
         if LINGUA_PLONE_INSTALLED:
             if ITranslatable.providedBy(child):
                 child_lang = child.Language()
                 # child lang can be empty string, only try to
                 # translate if explicit lang
                 if child_lang and child_lang != lang:
                     translation = child.getTranslation(lang)
                     if not translation:
                         continue  # ...with next obj in folder
                     child = translation
         # only traverse to allowed objects
         allowed = self.permitted(context=child, permission=VIEW_PERMISSION)
         if not allowed:
             continue
         # only traverse to objects listed in typesToList
         if child.portal_type not in types_to_list:
             continue
         # we've found a published object, which can be used as
         # possible endpoint, except it has 'traverse_view' enabled
         obj = child
         if child.defaultView() == "traverse_view":
             obj = self.find_endpoint(child, lang, types_to_list)
         break
     return obj
    def is_published(self):
        if IPloneSiteRoot.providedBy(self.context):
            return True

        main_obj = get_main_obj_belonging_to(self.context)
        configs = getUtility(IWorkflowConfigs)
        return configs.is_published(main_obj) or self.is_in_revision()
 def orderable(self):
     if _is_collection(self.context):
         return False
     if IPloneSiteRoot.providedBy(self.context):
         return True
     ordering = self.context.getOrdering()
     return IExplicitOrdering.providedBy(ordering)
Beispiel #29
0
    def allowedContentTypes(self, *args, **kwargs):
        types = super(DossierContainer,
                      self).allowedContentTypes(*args, **kwargs)
        # calculate depth
        depth = 0
        obj = self
        while IDossierMarker.providedBy(obj):
            depth += 1
            obj = aq_parent(aq_inner(obj))
            if IPloneSiteRoot.providedBy(obj):
                break

        # the adapter decides
        def filter_type(fti):
            # first we try the more specific one ...
            decider = queryMultiAdapter((self.REQUEST, self, fti),
                                        IConstrainTypeDecider,
                                        name=fti.portal_type)
            if not decider:
                # .. then we try the more general one
                decider = queryMultiAdapter((self.REQUEST, self, fti),
                                            IConstrainTypeDecider)
            if decider:
                return decider.addable(depth)
            # if we don't have an adapter, we just allow it
            return True

        # filter
        return filter(filter_type, types)
Beispiel #30
0
def get_specific_parent(startobj, criteria):
    """Finds a specific parent for the startobj

    Criteria is a callable. For example:
    >>> criteria = lambda o: ISpecification.providedBy(o)

    If nothing is found, raise ValueError
    """

    parent = startobj
    find = None
    while not criteria(parent):
        try:
            parent = aq_parent(aq_inner(parent))
        except AttributeError:
            raise ValueError
        if IPloneSiteRoot.providedBy(parent):
            raise ValueError

    if criteria(parent): #doublecheck just to make sure
        find = parent

    if find is None:
        raise ValueError

    return find
Beispiel #31
0
    def allowedContentTypes(self, *args, **kwargs):
        types = super(
            DossierContainer, self).allowedContentTypes(*args, **kwargs)
        # calculate depth
        depth = 0
        obj = self
        while IDossierMarker.providedBy(obj):
            depth += 1
            obj = aq_parent(aq_inner(obj))
            if IPloneSiteRoot.providedBy(obj):
                break

        # the adapter decides
        def filter_type(fti):
            # first we try the more specific one ...
            decider = queryMultiAdapter((self.REQUEST, self, fti),
                                    IConstrainTypeDecider,
                                    name=fti.portal_type)
            if not decider:
                # .. then we try the more general one
                decider = queryMultiAdapter((self.REQUEST, self, fti),
                                        IConstrainTypeDecider)
            if decider:
                return decider.addable(depth)
            # if we don't have an adapter, we just allow it
            return True
        # filter
        return filter(filter_type, types)
Beispiel #32
0
    def replace_interactive_user(self, principal):
        """Replaces interactive users in the principal.
        """

        if principal == 'responsible':
            # find the dossier
            dossier = self.context
            while not IDossierMarker.providedBy(dossier):
                if IPloneSiteRoot.providedBy(dossier):
                    raise ValueError('Could not find dossier')
                dossier = aq_parent(aq_inner(dossier))
            # get the responsible of the dossier
            wrapped_dossier = IDossier(dossier)
            return wrapped_dossier.responsible

        elif principal == 'current_user':
            # get the current user
            mtool = getToolByName(self.context, 'portal_membership')
            member = mtool.getAuthenticatedMember()
            if not member:
                raise Unauthorized()
            return member.getId()

        else:
            return principal
Beispiel #33
0
def run(app):
    singleton.SingleInstance('crawler')

    app = spoof_request(app)  # noqa
    login_as_admin(app)  # noqa

    count = 0

    while True:
        try:
            if 'site-id' in sys.argv:
                siteid = sys.argv['site-id']
                setup_site(app[siteid])
                crawl_site(app[siteid])  # noqa
            else:
                for oid in app.objectIds():  # noqa
                    obj = app[oid]  # noqa
                    if IPloneSiteRoot.providedBy(obj):
                        try:
                            setup_site(obj)
                            obj._p_jar.sync()
                            crawl_site(obj, count % 10 == 0)
                        except Exception:
                            logger.error('Error crawling site %s' % oid,
                                         exc_info=True)
        except KeyError:
            pass
        except Exception:
            logger.error('Error setting up crawling', exc_info=True)

        logger.info('Waiting to crawl again')
        time.sleep(10 * 60)
        count += 1
Beispiel #34
0
 def publishTraverse(self, request, name):
     if not IPloneSiteRoot.providedBy(self.context):
         # stop traversing
         request['TraversalRequestNameStack'] = []
         # return angular app view
         return AngularAppRootView(self.context, self.request)()
     return super(AngularAppRedirectorTraverser,
                  self).publishTraverse(request, name)
Beispiel #35
0
def get_uid(content):
    """Return content identifier to use in ES.
    """
    if IPloneSiteRoot.providedBy(content):
        uid = 'root'
    else:
        uid = content.UID()
    return uid or None
def get_uid(content):
    """Return content identifier to use in ES.
    """
    if IPloneSiteRoot.providedBy(content):
        uid = 'root'
    else:
        uid = content.UID()
    return uid or None
Beispiel #37
0
    def __call__(self, config):
        if IPloneSiteRoot.providedBy(self.context):
            return {}

        parent = aq_parent(aq_inner(self.context))
        return {'parent': {'@url': parent.absolute_url() + '/api/metadata',
                           'id': parent.getId(),
                           'title': parent.Title()}}
Beispiel #38
0
def getOrdering(context):
    if IPloneSiteRoot.providedBy(context):
        return context
    else:
        ordering = context.getOrdering()
        if not IExplicitOrdering.providedBy(ordering):
            return None
        return ordering
Beispiel #39
0
 def getOrdering(self):
     if IPloneSiteRoot.providedBy(self.context):
         return self.context
     elif getattr(self.context, 'getOrdering', None):
         ordering = self.context.getOrdering()
         if not IExplicitOrdering.providedBy(ordering):
             return None
         return ordering
Beispiel #40
0
def getOrdering(context):
    if IPloneSiteRoot.providedBy(context):
        return context
    else:
        ordering = context.getOrdering()
        if not IExplicitOrdering.providedBy(ordering):
            return None
        return ordering
Beispiel #41
0
def get_popularity(site):
    setSite(site)
    catalog = api.portal.get_tool('portal_catalog')
    es = ElasticSearchCatalog(catalog)
    if not es.enabled:
        return

    service = analytics.get_ga_service()
    if not service:
        return

    profile = analytics.get_ga_profile(service)
    if not profile:
        return

    bulk_data = []
    bulk_size = es.get_setting('bulk_size', 50)
    conn = es.connection

    site._p_jar.sync()
    for path, page_views in get_results(service, profile)['rows']:
        path = path.split('?')[0].lstrip('/').replace('/view',
                                                      '').split('@@')[0]
        ob = site.restrictedTraverse(str(path), None)
        if ob is None:
            continue

        annotations = IAnnotations(ob)
        data = {'page_views': int(page_views)}
        counts = annotations.get(COUNT_ANNOTATION_KEY, OOBTree())
        counts['page_views'] = int(page_views)
        annotations[COUNT_ANNOTATION_KEY] = counts
        for key, value in counts.items():
            if key in ('page_views', ):
                continue
            data[key + '_shares'] = value

        if IPloneSiteRoot.providedBy(ob):
            ob = ob[get_default_page(ob)]

        bulk_data.extend([{
            'update': {
                '_index': es.index_name,
                '_id': IUUID(ob)
            }
        }, {
            'doc': data
        }])

        if len(bulk_data) % bulk_size == 0:
            conn.bulk(index=es.index_name, body=bulk_data)
            bulk_data = []
            transaction.commit()
            site._p_jar.sync()

    if len(bulk_data) > 0:
        conn.bulk(index=es.index_name, body=bulk_data)
    transaction.commit()
    def parent_category(self):

        for o in self.context.aq_chain:

            if IPloneSiteRoot.providedBy(o):
                break

            elif IAtlasStructure.providedBy(o):
                return o
 def _getSubSiteParentFolder(self):
     """Return the first parent folder found that implements the interface IMonetCalendarSearchRoot"""
     for parent in aq_chain(aq_inner(self.context)):
         if IMonetCalendarSearchRoot.providedBy(parent):
             return parent
         # If linguaplone is there we need to stop before reaching the site, but onto the en/es/it folders...
         if INavigationRoot.providedBy(parent) and not IPloneSiteRoot.providedBy(parent):
             return parent
     return None
    def update(self):
        portal = api.portal.get()
        if IPloneSiteRoot.providedBy(portal):
            annotations = IAnnotations(portal)
            field = self.fields['newsflash'].field
            field.default = annotations.get('collective.newsflash.newsflash', [])

        # call the base class version - this is very important!
        super(NewsFlashEditForm, self).update()
    def all_parent_categories(self):

        for o in self.context.aq_chain:

            if IPloneSiteRoot.providedBy(o):
                break

            elif IAtlasStructure.providedBy(o):
                yield o
Beispiel #46
0
    def initial_site_area_filter(self):
        if 'facet.field' in self.request.form:
            return None
        obj = aq_inner(self.context)

        if IPloneSiteRoot.providedBy(api.portal.get_navigation_root(obj)):
            return None
        else:
            return site_area_indexer(obj)()
Beispiel #47
0
def top_dossier_title(obj):
    """return the tilte of the top containing dossier."""
    dossier_title = ''
    while not IPloneSiteRoot.providedBy(obj):
        if IDossierMarker.providedBy(
            obj) or obj.portal_type == 'opengever.inbox.inbox':
            dossier_title = obj.Title()
        obj = aq_parent(aq_inner(obj))
    return dossier_title
Beispiel #48
0
    def enabled(self):

        for i in aq_chain(self.context):

            if IInspectletEnabled.providedBy(i):
                return True

            if IPloneSiteRoot.providedBy(i):
                break
Beispiel #49
0
 def items(self):
     query = {
         'sort_on': 'effective',
         'sort_order': 'descending',
     }
     if IPloneSiteRoot.providedBy(self.context):
         query['object_provides'] = ITopPageFeed.__identifier__
     else:
         query['object_provides'] = IMicroSiteFeed.__identifier__
     return self._items(**query)
 def publishTraverse(self, request, name):
     if not IPloneSiteRoot.providedBy(self.context):
         # stop traversing
         request['TraversalRequestNameStack'] = []
         # return angular app view
         return AngularAppRootView(self.context, self.request)()
     return super(AngularAppRedirectorTraverser, self).publishTraverse(
         request,
         name
     )
Beispiel #51
0
 def _get_dossier_depth(self):
     # calculate depth
     depth = 0
     obj = self
     while IDossierMarker.providedBy(obj):
         depth += 1
         obj = aq_parent(aq_inner(obj))
         if IPloneSiteRoot.providedBy(obj):
             break
     return depth
    def __call__(self):
        # Disable theming for ajax requests
        self.request.response.setHeader('X-Theme-Disabled', 'True')

        self.parent = None
        if not IPloneSiteRoot.providedBy(self.context):
            self.parent = aq_parent(aq_inner(self.context))
        self.children = self.sub_objects(self.context)

        return self.template()
Beispiel #53
0
    def getBlogRoot(self, context):
        obj = context

        while not IPloneSiteRoot.providedBy(obj):
            if IBlog.providedBy(obj):
                return obj
            else:
                obj = aq_parent(aq_inner(obj))

        return None
Beispiel #54
0
 def items(self):
     query = {
         'sort_on': 'effective',
         'sort_order': 'descending',
     }
     if IPloneSiteRoot.providedBy(self.context):
         query['object_provides'] = ITopPageFeed.__identifier__
     else:
         query['object_provides'] = IMicroSiteFeed.__identifier__
     return self._items(**query)
def run(app):
    singleton.SingleInstance('forcedpublishalert')

    user = app.acl_users.getUser('admin')  # noqa
    newSecurityManager(None, user.__of__(app.acl_users))  # noqa

    for oid in app.objectIds():  # noqa
        obj = app[oid]  # noqa
        if IPloneSiteRoot.providedBy(obj):
            check_site(obj)
Beispiel #56
0
    def find_dossier(self):
        obj = self.context

        while not IPloneSiteRoot.providedBy(obj):
            if IDossierMarker.providedBy(obj):
                return obj
            else:
                obj = aq_parent(aq_inner(obj))

        return None
Beispiel #57
0
def run(app):
    singleton.SingleInstance('socialcounts')

    user = app.acl_users.getUser('admin')  # noqa
    newSecurityManager(None, user.__of__(app.acl_users))  # noqa

    for oid in app.objectIds():  # noqa
        obj = app[oid]  # noqa
        if IPloneSiteRoot.providedBy(obj):
            retrieve(obj)