add caching to folder views
This commit is contained in:
parent
e01ea8c5ee
commit
3befd13816
|
@ -9,6 +9,7 @@
|
|||
<body>
|
||||
<metal:main fill-slot="main">
|
||||
<tal:main-macro metal:define-macro="main">
|
||||
<tal:block tal:define="cache view/cache"/>
|
||||
|
||||
<div tal:replace="structure provider:plone.abovecontenttitle" />
|
||||
<h1 metal:use-macro="context/kss_generic_macros/macros/generic_title_view">Title</h1>
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
<metal:main fill-slot="main">
|
||||
<tal:main-macro metal:define-macro="main">
|
||||
<tal:block tal:define="cache view/cache"/>
|
||||
|
||||
<div tal:replace="structure provider:plone.abovecontenttitle" />
|
||||
|
||||
|
|
|
@ -17,9 +17,16 @@ from plone.registry.interfaces import IRegistry
|
|||
from tabellio.config.interfaces import ITabellioSettings
|
||||
import tabellio.config.utils
|
||||
|
||||
from misc import Cached
|
||||
|
||||
try:
|
||||
from plone.app.caching.operations.utils import setCacheHeaders
|
||||
except ImportError:
|
||||
setCacheHeaders = None
|
||||
|
||||
import cairoplot
|
||||
|
||||
class View(BrowserView):
|
||||
class View(BrowserView, Cached):
|
||||
def birthline(self):
|
||||
if not self.context.birthdate:
|
||||
return
|
||||
|
@ -203,18 +210,21 @@ class FolderView(BrowserView):
|
|||
class IDeputiesAndOthersFolderView(Interface):
|
||||
pass
|
||||
|
||||
class DeputiesAndOthersFolderView(FolderView):
|
||||
class DeputiesAndOthersFolderView(FolderView, Cached):
|
||||
pass
|
||||
|
||||
class IPfbDeputiesFolderView(Interface):
|
||||
pass
|
||||
|
||||
class PfbDeputiesFolderView(FolderView):
|
||||
class PfbDeputiesFolderView(FolderView, Cached):
|
||||
pass
|
||||
|
||||
class GenderStatsView(BrowserView):
|
||||
def __call__(self):
|
||||
self.request.response.setHeader('Content-type', 'image/png')
|
||||
if setCacheHeaders:
|
||||
setCacheHeaders(self, self.request, self.request.response,
|
||||
maxage=3600, smaxage=3600)
|
||||
data = {u'Hommes': len([x for x in self.context.values() if
|
||||
x.Type() == 'Deputy' and x.sex == 'M' and x.active]),
|
||||
u'Femmes': len([x for x in self.context.values() if
|
||||
|
@ -264,6 +274,9 @@ def hexa_to_float(code):
|
|||
class AgeStatsView(BrowserView):
|
||||
def __call__(self):
|
||||
self.request.response.setHeader('Content-type', 'image/png')
|
||||
if setCacheHeaders:
|
||||
setCacheHeaders(self, self.request, self.request.response,
|
||||
maxage=3600, smaxage=3600)
|
||||
ageranges = [x.agerange for x in self.context.values() if
|
||||
x.Type() == 'Deputy' and x.active]
|
||||
x_labels = ('m30', 'd30-40', 'd40-50', 'd50-60', 'd60-70', 'p70')
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
<metal:main fill-slot="main">
|
||||
<tal:main-macro metal:define-macro="main">
|
||||
<tal:block tal:define="cache view/cache"/>
|
||||
<div tal:replace="structure provider:plone.abovecontenttitle" />
|
||||
<h1 metal:use-macro="context/kss_generic_macros/macros/generic_title_view">Title</h1>
|
||||
<div tal:replace="structure provider:plone.belowcontenttitle" />
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
<metal:main fill-slot="main">
|
||||
<tal:main-macro metal:define-macro="main">
|
||||
<tal:block tal:define="cache view/cache"/>
|
||||
<div tal:replace="structure provider:plone.abovecontenttitle" />
|
||||
<h1 metal:use-macro="context/kss_generic_macros/macros/generic_title_view">Title</h1>
|
||||
<div tal:replace="structure provider:plone.belowcontenttitle" />
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
<metal:main fill-slot="main">
|
||||
<tal:main-macro metal:define-macro="main">
|
||||
<tal:block tal:define="cache view/cache"/>
|
||||
<div tal:replace="structure provider:plone.abovecontenttitle" />
|
||||
<h1 metal:use-macro="context/kss_generic_macros/macros/generic_title_view">Title</h1>
|
||||
<div tal:replace="structure provider:plone.belowcontenttitle" />
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
<body>
|
||||
<metal:main fill-slot="main">
|
||||
<tal:main-macro metal:define-macro="main">
|
||||
<tal:block tal:define="cache view/cache"/>
|
||||
|
||||
<div tal:replace="structure provider:plone.abovecontenttitle" />
|
||||
<h1 metal:use-macro="context/kss_generic_macros/macros/generic_title_view">Title</h1>
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
<body>
|
||||
<metal:main fill-slot="main">
|
||||
<tal:main-macro metal:define-macro="main">
|
||||
<tal:block tal:define="cache view/cache"/>
|
||||
|
||||
<div tal:replace="structure provider:plone.abovecontenttitle" />
|
||||
<h1 metal:use-macro="context/kss_generic_macros/macros/generic_title_view">Title</h1>
|
||||
|
|
|
@ -6,20 +6,30 @@ from zope import component
|
|||
|
||||
from Products.CMFCore.utils import getToolByName
|
||||
|
||||
try:
|
||||
from plone.app.caching.operations.utils import setCacheHeaders
|
||||
except ImportError:
|
||||
setCacheHeaders = None
|
||||
|
||||
from tabellio.agenda.utils import MonthlyView
|
||||
|
||||
class Cached:
|
||||
def cache(self, duration=3600):
|
||||
if setCacheHeaders:
|
||||
setCacheHeaders(self, self.request, self.request.response,
|
||||
maxage=duration, smaxage=duration)
|
||||
|
||||
|
||||
class IFolderWithBottomNavView(Interface):
|
||||
pass
|
||||
|
||||
class FolderWithBottomNavView(BrowserView):
|
||||
class FolderWithBottomNavView(BrowserView, Cached):
|
||||
pass
|
||||
|
||||
class IPressFolder(Interface):
|
||||
pass
|
||||
|
||||
class PressFolder(BrowserView):
|
||||
class PressFolder(BrowserView, Cached):
|
||||
def getRecent(self):
|
||||
catalog = getToolByName(self.context, 'portal_catalog')
|
||||
folder_path = '/'.join(self.context.getPhysicalPath() + ('communiques',))
|
||||
|
@ -32,7 +42,7 @@ class PressFolder(BrowserView):
|
|||
class IPcfHomeFolder(Interface):
|
||||
pass
|
||||
|
||||
class PcfHomeFolder(BrowserView):
|
||||
class PcfHomeFolder(BrowserView, Cached):
|
||||
def slider_items(self):
|
||||
catalog = getToolByName(self.context, 'portal_catalog')
|
||||
objects = catalog(portal_type=['tabellio.webviews.slidernews'])
|
||||
|
@ -153,14 +163,14 @@ class PcfHomeFolder(BrowserView):
|
|||
class IComiteMixteFolder(Interface):
|
||||
pass
|
||||
|
||||
class ComiteMixteFolder(BrowserView):
|
||||
class ComiteMixteFolder(BrowserView, Cached):
|
||||
pass
|
||||
|
||||
|
||||
class IFolderWithRecentDocs(Interface):
|
||||
pass
|
||||
|
||||
class FolderWithRecentDocs(BrowserView):
|
||||
class FolderWithRecentDocs(BrowserView, Cached):
|
||||
def last_docs(self):
|
||||
catalog = getToolByName(self.context, 'portal_catalog')
|
||||
return catalog(
|
||||
|
@ -170,5 +180,6 @@ class FolderWithRecentDocs(BrowserView):
|
|||
class IFolderNoNoNav(Interface):
|
||||
pass
|
||||
|
||||
class FolderNoNoNav(BrowserView):
|
||||
class FolderNoNoNav(BrowserView, Cached):
|
||||
pass
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
<body>
|
||||
<metal:main fill-slot="main">
|
||||
<tal:main-macro metal:define-macro="main">
|
||||
<tal:block tal:define="cache view/cache"/>
|
||||
|
||||
<style type="text/css">
|
||||
#slider-container {
|
||||
|
|
|
@ -10,6 +10,11 @@ from plone.formwidget.contenttree import ObjPathSourceBinder
|
|||
from plone.app.textfield import RichText
|
||||
from plone.namedfile.field import NamedImage
|
||||
|
||||
try:
|
||||
from plone.app.caching.operations.utils import setCacheHeaders
|
||||
except ImportError:
|
||||
setCacheHeaders = None
|
||||
|
||||
from tabellio.webviews import MessageFactory as _
|
||||
|
||||
class ISliderNews(form.Schema):
|
||||
|
@ -27,4 +32,8 @@ class View(grok.View):
|
|||
class PictureView(BrowserView):
|
||||
def __call__(self):
|
||||
self.request.response.setHeader('Content-type', self.context.picture.contentType)
|
||||
if setCacheHeaders:
|
||||
setCacheHeaders(self, self.request, self.request.response,
|
||||
maxage=3600, smaxage=3600,
|
||||
lastModified=self.context.modification_date.asdatetime())
|
||||
return self.context.picture.data
|
||||
|
|
Reference in New Issue