Open zopyx opened 2 years ago
The basic assumption that every parent is a Folder
of this code
is wrong. Parent containers can be arbitrary containerish types. This must be taken into account.
It also does not help (as a workaround) to import some container type before the other container type because there parents might be mixed in any arbitrary combination.
There is perhaps another flaw in the parent handling. Our File.json
contains an item http://nohost/eteaching/praxis/digital-learning-map-2020/180202_CfP_pdf.pdf
with this parent
:
'parent': {'@id': 'http://nohost/eteaching/praxis/digital-learning-map-2020',
'@type': 'eteaching.policy.projectsite',
'description': 'Was macht Lernen mit digitalen Medien an '
'Hochschulen erfolgreich? Das untersuchte das vom '
'BMBF geförderte Projekt Digital Learning Map 2020 '
'(LearnMap). Das dreijährige Projekt lief von 2017 '
'bis Anfang 2020 am Leibniz-Institut für '
'Wissensmedien (IWM) in Tübingen und betrachtete '
'das Thema Digitalisierung von Hochschulen aus '
'unterschiedlichen Perspektiven.',
'review_state': 'published',
'title': 'Digital Learning Map 2020'},
With the current implementation, both parent folders praxis/digital-learning-map-2020
would be created as Folder
which is wrong as discussed above. The container type for digital-learning-map-2020
could be created correctly with the information given from parent
. However, there is no information about praxis
which could a non-Folder
too.
I think, we need
parents
information on the export side rather than only parent
collective.exportimport
would have to deal with multiple parents
and arbitrary @type
information for each parent rather than assuming Folder
I implemented the @parents
export through a customer export hook like
def global_dict_hook(self, item, obj):
"""Use this to modify or skip the serialized data by type.
Return the modified dict (item) or None if you want to skip this particular object.
"""
def getAcquisitionChain(object):
inner = object.aq_inner
iter = inner
while iter is not None:
yield iter
if ISiteRoot.providedBy(iter):
break
if not hasattr(iter, "aq_parent"):
raise RuntimeError("Parent traversing interrupted by object: " + str(parent))
iter = iter.aq_parent
parents = list()
p_chain = reversed(list(getAcquisitionChain(obj)))
for p in p_chain:
try:
state = get_state(p)
except:
state = ""
if p.portal_type != 'Plone Site' and p != obj:
parents.append({
"@id": p.absolute_url(),
"@type": p.portal_type,
"description": p.Description(),
"title": p.Title(),
"review_state": state
})
item["parents"] = parents
The following (ugly) code recreates the folderish objects with the correct portal_type and workflow state:
Situation:
File.json
Folder
instances but more specialized DX container classesFolder
independent of@type
value of the parent item:https://github.com/collective/collective.exportimport/blob/main/src/collective/exportimport/import_content.py#L831