From bcc745244b1a4eb71d0b70be20180e7efec9a3de Mon Sep 17 00:00:00 2001 From: Shingo Aoyama Date: Thu, 9 May 2024 10:24:42 +1200 Subject: [PATCH] Setting for unique constraint on project titles --- coldfront/config/core.py | 1 + coldfront/core/project/models.py | 3 ++- docs/pages/config.md | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/coldfront/config/core.py b/coldfront/config/core.py index 581452f40..537d7671a 100644 --- a/coldfront/config/core.py +++ b/coldfront/config/core.py @@ -17,6 +17,7 @@ # Enable Project Review #------------------------------------------------------------------------------ PROJECT_ENABLE_PROJECT_REVIEW = ENV.bool('PROJECT_ENABLE_PROJECT_REVIEW', default=True) +PROJECT_TITLE_UNIQUE = ENV.bool('PROJECT_TITLE_UNIQUE', default=False) #------------------------------------------------------------------------------ # Allocation related diff --git a/coldfront/core/project/models.py b/coldfront/core/project/models.py index 45f9470ac..a1d4c817e 100644 --- a/coldfront/core/project/models.py +++ b/coldfront/core/project/models.py @@ -15,6 +15,7 @@ from coldfront.core.utils.common import import_from_settings PROJECT_ENABLE_PROJECT_REVIEW = import_from_settings('PROJECT_ENABLE_PROJECT_REVIEW', False) +PROJECT_TITLE_UNIQUE = import_from_settings('PROJECT_TITLE_UNIQUE', False) class ProjectPermission(Enum): """ A project permission stores the user, manager, pi, and update fields of a project. """ @@ -76,7 +77,7 @@ def get_by_natural_key(self, title, pi_username): We do not have information about your research. Please provide a detailed description of your work and update your field of science. Thank you! ''' - title = models.CharField(max_length=255,) + title = models.CharField(max_length=255, unique=PROJECT_TITLE_UNIQUE,) pi = models.ForeignKey(User, on_delete=models.CASCADE,) description = models.TextField( default=DEFAULT_DESCRIPTION, diff --git a/docs/pages/config.md b/docs/pages/config.md index bd1983329..3ba73792b 100644 --- a/docs/pages/config.md +++ b/docs/pages/config.md @@ -87,6 +87,7 @@ The following settings are ColdFront specific settings related to the core appli | CENTER_PROJECT_RENEWAL_HELP_URL | The URL of the article describing project renewals | | CENTER_BASE_URL | The base URL of your center. | | PROJECT_ENABLE_PROJECT_REVIEW | Enable or disable project reviews. Default True| +| PROJECT_TITLE_UNIQUE | Enable or disable unique constraint on project titles. Default False | | ALLOCATION_ENABLE_ALLOCATION_RENEWAL | Enable or disable allocation renewals. Default True | | ALLOCATION_DEFAULT_ALLOCATION_LENGTH | Default number of days an allocation is active for. Default 365 | | ALLOCATION_ENABLE_CHANGE_REQUESTS_BY_DEFAULT | Enable or disable allocation change requests. Default True |