summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2012-01-04 14:12:59 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2012-01-04 14:12:59 (GMT)
commit3befd138166ba43f476f2da9d10b84c5e5d88ca9 (patch)
tree815b7a0376c5d648d27f1482bdba91c2228acb94
parente01ea8c5ee88227f799b73498ccc92f533fff379 (diff)
downloadtabellio.webviews-3befd138166ba43f476f2da9d10b84c5e5d88ca9.zip
tabellio.webviews-3befd138166ba43f476f2da9d10b84c5e5d88ca9.tar.gz
tabellio.webviews-3befd138166ba43f476f2da9d10b84c5e5d88ca9.tar.bz2
add caching to folder views
-rw-r--r--tabellio/webviews/comitemixte_folder.pt1
-rw-r--r--tabellio/webviews/deputy.pt1
-rw-r--r--tabellio/webviews/deputy.py19
-rw-r--r--tabellio/webviews/deputy_and_others_folder.pt1
-rw-r--r--tabellio/webviews/deputy_folder.pt1
-rw-r--r--tabellio/webviews/deputy_pfb_folder.pt1
-rw-r--r--tabellio/webviews/folder_bottom_nav_view.pt1
-rw-r--r--tabellio/webviews/folder_recent_docs.pt1
-rw-r--r--tabellio/webviews/misc.py23
-rw-r--r--tabellio/webviews/pcfhome_folder.pt1
-rw-r--r--tabellio/webviews/slidernews.py9
11 files changed, 50 insertions, 9 deletions
diff --git a/tabellio/webviews/comitemixte_folder.pt b/tabellio/webviews/comitemixte_folder.pt
index ce72d8b..4c0357f 100644
--- a/tabellio/webviews/comitemixte_folder.pt
+++ b/tabellio/webviews/comitemixte_folder.pt
@@ -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>
diff --git a/tabellio/webviews/deputy.pt b/tabellio/webviews/deputy.pt
index 20eaea3..19639a5 100644
--- a/tabellio/webviews/deputy.pt
+++ b/tabellio/webviews/deputy.pt
@@ -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" />
diff --git a/tabellio/webviews/deputy.py b/tabellio/webviews/deputy.py
index d1835d0..52f07dd 100644
--- a/tabellio/webviews/deputy.py
+++ b/tabellio/webviews/deputy.py
@@ -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')
diff --git a/tabellio/webviews/deputy_and_others_folder.pt b/tabellio/webviews/deputy_and_others_folder.pt
index 8444e4a..0994eb9 100644
--- a/tabellio/webviews/deputy_and_others_folder.pt
+++ b/tabellio/webviews/deputy_and_others_folder.pt
@@ -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" />
diff --git a/tabellio/webviews/deputy_folder.pt b/tabellio/webviews/deputy_folder.pt
index f08d6a1..92800c5 100644
--- a/tabellio/webviews/deputy_folder.pt
+++ b/tabellio/webviews/deputy_folder.pt
@@ -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" />
diff --git a/tabellio/webviews/deputy_pfb_folder.pt b/tabellio/webviews/deputy_pfb_folder.pt
index 86fc39a..131b8eb 100644
--- a/tabellio/webviews/deputy_pfb_folder.pt
+++ b/tabellio/webviews/deputy_pfb_folder.pt
@@ -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" />
diff --git a/tabellio/webviews/folder_bottom_nav_view.pt b/tabellio/webviews/folder_bottom_nav_view.pt
index 3caf2bf..ad010e2 100644
--- a/tabellio/webviews/folder_bottom_nav_view.pt
+++ b/tabellio/webviews/folder_bottom_nav_view.pt
@@ -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>
diff --git a/tabellio/webviews/folder_recent_docs.pt b/tabellio/webviews/folder_recent_docs.pt
index 5c28c4b..935ffa6 100644
--- a/tabellio/webviews/folder_recent_docs.pt
+++ b/tabellio/webviews/folder_recent_docs.pt
@@ -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>
diff --git a/tabellio/webviews/misc.py b/tabellio/webviews/misc.py
index 255a00d..7a926e4 100644
--- a/tabellio/webviews/misc.py
+++ b/tabellio/webviews/misc.py
@@ -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
+
diff --git a/tabellio/webviews/pcfhome_folder.pt b/tabellio/webviews/pcfhome_folder.pt
index 02f40ae..7babeca 100644
--- a/tabellio/webviews/pcfhome_folder.pt
+++ b/tabellio/webviews/pcfhome_folder.pt
@@ -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 {
diff --git a/tabellio/webviews/slidernews.py b/tabellio/webviews/slidernews.py
index 781f667..65022c0 100644
--- a/tabellio/webviews/slidernews.py
+++ b/tabellio/webviews/slidernews.py
@@ -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