Skip to content
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

Python3 #170

Open
wants to merge 295 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
295 commits
Select commit Hold shift + click to select a range
cb82fe2
fix browser:menuItems
laszlocseh Nov 29, 2024
16b9ac5
remove CoverNoTitleView
laszlocseh Nov 29, 2024
0bd8019
remove collective.dexteritytextindexer
laszlocseh Nov 29, 2024
d44ff11
remove collective.dexteritytextindexer
laszlocseh Nov 29, 2024
9894605
remove code IAceItem
laszlocseh Nov 29, 2024
f4b8f97
remove imports IAceMeasure
laszlocseh Nov 29, 2024
2a0bbf0
remove imports IC3sIndicator
laszlocseh Nov 29, 2024
7bfcd87
remove imports IC3sIndicator
laszlocseh Nov 29, 2024
a2adcb0
remove plone.formwidget.contenttree
laszlocseh Dec 1, 2024
063f936
remove plone.formwidget.contenttree
laszlocseh Dec 1, 2024
8de39cc
remove timezone
laszlocseh Dec 1, 2024
d4eeac9
remove image
laszlocseh Dec 1, 2024
de3b20b
remove IAction imports
laszlocseh Dec 1, 2024
3252106
remove eea.climateadapt.aceitem.IIndicator
laszlocseh Dec 1, 2024
3de6534
remove IC3sIndicator
laszlocseh Dec 1, 2024
4c5d708
remove eea.climateadapt.aceitem.IPublicationReport
laszlocseh Dec 1, 2024
f1a8620
remove more interfaces
laszlocseh Dec 1, 2024
7ecaf8f
remove package osgeo
laszlocseh Dec 1, 2024
51ac00c
remove more interfaces
laszlocseh Dec 1, 2024
5c37624
remove more interfaces
laszlocseh Dec 1, 2024
fc52987
remove tlspu.cookiepolicy
laszlocseh Dec 1, 2024
f216d36
remove .upgrades
laszlocseh Dec 1, 2024
16a9993
remove AceProjectSerializer
laszlocseh Dec 1, 2024
9e84713
remove OrganisationSerializer
laszlocseh Dec 1, 2024
048dee2
remove geolocation_converter
laszlocseh Dec 2, 2024
71ae94d
remove more interfaces
laszlocseh Dec 2, 2024
406b3fb
remove IAceItem
laszlocseh Dec 2, 2024
71f3f9e
remove aceitem
laszlocseh Dec 2, 2024
5fea135
remove Products.LDAPUserFolder
laszlocseh Dec 2, 2024
edc458c
remove .cache
laszlocseh Dec 2, 2024
fa6a49a
remove IObjectEvent
laszlocseh Dec 2, 2024
9170a92
remove isLinked
laszlocseh Dec 2, 2024
be14c4e
remove patches.zcml
laszlocseh Dec 2, 2024
a71edd6
remove plone.app.imagecropping
laszlocseh Dec 2, 2024
5ad3990
remove search_type
laszlocseh Dec 2, 2024
d2107ca
remove catalog
laszlocseh Dec 2, 2024
b84891a
remove CcaItemsFieldWidget
laszlocseh Dec 2, 2024
7332a15
remove eea.facetednavigation
laszlocseh Dec 2, 2024
f392659
remove IAceMeasure
laszlocseh Dec 2, 2024
8b28476
remove IWorkflowMessageEvent
laszlocseh Dec 2, 2024
d2dc377
remove IIndicatorMessageEvent
laszlocseh Dec 2, 2024
63706d5
replace BeautifulSoup with bs4
laszlocseh Dec 2, 2024
90149b3
remove .overrides.DisplaySubMenuItem
laszlocseh Dec 2, 2024
c7404ce
remove .overrides
laszlocseh Dec 2, 2024
f1cd778
remove Products.ResourceRegistries
laszlocseh Dec 2, 2024
5510f82
remove collective.excelexport
laszlocseh Dec 2, 2024
2b04903
remove DatetimeWidgetConverter
laszlocseh Dec 2, 2024
ff74873
remove Conflicting configurations
laszlocseh Dec 2, 2024
ce8024f
remove primephoto, suppphotos
laszlocseh Dec 2, 2024
90d6e37
remove dependency profiles
laszlocseh Dec 2, 2024
f4501df
Comment code about cache invalidation
tiberiuichim Dec 2, 2024
5658ba3
Remove importer and migration
tiberiuichim Dec 2, 2024
4fbcf64
We need translation, we don't need sat
tiberiuichim Dec 2, 2024
3bdee74
We don't need any views
tiberiuichim Dec 2, 2024
ee01d6a
Add types from export from plone4 site
tiberiuichim Dec 2, 2024
f669bc1
Temp renamed xml files in profile default
tiberiuichim Dec 2, 2024
f29987e
Try to re-enable classes
tiberiuichim Dec 2, 2024
e92769c
add back more intefaces
laszlocseh Dec 3, 2024
53c9e73
add back more interfaces
laszlocseh Dec 3, 2024
57d4ad0
remove BetterAjaxSelectWidget
laszlocseh Dec 3, 2024
6e88f48
replace plone.autoform.directives.fieldset with plone.supermodel.mode…
laszlocseh Dec 3, 2024
602a947
add back IaceProject fields
laszlocseh Dec 3, 2024
e4dfb7e
add back IaceProject partners
laszlocseh Dec 3, 2024
41cc76d
fix IAceProject long_description
laszlocseh Dec 3, 2024
384a4d8
fix IAceProject source field
laszlocseh Dec 3, 2024
50d3e85
fix IC3sIndicator
laszlocseh Dec 3, 2024
246223d
remove organisational_links field
laszlocseh Dec 3, 2024
95c4756
enable AceVideo
laszlocseh Dec 3, 2024
3d7d9db
add back IFrontpageSlide
laszlocseh Dec 3, 2024
2e9ea4e
fix IndentationError
laszlocseh Dec 3, 2024
d02d466
fix IndentationError
laszlocseh Dec 3, 2024
e0e62cc
remove .decode in vocabulary.py
laszlocseh Dec 4, 2024
8e96e51
Add workflow from production
tiberiuichim Dec 4, 2024
e634c72
Fix workflows.xml
tiberiuichim Dec 4, 2024
cc6bf65
Work on behaviors
tiberiuichim Dec 4, 2024
14569f6
Add fix_content script
tiberiuichim Dec 4, 2024
ba82651
Fix publication date
tiberiuichim Dec 4, 2024
51a3321
Fix geochars
tiberiuichim Dec 4, 2024
5643a7e
Fix sectors, climate_impacts in importer
tiberiuichim Dec 4, 2024
6fe667d
Add IC3S indicator iterface
tiberiuichim Dec 4, 2024
7a2a04d
Fix other fields
tiberiuichim Dec 4, 2024
33f2595
Fix other fields
tiberiuichim Dec 4, 2024
2697f47
Fix other fields
tiberiuichim Dec 5, 2024
1bf35cd
Fix other fields
tiberiuichim Dec 5, 2024
38286aa
Fix other fields
tiberiuichim Dec 5, 2024
b18d75c
Fix other fields
tiberiuichim Dec 5, 2024
3ea4724
Fix other fields
tiberiuichim Dec 5, 2024
d003d99
Set websites to be list of textlines, to enable import
tiberiuichim Dec 5, 2024
8a0e0d4
update content types
laszlocseh Dec 5, 2024
182f140
TODO fix later: add Cover and EasyForm content type
laszlocseh Dec 5, 2024
01a0956
Simplify types.xml
tiberiuichim Dec 5, 2024
014479f
Fix other fields
tiberiuichim Dec 5, 2024
0efcdd3
Fix other fields
tiberiuichim Dec 5, 2024
7ea41e3
added fix_origin_website to script/fix_content.py
laszlocseh Dec 5, 2024
2a33527
Fix mission story
tiberiuichim Dec 5, 2024
c81c68f
added fix_special_tags
laszlocseh Dec 5, 2024
97529a1
added more content fixes
laszlocseh Dec 5, 2024
9f42138
set Organisation contact field to required=False for migration
laszlocseh Dec 5, 2024
c585704
more fixes
laszlocseh Dec 5, 2024
357c4fa
Fix other fields
tiberiuichim Dec 6, 2024
e3fdd8a
Fix icon_expr in content types
tiberiuichim Dec 6, 2024
367ffc6
Make types importable
tiberiuichim Dec 6, 2024
9155781
Fix casestudy content type
tiberiuichim Dec 6, 2024
3e01780
Fix other fields
tiberiuichim Dec 6, 2024
bb6d2a9
Don't fix urls
tiberiuichim Dec 6, 2024
45478a5
Don't fix urls
tiberiuichim Dec 6, 2024
6a86a2e
Temp fix for websites field
tiberiuichim Dec 6, 2024
38c33c8
Fix adaptation options
tiberiuichim Dec 6, 2024
896caff
Use json_compatible
tiberiuichim Dec 6, 2024
76bf04a
add back missing fields for case studies
laszlocseh Dec 6, 2024
012d0a1
Remap content types
tiberiuichim Dec 6, 2024
b0698a8
Avoid crash from unimported errors
tiberiuichim Dec 6, 2024
65b93ca
Add language to registry.xml
tiberiuichim Dec 6, 2024
bd05fae
fix error in countryprofile restapi
laszlocseh Dec 9, 2024
3c9ddeb
add back transnationalregions.py
laszlocseh Dec 9, 2024
0c59443
fix error in serializer.py
laszlocseh Dec 9, 2024
cde5ddd
fix error in transnationalregions.py
laszlocseh Dec 9, 2024
189779d
add back tiles
laszlocseh Dec 9, 2024
b95ec79
Comment breadcrumbs
tiberiuichim Dec 10, 2024
cfc87a0
Fix transnational regions so it doesn't depend on tiles
tiberiuichim Dec 10, 2024
8074529
Add script to fix localroles export
tiberiuichim Dec 11, 2024
1fd09e4
add fix_publishing_date
laszlocseh Dec 13, 2024
9d94401
Merge branch 'python3' of ssh://github.com/eea/eea.climateadapt.plone…
laszlocseh Dec 13, 2024
6a556bf
Add filter script
tiberiuichim Dec 16, 2024
7708384
Add comment
tiberiuichim Dec 16, 2024
85aa43f
added temporary patch to import_blob_paths
laszlocseh Dec 17, 2024
074113a
add back navigation customization
laszlocseh Dec 18, 2024
c0e5089
Layers
tiberiuichim Dec 18, 2024
a0d918c
fix toplevel navigation
laszlocseh Dec 18, 2024
a93037a
fix portal_tabs_view override
laszlocseh Dec 18, 2024
d7d8968
fix to properly display nav_title
laszlocseh Dec 18, 2024
1dd076e
try to cleanup catalog
laszlocseh Dec 19, 2024
cbb305b
update fix_content: for covers set exclude_from_nav to true
laszlocseh Dec 20, 2024
53289bd
update catalog.xml
laszlocseh Dec 20, 2024
19d673e
Merge master (#171)
tiberiuichim Jan 9, 2025
3477057
add back some removed content types
laszlocseh Jan 17, 2025
06d04bf
modify fix_content to run on folder
laszlocseh Jan 17, 2025
f895c05
added view to migrate absolute urls to resolveuid
laszlocseh Jan 22, 2025
4fc6ceb
added view to migrate absolute urls to resolveuid
laszlocseh Jan 22, 2025
1e5bf38
flake
tiberiuichim Jan 22, 2025
2554fcf
Skip if error file
tiberiuichim Jan 22, 2025
dde79fe
Add metadata.xml
tiberiuichim Jan 22, 2025
e0d4948
More fields
tiberiuichim Jan 22, 2025
30bb845
Add event_url
tiberiuichim Jan 22, 2025
69d6932
Add title as pottential empty field
tiberiuichim Jan 22, 2025
600e15d
Fix navigation for restapi
tiberiuichim Jan 23, 2025
04a4349
Allow transnational regions to run
tiberiuichim Jan 24, 2025
c792e06
Fix half of country profiles
tiberiuichim Jan 24, 2025
c6e2c5d
Add hardcoded country profiles
tiberiuichim Jan 24, 2025
4f2869a
The other part of country profiles
tiberiuichim Jan 24, 2025
a8a4b45
Add image sizes to registry
tiberiuichim Jan 24, 2025
78e9d62
Fix country block on frontpage
tiberiuichim Jan 24, 2025
2e31b3a
Another check for errors.json
tiberiuichim Jan 27, 2025
a14b4e9
Add exportimport
tiberiuichim Jan 27, 2025
1ccbfeb
Add fixer for blocks
tiberiuichim Jan 27, 2025
47e0400
Add gopdb
tiberiuichim Jan 27, 2025
d1c5759
Fix preview_image as list
tiberiuichim Jan 27, 2025
cd0798e
added import steps
laszlocseh Jan 28, 2025
a16b854
Merge branch 'python3' of ssh://github.com/eea/eea.climateadapt.plone…
laszlocseh Jan 28, 2025
b7cec25
update import steps
laszlocseh Jan 28, 2025
3c6956d
add EasyForm to types
laszlocseh Jan 28, 2025
a8965f3
fix missing module in content type EasyForm
laszlocseh Jan 28, 2025
40da21c
added step in fix_content to replace internal urls
laszlocseh Jan 29, 2025
0d2f54e
more fields to fix_missing_field_values
laszlocseh Jan 29, 2025
15ba30d
more fields to fix_missing_field_values
laszlocseh Jan 29, 2025
6157ac6
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
0522f04
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
6aba8a8
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
a16146b
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
5786eb4
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
32d3c38
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
8f0d7e6
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
9935c48
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
97a53f3
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
8370a9e
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
fd80747
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
2efafe7
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
cb4e6f8
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
945a0b9
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
ce8c11f
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
3eb5e49
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
5fa58d3
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
7fe1192
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
e05161f
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
7dd0593
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
0a8466d
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
c215ac3
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
7483465
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
676a945
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
c6ef18b
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
39a6cfc
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
3aa3b5f
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
f5cb734
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
46e6c71
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
3076956
fix for data_type field in fix_content
laszlocseh Jan 30, 2025
336d4d1
update startfrom fix_content
laszlocseh Jan 30, 2025
2a2fc2c
new script list_broken_content and more fixes in fix_content
laszlocseh Jan 31, 2025
2b24b3d
fix storage_type none values
laszlocseh Jan 31, 2025
99f7772
update import steps
laszlocseh Jan 31, 2025
6d7baef
update import steps
laszlocseh Jan 31, 2025
91f83a5
more fixes in fix_content
laszlocseh Jan 31, 2025
8294bf5
more skips in fix_content
laszlocseh Jan 31, 2025
03a17f1
more skips in fix_content
laszlocseh Jan 31, 2025
3638eca
more skips in fix_content
laszlocseh Jan 31, 2025
e5117e4
update import steps
laszlocseh Feb 3, 2025
aa70d9d
fix: custom ImportTranslations to commit after 1000 objects
laszlocseh Feb 4, 2025
ba2d173
fix error in exportimport
laszlocseh Feb 4, 2025
bc251b4
more logs to ImportTranslatiosn
laszlocseh Feb 4, 2025
5f0f6a0
Switch layer for nav registration
tiberiuichim Feb 4, 2025
bc37fde
Switch layers
tiberiuichim Feb 4, 2025
a09b1fd
Let's try this layer
tiberiuichim Feb 4, 2025
44b888a
Inherit from IEeaVoltoPolicyLayer
tiberiuichim Feb 4, 2025
d44f89f
add marker interfaces for collective.cover.content
laszlocseh Feb 5, 2025
f9796df
fix: RichttextFieldSerializer to return string instead of bytes
laszlocseh Feb 6, 2025
75cf8d5
add plone.base.interfaces.siteroot.INavigationRoot interface for Subsite
laszlocseh Feb 6, 2025
22c7f6f
enable health homepage related code
laszlocseh Feb 6, 2025
64987bb
make observatory Subsite and INavigationRoot
laszlocseh Feb 6, 2025
3e3e755
add back code for ECDE
laszlocseh Feb 7, 2025
35e7ba9
add back code for ECDE
laszlocseh Feb 7, 2025
2d7a038
add annotation keys to be exported
laszlocseh Feb 7, 2025
36ecef1
fix decode error in ECDE
laszlocseh Feb 7, 2025
1644ecb
fix decode error in ECDE
laszlocseh Feb 7, 2025
1ad55a3
update import_steps
laszlocseh Feb 10, 2025
338cb11
add missing data_type
laszlocseh Feb 12, 2025
811a7fc
remove pdb
laszlocseh Feb 12, 2025
b84553a
fix_content updates and remove pdb
laszlocseh Feb 12, 2025
73b6c86
fix: add indexes macro_regions and bio_regions
laszlocseh Feb 14, 2025
c6f113b
fix: remove adapters macro_regions and bio_regions
laszlocseh Feb 14, 2025
05ff228
fix catalog and macro_regions, bio_regions
laszlocseh Feb 14, 2025
13ca9fd
add back SearchAceContentBlockSerializer
laszlocseh Feb 14, 2025
7fad8b9
do not remove case_study elements in fix_elements
laszlocseh Feb 17, 2025
555e519
update import steps
laszlocseh Feb 18, 2025
69f9b29
Fix block
tiberiuichim Feb 13, 2025
c2759a1
fix KeywordsVocabulary to not return base64 encoded string
laszlocseh Feb 18, 2025
217080f
cleanup KeywordsVocabulary
laszlocseh Feb 18, 2025
b745987
fix casestudies map
laszlocseh Feb 18, 2025
bbe443d
update IP in fix_content
laszlocseh Feb 19, 2025
9a22a55
update news_item behavior
laszlocseh Feb 19, 2025
7e68ae2
update news_item behavior
laszlocseh Feb 19, 2025
b3db1c6
enable lead image behavior for Subsite
laszlocseh Feb 20, 2025
9a84681
update import steps
laszlocseh Feb 20, 2025
0f63ee2
update News Item type
laszlocseh Feb 21, 2025
3911713
added News Item to type
laszlocseh Feb 21, 2025
2f84552
Fix special_tags index
tiberiuichim Feb 25, 2025
961b6f1
Remove extra definition of transformer
tiberiuichim Feb 26, 2025
43c37da
Don't insert extra images in slate img
tiberiuichim Feb 26, 2025
06ae229
Merge remote-tracking branch 'origin/master' into python3_merge_master
tiberiuichim Feb 27, 2025
4e60a51
Fix aceitem.py
tiberiuichim Feb 27, 2025
0720f37
Add dependency for collective.geolocationbehavior
tiberiuichim Feb 27, 2025
f6a4fbe
Merge pull request #173 from eea/python3_merge_master
tiberiuichim Feb 27, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
dist/*
*node_modules*
*~
*.bak
149 changes: 99 additions & 50 deletions eea/climateadapt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import OFS
import transaction
import collective.cover.config
# import collective.cover.config
from zope.i18nmessageid import MessageFactory as BaseMessageFactory

import Products.CMFCore.permissions
from AccessControl import ClassSecurityInfo
from AccessControl.class_init import InitializeClass
from eea.notifications import utils
# from eea.notifications import utils
from plone.dexterity.content import Container
from plone.i18n import normalizer
from App.ZApplication import ZApplicationWrapper


class UnicodeMessageFactory(BaseMessageFactory):
def __call__(self, *args, **kwds):
unicode_args = [unicode(s) for s in args]
unicode_args = [str(s) for s in args]
# __import__("pdb").set_trace()
return super(UnicodeMessageFactory, self).__call__(*unicode_args, **kwds)

Expand All @@ -30,7 +30,7 @@ def __call__(self, *args, **kwds):
# TODO: Find a way to do this without patching __ac_permissions__ directly
# monkey patch plone.dexterity.content.Container
# patch collective.cover grid system
collective.cover.config.DEFAULT_GRID_SYSTEM = "bootstrap3"
# collective.cover.config.DEFAULT_GRID_SYSTEM = "bootstrap3"

# patch max length URL fragment generation, makes for shorter IDs for content
normalizer.MAX_URL_LENGTH = 100
Expand Down Expand Up @@ -62,15 +62,15 @@ def drop_protected_attr_from_ac_permissions(attribute, classobj):


# Monkey eea.notifications get_tags
def get_tags_cca(obj):
try:
tags = obj.keywords
except Exception:
tags = ()
return tags
# def get_tags_cca(obj):
# try:
# tags = obj.keywords
# except Exception:
# tags = ()
# return tags


utils.get_tags = get_tags_cca
# utils.get_tags = get_tags_cca

# Raven repr monkey patch #129327

Expand All @@ -92,42 +92,91 @@ def ZApplicationWrapper__repr__(self):
ZApplicationWrapper.__repr__ = ZApplicationWrapper__repr__


def isLinked(obj):
"""check if the given content object is linked from another one
WARNING: this function can be time consuming !!
It deletes the object in a subtransaction that is rollbacked.
In other words, the object is kept safe.
Nevertheless, this implies that it also deletes recursively
all object's subobjects and references, which can be very
expensive.
"""
# first check to see if link integrity handling has been enabled at all
# and if so, if the removal of the object was already confirmed, i.e.
# while replaying the request; unfortunately this makes it necessary
# to import from plone.app.linkintegrity here, hence the try block...
try:
from plone.app.linkintegrity.interfaces import ILinkIntegrityInfo

info = ILinkIntegrityInfo(obj.REQUEST)
except (ImportError, TypeError):
# if p.a.li isn't installed the following check can be cut short...
return False
if not info.integrityCheckingEnabled():
return False
if info.isConfirmedItem(obj):
return True
# otherwise, when not replaying the request already, it is tried to
# delete the object, making it possible to find out if it was referenced,
# i.e. in case a link integrity exception was raised
linked = False
parent = obj.aq_inner.aq_parent
try:
savepoint = transaction.savepoint()
parent.manage_delObjects(obj.getId())
except OFS.ObjectManager.BeforeDeleteException:
linked = True
except Exception: # ignore other exceptions, not useful to us at this point
pass
finally:
savepoint.rollback()
return linked
# def isLinked(obj):
# """check if the given content object is linked from another one
# WARNING: this function can be time consuming !!
# It deletes the object in a subtransaction that is rollbacked.
# In other words, the object is kept safe.
# Nevertheless, this implies that it also deletes recursively
# all object's subobjects and references, which can be very
# expensive.
# """
# # first check to see if link integrity handling has been enabled at all
# # and if so, if the removal of the object was already confirmed, i.e.
# # while replaying the request; unfortunately this makes it necessary
# # to import from plone.app.linkintegrity here, hence the try block...
# try:
# from plone.app.linkintegrity.interfaces import ILinkIntegrityInfo

# info = ILinkIntegrityInfo(obj.REQUEST)
# except (ImportError, TypeError):
# # if p.a.li isn't installed the following check can be cut short...
# return False
# if not info.integrityCheckingEnabled():
# return False
# if info.isConfirmedItem(obj):
# return True
# # otherwise, when not replaying the request already, it is tried to
# # delete the object, making it possible to find out if it was referenced,
# # i.e. in case a link integrity exception was raised
# linked = False
# parent = obj.aq_inner.aq_parent
# try:
# savepoint = transaction.savepoint()
# parent.manage_delObjects(obj.getId())
# except OFS.ObjectManager.BeforeDeleteException:
# linked = True
# except Exception: # ignore other exceptions, not useful to us at this point
# pass
# finally:
# savepoint.rollback()
# return linked

# TODO remove this after plone 6 migration
from collective.exportimport.import_content import ImportContent
from collective.exportimport.import_content import get_absolute_blob_path
from plone.namedfile.file import NamedBlobFile
from plone.namedfile.file import NamedBlobImage

# Monkey patching import_blob_paths
_original_import_blob_paths = ImportContent.import_blob_paths

def patched_import_blob_paths(self, new, item):
for key, value in item.items():
# Look for dictionaries with a blob_path key.
if not isinstance(value, dict):
continue
blob_path = value.get("blob_path")
if not blob_path:
continue
abs_blob_path = get_absolute_blob_path(new, blob_path)
if not abs_blob_path:
return
__traceback_info__ = item
raise ValueError("Blob path {} does not exist!".format(blob_path))

# Determine the class to use: file or image.
filename = value["filename"]
content_type = value["content-type"]
if key == "file":
klass = NamedBlobFile
elif key == "image":
klass = NamedBlobImage
elif content_type.startswith("image"):
klass = NamedBlobImage
else:
klass = NamedBlobFile

# Write the field.
with open(abs_blob_path, "rb") as myfile:
blobdata = myfile.read()
field_value = klass(
data=blobdata,
contentType=content_type,
filename=filename,
)
setattr(new, key, field_value)

ImportContent.import_blob_paths = patched_import_blob_paths

print("Monkey patch for ImportContent.import_blob_paths applied")
Loading