Skip to content

Commit

Permalink
fix required description
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk committed Sep 17, 2024
1 parent dd168e6 commit 2bc4c00
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/iosanita/contenttypes/adapters/schema_tweaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, schema):
self.schema = schema

def __call__(self):
self.set_description_required()
# self.set_description_required()
self.fix_bando()

def set_description_required(self):
Expand Down
27 changes: 25 additions & 2 deletions src/iosanita/contenttypes/restapi/services/types/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from plone.restapi.services.types.get import TypesGet as BaseGet
from zope.interface import implementer
from zope.publisher.interfaces import IPublishTraverse
from iosanita.contenttypes.interfaces import IoSanitaMigrationMarker


class FieldsetsMismatchError(Exception):
Expand Down Expand Up @@ -139,15 +140,37 @@ def customize_versioning_fields_fieldset(self, result):
if fieldset.get("id") == "settings" and found:
fieldset["fields"].append(field)

return result
# return result

def set_description_required(self, result):
if IoSanitaMigrationMarker.providedBy(self.request):
return
portal_types = [
"Servizio",
"ComeFarePer",
"Struttura",
"News Item",
"Event",
"UnitaOrganizzativa",
"Documento",
"Bando",
]

if (
self.request.steps[-1] in portal_types
and "description" in result["properties"] # noqa
and "description" not in result["required"] # noqa
):
result["required"].append("description")

def reply(self):
result = super(TypesGet, self).reply()
if "fieldsets" in result:
result["fieldsets"] = self.reorder_fieldsets(schema=result)

if "title" in result:
result = self.customize_versioning_fields_fieldset(result)
self.customize_versioning_fields_fieldset(result)
self.set_description_required(result)
return result

def get_order_by_type(self, portal_type):
Expand Down
2 changes: 1 addition & 1 deletion src/iosanita/contenttypes/tests/test_ct_bando.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_bando_required_fields(self):
"descrizione_estesa",
"come_partecipare",
"modalita_selezione",
# "description", is required from schema_tweaks.py but it doesn't apply in test
"description",
]
),
)
Expand Down
2 changes: 1 addition & 1 deletion src/iosanita/contenttypes/tests/test_ct_come_fare_per.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def test_come_fare_per_required_fields(self):
[
"panoramica",
"title",
# "description", is required from schema_tweaks.py but it doesn't apply in test
"description",
]
),
)
Expand Down
2 changes: 1 addition & 1 deletion src/iosanita/contenttypes/tests/test_ct_documento.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_documento_required_fields(self):
"descrizione_estesa",
"uo_correlata",
"file",
# "description", is required from schema_tweaks.py but it doesn't apply in test
"description",
]
),
)
Expand Down
2 changes: 1 addition & 1 deletion src/iosanita/contenttypes/tests/test_ct_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_event_required_fields(self):
"start",
"tipologia_evento",
"title",
# "description", is required from schema_tweaks.py but it doesn't apply in test
"description",
]
),
)
Expand Down
1 change: 0 additions & 1 deletion src/iosanita/contenttypes/tests/test_ct_modulo.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def test_modulo_required_fields(self):
[
"title",
"file",
# "description", is required from schema_tweaks.py but it doesn't apply in test
]
),
)
Expand Down
2 changes: 1 addition & 1 deletion src/iosanita/contenttypes/tests/test_ct_news.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def test_bando_required_fields(self):
"descrizione_estesa",
"title",
"uo_correlata",
# "description", is required from schema_tweaks.py but it doesn't apply in test
"description",
]
),
)
Expand Down
4 changes: 2 additions & 2 deletions src/iosanita/contenttypes/tests/test_ct_servizio.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_servizio_required_fields(self):
"come_accedere",
"tempi_attesa",
"costi",
# "description", is required from schema_tweaks.py but it doesn't apply in test
"description",
"orari",
"uo_correlata",
"responsabile_correlato",
Expand Down Expand Up @@ -260,7 +260,7 @@ def test_servizio_default_children(self):
container=self.portal, type="Servizio", title="xxx"
)

self.assertEqual(servizio.keys(), ["allegati"])
self.assertEqual(servizio.keys(), ["modulistica", "allegati"])

def test_servizio_allegati_has_filtered_addable_types(self):
servizio = api.content.create(
Expand Down
2 changes: 1 addition & 1 deletion src/iosanita/contenttypes/tests/test_ct_struttura.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_struttura_required_fields(self):
sorted(
[
"come_accedere",
# "description", is required from schema_tweaks.py but it doesn't apply in test
"description",
"orari",
"pdc_correlato",
"responsabile_correlato",
Expand Down
2 changes: 1 addition & 1 deletion src/iosanita/contenttypes/tests/test_ct_uo.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_uo_required_fields(self):
sorted(
[
"competenze",
# "description", is required from schema_tweaks.py but it doesn't apply in test
"description",
"orari",
"pdc_correlato",
"responsabile_correlato",
Expand Down

0 comments on commit 2bc4c00

Please sign in to comment.