From 341649a2d1e46c28a4eb14698d6c5fde5415688e Mon Sep 17 00:00:00 2001 From: Tim DiLauro Date: Mon, 4 Nov 2024 09:10:57 -0500 Subject: [PATCH] Add configuration settings for collections subscriptions. --- src/palace/manager/api/circulation.py | 27 ++++++++++++++++++++++ src/palace/manager/integration/settings.py | 1 + tests/manager/api/admin/test_form_data.py | 20 ++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/src/palace/manager/api/circulation.py b/src/palace/manager/api/circulation.py index bd1a8a07a5..127e25bdf6 100644 --- a/src/palace/manager/api/circulation.py +++ b/src/palace/manager/api/circulation.py @@ -563,6 +563,33 @@ class BaseCirculationApiSettings(BaseSettings): ) } + subscription_activation_date: str | None = FormField( + default=None, + form=ConfigurationFormItem( + label=_("Collection Subscription Activation Date"), + type=ConfigurationFormItemType.DATE, + description=( + "A date before which this collection is considered inactive. Associated libraries" + " will not be considered to be subscribed until this date). If not specified," + " it will not restrict any associated library's subscription status." + ), + required=False, + ), + ) + subscription_expiration_date: str | None = FormField( + default=None, + form=ConfigurationFormItem( + label=_("Collection Subscription Expiration Date"), + type=ConfigurationFormItemType.DATE, + description=( + "A date after which this collection is considered inactive. Associated libraries" + " will not be considered to be subscribed beyond this date). If not specified," + " it will not restrict any associated library's subscription status." + ), + required=False, + ), + ) + SettingsType = TypeVar("SettingsType", bound=BaseCirculationApiSettings, covariant=True) LibrarySettingsType = TypeVar("LibrarySettingsType", bound=BaseSettings, covariant=True) diff --git a/src/palace/manager/integration/settings.py b/src/palace/manager/integration/settings.py index ddbbc13b69..49d8b340ec 100644 --- a/src/palace/manager/integration/settings.py +++ b/src/palace/manager/integration/settings.py @@ -178,6 +178,7 @@ class ConfigurationFormItemType(Enum): """Enumeration of configuration setting types""" TEXT = None + DATE = "date-picker" TEXTAREA = "textarea" SELECT = "select" LIST = "list" diff --git a/tests/manager/api/admin/test_form_data.py b/tests/manager/api/admin/test_form_data.py index ada73e4f9e..1c1a020232 100644 --- a/tests/manager/api/admin/test_form_data.py +++ b/tests/manager/api/admin/test_form_data.py @@ -30,6 +30,22 @@ class MockSettings(BaseSettings): label="Field 3", ), ) + field4: str | None = FormField( + None, + form=ConfigurationFormItem( + label="Date field", + type=ConfigurationFormItemType.DATE, + description="A date.", + ), + ) + field5: str | None = FormField( + None, + form=ConfigurationFormItem( + label="Another date field", + type=ConfigurationFormItemType.DATE, + description="Another date.", + ), + ) def test_get_settings(): @@ -41,9 +57,13 @@ def test_get_settings(): ("field2_value3", "blah blah"), ("field2_value4", "blah blah blah"), ("field3", "value5"), + ("field4", "2024-10-23"), + ("field5", ""), ] ) settings = ProcessFormData.get_settings(MockSettings, data) assert settings.field1 == ["value1", "value2"] assert settings.field2 == ["value3", "value4"] assert settings.field3 == "value5" + assert settings.field4 == "2024-10-23" + assert settings.field5 is None