57 """Base view""" |
57 """Base view""" |
58 |
58 |
59 content_type = VIEW_CONTENT_TYPE |
59 content_type = VIEW_CONTENT_TYPE |
60 content_name = VIEW_CONTENT_NAME |
60 content_name = VIEW_CONTENT_NAME |
61 |
61 |
|
62 select_context_type = FieldProperty(IWfView['select_context_type']) |
62 selected_content_types = FieldProperty(IWfView['selected_content_types']) |
63 selected_content_types = FieldProperty(IWfView['selected_content_types']) |
63 order_by = FieldProperty(IWfView['order_by']) |
64 order_by = FieldProperty(IWfView['order_by']) |
64 reversed_order = FieldProperty(IWfView['reversed_order']) |
65 reversed_order = FieldProperty(IWfView['reversed_order']) |
65 limit = FieldProperty(IWfView['limit']) |
66 limit = FieldProperty(IWfView['limit']) |
66 |
67 |
71 if not name: |
72 if not name: |
72 continue |
73 continue |
73 if adapter.is_using_context: |
74 if adapter.is_using_context: |
74 return True |
75 return True |
75 return False |
76 return False |
|
77 |
|
78 def get_content_types(self, context): |
|
79 content_types = set() |
|
80 if self.select_context_type: |
|
81 content_types.add(context.content_type) |
|
82 if self.selected_content_types: |
|
83 content_types |= set(self.selected_content_types) |
|
84 return list(content_types) |
76 |
85 |
77 def get_results(self, context): |
86 def get_results(self, context): |
78 intids = get_utility(IIntIds) |
87 intids = get_utility(IIntIds) |
79 views_cache = get_cache(VIEWS_CACHE_REGION, VIEWS_CACHE_NAME) |
88 views_cache = get_cache(VIEWS_CACHE_REGION, VIEWS_CACHE_NAME) |
80 if self.is_using_context: |
89 if self.is_using_context: |
113 |
122 |
114 def get_params(self, context): |
123 def get_params(self, context): |
115 view = self.context |
124 view = self.context |
116 catalog = get_utility(ICatalog) |
125 catalog = get_utility(ICatalog) |
117 registry = get_current_registry() |
126 registry = get_current_registry() |
118 params = Any(catalog['content_type'], view.selected_content_types) |
127 # check publication dates |
|
128 now = tztime(datetime.utcnow()) |
|
129 params = Lt(catalog['effective_date'], now) |
|
130 params &= Gt(catalog['push_end_date'], now) |
|
131 # check content types |
|
132 content_types = view.get_content_types(context) |
|
133 if content_types: |
|
134 params &= Any(catalog['content_type'], content_types) |
|
135 # check workflow states |
119 wf_params = None |
136 wf_params = None |
120 for workflow in registry.getAllUtilitiesRegisteredFor(IWorkflow): |
137 for workflow in registry.getAllUtilitiesRegisteredFor(IWorkflow): |
121 wf_params = or_(wf_params, Any(catalog['workflow_state'], workflow.published_states)) |
138 wf_params = or_(wf_params, Any(catalog['workflow_state'], workflow.published_states)) |
122 params &= wf_params |
139 params &= wf_params |
123 now = tztime(datetime.utcnow()) |
140 # check custom extensions |
124 params &= Lt(catalog['effective_date'], now) |
|
125 params &= Gt(catalog['push_end_date'], now) |
|
126 for name, adapter in sorted(registry.getAdapters((view,), IViewQueryParamsExtension), |
141 for name, adapter in sorted(registry.getAdapters((view,), IViewQueryParamsExtension), |
127 key=lambda x: x[1].weight): |
142 key=lambda x: x[1].weight): |
128 new_params = adapter.get_params(context) |
143 new_params = adapter.get_params(context) |
129 if new_params: |
144 if new_params: |
130 params &= new_params |
145 params &= new_params |