Skip to content

Commit

Permalink
Fix upgrade step
Browse files Browse the repository at this point in the history
  • Loading branch information
folix-01 committed Jul 21, 2023
1 parent b043fff commit e2550f2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Changelog
5.0.5 (unreleased)
------------------

- Nothing changed yet.
- Fix bad upgrade step.
[folix-01]


5.0.4 (2023-07-04)
Expand Down
34 changes: 25 additions & 9 deletions src/design/plone/policy/upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@


def update_profile(context, profile, run_dependencies=True):
context.runImportStepFromProfile(DEFAULT_PROFILE, profile, run_dependencies)
context.runImportStepFromProfile(
DEFAULT_PROFILE, profile, run_dependencies
)


def update_types(context):
Expand Down Expand Up @@ -64,7 +66,9 @@ def fix_field_name(blocks):
installOrReinstallProduct(api.portal.get(), "collective.volto.formsupport")
logger.info("Changing form block fields.")
i = 0
brains = api.content.find(object_provides="plone.restapi.behaviors.IBlocks")
brains = api.content.find(
object_provides="plone.restapi.behaviors.IBlocks"
)
tot = len(brains)
fixed_items = []
for brain in brains:
Expand Down Expand Up @@ -93,7 +97,9 @@ def to_1300(context):


def to_1400(context):
old = api.portal.get_registry_record(name="design.plone.policy.twitter_token")
old = api.portal.get_registry_record(
name="design.plone.policy.twitter_token"
)
context.runAllImportStepsFromProfile("profile-design.plone.policy:to_1400")
update_registry(context)

Expand Down Expand Up @@ -174,7 +180,9 @@ def to_1910(context):
else:
new_sizes.append(size)
if "midi 300:65536" not in new_sizes:
new_sizes.insert(new_sizes.index("mini 200:65536") + 1, "midi 300:65536")
new_sizes.insert(
new_sizes.index("mini 200:65536") + 1, "midi 300:65536"
)
api.portal.set_registry_record("plone.allowed_sizes", new_sizes)


Expand Down Expand Up @@ -235,7 +243,9 @@ def fix_block(blocks):
blocks = value.get("blocks", {})
except AttributeError:
logger.warning(
"[RICHTEXT] - {} (not converted)".format(brain.getURL())
"[RICHTEXT] - {} (not converted)".format(
brain.getURL()
)
)
if blocks:
res = fix_block(blocks)
Expand Down Expand Up @@ -263,7 +273,9 @@ def update_folders(context, CHANGES=[], NEW_ITEMS=[]):
portal_name = portal.getId()
for item in CHANGES:
try:
folder = portal.restrictedTraverse("{}{}".format(portal_name, item))
folder = portal.restrictedTraverse(
"{}{}".format(portal_name, item)
)
old_title = folder.title
old_path = "/".join(folder.getPhysicalPath())
api.content.rename(obj=folder, new_id=CHANGES[item][1])
Expand All @@ -277,7 +289,9 @@ def update_folders(context, CHANGES=[], NEW_ITEMS=[]):
)
)
except KeyError:
logger.info("{} Impossibile modificare {}{}".format(RED, item, ENDC))
logger.info(
"{} Impossibile modificare {}{}".format(RED, item, ENDC)
)

for item in NEW_ITEMS:
folder = portal.restrictedTraverse("{}{}".format(portal_name, item[0]))
Expand Down Expand Up @@ -370,7 +384,7 @@ def to_3100(context):
def to_3101(context):
def remove_twitter(blocks_orig):
blocks = deepcopy(blocks_orig)
for key, block in blocks.items():
for key, block in deepcopy(blocks).items():
if block.get("@type", "") == "twitter_posts":
del blocks[key]

Expand All @@ -391,7 +405,9 @@ def remove_twitter(blocks_orig):
blocks = value.get("blocks", {})
except AttributeError:
logger.warning(
"[BLOCK] - {} (not converted)".format(brain.getURL())
"[BLOCK] - {} (not converted)".format(
brain.getURL()
)
)
if blocks:
item.blocks = remove_twitter(blocks)

0 comments on commit e2550f2

Please sign in to comment.