16 # import standard library |
16 # import standard library |
17 |
17 |
18 # import interfaces |
18 # import interfaces |
19 from hypatia.interfaces import ICatalog |
19 from hypatia.interfaces import ICatalog |
20 from pyams_content.interfaces import IBaseContentInfo |
20 from pyams_content.interfaces import IBaseContentInfo |
21 from pyams_content.interfaces.review import IReviewComments |
21 from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE |
|
22 from pyams_content.features.review.interfaces import IReviewComments |
22 from pyams_content.shared.common.interfaces import IWfSharedContent, IWfSharedContentRoles, ISharedContent, ISharedTool |
23 from pyams_content.shared.common.interfaces import IWfSharedContent, IWfSharedContentRoles, ISharedContent, ISharedTool |
|
24 from pyams_i18n.interfaces import II18nManager, II18n |
23 from pyams_security.interfaces import IDefaultProtectionPolicy |
25 from pyams_security.interfaces import IDefaultProtectionPolicy |
24 from pyams_sequence.interfaces import ISequentialIdTarget, ISequentialIdInfo |
26 from pyams_sequence.interfaces import ISequentialIdTarget, ISequentialIdInfo |
25 from pyams_utils.interfaces import VIEW_PERMISSION |
27 from pyams_utils.interfaces import VIEW_PERMISSION |
26 from pyams_workflow.interfaces import IWorkflowPublicationSupport, IWorkflow, IObjectClonedEvent, IWorkflowVersions |
28 from pyams_workflow.interfaces import IWorkflowPublicationSupport, IWorkflow, IObjectClonedEvent, IWorkflowVersions |
27 from pyramid.interfaces import IWSGIApplicationCreatedEvent |
29 from pyramid.interfaces import IWSGIApplicationCreatedEvent |
29 from zope.intid.interfaces import IIntIds |
31 from zope.intid.interfaces import IIntIds |
30 from zope.lifecycleevent.interfaces import IObjectModifiedEvent |
32 from zope.lifecycleevent.interfaces import IObjectModifiedEvent |
31 |
33 |
32 # import packages |
34 # import packages |
33 from persistent import Persistent |
35 from persistent import Persistent |
|
36 from pyams_content.features.checker import BaseContentChecker |
34 from pyams_i18n.content import I18nManagerMixin |
37 from pyams_i18n.content import I18nManagerMixin |
35 from pyams_security.property import RolePrincipalsFieldProperty |
38 from pyams_security.property import RolePrincipalsFieldProperty |
36 from pyams_security.security import ProtectedObject |
39 from pyams_security.security import ProtectedObject |
37 from pyams_security.utility import get_principal |
40 from pyams_security.utility import get_principal |
38 from pyams_utils.adapter import adapter_config, ContextAdapter |
41 from pyams_utils.adapter import adapter_config, ContextAdapter |
172 contributors.add(principal_id) |
175 contributors.add(principal_id) |
173 content.contributors = contributors |
176 content.contributors = contributors |
174 # reset modifiers |
177 # reset modifiers |
175 content.modifiers = set() |
178 content.modifiers = set() |
176 # clear review comments |
179 # clear review comments |
177 IReviewComments(content).clear() |
180 comments = IReviewComments(content, None) |
|
181 if comments is not None: |
|
182 comments.clear() |
178 |
183 |
179 |
184 |
180 @adapter_config(context=IWfSharedContent, provides=ISequentialIdInfo) |
185 @adapter_config(context=IWfSharedContent, provides=ISequentialIdInfo) |
181 def WfSharedContentSequenceAdapter(context): |
186 def WfSharedContentSequenceAdapter(context): |
182 """Shared content sequence adapter""" |
187 """Shared content sequence adapter""" |
202 """Shared content workflow adapter""" |
207 """Shared content workflow adapter""" |
203 parent = get_parent(context, ISharedTool) |
208 parent = get_parent(context, ISharedTool) |
204 return query_utility(IWorkflow, name=parent.shared_content_workflow) |
209 return query_utility(IWorkflow, name=parent.shared_content_workflow) |
205 |
210 |
206 |
211 |
|
212 @adapter_config(name='properties', context=IWfSharedContent, provides=IContentChecker) |
|
213 class WfSharedContentChecker(BaseContentChecker): |
|
214 """Default shared content checker""" |
|
215 |
|
216 label = _("Properties") |
|
217 |
|
218 def inner_check(self, request): |
|
219 output = [] |
|
220 translate = request.localizer.translate |
|
221 missing_value = translate(MISSING_VALUE) |
|
222 missing_lang_value = translate(MISSING_LANG_VALUE) |
|
223 i18n = II18n(self.context) |
|
224 langs = II18nManager(self.context).get_languages() |
|
225 for attr in ('title', 'short_name', 'description'): |
|
226 for lang in langs: |
|
227 value = i18n.get_attribute(attr, lang, request) |
|
228 if not value: |
|
229 if len(langs) == 1: |
|
230 output.append(missing_value.format(field=translate(IWfSharedContent[attr].title))) |
|
231 else: |
|
232 output.append(missing_lang_value.format(field=translate(IWfSharedContent[attr].title), |
|
233 lang=lang)) |
|
234 if not self.context.keywords: |
|
235 output.append(missing_value.format(field=translate(IWfSharedContent['keywords'].title))) |
|
236 return output |
|
237 |
|
238 |
207 # |
239 # |
208 # Main shared content class and adapters |
240 # Main shared content class and adapters |
209 # |
241 # |
210 |
242 |
211 @implementer(ISharedContent, ISequentialIdTarget) |
243 @implementer(ISharedContent, ISequentialIdTarget) |