-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: develop
Are you sure you want to change the base?
Changes from 24 commits
6df26b6
669f7db
1463702
d8f7eab
019ec1d
a6c72b6
9b54a98
432e22e
95ce986
42490ec
7e1fbb5
1bf5558
ad4fb61
f825391
7c7a00e
4692bf0
0e74225
0722087
36a72ed
3462bb3
5b2cda2
a51f7fb
b4ceb32
2965e73
7592d59
9c15011
0e77fa2
b5194c1
6ada665
5c36461
d574b88
5520424
6d9c59a
982e3e3
93ddf36
b88b408
288f8b2
de97316
fc3fd1b
6d0bb37
160b093
06d69ed
285f359
53cbd1f
cd645be
06302fc
561009c
a46626e
5f687a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
"""Copy action for content rules.""" | ||
|
||
import copy | ||
from urllib.parse import urlparse | ||
import transaction | ||
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 | ||
|
||
try: | ||
from plone.base.utils import pretty_title_or_id | ||
except ImportError: | ||
|
@@ -23,7 +31,19 @@ | |
from zope.event import notify | ||
from zope.interface import implementer | ||
from zope.interface import Interface | ||
from zope.lifecycleevent import ObjectCopiedEvent | ||
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 | ||
|
||
|
||
class ICopyAction(Interface): | ||
|
@@ -75,11 +95,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 | ||
|
@@ -100,7 +122,7 @@ def __call__(self): | |
|
||
old_id = obj.getId() | ||
new_id = self.generate_id(target, old_id) | ||
if not new_id.endswith('.1'): | ||
if not new_id.endswith(".1"): | ||
# Version already exists, redirect to it - refs #279130 | ||
return True | ||
|
||
|
@@ -128,9 +150,26 @@ def __call__(self): | |
|
||
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): | ||
new_block = copy.deepcopy(block_data) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is necessary. In place modifying |
||
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)) | ||
new_block["url"] = url | ||
block_data.clear() | ||
block_data.update(new_block) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need |
||
modified(obj) | ||
dobri1408 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
transaction.commit() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also the |
||
return True | ||
|
||
def error(self, obj, error): | ||
|
@@ -169,6 +208,7 @@ class CopyAddForm(ActionAddForm): | |
|
||
class CopyAddFormView(ContentRuleFormWrapper): | ||
"""A wrapper for the add form.""" | ||
|
||
form = CopyAddForm | ||
|
||
|
||
|
@@ -186,4 +226,5 @@ class CopyEditForm(ActionEditForm): | |
|
||
class CopyEditFormView(ContentRuleFormWrapper): | ||
"""A wrapper for the edit form.""" | ||
|
||
form = CopyEditForm |
There was a problem hiding this comment.
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