-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[settings] | ||
profile = plone |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# -*- coding: utf-8 -*- | ||
from .upgrades import logger | ||
from Acquisition import aq_base | ||
from plone import api | ||
from plone.namedfile import file | ||
|
||
|
||
def to_7300(context): | ||
|
||
mapping = { | ||
# portal_type | ||
"Documento Personale": { | ||
# field: "type" | ||
"immagine": "image", | ||
"pratica_associata": "file", | ||
}, | ||
"Messaggio": { | ||
"documenti _allegati": "file", | ||
}, | ||
"Persona": { | ||
"foto_persona": "image", | ||
}, | ||
"RicevutaPagamento": { | ||
"stampa_ricevuta": "file", | ||
"pratica_associata": "file", | ||
"allegato": "file", | ||
}, | ||
} | ||
|
||
mapping_types = { | ||
"image": (file.NamedImage, file.NamedBlobImage), | ||
"file": (file.NamedFile, file.NamedBlobFile), | ||
} | ||
|
||
for portal_type, fields in mapping.items(): | ||
brains = api.content.find(unrestricted=True, portal_type=portal_type) | ||
logger.info("Updating fields for %s %s objects", portal_type, len(brains)) | ||
for brain in brains: | ||
obj = aq_base(brain.getObject()) | ||
for fieldname, _type in fields.items(): | ||
value = getattr(obj, fieldname, None) | ||
# if value: | ||
# import pdb; pdb.set_trace() | ||
if value and isinstance(value, mapping_types[_type][0]): | ||
logger.info("Updated %s for %s", fieldname, brain.getPath()) | ||
setattr( | ||
obj, | ||
fieldname, | ||
mapping_types[_type][1]( | ||
data=value.data, | ||
contentType=value.contentType, | ||
filename=value.filename, | ||
), | ||
) | ||
logger.info("Finished updating fields") |