summaryrefslogtreecommitdiffstats
path: root/tabellio/webviews/deputy.py
diff options
context:
space:
mode:
Diffstat (limited to 'tabellio/webviews/deputy.py')
-rw-r--r--tabellio/webviews/deputy.py19
1 files changed, 16 insertions, 3 deletions
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')