Skip to content

Commit

Permalink
Fix upgrade step for migrating "base_path"
Browse files Browse the repository at this point in the history
  • Loading branch information
petschki committed Mar 22, 2024
1 parent e772725 commit 4a9fe25
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 35 deletions.
28 changes: 8 additions & 20 deletions collective/behavior/relatedmedia/related_images.pt
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,16 @@
i18n:domain="collective.behavior.relatedmedia"
>

<a rel="prettyPhoto[relatedImages]"
data-fancybox="relatedImages"
tal:repeat="img images"
data-caption="${img/title}"
href="${img/url}"
class="image-item uuid-${img/uuid} ${python:repeat['img'].start and ' first' or ''}"
>
<img tal:replace="structure img/tag" />
<span class="caption"
tal:condition="img/show_caption|nothing"
>
<span class="caption-title">${img/title}</span>
<span class="caption-description">${img/description}</span>
</span>
<a tal:repeat="img images" class="image-item mb-3 ${python:'first' if repeat['img'].start else ''}" rel="prettyPhoto[relatedImages]" data-fancybox="relatedImages"
href="${img/url}" data-caption="${img/title}">
<img tal:replace="structure img/tag" />
<span class="caption small clearfix text-body-secondary lh-1"
tal:condition="img/show_caption|nothing">
<span class="caption-title">${img/title}</span>
<span class="caption-description">${img/description}</span>
</span>
</a>

<a href="${context/absolute_url}/@@edit-gallery"
class="btn btn-secondary edit-gallery pat-plone-modal"
data-pat-plone-modal='{"modalSizeClass": "modal-xl"}'
i18n:translate=""
tal:condition="view/can_edit">edit gallery</a>

<div class="discreet"
tal:condition="not:images"
i18n:translate=""
Expand Down
13 changes: 11 additions & 2 deletions collective/behavior/relatedmedia/upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ def migrate_base_path_relations(context):

catalog = api.portal.get_tool("portal_catalog")
items = catalog(
object_provides="collective.behavior.relatedmedia.behavior.IRelatedMedia",
object_provides=[
"collective.behavior.relatedmedia.interfaces.IRelatedMedia", # old name
IRelatedMediaBehavior.__identifier__,
]
)
_num_items = len(items)

Expand Down Expand Up @@ -62,7 +65,13 @@ def migrate_base_path_relations(context):

logger.info(f"{idx}/{_num_items} migrating {item.getPath()}.")

for media in catalog(path=base_path.to_path):
for media in catalog(
path={
"query": base_path.to_path,
"depth": 1,
},
sort_on="getObjPositionInParent",
):
# related images
if media.portal_type == "Image":
img_obj = media.getObject()
Expand Down
15 changes: 2 additions & 13 deletions collective/behavior/relatedmedia/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,11 @@ def get_related_media(context, portal_type=None):

context = aq_inner(context)
rm_behavior = IRelatedMedia(context, None)
rel_media = []

if not rm_behavior:
return []
return rel_media

rel_media = []
if rm_behavior.related_media_base_path:
try:
rm_base = rm_behavior.related_media_base_path.to_object
rel_media = [
i.getObject()
for i in rm_base.restrictedTraverse("@@contentlisting")(
portal_type=portal_type
)
]
except Exception:
rel_media = []
if portal_type in ("Image", None):
rel_media += [i.to_object for i in rm_behavior.related_images if i.to_object]
elif portal_type in ("File", None):
Expand Down

0 comments on commit 4a9fe25

Please sign in to comment.