Skip to content

IMS Indicator on new version should update links to figures 282960 #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 49 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
6df26b6
Update version.py
dobri1408 Feb 25, 2025
669f7db
Update version.py
dobri1408 Feb 25, 2025
1463702
Update version.py
dobri1408 Feb 25, 2025
d8f7eab
Update version.py
dobri1408 Feb 25, 2025
019ec1d
Update version.py
dobri1408 Feb 25, 2025
a6c72b6
Update version.py
dobri1408 Feb 25, 2025
9b54a98
Update version.py
dobri1408 Feb 25, 2025
432e22e
Update version.py
dobri1408 Feb 25, 2025
95ce986
Update version.py
dobri1408 Feb 25, 2025
42490ec
Update version.py
dobri1408 Feb 25, 2025
7e1fbb5
Update version.py
dobri1408 Feb 25, 2025
1bf5558
Update version.py
dobri1408 Feb 25, 2025
ad4fb61
Update version.py
dobri1408 Feb 25, 2025
f825391
Update version.py
dobri1408 Feb 25, 2025
7c7a00e
Update version.py
dobri1408 Feb 25, 2025
4692bf0
Update version.py
dobri1408 Feb 25, 2025
0e74225
Update version.py
dobri1408 Feb 26, 2025
0722087
Update version.py
dobri1408 Feb 26, 2025
36a72ed
Update version.py
dobri1408 Feb 26, 2025
3462bb3
Update version.py
dobri1408 Feb 26, 2025
5b2cda2
Update version.py
dobri1408 Feb 26, 2025
a51f7fb
Merge branch 'develop' into update_datafigure
dobri1408 May 14, 2025
b4ceb32
Update version.py
dobri1408 May 14, 2025
2965e73
Update version.py
dobri1408 May 14, 2025
7592d59
Update version.py
dobri1408 May 14, 2025
9c15011
chore: fix pep8
avoinea May 19, 2025
0e77fa2
simplify
dobri1408 May 19, 2025
b5194c1
simplify
dobri1408 May 19, 2025
6ada665
clean spaces
dobri1408 May 19, 2025
5c36461
clean spaces
dobri1408 May 19, 2025
d574b88
fix pep8
dobri1408 May 19, 2025
5520424
please fix pep8
dobri1408 May 19, 2025
6d9c59a
please fix pep8
dobri1408 May 19, 2025
982e3e3
Add initial page to relatedItems
Narcis2005 May 20, 2025
93ddf36
Fix shortname changes breaking drafts
Narcis2005 May 21, 2025
b88b408
linting
Narcis2005 May 21, 2025
288f8b2
linting
Narcis2005 May 21, 2025
de97316
lLinting
Narcis2005 May 21, 2025
fc3fd1b
Linter
Narcis2005 May 21, 2025
6d0bb37
Merge pull request #54 from eea/fix_renaming
dobri1408 May 21, 2025
160b093
Stop using relatedItems and create new field, fix creating multiple d…
Narcis2005 May 27, 2025
06d69ed
Linter
Narcis2005 May 27, 2025
285f359
linting
Narcis2005 May 27, 2025
53cbd1f
Make field a simple uid
Narcis2005 May 28, 2025
cd645be
Linting
Narcis2005 May 28, 2025
06302fc
Linter
Narcis2005 May 28, 2025
561009c
Linter
Narcis2005 May 28, 2025
a46626e
Check if attribute exists
Narcis2005 May 28, 2025
5f687a5
Merge pull request #55 from eea/parent_draft
dobri1408 May 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions eea/dexterity/indicators/contentrules/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from plone.app.contentrules.browser.formhelper import (
NullAddForm,
)
from plone.app.uuid.utils import uuidToObject
from plone.contentrules.rule.interfaces import IExecutable, IRuleElementData
from zope import schema
from zope.component import adapter
Expand Down Expand Up @@ -62,12 +63,18 @@ def __call__(self):
elif oid.endswith(".1"):
old_id = oid.replace(".1", "", 1)
new_id = old_id + "-%d" % time()

if not (old_id and new_id):
return True

try:
old_version = parent[old_id]
if (
old_id not in parent and
hasattr(obj, 'copied_from') and
obj.copied_from
):
old_version = uuidToObject(obj.copied_from)
obj.copied_from = ""
else:
old_version = parent[old_id]
api.content.transition(
obj=old_version,
transition="markForDeletion",
Expand Down
70 changes: 64 additions & 6 deletions eea/dexterity/indicators/contentrules/version.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
"""Copy action for content rules."""

from urllib.parse import urlparse
from Acquisition import aq_base
from OFS.event import ObjectClonedEvent
from OFS.SimpleItem import SimpleItem
import OFS.subscribers
from plone.restapi.blocks import visit_blocks
from plone.app.contentrules import PloneMessageFactory as _
from plone.app.contentrules.actions import ActionAddForm
from plone.app.contentrules.actions import ActionEditForm
from plone.app.contentrules.browser.formhelper import ContentRuleFormWrapper
from plone.app.vocabularies.catalog import CatalogSource
from plone.contentrules.rule.interfaces import IExecutable
from plone.contentrules.rule.interfaces import IRuleElementData
from plone.restapi.serializer.utils import uid_to_url
from plone.restapi.deserializer.utils import path2uid
from plone import api

try:
from plone.base.utils import pretty_title_or_id
except ImportError:
Expand All @@ -21,9 +28,40 @@
from zope import schema
from zope.component import adapter
from zope.event import notify
from zope.interface import implementer
from zope.interface import Interface
from zope.lifecycleevent import ObjectCopiedEvent
from zope.interface import implementer, Interface
from zope.lifecycleevent import ObjectCopiedEvent, modified


def getLink(path):
"""
Get link
"""

URL = urlparse(path)

if URL.netloc.startswith("localhost") and URL.scheme:
return path.replace(URL.scheme + "://" + URL.netloc, "")
return path


def draftExistsFor(originalObj):
"""
Check if an indicator has a draft already created.
"""
catalog = api.portal.get_tool("portal_catalog")

origUid = originalObj.UID()
results = catalog.searchResults(
portal_type="ims_indicator",
copied_from=origUid,
)

for brain in results:
if hasattr(brain, 'UID') and brain.UID != origUid:
obj = brain.getObject()
if hasattr(obj, 'copied_from') and obj.copied_from == origUid:
return True
return False


class ICopyAction(Interface):
Expand Down Expand Up @@ -75,11 +113,13 @@ def __init__(self, context, element, event):
self.event = event

def __call__(self):

portal_url = getToolByName(self.context, "portal_url", None)
if portal_url is None:
return False

obj = self.event.object
previous_obj_path = obj.absolute_url_path()

path = self.element.target_folder
change_note = self.element.change_note
Expand All @@ -100,7 +140,7 @@ def __call__(self):

old_id = obj.getId()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verify here if there is in related items an uid even if this is return .1, maybe that .1 is renamed

new_id = self.generate_id(target, old_id)
if not new_id.endswith('.1'):
if not new_id.endswith(".1") or draftExistsFor(obj):
# Version already exists, redirect to it - refs #279130
return True

Expand All @@ -123,14 +163,30 @@ def __call__(self):
obj.wl_clearLocks()

obj._postCopy(target, op=0)
try:
obj.copied_from = orig_obj.UID()
except Exception as e:
self.error(obj, str(e))

OFS.subscribers.compatibilityCall("manage_afterClone", obj, obj)

notify(ObjectClonedEvent(obj))

pr = getToolByName(obj, 'portal_repository')
pr = getToolByName(obj, "portal_repository")
pr.save(obj=obj, comment=change_note)

# CHANGE URL OF FIGURES TO THE NEW DRAFT VERSION
for block_data in visit_blocks(obj, obj.blocks):
if (block_data.get("@type") == "embed_content" and
"url" in block_data):
url = uid_to_url(block_data["url"])
if previous_obj_path in url:
url = url.replace(
previous_obj_path,
previous_obj_path + ".1"
)
url = path2uid(context=self.context, link=getLink(url))
block_data["url"] = url
modified(obj)
return True

def error(self, obj, error):
Expand Down Expand Up @@ -169,6 +225,7 @@ class CopyAddForm(ActionAddForm):

class CopyAddFormView(ContentRuleFormWrapper):
"""A wrapper for the add form."""

form = CopyAddForm


Expand All @@ -186,4 +243,5 @@ class CopyEditForm(ActionEditForm):

class CopyEditFormView(ContentRuleFormWrapper):
"""A wrapper for the edit form."""

form = CopyEditForm
8 changes: 8 additions & 0 deletions eea/dexterity/indicators/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from zope.interface import provider, Interface
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
from zope.schema import Int
from zope import schema


class IEeaDexterityIndicatorsLayer(IDefaultBrowserLayer):
Expand Down Expand Up @@ -42,6 +43,7 @@ class IIndicatorMetadata(model.Schema):
"topics",
"temporal_coverage",
"geo_coverage",
"copied_from"
],
)

Expand Down Expand Up @@ -76,6 +78,12 @@ class IIndicatorMetadata(model.Schema):
default={"readOnly": True, "geolocation": []},
)

copied_from = schema.TextLine(
title=_("Original Parent UID"),
required=False,
)

directives.omitted("copied_from")
#
# Supporting information
#
Expand Down