--- a/src/pyams_content/component/association/__init__.py Thu Jul 12 17:35:20 2018 +0200
+++ b/src/pyams_content/component/association/__init__.py Thu Jul 12 17:35:51 2018 +0200
@@ -42,6 +42,9 @@
visible = FieldProperty(IAssociationItem['visible'])
+ def is_visible(self, request=None):
+ return True
+
def get_url(self, request=None, view_name=None):
return absolute_url(self, request, view_name)
--- a/src/pyams_content/component/association/container.py Thu Jul 12 17:35:20 2018 +0200
+++ b/src/pyams_content/component/association/container.py Thu Jul 12 17:35:51 2018 +0200
@@ -19,6 +19,7 @@
from pyams_content.component.association.interfaces import IAssociationContainer, IAssociationContainerTarget, \
ASSOCIATION_CONTAINER_KEY, IAssociationItem, IAssociationInfo
from pyams_content.features.checker.interfaces import IContentChecker
+from pyams_zmi.layer import IAdminLayer
from zope.location.interfaces import ISublocations
from zope.traversing.interfaces import ITraversable
@@ -54,8 +55,10 @@
# make sure that association item is correctly indexed
index_object(value)
- def get_visible_items(self):
- return filter(lambda x: IAssociationItem(x).visible, self.values())
+ def get_visible_items(self, request=None):
+ for item in filter(lambda x: IAssociationItem(x).visible, self.values()):
+ if IAdminLayer.providedBy(request) or item.is_visible(request):
+ yield item
@adapter_config(context=IAssociationContainerTarget, provides=IAssociationContainer)
--- a/src/pyams_content/component/association/interfaces/__init__.py Thu Jul 12 17:35:20 2018 +0200
+++ b/src/pyams_content/component/association/interfaces/__init__.py Thu Jul 12 17:35:51 2018 +0200
@@ -44,6 +44,9 @@
required=True,
default=True)
+ def is_visible(self, request=None):
+ """Is association item published?"""
+
def get_url(self, request=None, view_name=None):
"""Get link URL"""
@@ -70,7 +73,7 @@
def append(self, value, notify=True):
"""Append given value to container"""
- def get_visible_items(self):
+ def get_visible_items(self, request=None):
"""Get list of visible items"""
--- a/src/pyams_content/component/keynumber/__init__.py Thu Jul 12 17:35:20 2018 +0200
+++ b/src/pyams_content/component/keynumber/__init__.py Thu Jul 12 17:35:51 2018 +0200
@@ -146,7 +146,7 @@
index_object(value)
def get_visible_items(self):
- return filter(lambda x: IKeyNumber(x).visible, self.values())
+ yield from filter(lambda x: IKeyNumber(x).visible, self.values())
@adapter_config(context=IKeyNumberContainerTarget, provides=IKeyNumberContainer)
--- a/src/pyams_content/component/keynumber/portlet/zmi/templates/keynumber-preview.pt Thu Jul 12 17:35:20 2018 +0200
+++ b/src/pyams_content/component/keynumber/portlet/zmi/templates/keynumber-preview.pt Thu Jul 12 17:35:51 2018 +0200
@@ -21,7 +21,7 @@
</tal:var>
</li>
</ul>
- <div tal:define="visible_links list(settings.links.get_visible_items())"
+ <div tal:define="visible_links list(settings.links.get_visible_items(request))"
tal:condition="visible_links">
<u><i18n:var translate="" >Associated links</i18n:var> :</u>
<ul>
--- a/src/pyams_content/component/links/__init__.py Thu Jul 12 17:35:20 2018 +0200
+++ b/src/pyams_content/component/links/__init__.py Thu Jul 12 17:35:51 2018 +0200
@@ -24,12 +24,12 @@
from pyams_form.interfaces.form import IFormContextPermissionChecker
from pyams_i18n.interfaces import II18n
from pyams_sequence.interfaces import ISequentialIdInfo
-from pyams_workflow.interfaces import IWorkflow
+from pyams_workflow.interfaces import IWorkflow, IWorkflowPublicationInfo
# import packages
from pyams_content.component.association import AssociationItem
from pyams_content.features.checker import BaseContentChecker
-from pyams_sequence.utility import get_reference_target
+from pyams_sequence.reference import get_reference_target
from pyams_utils.adapter import adapter_config, ContextAdapter
from pyams_utils.registry import query_utility
from pyams_utils.request import check_request
@@ -124,8 +124,22 @@
reference = FieldProperty(IInternalLink['reference'])
+ @volatile_property
+ def target(self):
+ return get_reference_target(self.reference)
+
def get_target(self, state=None):
- return get_reference_target(self.reference, state)
+ if not state:
+ return self.target
+ else:
+ return get_reference_target(self.reference, state)
+
+ def is_visible(self, request=None):
+ target = self.get_target()
+ if target is not None:
+ publication_info = IWorkflowPublicationInfo(target, None)
+ if publication_info is not None:
+ return publication_info.is_visible(request)
def get_editor_url(self):
return 'oid://{0}'.format(self.reference)
--- a/src/pyams_content/component/links/interfaces/__init__.py Thu Jul 12 17:35:20 2018 +0200
+++ b/src/pyams_content/component/links/interfaces/__init__.py Thu Jul 12 17:35:51 2018 +0200
@@ -54,9 +54,6 @@
class IInternalLink(IBaseLink, IInternalReference):
"""Internal link interface"""
- def get_target(self, state=None):
- """Get reference target"""
-
class IExternalLink(IBaseLink):
"""External link interface"""
--- a/src/pyams_content/component/paragraph/interfaces/contact.py Thu Jul 12 17:35:20 2018 +0200
+++ b/src/pyams_content/component/paragraph/interfaces/contact.py Thu Jul 12 17:35:51 2018 +0200
@@ -28,7 +28,7 @@
else:
have_gis = True
from pyams_i18n.schema import I18nTextLineField
-from pyams_sequence.schema import InternalReference
+from pyams_sequence.schema import InternalReferenceField
from pyams_utils.schema import MailAddressField
from zope.schema import TextLine, Text, Choice
@@ -59,10 +59,10 @@
description=_("Contact email address"),
required=False)
- contact_form = InternalReference(title=_("Contact form"),
- description=_("Reference of contact form"),
- required=False,
- content_type=FORM_CONTENT_TYPE)
+ contact_form = InternalReferenceField(title=_("Contact form"),
+ description=_("Reference of contact form"),
+ required=False,
+ content_type=FORM_CONTENT_TYPE)
photo = ImageField(title=_("Photo"),
description=_("Use 'browse' button to select contact picture"),
--- a/src/pyams_content/component/paragraph/milestone.py Thu Jul 12 17:35:20 2018 +0200
+++ b/src/pyams_content/component/paragraph/milestone.py Thu Jul 12 17:35:51 2018 +0200
@@ -167,7 +167,7 @@
index_object(value)
def get_visible_items(self):
- return filter(lambda x: IMilestone(x).visible, self.values())
+ yield from filter(lambda x: IMilestone(x).visible, self.values())
@adapter_config(context=IMilestoneContainerTarget, provides=IMilestoneContainer)
--- a/src/pyams_content/component/paragraph/pictogram.py Thu Jul 12 17:35:20 2018 +0200
+++ b/src/pyams_content/component/paragraph/pictogram.py Thu Jul 12 17:35:51 2018 +0200
@@ -158,7 +158,7 @@
index_object(value)
def get_visible_items(self):
- return filter(lambda x: IPictogramItem(x).visible, self.values())
+ yield from filter(lambda x: IPictogramItem(x).visible, self.values())
@adapter_config(context=IPictogramContainerTarget, provides=IPictogramContainer)
--- a/src/pyams_content/features/alert/__init__.py Thu Jul 12 17:35:20 2018 +0200
+++ b/src/pyams_content/features/alert/__init__.py Thu Jul 12 17:35:51 2018 +0200
@@ -23,7 +23,7 @@
from pyams_form.interfaces.form import IFormContextPermissionChecker
# import packages
-from pyams_sequence.utility import get_reference_target
+from pyams_sequence.reference import get_reference_target
from pyams_utils.adapter import adapter_config, ContextAdapter
from pyams_utils.registry import query_utility
from pyams_utils.zodb import volatile_property
@@ -61,9 +61,16 @@
table = query_utility(IPictogramTable)
return table.get(self.pictogram_name)
- def get_target(self):
+ @volatile_property
+ def target(self):
return get_reference_target(self.reference)
+ def get_target(self, state=None):
+ if not state:
+ return self.target
+ else:
+ return get_reference_target(self.reference)
+
@adapter_config(context=IAlertItem, provides=IFormContextPermissionChecker)
class AlertitemPermissionChecker(ContextAdapter):
--- a/src/pyams_content/features/alert/container.py Thu Jul 12 17:35:20 2018 +0200
+++ b/src/pyams_content/features/alert/container.py Thu Jul 12 17:35:51 2018 +0200
@@ -46,7 +46,7 @@
index_object(value)
def get_visible_items(self):
- return filter(lambda x: IAlertItem(x).visible, self.values())
+ yield from filter(lambda x: IAlertItem(x).visible, self.values())
@adapter_config(context=IAlertTarget, provides=IAlertContainer)
--- a/src/pyams_content/features/alert/interfaces.py Thu Jul 12 17:35:20 2018 +0200
+++ b/src/pyams_content/features/alert/interfaces.py Thu Jul 12 17:35:51 2018 +0200
@@ -24,7 +24,7 @@
# import packages
from pyams_i18n.schema import I18nTextLineField
-from pyams_sequence.schema import InternalReference
+from pyams_sequence.schema import InternalReferenceField
from zope.container.constraints import containers, contains
from zope.interface import Interface, Attribute
from zope.schema import Bool, Choice, Datetime, Int
@@ -70,11 +70,11 @@
description=_("Alert message"),
required=True)
- reference = InternalReference(title=_("Internal reference"),
- description=_("Internal link target reference. You can search a reference using "
+ reference = InternalReferenceField(title=_("Internal reference"),
+ description=_("Internal link target reference. You can search a reference using "
"'+' followed by internal number, of by entering text matching "
"content title."),
- required=False)
+ required=False)
pictogram_name = Choice(title=_("Pictogram"),
description=_("Name of the pictogram to select"),
@@ -98,9 +98,6 @@
min=0,
default=48)
- def get_target(self):
- """Get internal reference target"""
-
class IAlertContainer(IOrderedContainer):
"""Alert container interface"""
--- a/src/pyams_content/features/menu/__init__.py Thu Jul 12 17:35:20 2018 +0200
+++ b/src/pyams_content/features/menu/__init__.py Thu Jul 12 17:35:51 2018 +0200
@@ -20,7 +20,8 @@
# import packages
from pyams_content.component.association.container import AssociationContainer
-from pyams_sequence.utility import get_reference_target
+from pyams_sequence.reference import get_reference_target
+from pyams_utils.zodb import volatile_property
from zope.interface import implementer
from zope.schema.fieldproperty import FieldProperty
@@ -37,13 +38,20 @@
title = FieldProperty(IMenu['title'])
reference = FieldProperty(IMenu['reference'])
- def get_target(self):
+ @volatile_property
+ def target(self):
return get_reference_target(self.reference)
+ def get_target(self, state=None):
+ if not state:
+ return self.target
+ else:
+ return get_reference_target(self.reference)
+
@implementer(IMenusContainer)
class MenusContainer(AssociationContainer):
"""Associations menus container"""
- def get_visible_items(self):
- return filter(lambda x: IMenu(x).visible, self.values())
+ def get_visible_items(self, request=None):
+ yield from filter(lambda x: IMenu(x).visible, self.values())
--- a/src/pyams_content/features/menu/interfaces/__init__.py Thu Jul 12 17:35:20 2018 +0200
+++ b/src/pyams_content/features/menu/interfaces/__init__.py Thu Jul 12 17:35:51 2018 +0200
@@ -17,10 +17,11 @@
# import interfaces
from pyams_content.component.association.interfaces import IAssociationContainer, IAssociationContainerTarget
+from pyams_sequence.interfaces import IInternalReference
# import packages
from pyams_i18n.schema import I18nTextLineField
-from pyams_sequence.schema import InternalReference
+from pyams_sequence.schema import InternalReferenceField
from zope.container.constraints import containers, contains
from zope.interface import Interface
from zope.schema import Bool
@@ -50,7 +51,7 @@
"""Menu links container marker interface"""
-class IMenu(IMenuLinksContainer):
+class IMenu(IMenuLinksContainer, IInternalReference):
"""Menu container interface"""
containers('.IMenusContainer')
@@ -64,12 +65,9 @@
description=_("Displayed menu label"),
required=True)
- reference = InternalReference(title=_("Internal reference"),
- description=_("Direct reference to menu target"),
- required=False)
-
- def get_target(self):
- """Get reference target"""
+ reference = InternalReferenceField(title=_("Internal reference"),
+ description=_("Direct reference to menu target"),
+ required=False)
class IMenusContainer(IAssociationContainer):
--- a/src/pyams_content/shared/common/skin/oid.py Thu Jul 12 17:35:20 2018 +0200
+++ b/src/pyams_content/shared/common/skin/oid.py Thu Jul 12 17:35:51 2018 +0200
@@ -23,7 +23,7 @@
from zope.traversing.interfaces import ITraversable
# import packages
-from pyams_sequence.utility import get_reference_target
+from pyams_sequence.reference import get_reference_target
from pyams_utils.adapter import adapter_config, ContextRequestAdapter
from pyams_utils.registry import get_utility
from pyramid.exceptions import NotFound
--- a/src/pyams_content/shared/imagemap/interfaces/__init__.py Thu Jul 12 17:35:20 2018 +0200
+++ b/src/pyams_content/shared/imagemap/interfaces/__init__.py Thu Jul 12 17:35:51 2018 +0200
@@ -18,12 +18,13 @@
# import interfaces
from pyams_content.component.paragraph.interfaces import IBaseParagraph
from pyams_content.shared.common.interfaces import ISharedTool, IWfSharedContent, ISharedContent
+from pyams_sequence.interfaces import IInternalReference
from zope.annotation.interfaces import IAttributeAnnotatable
# import packages
from pyams_content.shared.imagemap.schema import MapArea
from pyams_i18n.schema import I18nTextLineField, I18nImageField
-from pyams_sequence.schema import InternalReference
+from pyams_sequence.schema import InternalReferenceField
from pyams_utils.schema import PersistentDict
from zope.interface import Interface
from zope.schema import Object, Choice
@@ -89,17 +90,14 @@
IMAGEMAP_PARAGRAPH_RENDERERS = 'PyAMS.paragraph.imagemap.renderers'
-class IImageMapParagraph(IBaseParagraph):
+class IImageMapParagraph(IBaseParagraph, IInternalReference):
"""Image map paragraph"""
- reference = InternalReference(title=_("Internal reference"),
- description=_("Reference to image map object"),
- content_type=IMAGEMAP_CONTENT_TYPE)
+ reference = InternalReferenceField(title=_("Internal reference"),
+ description=_("Reference to image map object"),
+ content_type=IMAGEMAP_CONTENT_TYPE)
renderer = Choice(title=_("Image map template"),
description=_("Presentation template used for this paragraph"),
vocabulary=IMAGEMAP_PARAGRAPH_RENDERERS,
default='default')
-
- def get_target(self, state=None):
- """Get reference target"""
--- a/src/pyams_content/shared/imagemap/paragraph.py Thu Jul 12 17:35:20 2018 +0200
+++ b/src/pyams_content/shared/imagemap/paragraph.py Thu Jul 12 17:35:51 2018 +0200
@@ -26,12 +26,13 @@
# import packages
from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker, BaseParagraphFactory
from pyams_content.features.renderer import RenderersVocabulary
-from pyams_sequence.utility import get_reference_target
+from pyams_sequence.reference import get_reference_target
from pyams_utils.adapter import adapter_config
from pyams_utils.factory import factory_config
from pyams_utils.registry import utility_config, get_utility
from pyams_utils.traversing import get_parent
from pyams_utils.vocabulary import vocabulary_config
+from pyams_utils.zodb import volatile_property
from zope.interface import implementer
from zope.schema.fieldproperty import FieldProperty
@@ -49,8 +50,15 @@
reference = FieldProperty(IImageMapParagraph['reference'])
renderer = FieldProperty(IImageMapParagraph['renderer'])
+ @volatile_property
+ def target(self):
+ return get_reference_target(self.reference)
+
def get_target(self, state=None):
- return get_reference_target(self.reference, state)
+ if not state:
+ return self.target
+ else:
+ return get_reference_target(self.reference, state)
@utility_config(name=IMAGEMAP_PARAGRAPH_TYPE, provides=IParagraphFactory)
--- a/src/pyams_content/shared/logo/interfaces/__init__.py Thu Jul 12 17:35:20 2018 +0200
+++ b/src/pyams_content/shared/logo/interfaces/__init__.py Thu Jul 12 17:35:51 2018 +0200
@@ -18,10 +18,11 @@
# import interfaces
from pyams_content.component.paragraph import IBaseParagraph
from pyams_content.shared.common.interfaces import ISharedTool, IWfSharedContent, ISharedContent
+from pyams_sequence.interfaces import IInternalReferencesList
# import packages
from pyams_file.schema import ImageField
-from pyams_sequence.schema import InternalReferencesList
+from pyams_sequence.schema import InternalReferencesListField
from zope.interface import Interface
from zope.schema import URI, Choice
@@ -70,17 +71,14 @@
LOGOS_PARAGRAPH_RENDERERS = 'PyAMS.shared.logos.renderers'
-class ILogosParagraph(IBaseParagraph):
+class ILogosParagraph(IBaseParagraph, IInternalReferencesList):
"""Logos paragraph"""
- references = InternalReferencesList(title=_("Logos references"),
- description=_("List of internal logos references"),
- content_type=LOGO_CONTENT_TYPE)
+ references = InternalReferencesListField(title=_("Logos references"),
+ description=_("List of internal logos references"),
+ content_type=LOGO_CONTENT_TYPE)
renderer = Choice(title=_("Logos template"),
description=_("Presentation template used for this paragraph"),
vocabulary=LOGOS_PARAGRAPH_RENDERERS,
default='default')
-
- def get_targets(self, state=None):
- """Get references targets"""
--- a/src/pyams_content/shared/logo/paragraph.py Thu Jul 12 17:35:20 2018 +0200
+++ b/src/pyams_content/shared/logo/paragraph.py Thu Jul 12 17:35:51 2018 +0200
@@ -9,6 +9,7 @@
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
+from pyams_utils.zodb import volatile_property
__docformat__ = 'restructuredtext'
@@ -26,7 +27,7 @@
# import packages
from pyams_content.component.paragraph import BaseParagraph, IParagraphFactory, BaseParagraphFactory, \
BaseParagraphContentChecker
-from pyams_sequence.utility import get_reference_target
+from pyams_sequence.reference import get_reference_target
from pyams_utils.adapter import adapter_config
from pyams_utils.registry import utility_config, get_utility
from pyams_utils.request import check_request
--- a/src/pyams_content/shared/site/interfaces/__init__.py Thu Jul 12 17:35:20 2018 +0200
+++ b/src/pyams_content/shared/site/interfaces/__init__.py Thu Jul 12 17:35:51 2018 +0200
@@ -119,6 +119,3 @@
description=_("If 'no', link is not visible"),
required=True,
default=True)
-
- def get_target(self):
- """Get reference target"""
--- a/src/pyams_content/shared/site/link.py Thu Jul 12 17:35:20 2018 +0200
+++ b/src/pyams_content/shared/site/link.py Thu Jul 12 17:35:51 2018 +0200
@@ -23,9 +23,10 @@
# import packages
from persistent import Persistent
-from pyams_sequence.utility import get_reference_target
+from pyams_sequence.reference import get_reference_target
from pyams_skin.layer import IPyAMSUserLayer
from pyams_utils.adapter import adapter_config
+from pyams_utils.zodb import volatile_property
from zope.container.contained import Contained
from zope.interface import implementer
from zope.schema.fieldproperty import FieldProperty
@@ -50,7 +51,8 @@
def is_deletable(self):
return True
- def get_target(self):
+ @volatile_property
+ def target(self):
target = get_reference_target(self.reference)
if IWorkflowVersion.providedBy(target):
workflow = IWorkflow(target, None)
@@ -62,6 +64,9 @@
target = versions[-1]
return target
+ def get_target(self, state=None):
+ return self.target
+
@adapter_config(context=IContentLink, provides=IWorkflow)
def content_link_workflow_info(context):
--- a/src/pyams_content/shared/view/portlet/__init__.py Thu Jul 12 17:35:20 2018 +0200
+++ b/src/pyams_content/shared/view/portlet/__init__.py Thu Jul 12 17:35:51 2018 +0200
@@ -17,18 +17,19 @@
from itertools import islice
# import interfaces
-from pyams_content.shared.view.interfaces import IViewsMerger
+from pyams_content.shared.view.interfaces import IViewsMerger, IViewsManager
from pyams_content.shared.view.portlet.interfaces import IViewItemsPortletSettings, VIEW_DISPLAY_CONTEXT
from pyams_portal.interfaces import PREVIEW_MODE
from pyams_utils.interfaces import VIEW_PERMISSION
from pyams_utils.interfaces.url import DISPLAY_CONTEXT
+from pyams_workflow.interfaces import IWorkflow
# import packages
-from pyams_content.workflow import PUBLISHED_STATES
from pyams_portal.portlet import PortletSettings, portlet_config, Portlet
-from pyams_sequence.utility import get_sequence_target
+from pyams_sequence.reference import get_sequence_target
from pyams_utils.factory import factory_config
from pyams_utils.list import unique_iter
+from pyams_utils.registry import get_utility
from pyams_utils.request import check_request
from zope.interface import implementer
from zope.schema.fieldproperty import FieldProperty
@@ -51,8 +52,10 @@
limit = FieldProperty(IViewItemsPortletSettings['limit'])
def get_views(self):
+ views_manager = get_utility(IViewsManager)
+ workflow = IWorkflow(views_manager)
for oid in self.views or ():
- view = get_sequence_target(oid, state=PUBLISHED_STATES)
+ view = get_sequence_target(oid, state=workflow.published_states)
if view is not None:
yield view
--- a/src/pyams_content/shared/view/portlet/interfaces.py Thu Jul 12 17:35:20 2018 +0200
+++ b/src/pyams_content/shared/view/portlet/interfaces.py Thu Jul 12 17:35:51 2018 +0200
@@ -23,7 +23,7 @@
from pyams_content.shared.view import WfView
from pyams_content.shared.view.merge import CONCAT_VIEWS_MERGE_MODE
from pyams_i18n.schema import I18nTextLineField
-from pyams_sequence.schema import InternalReferencesList
+from pyams_sequence.schema import InternalReferencesListField
from zope.schema import Choice, Int
from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
@@ -56,12 +56,12 @@
title = I18nTextLineField(title=_("Title"),
required=False)
- views = InternalReferencesList(title=_("Selected views"),
- description=_("Reference to the view(s) from which items are extracted; "
- "you can combine several views together and specify in which order "
- "they should be mixed"),
- content_type=WfView.content_type,
- required=True)
+ views = InternalReferencesListField(title=_("Selected views"),
+ description=_("Reference to the view(s) from which items are extracted; "
+ "you can combine several views together and specify in which "
+ "order they should be mixed"),
+ content_type=WfView.content_type,
+ required=True)
def get_views(self):
"""Get iterator over selected views"""