예제 #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()
예제 #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)
예제 #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())
예제 #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()))
예제 #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())
예제 #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()))
예제 #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))
예제 #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())
예제 #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
예제 #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
예제 #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()
예제 #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
예제 #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)
예제 #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))
예제 #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 ''
예제 #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)
예제 #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()
예제 #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()
예제 #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()
예제 #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()
예제 #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)
예제 #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
예제 #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)))
예제 #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
예제 #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)))
예제 #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])
예제 #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])
예제 #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
예제 #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)
예제 #30
0
 def __call__(self):
     context = getContext(self.published)
     messages = get_messages_to_show(context)
     return 'msgviewlet_' + '_'.join([_modified(msg) for msg in messages])
예제 #31
0
 def __call__(self):
     context = getContext(self.published)
     return 'cm_' + _modified(context)
예제 #32
0
 def __call__(self):
     parent = getContext(self.context)
     if parent is not None:
         return ILastModified(parent)()
     return None
예제 #33
0
 def __call__(self):
     parent = getContext(self.context)
     if parent is not None:
         return ILastModified(parent)()
     return None