Ejemplo n.º 1
0
    def __call__(self):
        context = getContext(self.published)
        portal_state = queryMultiAdapter((context, self.request), name=u'plone_portal_state')
        if portal_state is None:
            return None

        return portal_state.language()
Ejemplo n.º 2
0
    def modifyResponse(self, rulename, response, class_=None):
        options = lookupOptions(class_ or self.__class__, rulename)

        maxage = options.get("maxage", self.maxage)
        smaxage = options.get("smaxage", self.smaxage)
        etags = options.get("etags") or self.etags

        anonOnly = options.get("anonOnly", self.anonOnly)
        ramCache = options.get("ramCache", self.ramCache)
        vary = options.get("vary", self.vary)

        # Add the ``anonymousOrRandom`` etag if we are anonymous only
        if anonOnly:
            if etags is None:
                etags = ["anonymousOrRandom"]
            elif "anonymousOrRandom" not in etags:
                etags = tuple(etags) + ("anonymousOrRandom",)

        etag = getETagAnnotation(self.published, self.request, etags)
        lastModified = getLastModifiedAnnotation(self.published, self.request, options["lastModified"])

        # Check for cache stop request variables
        if cacheStop(self.request, rulename):
            # only stop with etags if configured
            if etags:
                etag = "%s%d" % (time.time(), random.randint(0, 1000))
                return setCacheHeaders(self.published, self.request, response, etag=etag)
            # XXX: should there be an else here? Last modified works without extra headers.
            #      Are there other config options?

        # Do the maxage/smaxage settings allow for proxy caching?
        proxyCache = smaxage or (maxage and smaxage is None)

        # Check if the content can be cached in shared caches
        public = True
        if ramCache or proxyCache:
            if etags is not None:
                if "userid" in etags or "anonymousOrRandom" in etags or "roles" in etags:
                    context = getContext(self.published)
                    portal_state = getMultiAdapter((context, self.request), name=u"plone_portal_state")
                    public = portal_state.anonymous()
            public = public and visibleToRole(self.published, role="Anonymous")

        if proxyCache and not public:
            # This is private so keep it out of both shared and browser caches
            maxage = smaxage = 0

        setCacheHeaders(
            self.published,
            self.request,
            response,
            maxage=maxage,
            smaxage=smaxage,
            etag=etag,
            lastModified=lastModified,
            vary=vary,
        )

        if ramCache and public:
            cacheInRAM(self.published, self.request, response, etag=etag, lastModified=lastModified)
Ejemplo n.º 3
0
    def __call__(self):
        context = getContext(self.published)
        tools = queryMultiAdapter((context, self.request), name=u'plone_tools')
        if tools is None:
            return None

        return str(tools.catalog().getCounter())
Ejemplo n.º 4
0
 def __call__(self):
     context = getContext(self.published)
     context_state = queryMultiAdapter(
         (context, self.request), name=u'plone_context_state')
     if context_state is None:
         return None
     return str(int(context_state.is_locked()))
Ejemplo n.º 5
0
    def __call__(self):
        context = getContext(self.published)
        tools = queryMultiAdapter((context, self.request), name=u'plone_tools')
        if tools is None:
            return None

        return str(tools.catalog().getCounter())
Ejemplo n.º 6
0
 def __call__(self):
     context = getContext(self.published)
     context_state = queryMultiAdapter((context, self.request),
                                       name=u'plone_context_state')
     if context_state is None:
         return None
     return str(int(context_state.is_locked()))
Ejemplo n.º 7
0
 def __call__(self):
     context = getContext(self.published)
     portal_state = queryMultiAdapter((context, self.request), name=u'plone_portal_state')
     if portal_state is None:
         return None
     if portal_state.anonymous():
         return None
     return "%s%d" % (time.time(), random.randint(0, 1000))
Ejemplo n.º 8
0
 def __call__(self):
     registry = getContext(self.context, IResourceRegistry)
     if (registry is None or registry.getDebugMode()
             or not registry.isCacheable(self.context.__name__)):
         return None
     mtime = getattr(registry.aq_base, '_p_mtime', None)
     if mtime is not None and mtime > 0:
         return datetime.fromtimestamp(mtime, tzlocal())
Ejemplo n.º 9
0
 def __call__(self):
     context = getContext(self.published)
     tool = api.portal.get_tool('portal_plonemeeting')
     res = 'pm_0'
     if context.portal_type in tool.getAdvicePortalTypeIds():
         parent = context.aq_inner.aq_parent
         res = 'pm_' + _modified(parent)
     return res
Ejemplo n.º 10
0
 def __call__(self):
     context = getContext(self.published)
     tool = api.portal.get_tool('portal_plonemeeting')
     cfg = tool.getMeetingConfig(context)
     res = 'cfgm_0'
     if cfg:
         res = 'cfgm_' + _modified(cfg)
     return res
Ejemplo n.º 11
0
    def __call__(self):
        context = getContext(self.published)
        portal_state = queryMultiAdapter((context, self.request),
                                         name=u'plone_portal_state')
        if portal_state is None:
            return None

        return portal_state.language()
Ejemplo n.º 12
0
 def __call__(self):
     registry = getContext(self.context, IResourceRegistry)
     if registry is not None:
         if registry.getDebugMode() or not registry.isCacheable(self.context.__name__):
             return None
         mtime = getattr(registry.aq_base, '_p_mtime', None)
         if mtime is not None and mtime > 0:
             return datetime.fromtimestamp(mtime, tzlocal())
     return None
Ejemplo n.º 13
0
        def modifyResponse(self, rulename, response):
            registry = getContext(self.published, IResourceRegistry)

            if registry is not None:
                if registry.getDebugMode() or not registry.isCacheable(self.published.__name__):
                    doNotCache(self.published, self.request, response)
                    return

            super(ResourceRegistriesCaching, self).modifyResponse(rulename, response, class_=StrongCaching)
Ejemplo n.º 14
0
 def __call__(self):
     context = getContext(self.published)
     portal_state = queryMultiAdapter((context, self.request),
                                      name=u'plone_portal_state')
     if portal_state is None:
         return None
     if portal_state.anonymous():
         return None
     return "%s%d" % (time.time(), random.randint(0, 1000))
Ejemplo n.º 15
0
    def __call__(self):
        storage_key_generator = queryMultiAdapter(
            (getContext(self.published), self.published, self.request),
            IDefaultTabStorageKeyGenerator)
        if storage_key_generator is None:
            return ''

        storage_key = storage_key_generator.get_key()
        return IDictStorage(self.published).get(storage_key) or ''
Ejemplo n.º 16
0
    def modifyResponse(self, rulename, response, class_=None):
        options = lookupOptions(class_ or self.__class__, rulename)

        maxage   = options.get('maxage') or self.maxage
        smaxage  = options.get('smaxage') or self.smaxage
        etags    = options.get('etags') or self.etags

        anonOnly = options.get('anonOnly', self.anonOnly)
        ramCache = options.get('ramCache', self.ramCache)
        vary     = options.get('vary', self.vary)

        # Add the ``anonymousOrRandom`` etag if we are anonymous only
        if anonOnly:
            if etags is None:
                etags = ['anonymousOrRandom']
            elif 'anonymousOrRandom' not in etags:
                etags = tuple(etags) + ('anonymousOrRandom',)

        etag = getETagAnnotation(self.published, self.request, etags)
        lastModified = getLastModifiedAnnotation(self.published, self.request, options['lastModified'])

        # Check for cache stop request variables
        if cacheStop(self.request, rulename):
            # only stop with etags if configured
            if etags:
                etag = "%s%d" % (time.time(), random.randint(0, 1000))
                return setCacheHeaders(self.published, self.request, response, etag=etag)
            # XXX: should there be an else here? Last modified works without extra headers.
            #      Are there other config options?

        # Do the maxage/smaxage settings allow for proxy caching?
        proxyCache = smaxage or (maxage and smaxage is None)

        # Check if the content can be cached in shared caches
        public = True
        if ramCache or proxyCache:
            if etags is not None:
                if 'userid' in etags or 'anonymousOrRandom' in etags or 'roles' in etags:
                    context = getContext(self.published)
                    portal_state = getMultiAdapter((context, self.request), name=u'plone_portal_state')
                    public = portal_state.anonymous()
            public = public and visibleToRole(self.published, role='Anonymous')

        if proxyCache and not public:
            # This is private so keep it out of proxy caches
            if maxage == 0:
                # maxage is zero so just omit smaxage
                smaxage=None
            else:
                # maxage is missing or non-zero so expire smaxage
                smaxage=0

        setCacheHeaders(self.published, self.request, response, maxage=maxage, smaxage=smaxage,
            etag=etag, lastModified=lastModified, vary=vary)

        if ramCache and public:
            cacheInRAM(self.published, self.request, response, etag=etag, lastModified=lastModified)
Ejemplo n.º 17
0
    def __call__(self):
        context = getContext(self.published)
        portal_state = queryMultiAdapter((context, self.request), name=u'plone_portal_state')
        if portal_state is None:
            return None

        member = portal_state.member()
        if member is None:
            return None

        return member.getId()
Ejemplo n.º 18
0
    def __call__(self):
        context = getContext(self.published)
        portal_state = queryMultiAdapter((context, self.request),
                                         name=u'plone_portal_state')
        if portal_state is None:
            return None

        member = portal_state.member()
        if member is None:
            return None

        return member.getId()
Ejemplo n.º 19
0
    def __call__(self):
        context = getContext(self.published)

        portal_skins = getToolByName(context, 'portal_skins', None)
        if portal_skins is None:
            return None

        requestVariable = portal_skins.getRequestVarname()
        if requestVariable in self.request:
            return self.request[requestVariable]

        return portal_skins.getDefaultSkin()
Ejemplo n.º 20
0
    def __call__(self):
        context = getContext(self.published)

        portal_skins = getToolByName(context, 'portal_skins', None)
        if portal_skins is None:
            return None

        requestVariable = portal_skins.getRequestVarname()
        if requestVariable in self.request:
            return self.request[requestVariable]

        return portal_skins.getDefaultSkin()
Ejemplo n.º 21
0
        def modifyResponse(self, rulename, response):
            registry = getContext(self.published, IResourceRegistry)

            if registry is not None:
                if registry.getDebugMode() or not registry.isCacheable(
                        self.published.__name__):
                    doNotCache(self.published, self.request, response)
                    return

            super(ResourceRegistriesCaching,
                  self).modifyResponse(rulename,
                                       response,
                                       class_=StrongCaching)
Ejemplo n.º 22
0
    def interceptResponse(self, rulename, response, class_=None):
        options = lookupOptions(class_ or self.__class__, rulename)

        etags = options.get('etags') or self.etags
        anonOnly = options.get('anonOnly', self.anonOnly)
        ramCache = options.get('ramCache', self.ramCache)
        lastModified = options.get('lastModified', self.lastModified)

        # Add the ``anonymousOrRandom`` etag if we are anonymous only
        if anonOnly:
            if etags is None:
                etags = ['anonymousOrRandom']
            elif 'anonymousOrRandom' not in etags:
                etags = tuple(etags) + ('anonymousOrRandom',)

        etag = getETagAnnotation(self.published, self.request, keys=etags)
        lastModified = getLastModifiedAnnotation(
            self.published, self.request, lastModified=lastModified)

        # Check for cache stop request variables
        if cacheStop(self.request, rulename):
            return None

        # Check if this should be a 304 response
        if not isModified(self.request, etag=etag, lastModified=lastModified):
            return notModified(
                self.published,
                self.request,
                response,
                etag=etag,
                lastModified=lastModified
            )

        # Check if this is in the ram cache
        if ramCache:
            context = getContext(self.published)
            portal_state = getMultiAdapter(
                (context, self.request), name=u'plone_portal_state')

            if portal_state.anonymous():
                cached = fetchFromRAMCache(
                    self.request, etag=etag, lastModified=lastModified)
                if cached is not None:
                    return cachedResponse(
                        self.published,
                        self.request,
                        response,
                        *cached
                    )

        return None
Ejemplo n.º 23
0
    def __call__(self):
        context = getContext(self.published)
        portal_state = queryMultiAdapter((context, self.request), name=u'plone_portal_state')
        if portal_state is None:
            return None

        if portal_state.anonymous():
            return 'Anonymous'

        member = portal_state.member()
        if member is None:
            return None

        return ';'.join(sorted(member.getRolesInContext(context)))
Ejemplo n.º 24
0
    def interceptResponse(self, rulename, response, class_=None):
        options = lookupOptions(class_ or self.__class__, rulename)

        etags = options.get('etags') or self.etags
        anonOnly = options.get('anonOnly', self.anonOnly)
        ramCache = options.get('ramCache', self.ramCache)
        lastModified = options.get('lastModified', self.lastModified)

        # Add the ``anonymousOrRandom`` etag if we are anonymous only
        if anonOnly:
            if etags is None:
                etags = ['anonymousOrRandom']
            elif 'anonymousOrRandom' not in etags:
                etags = tuple(etags) + ('anonymousOrRandom', )

        etag = getETagAnnotation(self.published, self.request, keys=etags)
        lastModified = getLastModifiedAnnotation(self.published,
                                                 self.request,
                                                 lastModified=lastModified)

        # Check for cache stop request variables
        if cacheStop(self.request, rulename):
            return None

        # Check if this should be a 304 response
        if not isModified(self.request, etag=etag, lastModified=lastModified):
            return notModified(
                self.published,
                self.request,
                response,
                etag=etag,
                lastModified=lastModified,
            )

        # Check if this is in the ram cache
        if ramCache:
            context = getContext(self.published)
            portal_state = getMultiAdapter((context, self.request),
                                           name=u'plone_portal_state')

            if portal_state.anonymous():
                cached = fetchFromRAMCache(self.request,
                                           etag=etag,
                                           lastModified=lastModified)
                if cached is not None:
                    return cachedResponse(self.published, self.request,
                                          response, *cached)

        return None
Ejemplo n.º 25
0
    def __call__(self):
        context = getContext(self.published)
        portal_state = queryMultiAdapter((context, self.request),
                                         name=u'plone_portal_state')
        if portal_state is None:
            return None

        if portal_state.anonymous():
            return 'Anonymous'

        member = portal_state.member()
        if member is None:
            return None

        return ';'.join(sorted(member.getRolesInContext(context)))
Ejemplo n.º 26
0
    def __call__(self):
        context = getContext(self.published)

        registries = []
        registries.append(getToolByName(context, 'portal_css', None))
        registries.append(getToolByName(context, 'portal_javascripts', None))
        registries.append(getToolByName(context, 'portal_kss', None))

        mtimes = []
        now = time.time()
        for registry in registries:
            mtime = now
            if registry is not None:
                mtime = getattr(registry.aq_base, '_p_mtime', now)
                mtimes.append(mtime)

        mtimes.sort()
        return str(mtimes[-1])
Ejemplo n.º 27
0
    def __call__(self):
        context = getContext(self.published)

        registries = []
        registries.append(getToolByName(context, 'portal_css', None))
        registries.append(getToolByName(context, 'portal_javascripts', None))
        registries.append(getToolByName(context, 'portal_kss', None))

        mtimes = []
        now = time.time()
        for registry in registries:
            mtime = now
            if registry is not None:
                mtime = getattr(registry.aq_base, '_p_mtime', now)
                mtimes.append(mtime)

        mtimes.sort()
        return str(mtimes[-1])
Ejemplo n.º 28
0
 def __call__(self):
     context = getContext(self.published)
     res = 'lm_0'
     if context.meta_type == 'MeetingItem':
         meeting = context.getMeeting()
         if meeting:
             res = 'lm_' + _modified(meeting)
     elif context.portal_type == 'Folder':
         # in case this is a meeting folder
         # we return last Meeting modified when using MeetingConfig.redirectToNextMeeting
         tool = api.portal.get_tool('portal_plonemeeting')
         cfg = tool.getMeetingConfig(context)
         if cfg and cfg.getRedirectToNextMeeting():
             # this changes when meeting added/removed/date changed
             meeting_date_last_modified = get_cachekey_volatile(
                 'Products.PloneMeeting.Meeting.date')
             res = 'lm_' + _modified(date=meeting_date_last_modified)
     return res
Ejemplo n.º 29
0
    def modifyResponse(self, rulename, response, class_=None):
        options = lookupOptions(class_ or self.__class__, rulename)

        maxage = options.get('maxage', self.maxage)
        smaxage = options.get('smaxage', self.smaxage)
        etags = options.get('etags') or self.etags

        anonOnly = options.get('anonOnly', self.anonOnly)
        ramCache = options.get('ramCache', self.ramCache)
        vary = options.get('vary', self.vary)

        # Add the ``anonymousOrRandom`` etag if we are anonymous only
        if anonOnly:
            if etags is None:
                etags = ['anonymousOrRandom']
            elif 'anonymousOrRandom' not in etags:
                etags = tuple(etags) + ('anonymousOrRandom', )

        etag = getETagAnnotation(self.published, self.request, etags)
        lastModified = getLastModifiedAnnotation(self.published, self.request,
                                                 options['lastModified'])

        # Check for cache stop request variables
        if cacheStop(self.request, rulename):
            # only stop with etags if configured
            if etags:
                etag = "%s%d" % (time.time(), random.randint(0, 1000))
                return setCacheHeaders(self.published,
                                       self.request,
                                       response,
                                       etag=etag)
            # XXX: should there be an else here? Last modified works without extra headers.
            #      Are there other config options?

        # Do the maxage/smaxage settings allow for proxy caching?
        proxyCache = smaxage or (maxage and smaxage is None)

        # Check if the content can be cached in shared caches
        public = True
        if ramCache or proxyCache:
            if etags is not None:
                if 'userid' in etags or 'anonymousOrRandom' in etags or 'roles' in etags:
                    context = getContext(self.published)
                    portal_state = getMultiAdapter((context, self.request),
                                                   name=u'plone_portal_state')
                    public = portal_state.anonymous()
            public = public and visibleToRole(self.published, role='Anonymous')

        if proxyCache and not public:
            # This is private so keep it out of both shared and browser caches
            maxage = smaxage = 0

        setCacheHeaders(self.published,
                        self.request,
                        response,
                        maxage=maxage,
                        smaxage=smaxage,
                        etag=etag,
                        lastModified=lastModified,
                        vary=vary)

        if ramCache and public:
            cacheInRAM(self.published,
                       self.request,
                       response,
                       etag=etag,
                       lastModified=lastModified)
Ejemplo n.º 30
0
 def __call__(self):
     context = getContext(self.published)
     messages = get_messages_to_show(context)
     return 'msgviewlet_' + '_'.join([_modified(msg) for msg in messages])
Ejemplo n.º 31
0
 def __call__(self):
     context = getContext(self.published)
     return 'cm_' + _modified(context)
Ejemplo n.º 32
0
 def __call__(self):
     parent = getContext(self.context)
     if parent is not None:
         return ILastModified(parent)()
     return None
Ejemplo n.º 33
0
 def __call__(self):
     parent = getContext(self.context)
     if parent is not None:
         return ILastModified(parent)()
     return None