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