Skip to content

Commit

Permalink
PrenotazioniFolder.cosa_serve field type to RichText (#100)
Browse files Browse the repository at this point in the history
* Transform PrenotazioniFolder.cosa_serve to RichText field type

* Add upgrade step

* Add logging

* Blacked
  • Loading branch information
folix-01 authored Oct 6, 2023
1 parent 040d59e commit 2e50397
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changelog
2.0.1 (unreleased)
------------------

- Change PrenotazioniFolder.cosa_serve field type to RichText
[folix-01]

- Utilizzare defaultFactory se il default è una funzione, altrimenti non viene
eseguita nel momento corretto.
[mamico]
Expand Down
2 changes: 1 addition & 1 deletion src/redturtle/prenotazioni/content/prenotazioni_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class IPrenotazioniFolder(model.Schema):

form.mode(descriptionAgenda="display")

cosa_serve = schema.Text(
cosa_serve = RichText(
required=False,
title=_("Cosa serve", default="Cosa serve"),
description=_(
Expand Down
2 changes: 1 addition & 1 deletion src/redturtle/prenotazioni/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<version>1804</version>
<version>1805</version>
<dependencies>
<dependency>profile-plone.app.dexterity:default</dependency>
<dependency>profile-collective.z3cform.datagridfield:default</dependency>
Expand Down
20 changes: 20 additions & 0 deletions src/redturtle/prenotazioni/upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,23 @@ def to_1804(self):
):
logger.info("Updating <{UID}>.max_bookings_allowed=2".format(UID=brain.UID))
brain.getObject().max_bookings_allowed = 2


def to_1805(self):
from plone.app.textfield.value import RichTextValue

for brain in api.portal.get_tool("portal_catalog")(
portal_type="PrenotazioniFolder"
):
obj = brain.getObject()

if obj.cosa_serve and type(obj.cosa_serve) is not RichTextValue:
obj.cosa_serve = RichTextValue(
raw=obj.cosa_serve,
mimeType="text/html",
outputMimeType="text/html",
encoding="utf-8",
)
logger.info(
"Converted <{UID}>.cosa_serve to RichText".format(UID=brain.UID)
)
10 changes: 10 additions & 0 deletions src/redturtle/prenotazioni/upgrades.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,14 @@
handler=".upgrades.to_1804"
/>
</genericsetup:upgradeSteps>
<genericsetup:upgradeSteps
profile="redturtle.prenotazioni:default"
source="1804"
destination="1805"
>
<genericsetup:upgradeStep
title="Convert PrenotazioniFolder.cosa_serve type to RichText"
handler=".upgrades.to_1805"
/>
</genericsetup:upgradeSteps>
</configure>

0 comments on commit 2e50397

Please sign in to comment.