Skip to content

Commit

Permalink
Add upgrade-step to set a default cost text for events (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk authored Oct 26, 2023
1 parent b5a7dd0 commit 0ea8f2e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 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
6.0.20 (unreleased)
-------------------

- Nothing changed yet.
- Add upgrade-step to set a default cost text for events.
[cekk]


6.0.19 (2023-10-25)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<metadata>
<version>7011</version>
<version>7012</version>
<dependencies>
<dependency>profile-redturtle.bandi:default</dependency>
<dependency>profile-collective.venue:default</dependency>
Expand Down
11 changes: 10 additions & 1 deletion src/design/plone/contenttypes/upgrades/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -764,5 +764,14 @@
handler=".upgrades.to_7011"
/>
</genericsetup:upgradeSteps>

<genericsetup:upgradeSteps
profile="design.plone.contenttypes:default"
source="7011"
destination="7012"
>
<genericsetup:upgradeStep
title="Set default value in prezzo field because now is required"
handler=".upgrades.to_7012"
/>
</genericsetup:upgradeSteps>
</configure>
43 changes: 43 additions & 0 deletions src/design/plone/contenttypes/upgrades/upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from Products.CMFPlone.interfaces import ISelectableConstrainTypes
from redturtle.bandi.interfaces.settings import IBandoSettings
from transaction import commit
from uuid import uuid4
from z3c.relationfield import RelationValue
from zope.component import getUtility
from zope.event import notify
Expand Down Expand Up @@ -1501,3 +1502,45 @@ def to_7011(context):
doc = brain.getObject()
doc.reindexObject(idxs=["SearchableText"])
logger.info("Ends of reindex")


def to_7012(context):
logger.info("Set default value in prezzo field because now is required.")

brains = api.content.find(portal_type=["Event"])
tot = len(brains)
logger.info(f"Found {tot} Events.")
i = 0
fixed = []
for brain in brains:
i += 1
if i % 100 == 0:
logger.info("Progress: {}/{}".format(i, tot))
event = brain.getObject()
prezzo = getattr(event, "prezzo", None)
if not prezzo or prezzo == {"blocks": {}, "blocks_layout": {"items": []}}:
fixed.append(brain.getPath())
uid = str(uuid4())
event.prezzo = {
"blocks": {
uid: {
"@type": "text",
"text": {
"blocks": [
{
"key": "fvsj1",
"text": "Eventuali costi sono indicati nella descrizione dell’evento.",
"type": "unstyled",
"depth": 0,
"inlineStyleRanges": [],
"entityRanges": [],
"data": {},
}
],
"entityMap": {},
},
}
},
"blocks_layout": {"items": [uid]},
}
logger.info(f"Fixed {len(fixed)} Events.")

0 comments on commit 0ea8f2e

Please sign in to comment.