From d8a8371b097b21808312eaf7309a77d6a0671013 Mon Sep 17 00:00:00 2001 From: Danang Date: Sun, 6 Aug 2023 19:22:31 +0000 Subject: [PATCH] exclude OAB from dataset short code length check --- django_project/dashboard/api_views/dataset.py | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/django_project/dashboard/api_views/dataset.py b/django_project/dashboard/api_views/dataset.py index b1abfa40..2abfdd9c 100644 --- a/django_project/dashboard/api_views/dataset.py +++ b/django_project/dashboard/api_views/dataset.py @@ -1114,11 +1114,6 @@ class CheckDatasetShortCode(AzureAuthRequiredMixin, APIView): @staticmethod def check_dataset_short_code(short_code, dataset=None): """Return True if short_code is available""" - if len(short_code) != DATASET_SHORT_CODE_MAX_LENGTH: - return False, ( - 'ShortCode must be ' - f'{DATASET_SHORT_CODE_MAX_LENGTH} characters' - ) check_dataset = Dataset.objects.filter( short_code=short_code ) @@ -1126,6 +1121,21 @@ def check_dataset_short_code(short_code, dataset=None): check_dataset = check_dataset.exclude( id=dataset.id ) + exclusion = SitePreferences.preferences().short_code_exclusion + if exclusion and short_code == exclusion: + if not check_dataset.exists(): + return True, None + else: + return ( + False, + f'Master dataset with short_code {short_code} ' + 'has been created!' + ) + elif len(short_code) != DATASET_SHORT_CODE_MAX_LENGTH: + return False, ( + 'ShortCode must be ' + f'{DATASET_SHORT_CODE_MAX_LENGTH} characters' + ) is_available = not check_dataset.exists() error = None if not is_available: