def test_get_default_page_step_3_1(self):
        # 3. Else, look up the attribute default_page on the object, without
        #    acquisition in place
        # 3.1 look for a content in the container with the id, no acquisition!
        self.folder.invokeFactory('Document', 'd1', title=u"Doc 1")
        from Products.CMFPlone.defaultpage import get_default_page

        # set doc d1 must work
        self.folder.default_page = 'd1'
        self.assertEqual('d1', get_default_page(self.folder))

        # set doc d2 must fail and return None
        self.folder.default_page = 'd2'
        self.assertIsNone(get_default_page(self.folder))

        # list of possible values is allowed
        self.folder.default_page = ['d2', 'd1']
        self.assertEqual('d1', get_default_page(self.folder))

        # list of impossible values return None
        self.folder.default_page = ['d2', 'd3']
        self.assertIsNone(get_default_page(self.folder))

        # acquisition check, must not work
        self.folder.invokeFactory('Folder', 'f1', title=u"Sub Folder 1")
        self.folder.f1.invokeFactory('Document', 'd2', title=u"Document 2")
        self.folder.default_page = 'd2'
        self.assertIsNone(get_default_page(self.folder.f1))
Пример #2
0
    def test_get_default_page_step_3_1(self):
        # 3. Else, look up the attribute default_page on the object, without
        #    acquisition in place
        # 3.1 look for a content in the container with the id, no acquisition!
        self.folder.invokeFactory('Document', 'd1', title="Doc 1")
        from Products.CMFPlone.defaultpage import get_default_page

        # set doc d1 must work
        self.folder.default_page = 'd1'
        self.assertEqual('d1', get_default_page(self.folder))

        # set doc d2 must fail and return None
        self.folder.default_page = 'd2'
        self.assertIsNone(get_default_page(self.folder))

        # list of possible values is allowed
        self.folder.default_page = ['d2', 'd1']
        self.assertEqual('d1', get_default_page(self.folder))

        # list of impossible values return None
        self.folder.default_page = ['d2', 'd3']
        self.assertIsNone(get_default_page(self.folder))

        # acquisition check, must not work
        self.folder.invokeFactory('Folder', 'f1', title="Sub Folder 1")
        self.folder.f1.invokeFactory('Document', 'd2', title="Document 2")
        self.folder.default_page = 'd2'
        self.assertIsNone(get_default_page(self.folder.f1))
    def test_get_default_page_step_2(self):
        # Else check for IBrowserDefault, either if the container implements
        # it or if an adapter exists. In both cases fetch its FTI and either
        # take it if it implements IDynamicViewTypeInformation or adapt it to
        # IDynamicViewTypeInformation. call get_default_page on the implementer
        # and take value if given.

        # first check some preconditions
        #
        # 1) a folder provides IBrowserDefault
        from Products.CMFDynamicViewFTI.interfaces import IBrowserDefault
        self.assertTrue(IBrowserDefault.providedBy(self.folder))

        # 2) a folder also provides an fti that implements
        #    IDynamicViewTypeInformation
        from Products.CMFDynamicViewFTI.interfaces import IDynamicViewTypeInformation  # noqa
        fti = self.folder.getTypeInfo()
        self.assertTrue(IDynamicViewTypeInformation.providedBy(fti))

        # so if we set a document as defaultpage
        self.folder.invokeFactory('Document', 'd1', title=u"Doc 1")
        self.folder.setDefaultPage('d1')

        # 3) fti should return it
        self.assertEqual(
            'd1',
            fti.getDefaultPage(self.folder, check_exists=True)
        )

        # now test since we're sure everythings set up correctly
        from Products.CMFPlone.defaultpage import get_default_page
        self.assertEqual('d1', get_default_page(self.folder))
Пример #4
0
    def test_get_default_page_step_3_2(self):
        # 3. Else, look up the attribute default_page on the object, without
        #    acquisition in place
        # 3.2 look for a content at portal, with acquisition
        self.portal.invokeFactory('Document', 'd1', title="Doc 1")
        self.folder.default_page = 'd1'
        from Products.CMFPlone.defaultpage import get_default_page

        # now it must acquire from portal
        self.assertEqual('d1', get_default_page(self.folder))

        # fetch from i.e. portal_skins by acquisition
        # test_rendering.pt is in portal_skins/plone_templates and so available
        # by acquisition
        self.folder.default_page = 'test_rendering'
        self.assertEqual('test_rendering', get_default_page(self.folder))
    def test_get_default_page_step_3_2(self):
        # 3. Else, look up the attribute default_page on the object, without
        #    acquisition in place
        # 3.2 look for a content at portal, with acquisition
        self.portal.invokeFactory('Document', 'd1', title=u"Doc 1")
        self.folder.default_page = 'd1'
        from Products.CMFPlone.defaultpage import get_default_page

        # now it must acquire from portal
        self.assertEqual('d1', get_default_page(self.folder))

        # fetch from i.e. portal_skins by acquisition
        # test_rendering.pt is in portal_skins/plone_templates and so available
        # by acquisition
        self.folder.default_page = 'test_rendering'
        self.assertEqual('test_rendering', get_default_page(self.folder))
Пример #6
0
    def test_get_default_page_step_2(self):
        # Else check for IBrowserDefault, either if the container implements
        # it or if an adapter exists. In both cases fetch its FTI and either
        # take it if it implements IDynamicViewTypeInformation or adapt it to
        # IDynamicViewTypeInformation. call get_default_page on the implementer
        # and take value if given.

        # first check some preconditions
        #
        # 1) a folder provides IBrowserDefault
        from Products.CMFDynamicViewFTI.interfaces import IBrowserDefault
        self.assertTrue(IBrowserDefault.providedBy(self.folder))

        # 2) a folder also provides an fti that implements
        #    IDynamicViewTypeInformation
        from Products.CMFDynamicViewFTI.interfaces import IDynamicViewTypeInformation  # noqa
        fti = self.folder.getTypeInfo()
        self.assertTrue(IDynamicViewTypeInformation.providedBy(fti))

        # so if we set a document as defaultpage
        self.folder.invokeFactory('Document', 'd1', title="Doc 1")
        self.folder.setDefaultPage('d1')

        # 3) fti should return it
        self.assertEqual('d1',
                         fti.getDefaultPage(self.folder, check_exists=True))

        # now test since we're sure everythings set up correctly
        from Products.CMFPlone.defaultpage import get_default_page
        self.assertEqual('d1', get_default_page(self.folder))
    def test_get_default_page_step_1(self):
        # A content object called 'index_html' wins
        self.folder.invokeFactory('Document', 'd1', title=u"Doc 1")
        self.folder.setDefaultPage('d1')
        self.folder.invokeFactory('Document', 'index_html', title=u"Doc 2")

        from Products.CMFPlone.defaultpage import get_default_page
        self.assertEqual('index_html', get_default_page(self.folder))
Пример #8
0
    def test_get_default_page_step_1(self):
        # A content object called 'index_html' wins
        self.folder.invokeFactory('Document', 'd1', title="Doc 1")
        self.folder.setDefaultPage('d1')
        self.folder.invokeFactory('Document', 'index_html', title="Doc 2")

        from Products.CMFPlone.defaultpage import get_default_page
        self.assertEqual('index_html', get_default_page(self.folder))
Пример #9
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 test_get_default_page_step_4(self):
        # 4. Else, look up the property default_page in site_properties for
        #   magic ids and test these
        registry = getUtility(IRegistry)
        registry['plone.default_page'] = [u'd1']
        self.folder.invokeFactory('Document', 'd1', title=u"Doc 1")

        from Products.CMFPlone.defaultpage import get_default_page
        self.assertEqual('d1', get_default_page(self.folder))
    def test_get_default_page_step_4(self):
        # 4. Else, look up the property default_page in site_properties for
        #   magic ids and test these
        sp = self.portal.portal_properties.site_properties
        sp.manage_changeProperties(default_page=('d1',))
        self.folder.invokeFactory('Document', 'd1', title=u"Doc 1")

        from Products.CMFPlone.defaultpage import get_default_page
        self.assertEqual('d1', get_default_page(self.folder))
Пример #12
0
    def test_get_default_page_step_4(self):
        # 4. Else, look up the property default_page in site_properties for
        #   magic ids and test these
        registry = getUtility(IRegistry)
        registry['plone.default_page'] = ['d1']
        self.folder.invokeFactory('Document', 'd1', title="Doc 1")

        from Products.CMFPlone.defaultpage import get_default_page
        self.assertEqual('d1', get_default_page(self.folder))
Пример #13
0
    def test_get_default_page_step_4(self):
        # 4. Else, look up the property default_page in site_properties for
        #   magic ids and test these
        sp = self.portal.portal_properties.site_properties
        sp.manage_changeProperties(default_page=('d1', ))
        self.folder.invokeFactory('Document', 'd1', title=u"Doc 1")

        from Products.CMFPlone.defaultpage import get_default_page
        self.assertEqual('d1', get_default_page(self.folder))
    def test_get_default_page_step_3_2(self):
        # 3. Else, look up the attribute default_page on the object, without
        #    acquisition in place
        # 3.2 look for a content at portal, with acquisition
        self.portal.invokeFactory('Document', 'd1', title="Doc 1")
        self.folder.default_page = 'd1'
        from Products.CMFPlone.defaultpage import get_default_page

        # now it must acquire from portal
        self.assertEqual('d1', get_default_page(self.folder))
Пример #15
0
    def purge(self):
        site_path = '/'.join(api.portal.get().getPhysicalPath())
        cf = cloudflare.get()
        paths = []
        urls = []

        context = self.context
        dp = get_default_page(context)
        if dp:
            try:
                context = context[dp]
            except Exception:
                pass
        objs = [context]
        for ref in get_content_links(context):
            try:
                objs.append(ref.to_object)
            except Exception:
                pass

        for obj in objs:
            paths.extend(getPathsToPurge(obj, self.request))

        for path in paths:
            urls.extend(cf.getUrlsToPurge(path))

        urls = list(set(urls))

        registry = getUtility(IRegistry)
        settings = registry.forInterface(ICachePurgingSettings, check=False)
        purger = queryUtility(IPurger)
        if purger and settings.cachingProxies:
            self.proxy_enabled = True
            for path in paths:
                for url in getURLsToPurge(path, settings.cachingProxies):
                    purger.purgeAsync(url)

        success = True
        if cf.enabled:
            self.cf_enabled = True
            resp = CastlePurger.purgeSync(urls, cf)
            success = resp.json()['success']
            notify(CacheInvalidatedEvent(self))

        nice_paths = []
        for path in paths:
            if 'VirtualHostRoot' in path:
                path = path.split('VirtualHostRoot')[-1]
            else:
                path = path[len(site_path):]
            nice_paths.append(path.decode('utf-8'))

        return nice_paths, success
    def item_children(self, obj):
        """ find translations among children of obj.
            Criteria:
                * if there is a default page, we look at content items of same type
            Excluded automatically from results
                * default page
                * excluded from nav
                * in the language of the default page, folder, site
        """
        def cmp_lang(a, b):
            return cmp(a['lang_name'], b['lang_name'])

        pl = api.portal.get_tool(name='portal_languages')
        languages = pl.getAvailableLanguages()
        site_language_info = languages.get(self.site_language())

        my_id = obj.id
        base_lang = None
        default_page_id = get_default_page(obj)
        default_page_type = None
        if default_page_id is not None:
            default_page = obj.get(default_page_id)
            if default_page is not None:
                base_lang = self.item_language(default_page)
                default_page_type = default_page.portal_type
        if base_lang is None:
            base_lang = self.item_language(obj)
        if default_page_type is not None:
            results = api.content.find(context=obj,
                                       portal_type=default_page_type,
                                       depth=1)
        else:
            results = api.content.find(context=obj, depth=1)
        results = [
            r for r in results
            if r.id not in (my_id, default_page_id) and not r.exclude_from_nav
        ]
        rez = []
        for r in results:
            ro = r.getObject()
            item_language = self.item_language(ro)
            lang_info = languages.get(item_language, site_language_info)
            if item_language != base_lang:
                rez.append(
                    dict(
                        lang=item_language,
                        url=ro.absolute_url(),
                        lang_name=lang_info[u'name'],
                        lang_native=lang_info[u'native'],
                    ))
        return sorted(rez, cmp_lang)
Пример #17
0
    def get_ld_data(self):
        result = ''
        ld = ILDData(self.context, None)
        if ld is None:
            return ''
        result += self._wrap_ld(ld.get_data())

        if ISiteRoot.providedBy(self.context):
            try:
                page = self.context[get_default_page(self.context)]
                result += self._wrap_ld(ILDData(page).get_data())
            except AttributeError:
                pass

        return result
Пример #18
0
    def find_banner(self):  # noqa: C901
        types = api.portal.get_registry_record(
            'collective.behavior.banner.browser.controlpanel.IBannerSettingsSchema.types'
        )  # noqa: E501
        context = aq_inner(self.context)
        # first handle the obj itself
        if IBanner.providedBy(context):
            if context.banner_hide:
                return False
            banner = self.banner(context)
            config_keys = [key for key in banner.keys() if key != 'banner_obj']
            if config_keys:
                return banner
            if context.banner_stop_inheriting:
                return False
            # if all the fields are empty and inheriting is not stopped
        if context.portal_type not in types:
            return False
        context = context.__parent__

        # we walk up the path
        for item in context.aq_chain:
            if IBanner.providedBy(item):
                # we have a banner. check.
                if item.banner_stop_inheriting:
                    return False
                banner = self.banner(item)
                config_keys = [
                    key for key in banner.keys() if key != 'banner_obj'
                ]
                if config_keys:
                    return banner
            if INavigationRoot.providedBy(item):
                default_page = get_default_page(item)
                if default_page:
                    default_page = item[default_page]
                    if IBanner.providedBy(default_page):
                        banner = self.banner(default_page)
                        if banner:
                            return banner
                return False
            if item.portal_type not in types:
                return False

        return False
Пример #19
0
    def __init__(self, context, request):
        super(EventListing, self).__init__(context, request)

        self.now = now = localized_now(context)

        # Try to get the default page
        default = get_default_page(context)
        self.default_context = context[default] if default else context

        self.is_collection = False
        if ICollection:
            self.is_collection = ICollection.providedBy(self.default_context)

        # Request parameter
        req = self.request.form

        b_size  = int(req.get('b_size', 0))
        if not b_size and self.is_collection:
            collection_behavior = ICollection(self.default_context)
            b_size = getattr(collection_behavior, 'item_count', 0)
        self.b_size = b_size or 10
        self.b_start = int(req.get('b_start', 0))
        self.orphan  = int(req.get('orphan', 1))
        self.mode    = req.get('mode', None)
        self._date   = req.get('date', None)
        self.tags    = req.get('tags', None)
        self.searchable_text = req.get('SearchableText', None)
        self.path    = req.get('path', None)

        day   = int(req.get('day', 0)) or None
        month = int(req.get('month', 0)) or None
        year  = int(req.get('year', 0)) or None

        if not self._date and day or month or year:
            self._date = date(year or now.year,
                              month or now.month,
                              day or now.day).isoformat()

        if self.mode is None:
            self.mode = 'day' if self._date else 'future'

        self.uid = None  # Used to get all occurrences from a single event. Overrides all other settings  # noqa
Пример #20
0
    def __init__(self, context, request):
        super(EventListing, self).__init__(context, request)

        self.now = now = localized_now(context)

        # Try to get the default page
        default = get_default_page(context)
        self.default_context = context[default] if default else context

        self.is_collection = False
        if ICollection:
            self.is_collection = ICollection.providedBy(self.default_context)

        # Request parameter
        req = self.request.form

        b_size = int(req.get('b_size', 0))
        if not b_size and self.is_collection:
            collection_behavior = ICollection(self.default_context)
            b_size = getattr(collection_behavior, 'item_count', 0)
        self.b_size = b_size or 10
        self.b_start = int(req.get('b_start', 0))
        self.orphan = int(req.get('orphan', 1))
        self.mode = req.get('mode', None)
        self._date = req.get('date', None)
        self.tags = req.get('tags', None)
        self.searchable_text = req.get('SearchableText', None)
        self.path = req.get('path', None)

        day = int(req.get('day', 0)) or None
        month = int(req.get('month', 0)) or None
        year = int(req.get('year', 0)) or None

        if not self._date and day or month or year:
            self._date = date(year or now.year, month or now.month, day
                              or now.day).isoformat()

        if self.mode is None:
            self.mode = 'day' if self._date else 'future'

        self.uid = None  # Used to get all occurrences from a single event. Overrides all other settings  # noqa
Пример #21
0
    def get_basic_tags(self):
        try:
            context = self.context
            if ISiteRoot.providedBy(context):
                try:
                    context = context[get_default_page(context)]
                except AttributeError:
                    pass
            tags = {
                'modificationDate': _date(context, 'modified'),
                'publicationDate': _date(context, 'effective'),
                'expirationDate': _date(context, 'expires'),
                'generator': CASTLE_VERSION_STRING,
                "distribution": "Global",
            }
            ldata = ILocation(context, None)
            if ldata is not None:
                if ldata.locations:
                    location = ldata.locations
                    if type(location) in (list, tuple, set):
                        location = location[0]
                    tags['location'] = location

            search = ISearch(context, None)
            if search is not None:
                robot_configuration = self._get_robot_config(search)
                config = robot_configuration[:]
                if 'index' not in config:
                    config.append('noindex')
                if 'follow' not in config:
                    config.append('nofollow')
                tags['robots'] = ','.join(config)

            return ''.join([
                u'<meta name="{}" content="{}">'.format(name, value)
                for name, value in tags.items()
            ])
        except Exception:
            return u''
Пример #22
0
 def getDefaultPage(self):
     return get_default_page(aq_inner(self.context))
Пример #23
0
 def getDefaultPage(self):
     return get_default_page(aq_inner(self.context))