18 # import interfaces |
18 # import interfaces |
19 from pyams_portal.interfaces import ISlotConfiguration, IPortalTemplateConfiguration, IPortalTemplate, IPortalPage |
19 from pyams_portal.interfaces import ISlotConfiguration, IPortalTemplateConfiguration, IPortalTemplate, IPortalPage |
20 |
20 |
21 # import packages |
21 # import packages |
22 from persistent import Persistent |
22 from persistent import Persistent |
|
23 from persistent.list import PersistentList |
23 from zope.container.contained import Contained |
24 from zope.container.contained import Contained |
24 from zope.interface import implementer |
25 from zope.interface import implementer |
25 from zope.schema.fieldproperty import FieldProperty |
26 from zope.schema.fieldproperty import FieldProperty |
26 |
|
27 |
|
28 PORTAL_SLOTS_KEY = 'pyams_portal.slots' |
|
29 |
27 |
30 |
28 |
31 @implementer(ISlotConfiguration) |
29 @implementer(ISlotConfiguration) |
32 class SlotConfiguration(Persistent, Contained): |
30 class SlotConfiguration(Persistent, Contained): |
33 """Portal slot class""" |
31 """Portal slot class""" |
34 |
32 |
35 slot_name = FieldProperty(ISlotConfiguration['slot_name']) |
33 slot_name = FieldProperty(ISlotConfiguration['slot_name']) |
|
34 _portlet_ids = FieldProperty(ISlotConfiguration['portlet_ids']) |
36 visible = FieldProperty(ISlotConfiguration['visible']) |
35 visible = FieldProperty(ISlotConfiguration['visible']) |
37 _inherit_parent = FieldProperty(ISlotConfiguration['inherit_parent']) |
36 xs_width = FieldProperty(ISlotConfiguration['xs_width']) |
38 _xs_width = FieldProperty(ISlotConfiguration['xs_width']) |
37 sm_width = FieldProperty(ISlotConfiguration['sm_width']) |
39 _sm_width = FieldProperty(ISlotConfiguration['sm_width']) |
38 md_width = FieldProperty(ISlotConfiguration['md_width']) |
40 _md_width = FieldProperty(ISlotConfiguration['md_width']) |
39 lg_width = FieldProperty(ISlotConfiguration['lg_width']) |
41 _lg_width = FieldProperty(ISlotConfiguration['lg_width']) |
40 css_class = FieldProperty(ISlotConfiguration['css_class']) |
42 _css_class = FieldProperty(ISlotConfiguration['css_class']) |
|
43 |
41 |
44 def __init__(self, slot_name, **kwargs): |
42 def __init__(self, slot_name, **kwargs): |
45 self.slot_name = slot_name |
43 self.slot_name = slot_name |
|
44 self._portlet_ids = PersistentList() |
46 self.xs_width = 12 |
45 self.xs_width = 12 |
47 self.sm_width = 12 |
46 self.sm_width = 12 |
48 self.md_width = 12 |
47 self.md_width = 12 |
49 self.lg_width = 12 |
48 self.lg_width = 12 |
50 for key, value in kwargs.items(): |
49 for key, value in kwargs.items(): |
56 return self.__parent__ |
55 return self.__parent__ |
57 else: |
56 else: |
58 return IPortalPage(self.__parent__).template |
57 return IPortalPage(self.__parent__).template |
59 |
58 |
60 @property |
59 @property |
61 def can_inherit(self): |
60 def portlet_ids(self): |
62 return IPortalPage.providedBy(self.__parent__) |
61 if IPortalTemplate.providedBy(self.__parent__): |
|
62 return self._portlet_ids |
|
63 else: |
|
64 config = IPortalTemplateConfiguration(self.template) |
|
65 return config.get_slot_configuration(self.slot_name).portlet_ids |
63 |
66 |
64 @property |
67 @portlet_ids.setter |
65 def inherit_parent(self): |
68 def portlet_ids(self, value): |
66 return self._inherit_parent if self.can_inherit else False |
69 if IPortalTemplate.providedBy(self.__parent__): |
67 |
70 self._portlet_ids = value |
68 @inherit_parent.setter |
|
69 def inherit_parent(self, value): |
|
70 self._inherit_parent = value |
|
71 |
|
72 @property |
|
73 def xs_width(self): |
|
74 if self.inherit_parent: |
|
75 config = IPortalTemplateConfiguration(self.template) |
|
76 return config.get_slot_configuration(self.slot_name).xs_width |
|
77 else: |
|
78 return self._xs_width |
|
79 |
|
80 @xs_width.setter |
|
81 def xs_width(self, value): |
|
82 self._xs_width = value |
|
83 |
|
84 @property |
|
85 def sm_width(self): |
|
86 if self.inherit_parent: |
|
87 config = IPortalTemplateConfiguration(self.template) |
|
88 return config.get_slot_configuration(self.slot_name).sm_width |
|
89 else: |
|
90 return self._sm_width |
|
91 |
|
92 @sm_width.setter |
|
93 def sm_width(self, value): |
|
94 self._sm_width = value |
|
95 |
|
96 @property |
|
97 def md_width(self): |
|
98 if self.inherit_parent: |
|
99 config = IPortalTemplateConfiguration(self.template) |
|
100 return config.get_slot_configuration(self.slot_name).md_width |
|
101 else: |
|
102 return self._md_width |
|
103 |
|
104 @md_width.setter |
|
105 def md_width(self, value): |
|
106 self._md_width = value |
|
107 |
|
108 @property |
|
109 def lg_width(self): |
|
110 if self.inherit_parent: |
|
111 config = IPortalTemplateConfiguration(self.template) |
|
112 return config.get_slot_configuration(self.slot_name).lg_width |
|
113 else: |
|
114 return self._lg_width |
|
115 |
|
116 @lg_width.setter |
|
117 def lg_width(self, value): |
|
118 self._lg_width = value |
|
119 |
|
120 @property |
|
121 def css_class(self): |
|
122 if self.inherit_parent: |
|
123 config = IPortalTemplateConfiguration(self.template) |
|
124 return config.get_slot_configuration(self.slot_name).css_class |
|
125 else: |
|
126 return self._css_class |
|
127 |
|
128 @css_class.setter |
|
129 def css_class(self, value): |
|
130 self._css_class = value |
|
131 |
71 |
132 def get_css_class(self, device=None): |
72 def get_css_class(self, device=None): |
133 if not device: |
73 if not device: |
134 device = ('xs', 'sm', 'md', 'lg') |
74 device = ('xs', 'sm', 'md', 'lg') |
135 elif isinstance(device, str): |
75 elif isinstance(device, str): |