-
Notifications
You must be signed in to change notification settings - Fork 1
/
pod_template.py
84 lines (66 loc) · 3.01 KB
/
pod_template.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# -*- coding: utf-8 -*-
from collective.documentgenerator.content.condition import ConfigurablePODTemplateCondition
from collective.documentgenerator.content.pod_template import ConfigurablePODTemplate
from collective.documentgenerator.content.pod_template import IConfigurablePODTemplate
from collective.eeafaceted.collectionwidget.interfaces import NotDashboardContextException
from collective.eeafaceted.collectionwidget.utils import getCurrentCollection
from collective.eeafaceted.dashboard import FacetedDashboardMessageFactory as _
from plone.autoform import directives as form
from z3c.form.browser.checkbox import CheckBoxFieldWidget
from z3c.form.browser.radio import RadioFieldWidget
from zope import schema
from zope.interface import implements
import logging
logger = logging.getLogger('collective.eeafaceted.dashboard: DashboardPODTemplate')
class IDashboardPODTemplate(IConfigurablePODTemplate):
"""
DashboardPODTemplate dexterity schema.
"""
form.widget('use_objects', RadioFieldWidget)
use_objects = schema.Bool(
title=_(u'Use objects as generation context'),
description=_(u'If selelected, receive awoken objects wrapped into their '
u' helper view rather than brains as generation context'),
default=False,
required=False,
)
form.widget('dashboard_collections', CheckBoxFieldWidget, multiple='multiple', size=15)
dashboard_collections = schema.List(
title=_(u'Allowed dashboard collections'),
description=_(u'Select for which dashboard collections the template will be available. '
u'If nothing is selected, the template will be available on every dashboards.'),
value_type=schema.Choice(source='collective.eeafaceted.dashboard.dashboardcollectionsvocabulary'),
required=True,
)
max_objects = schema.Int(
title=_(u'Maximum amount of objects to print'),
description=_(u'Enter the maximum amount of brains allowed in the generation context.'),
required=True,
default=500,
min=1,
)
form.omitted('pod_portal_types')
class DashboardPODTemplate(ConfigurablePODTemplate):
"""
DashboardPODTemplate dexterity class.
"""
implements(IDashboardPODTemplate)
class DashboardPODTemplateCondition(ConfigurablePODTemplateCondition):
"""
"""
def evaluate(self):
"""
Check:
- That we are on an allowed dashboard collection (if any defined);
- Original ConfigurablePODTemplateCondition conditions.
"""
allowed_collections = self.pod_template.dashboard_collections
if allowed_collections:
try:
current_collection = getCurrentCollection(self.context)
except NotDashboardContextException:
return False
if not current_collection or \
(allowed_collections and not current_collection.UID() in allowed_collections):
return False
return super(DashboardPODTemplateCondition, self).evaluate()