Updated links and external files management via use of 'associations'
authorThierry Florac <thierry.florac@onf.fr>
Mon, 11 Sep 2017 14:53:15 +0200
changeset 139 99a481dc4c89
parent 138 1643b6a9a02a
child 140 67bad9f880ee
Updated links and external files management via use of 'associations'
src/pyams_content/shared/blog/__init__.py
src/pyams_content/shared/imagemap/__init__.py
src/pyams_content/shared/imagemap/interfaces/__init__.py
src/pyams_content/shared/imagemap/zmi/area.py
src/pyams_content/shared/imagemap/zmi/container.py
src/pyams_content/shared/imagemap/zmi/properties.py
src/pyams_content/shared/imagemap/zmi/summary.py
src/pyams_content/shared/imagemap/zmi/templates/summary.pt
src/pyams_content/shared/news/__init__.py
src/pyams_content/shared/news/manager.py
--- a/src/pyams_content/shared/blog/__init__.py	Mon Sep 11 14:52:15 2017 +0200
+++ b/src/pyams_content/shared/blog/__init__.py	Mon Sep 11 14:53:15 2017 +0200
@@ -17,7 +17,6 @@
 
 # import interfaces
 from pyams_content.component.extfile.interfaces import IExtFileContainerTarget
-from pyams_content.component.gallery.interfaces import IGalleryContainerTarget
 from pyams_content.component.links.interfaces import ILinkContainerTarget
 from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget
 from pyams_content.component.theme.interfaces import IThemesTarget
@@ -28,8 +27,7 @@
 from zope.interface import implementer
 
 
-@implementer(IWfBlogPost, IParagraphContainerTarget, IThemesTarget, IExtFileContainerTarget, ILinkContainerTarget,
-             IGalleryContainerTarget)
+@implementer(IWfBlogPost, IParagraphContainerTarget, IThemesTarget, IExtFileContainerTarget, ILinkContainerTarget)
 class WfBlogPost(WfSharedContent):
     """Base blog post"""
 
--- a/src/pyams_content/shared/imagemap/__init__.py	Mon Sep 11 14:52:15 2017 +0200
+++ b/src/pyams_content/shared/imagemap/__init__.py	Mon Sep 11 14:53:15 2017 +0200
@@ -18,9 +18,11 @@
 from persistent.mapping import PersistentMapping
 
 # import interfaces
+from pyams_content.component.extfile.interfaces import IExtFileContainerTarget
 from pyams_content.component.links.interfaces import ILinkContainerTarget
 from pyams_content.shared.imagemap.interfaces import IMAGEMAP_CONTENT_TYPE, IMAGEMAP_CONTENT_NAME, \
     IWfImageMap, IImageMap, IImageMapArea
+from z3c.form.interfaces import NOT_CHANGED
 from zope.location.interfaces import ISublocations
 from zope.traversing.interfaces import ITraversable
 
@@ -45,7 +47,7 @@
     area = FieldProperty(IImageMapArea['area'])
 
 
-@implementer(IWfImageMap, ILinkContainerTarget)
+@implementer(IWfImageMap, IExtFileContainerTarget, ILinkContainerTarget)
 class WfImageMap(WfSharedContent):
     """Base image map"""
 
@@ -66,9 +68,12 @@
 
     @image.setter
     def image(self, value):
+        if value:
+            for image in value.values():
+                if image and (image is not NOT_CHANGED):
+                    self.areas = PersistentMapping()
+                    break
         self._image = value
-        if value:
-            self.areas = PersistentMapping()
 
     def add_area(self, area):
         self._index += 1
--- a/src/pyams_content/shared/imagemap/interfaces/__init__.py	Mon Sep 11 14:52:15 2017 +0200
+++ b/src/pyams_content/shared/imagemap/interfaces/__init__.py	Mon Sep 11 14:53:15 2017 +0200
@@ -39,15 +39,15 @@
 class IImageMapArea(IAttributeAnnotatable):
     """Image map area interface"""
 
-    title = I18nTextLineField(title=_("Area title"),
-                              description=_("Label associated with this area"),
-                              required=True)
-
     link = Choice(title=_("Link target"),
                   description=_("Internal or external link associated with this map area"),
-                  vocabulary="PyAMS content links",
+                  vocabulary="PyAMS content associations",
                   required=True)
 
+    title = I18nTextLineField(title=_("Alternate title"),
+                              description=_("Alternate label associated with this area"),
+                              required=False)
+
     area = MapArea(title=_("Map area coordinates"),
                    description=_("List of coordinates of image area"),
                    required=True)
--- a/src/pyams_content/shared/imagemap/zmi/area.py	Mon Sep 11 14:52:15 2017 +0200
+++ b/src/pyams_content/shared/imagemap/zmi/area.py	Mon Sep 11 14:53:15 2017 +0200
@@ -9,7 +9,6 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
-from pyams_i18n.interfaces import II18n
 
 __docformat__ = 'restructuredtext'
 
@@ -19,11 +18,11 @@
 # import interfaces
 from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION
 from pyams_content.shared.imagemap.interfaces import IWfImageMap, IImageMapArea
+from pyams_i18n.interfaces import II18n
 from pyams_skin.interfaces.viewlet import IWidgetTitleViewletManager
 from pyams_skin.layer import IPyAMSLayer
 
 # import packages
-from pyams_content.component.links.zmi.widget import SingleLinkLinkSelectFieldWidget
 from pyams_content.shared.imagemap import ImageMapArea
 from pyams_content.shared.imagemap.zmi.container import ImagemapAreasContainerView
 from pyams_content.shared.imagemap.zmi.widget import ImgareaInputFieldWidget
@@ -79,7 +78,6 @@
             return 'modal-large'
 
     fields = field.Fields(IImageMapArea)
-    fields['link'].widgetFactory = SingleLinkLinkSelectFieldWidget
     fields['area'].widgetFactory = ImgareaInputFieldWidget
 
     ajax_handler = 'add-area.json'
@@ -122,7 +120,6 @@
             return 'modal-large'
 
     fields = field.Fields(IImageMapArea)
-    fields['link'].widgetFactory = SingleLinkLinkSelectFieldWidget
     fields['area'].widgetFactory = ImgareaInputFieldWidget
 
     ajax_handler = 'properties.json'
--- a/src/pyams_content/shared/imagemap/zmi/container.py	Mon Sep 11 14:52:15 2017 +0200
+++ b/src/pyams_content/shared/imagemap/zmi/container.py	Mon Sep 11 14:53:15 2017 +0200
@@ -14,10 +14,9 @@
 
 
 # import standard library
-import html
 
 # import interfaces
-from pyams_content.component.links.interfaces import ILinkContainer, IInternalLink
+from pyams_content.component.association.interfaces import IAssociationContainer, IAssociationInfo
 from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION
 from pyams_content.shared.imagemap.interfaces import IWfImageMap
 from pyams_i18n.interfaces import II18n
@@ -33,7 +32,6 @@
 from pyams_content.shared.common.zmi import WfModifiedContentColumnMixin
 from pyams_form.security import ProtectedFormObjectMixin
 from pyams_pagelet.pagelet import pagelet_config
-from pyams_sequence.utility import get_sequence_dict
 from pyams_skin.table import BaseTable, I18nColumn, TrashColumn
 from pyams_skin.viewlet.menu import MenuItem
 from pyams_template.template import template_config
@@ -49,7 +47,7 @@
 
 
 @viewlet_config(name='areas.submenu', context=IWfImageMap, layer=IAdminLayer,
-                manager=IPropertiesMenu, permission=MANAGE_CONTENT_PERMISSION, weight=20)
+                manager=IPropertiesMenu, permission=MANAGE_CONTENT_PERMISSION, weight=30)
 class ImagemapAreasMenu(MenuItem):
     """Image map areas menu"""
 
@@ -123,7 +121,12 @@
     weight = 10
 
     def getValue(self, obj):
-        return II18n(obj).query_attribute('title', request=self.request)
+        title = II18n(obj).query_attribute('title', request=self.request)
+        if not title:
+            item = IAssociationContainer(self.context).get(obj.link)
+            if item is not None:
+                title = IAssociationInfo(item).user_title
+        return title
 
 
 @adapter_config(name='target', context=(IWfImageMap, IPyAMSLayer, ImagemapAreasTable), provides=IColumn)
@@ -135,14 +138,9 @@
     weight = 20
 
     def getValue(self, obj):
-        link = ILinkContainer(self.context).get(obj.link)
-        if link is None:
-            return '--'
-        if IInternalLink.providedBy(link):
-            mapping = get_sequence_dict(link.get_target())
-            return mapping['text']
-        else:
-            return html.escape(link.get_url(self.request))
+        item = IAssociationContainer(self.context).get(obj.link)
+        if item is not None:
+            return IAssociationInfo(item).inner_title
 
 
 @adapter_config(name='trash', context=(IWfImageMap, IPyAMSLayer, ImagemapAreasTable), provides=IColumn)
--- a/src/pyams_content/shared/imagemap/zmi/properties.py	Mon Sep 11 14:52:15 2017 +0200
+++ b/src/pyams_content/shared/imagemap/zmi/properties.py	Mon Sep 11 14:53:15 2017 +0200
@@ -40,6 +40,8 @@
 
     fields = field.Fields(IWfImageMap).select('image')
 
+    weight = 10
+
     def get_ajax_output(self, changes):
         if 'image' in changes.get(IWfImageMap, ()):
             translate = self.request.localizer.translate
--- a/src/pyams_content/shared/imagemap/zmi/summary.py	Mon Sep 11 14:52:15 2017 +0200
+++ b/src/pyams_content/shared/imagemap/zmi/summary.py	Mon Sep 11 14:53:15 2017 +0200
@@ -16,7 +16,7 @@
 # import standard library
 
 # import interfaces
-from pyams_content.component.links.interfaces import ILinkContainer
+from pyams_content.component.association.interfaces import IAssociationContainer, IAssociationInfo
 from pyams_content.shared.common.interfaces.zmi import IInnerSummaryView
 from pyams_content.shared.imagemap.interfaces import IWfImageMap
 from pyams_form.interfaces.form import IInnerTabForm
@@ -52,8 +52,10 @@
 class ImagemapSummaryView(object):
     """Image map summary view"""
 
-    def get_url(self, link):
+    def get_item(self, area):
         """Get URL of given link"""
-        link = ILinkContainer(self.context).get(link)
-        if link is not None:
-            return link.get_url(self.request)
+        item = IAssociationContainer(self.context).get(area.link)
+        return item if (item is not None and item.visible) else None
+
+    def get_item_info(self, item):
+        return IAssociationInfo(item, None)
--- a/src/pyams_content/shared/imagemap/zmi/templates/summary.pt	Mon Sep 11 14:52:15 2017 +0200
+++ b/src/pyams_content/shared/imagemap/zmi/templates/summary.pt	Mon Sep 11 14:53:15 2017 +0200
@@ -10,12 +10,17 @@
 				 data-ams-callback="PyAMS_content.imgmap.initSummary" />
 			<map name="imagemap_preview">
 				<tal:loop repeat="area context.areas.values()">
-					<area tal:define="href view.get_url(area.link)"
-						  tal:condition="href"
-						  shape="poly"
-						  tal:attributes="coords area.area;
-										  href href;
-										  title i18n:area.title;" />
+					<tal:var define="item view.get_item(area)"
+							 condition="item">
+						<area shape="poly"
+							  tal:define="info view.get_item_info(item);
+										  area_title i18n:area.title;
+										  item_title i18n:info.user_title;
+										  title area_title or item_title;"
+							  tal:attributes="coords area.area;
+											  href item.get_url(request);
+											  title title;" />
+					</tal:var>
 				</tal:loop>
 			</map>
 		</div>
--- a/src/pyams_content/shared/news/__init__.py	Mon Sep 11 14:52:15 2017 +0200
+++ b/src/pyams_content/shared/news/__init__.py	Mon Sep 11 14:53:15 2017 +0200
@@ -16,7 +16,6 @@
 # import standard library
 
 # import interfaces
-from pyams_content.component.gallery.interfaces import IGalleryContainerTarget
 from pyams_content.component.extfile.interfaces import IExtFileContainerTarget
 from pyams_content.component.links.interfaces import ILinkContainerTarget
 from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget
@@ -28,8 +27,7 @@
 from zope.interface import implementer
 
 
-@implementer(IWfNewsEvent, IParagraphContainerTarget, IThemesTarget, IExtFileContainerTarget, ILinkContainerTarget,
-             IGalleryContainerTarget)
+@implementer(IWfNewsEvent, IParagraphContainerTarget, IThemesTarget)
 class WfNewsEvent(WfSharedContent):
     """Base news event"""
 
--- a/src/pyams_content/shared/news/manager.py	Mon Sep 11 14:52:15 2017 +0200
+++ b/src/pyams_content/shared/news/manager.py	Mon Sep 11 14:53:15 2017 +0200
@@ -16,6 +16,7 @@
 # import standard library
 
 # import interfaces
+from pyams_content.component.paragraph.interfaces import IParagraphFactorySettings
 from pyams_content.component.theme.interfaces import IThemesManagerTarget
 from pyams_content.shared.news.interfaces import INewsManager, NEWS_CONTENT_TYPE
 from zope.annotation.interfaces import IAttributeAnnotatable
@@ -28,15 +29,18 @@
 from pyams_utils.traversing import get_parent
 from pyramid.events import subscriber
 from zope.interface import implementer
+from zope.schema.fieldproperty import FieldProperty
 
 
-@implementer(INewsManager, IThemesManagerTarget, IAttributeAnnotatable)
+@implementer(INewsManager, IParagraphFactorySettings, IThemesManagerTarget, IAttributeAnnotatable)
 class NewsManager(SharedTool):
     """News manager class"""
 
     shared_content_type = NEWS_CONTENT_TYPE
     shared_content_factory = NewsEvent
 
+    auto_created_paragraphs = FieldProperty(IParagraphFactorySettings['auto_created_paragraphs'])
+
 
 @subscriber(IObjectAddedEvent, context_selector=INewsManager)
 def handle_added_news_manager(event):