Skip to content

Commit

Permalink
exclude OAB from dataset short code length check
Browse files Browse the repository at this point in the history
  • Loading branch information
danangmassandy committed Aug 6, 2023
1 parent 1fac11c commit d8a8371
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions django_project/dashboard/api_views/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1114,18 +1114,28 @@ 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
)
if dataset:
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:
Expand Down

0 comments on commit d8a8371

Please sign in to comment.