Skip to content

Commit

Permalink
Add upgrade step
Browse files Browse the repository at this point in the history
  • Loading branch information
folix-01 committed Oct 6, 2023
1 parent bc12705 commit 23d9d8e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 26 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
33 changes: 8 additions & 25 deletions src/redturtle/prenotazioni/content/prenotazioni_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
from redturtle.prenotazioni import _
from redturtle.prenotazioni.browser.widget import WeekTableOverridesFieldWidget
from redturtle.prenotazioni.config import DEFAULT_VISIBLE_BOOKING_FIELDS
from redturtle.prenotazioni.content.validators import (
PauseValidator,
checkOverrides,
)
from redturtle.prenotazioni.content.validators import PauseValidator, checkOverrides

try:
from plone.app.dexterity import textindexer
Expand All @@ -45,9 +42,7 @@ def get_from_form(form, fieldname):
return value
return None

number_of_entry = request.form.get(
"form.widgets.{}.count".format(fieldname)
)
number_of_entry = request.form.get("form.widgets.{}.count".format(fieldname))
data = []
prefix = "form.widgets.{}".format(fieldname)
for counter in range(int(number_of_entry)):
Expand Down Expand Up @@ -87,9 +82,7 @@ class IWeekTableRow(model.Schema):
)

afternoon_start = schema.Choice(
title=_(
"afternoon_start_label", default="Start time in the afternoon"
),
title=_("afternoon_start_label", default="Start time in the afternoon"),
vocabulary="redturtle.prenotazioni.VocOreInizio",
required=False,
)
Expand Down Expand Up @@ -224,9 +217,7 @@ class IPrenotazioniFolder(model.Schema):
descriptionAgenda = RichText(
required=False,
title=_("Descrizione Agenda", default="Descrizione Agenda"),
description=_(
"Inserire il testo di presentazione dell'agenda corrente"
),
description=_("Inserire il testo di presentazione dell'agenda corrente"),
)

form.mode(descriptionAgenda="display")
Expand All @@ -241,9 +232,7 @@ class IPrenotazioniFolder(model.Schema):

directives.widget(visible_booking_fields=CheckBoxFieldWidget)
visible_booking_fields = schema.List(
title=_(
"label_visible_booking_fields", default="Visible booking fields"
),
title=_("label_visible_booking_fields", default="Visible booking fields"),
description=_(
"help_visible_booking_fields",
"User will not be able to add a booking unless those "
Expand All @@ -261,9 +250,7 @@ class IPrenotazioniFolder(model.Schema):

directives.widget(required_booking_fields=CheckBoxFieldWidget)
required_booking_fields = schema.List(
title=_(
"label_required_booking_fields", default="Required booking fields"
),
title=_("label_required_booking_fields", default="Required booking fields"),
description=_(
"help_required_booking_fields",
"User will not be able to add a booking unless those "
Expand Down Expand Up @@ -513,14 +500,10 @@ def data_validation(data):
raise Invalid(_("You should set a start time for afternoon."))
if interval["morning_start"] and interval["morning_end"]:
if interval["morning_start"] > interval["morning_end"]:
raise Invalid(
_("Morning start should not be greater than end.")
)
raise Invalid(_("Morning start should not be greater than end."))
if interval["afternoon_start"] and interval["afternoon_end"]:
if interval["afternoon_start"] > interval["afternoon_end"]:
raise Invalid(
_("Afternoon start should not be greater than end.")
)
raise Invalid(_("Afternoon start should not be greater than end."))

# TODO: definire o descrivere quando avviee la notifica
# TODO: inserire qui la chiave IO ? o su un config in zope.conf/environment ?
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
17 changes: 17 additions & 0 deletions src/redturtle/prenotazioni/upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,20 @@ 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",
)
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 23d9d8e

Please sign in to comment.