Skip to content

Commit

Permalink
Fix missing values for facilities lists
Browse files Browse the repository at this point in the history
This was causing `None` in REST views filters
  • Loading branch information
laulaz committed Nov 13, 2023
1 parent 56c0a15 commit 220f04b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ Changelog
1.2.2 (unreleased)
------------------

- Nothing changed yet.
- Fix missing values for topics / iam lists (causing `None` in REST views filters)
See https://github.com/collective/collective.solr/issues/366
[laulaz]


1.2.1 (2023-10-26)
Expand Down
1 change: 1 addition & 0 deletions src/imio/directory/core/contents/contact/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ class IContact(
"Important! These categories make it possible to highlight and geolocate certain basic services"
),
value_type=schema.Choice(vocabulary="imio.directory.vocabulary.Facilities"),
default=[],
required=False,
)
directives.widget(facilities=SelectFieldWidget)
Expand Down
2 changes: 1 addition & 1 deletion src/imio/directory/core/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>1011</version>
<version>1012</version>
<dependencies>
<dependency>profile-plone.app.dexterity:default</dependency>
<dependency>profile-plone.gallery:default</dependency>
Expand Down
9 changes: 9 additions & 0 deletions src/imio/directory/core/upgrades/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,13 @@
profile="imio.directory.core:default"
/>

<genericsetup:upgradeStep
title="Fix missing values for facilities lists"
description=""
source="1011"
destination="1012"
handler=".upgrades.fix_missing_values_for_facilities_lists"
profile="imio.directory.core:default"
/>

</configure>
12 changes: 12 additions & 0 deletions src/imio/directory/core/upgrades/upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,15 @@ def fix_type(contact, field_name):
fix_type(contact, "private_phones")
fix_type(contact, "private_mails")
fix_type(contact, "private_urls")


def fix_missing_values_for_facilities_lists(context):
catalog = api.portal.get_tool("portal_catalog")
with api.env.adopt_user(username="admin"):
brains = api.content.find(portal_type=["imio.directory.Contact"])
for brain in brains:
obj = brain.getObject()
if hasattr(obj, "facilities") and obj.facilities is None:
obj.facilities = []
catalog.catalog_object(obj, idxs=["facilities"])
logger.info(f"Fixed None list for Facilities on {obj.absolute_url()}")

0 comments on commit 220f04b

Please sign in to comment.