Skip to content

Commit

Permalink
Set max callsign length
Browse files Browse the repository at this point in the history
  • Loading branch information
elnappo committed Apr 16, 2019
1 parent 0a1a62e commit f3d8053
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions project_novis/callsign/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
CALLSIGN_REGEX_COMPILE = re.compile(CALLSIGN_REGEX)
CALLSIGN_EXTRACT_REGEX_COMPILE = re.compile(
r"(?=.*[a-zA-Z])([A-Z0-9]+[/_-])?([a-zA-Z]+[0-9][a-zA-Z]+)([/-_][A-Z0-9]+)?")
CALLSIGN_MAX_LENGTH = 16


class CallsignField(models.CharField):
Expand Down Expand Up @@ -95,12 +96,14 @@ def extract_callsign(value: str) -> str:
value = value.replace(" ", "").upper()

if CALLSIGN_REGEX_COMPILE.search(value):
return value
if len(value) <= CALLSIGN_MAX_LENGTH:
return value

callsign_groups = CALLSIGN_EXTRACT_REGEX_COMPILE.search(value)

if callsign_groups:
return callsign_groups.group(2)
if len(value) <= CALLSIGN_MAX_LENGTH:
return callsign_groups.group(2)

return ""

Expand Down

0 comments on commit f3d8053

Please sign in to comment.