Skip to content

Commit

Permalink
Implement pat-contentbrowser widget
Browse files Browse the repository at this point in the history
  • Loading branch information
petschki committed Sep 16, 2024
1 parent 8feba93 commit a783df5
Show file tree
Hide file tree
Showing 7 changed files with 356 additions and 58 deletions.
30 changes: 21 additions & 9 deletions plone/app/z3cform/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from datetime import time
from plone.app.z3cform import utils
from plone.app.z3cform.interfaces import IAjaxSelectWidget
from plone.app.z3cform.interfaces import IContentBrowserWidget
from plone.app.z3cform.interfaces import IDatetimeWidget
from plone.app.z3cform.interfaces import IDateWidget
from plone.app.z3cform.interfaces import ILinkWidget
from plone.app.z3cform.interfaces import IQueryStringWidget
from plone.app.z3cform.interfaces import IRelatedItemsWidget
from plone.app.z3cform.interfaces import ISelectWidget
from plone.app.z3cform.interfaces import ISingleCheckBoxBoolWidget
from plone.app.z3cform.interfaces import ITimeWidget
Expand Down Expand Up @@ -304,9 +304,9 @@ def toFieldValue(self, value):
return collectionType(untokenized_value)


@adapter(IRelation, IRelatedItemsWidget)
class RelationChoiceRelatedItemsWidgetConverter(BaseDataConverter):
"""Data converter for RelationChoice fields using the RelatedItemsWidget."""
@adapter(IRelation, IContentBrowserWidget)
class RelationChoiceContentBrowserWidgetConverter(BaseDataConverter):
"""Data converter for RelationChoice fields using the ContentBrowserWidget."""

def toWidgetValue(self, value):
if not value:
Expand All @@ -328,8 +328,15 @@ def toFieldValue(self, value):
return self.field.missing_value


# BBB
class RelationChoiceRelatedItemsWidgetConverter(
RelationChoiceContentBrowserWidgetConverter
):
"""backwards compatibility"""


@adapter(IRelation, ISequenceWidget)
class RelationChoiceSelectWidgetConverter(RelationChoiceRelatedItemsWidgetConverter):
class RelationChoiceSelectWidgetConverter(RelationChoiceContentBrowserWidgetConverter):
"""Data converter for RelationChoice fields using with SequenceWidgets,
which expect sequence values.
"""
Expand All @@ -341,9 +348,9 @@ def toWidgetValue(self, value):
return [IUUID(value)]


@adapter(ICollection, IRelatedItemsWidget)
class RelatedItemsDataConverter(BaseDataConverter):
"""Data converter for ICollection fields using the RelatedItemsWidget."""
@adapter(ICollection, IContentBrowserWidget)
class ContentBrowserDataConverter(BaseDataConverter):
"""Data converter for ICollection fields using the ContentBrowserWidget."""

def toWidgetValue(self, value):
"""Converts from field value to widget.
Expand Down Expand Up @@ -405,8 +412,13 @@ def toFieldValue(self, value):
return collectionType(valueType(v) for v in value)


# BBB
class RelatedItemsDataConverter(ContentBrowserDataConverter):
"""backwards compatibility"""


@adapter(IRelationList, ISequenceWidget)
class RelationListSelectWidgetDataConverter(RelatedItemsDataConverter):
class RelationListSelectWidgetDataConverter(ContentBrowserDataConverter):
"""Data converter for RelationChoice fields using with SequenceWidgets,
which expect sequence values.
"""
Expand Down
8 changes: 4 additions & 4 deletions plone/app/z3cform/converters.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
<adapter factory=".converters.SequenceSelect2WidgetConverter" />
<adapter factory=".converters.AjaxSelectWidgetConverter" />
<adapter factory=".converters.QueryStringDataConverter" />
<adapter factory=".converters.RelationChoiceRelatedItemsWidgetConverter" />
<adapter factory=".converters.RelationChoiceContentBrowserWidgetConverter" />
<adapter
factory=".converters.RelationChoiceRelatedItemsWidgetConverter"
factory=".converters.RelationChoiceContentBrowserWidgetConverter"
for="z3c.relationfield.interfaces.IRelationChoice
.interfaces.ITextWidget"
/>
<adapter factory=".converters.RelationChoiceSelectWidgetConverter" />
<adapter factory=".converters.RelatedItemsDataConverter" />
<adapter factory=".converters.ContentBrowserDataConverter" />
<adapter
factory=".converters.RelatedItemsDataConverter"
factory=".converters.ContentBrowserDataConverter"
for="z3c.relationfield.interfaces.IRelationList
.interfaces.ITextWidget"
/>
Expand Down
4 changes: 4 additions & 0 deletions plone/app/z3cform/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class IRelatedItemsWidget(ITextWidget):
"""Marker interface for the RelatedItemsWidget."""


class IContentBrowserWidget(ITextWidget):
"""Marker interface for the RelatedItemsWidget."""


class IRichTextWidget(patextfield_IRichTextWidget):
"""Marker interface for the TinyMCEWidget."""

Expand Down
44 changes: 44 additions & 0 deletions plone/app/z3cform/templates/contentbrowser_display.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<div class="contentbrowser-widget ${python:normalizeString(view.field.__class__.__name__)}-field"
id="form-widgets-${python:view.__name__}"
tal:define="
plone_view nocall:context/@@plone;
normalizeString python:plone_view.normalizeString;
items python: view.items();
"
tal:condition="items"
i18n:domain="plone"
>
<ul>
<li tal:repeat="item items">
<span title="${item_type}"
tal:define="
item_type python:item.portal_type;
item_type_class python:item.ContentTypeClass();
item_wf_state_class python:item.ReviewStateClass();
appendViewAction python:item.appendViewAction();
item_url python:item.getURL();
item_url python:item_url+'/view' if appendViewAction else item_url;
"
>

<a href="${item_url}">
<img class="mime-icon"
src="${python:item.MimeTypeIcon()}"
tal:condition="python:item_type =='File'"
/>

<span class="${item_type_class} ${item_wf_state_class} url"
tal:content="python:item.Title()"
>
Title
</span>
<span class="discreet"
tal:content="python:item.Description()"
>
Description
</span>
</a>
</span>
</li>
</ul>
</div>
80 changes: 39 additions & 41 deletions plone/app/z3cform/templates/relateditems_display.pt
Original file line number Diff line number Diff line change
@@ -1,46 +1,44 @@
<span class="relateditems-widget ${python:normalizeString(view.field.__class__.__name__)}-field"
id="form-widgets-${python:view.__name__}"
tal:define="
plone_view nocall:context/@@plone;
normalizeString python:plone_view.normalizeString;
items python: view.items();
"
tal:condition="items"
i18n:domain="plone"
<div class="relateditems-widget ${python:normalizeString(view.field.__class__.__name__)}-field"
id="form-widgets-${python:view.__name__}"
tal:define="
plone_view nocall:context/@@plone;
normalizeString python:plone_view.normalizeString;
items python: view.items();
"
tal:condition="items"
i18n:domain="plone"
>
<div>
<ul>
<li tal:repeat="item items">
<span title="${item_type}"
tal:define="
item_type python:item.portal_type;
item_type_class python:item.ContentTypeClass();
item_wf_state_class python:item.ReviewStateClass();
appendViewAction python:item.appendViewAction();
item_url python:item.getURL();
item_url python:item_url+'/view' if appendViewAction else item_url;
"
>
<ul>
<li tal:repeat="item items">
<span title="${item_type}"
tal:define="
item_type python:item.portal_type;
item_type_class python:item.ContentTypeClass();
item_wf_state_class python:item.ReviewStateClass();
appendViewAction python:item.appendViewAction();
item_url python:item.getURL();
item_url python:item_url+'/view' if appendViewAction else item_url;
"
>

<a href="${item_url}">
<img class="mime-icon"
src="${python:item.MimeTypeIcon()}"
tal:condition="python:item_type =='File'"
/>
<a href="${item_url}">
<img class="mime-icon"
src="${python:item.MimeTypeIcon()}"
tal:condition="python:item_type =='File'"
/>

<span class="${item_type_class} ${item_wf_state_class} url"
tal:content="python:item.Title()"
>
<span class="${item_type_class} ${item_wf_state_class} url"
tal:content="python:item.Title()"
>
Title
</span>
<span class="discreet"
tal:content="python:item.Description()"
>
</span>
<span class="discreet"
tal:content="python:item.Description()"
>
Description
</span>
</a>
</span>
</li>
</ul>
</div>
</span>
</span>
</a>
</span>
</li>
</ul>
</div>
17 changes: 13 additions & 4 deletions plone/app/z3cform/widgets.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -223,27 +223,36 @@

<!-- relateditems -->

<z3c:widgetTemplate
widget=".interfaces.IRelatedItemsWidget"
template="templates/relateditems_display.pt"
layer=".interfaces.IPloneFormLayer"
mode="display"
/>

<!-- contentbrowser -->

<adapter
factory=".widgets.relateditems.RelatedItemsFieldWidget"
factory=".widgets.contentbrowser.ContentBrowserFieldWidget"
for="z3c.relationfield.interfaces.IRelationChoice
plone.app.z3cform.interfaces.IPloneFormLayer"
/>

<adapter
factory=".widgets.relateditems.RelatedItemsFieldWidget"
factory=".widgets.contentbrowser.ContentBrowserFieldWidget"
for="z3c.relationfield.interfaces.IRelationList
plone.app.z3cform.interfaces.IPloneFormLayer"
/>

<adapter
factory=".widgets.relateditems.RelatedItemsFieldWidget"
factory=".widgets.contentbrowser.ContentBrowserFieldWidget"
for="zope.schema.interfaces.IChoice
plone.app.vocabularies.catalog.CatalogSource
plone.app.z3cform.interfaces.IPloneFormLayer"
/>

<z3c:widgetTemplate
widget=".interfaces.IRelatedItemsWidget"
widget=".interfaces.IContentBrowserWidget"
template="templates/relateditems_display.pt"
layer=".interfaces.IPloneFormLayer"
mode="display"
Expand Down
Loading

0 comments on commit a783df5

Please sign in to comment.