fix 500 error when including letters in dect number field, update description to clarify that the field is for numbers only. While here, update some other help_texts in the DectRegistration model, and add so numbers can be used in the letters field. Also allow using 0 and 1 in phone numbers, even though they can not be expressed as letters, only as 0 and 1. Fixes #481 and #480

This commit is contained in:
Thomas Steen Rasmussen 2020-03-10 19:08:28 +01:00
parent 8da8ac65c7
commit e02e912c5d
3 changed files with 56 additions and 16 deletions

View file

@ -9,14 +9,16 @@ class DectUtils:
""" """
DECT_MATRIX = { DECT_MATRIX = {
"2": ["A", "B", "C"], "0": ["0"],
"3": ["D", "E", "F"], "1": ["1"],
"4": ["G", "H", "I"], "2": ["2", "A", "B", "C"],
"5": ["J", "K", "L"], "3": ["3", "D", "E", "F"],
"6": ["M", "N", "O"], "4": ["4", "G", "H", "I"],
"7": ["P", "Q", "R", "S"], "5": ["5", "J", "K", "L"],
"8": ["T", "U", "V"], "6": ["6", "M", "N", "O"],
"9": ["W", "X", "Y", "Z"], "7": ["7", "P", "Q", "R", "S"],
"8": ["8", "T", "U", "V"],
"9": ["9", "W", "X", "Y", "Z"],
} }
def __init__(self): def __init__(self):
@ -32,11 +34,6 @@ class DectUtils:
""" """
Generator to recursively get all combinations of letters for this number Generator to recursively get all combinations of letters for this number
""" """
if "0" in numbers or "1" in numbers:
logger.error(
"Numbers with 0 or 1 in them are not expressible as letters, bail out"
)
return False
# loop over the possible letters for the first digit # loop over the possible letters for the first digit
for letter in self.DECT_MATRIX[numbers[0]]: for letter in self.DECT_MATRIX[numbers[0]]:
# if we have more digits.. # if we have more digits..

View file

@ -0,0 +1,37 @@
# Generated by Django 3.0.3 on 2020-03-10 18:02
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("phonebook", "0001_initial"),
]
operations = [
migrations.AlterField(
model_name="dectregistration",
name="description",
field=models.TextField(
blank=True,
help_text="Description of this registration, like a name/handle, or a location or service name.",
),
),
migrations.AlterField(
model_name="dectregistration",
name="letters",
field=models.CharField(
blank=True,
help_text="The letters or numbers chosen to represent this DECT number in the phonebook. Optional.",
max_length=9,
),
),
migrations.AlterField(
model_name="dectregistration",
name="number",
field=models.CharField(
help_text="The DECT phonenumber, four digits or more.", max_length=9
),
),
]

View file

@ -29,18 +29,18 @@ class DectRegistration(CampRelatedModel):
) )
number = models.CharField( number = models.CharField(
max_length=9, help_text="The DECT number, numeric or as letters", max_length=9, help_text="The DECT phonenumber, four digits or more.",
) )
letters = models.CharField( letters = models.CharField(
max_length=9, max_length=9,
blank=True, blank=True,
help_text="The letters chosen to represent this DECT number in the phonebook. Optional.", help_text="The letters or numbers chosen to represent this DECT number in the phonebook. Optional.",
) )
description = models.TextField( description = models.TextField(
blank=True, blank=True,
help_text="Description of this registration, like a name or a location or a service.", help_text="Description of this registration, like a name/handle, or a location or service name.",
) )
activation_code = models.CharField( activation_code = models.CharField(
@ -65,6 +65,12 @@ class DectRegistration(CampRelatedModel):
This code really belongs in model.clean(), but that gets called before form_valid() This code really belongs in model.clean(), but that gets called before form_valid()
which is where we set the Camp object for the model instance. which is where we set the Camp object for the model instance.
""" """
# First of all, check that number is numeric
try:
int(self.number)
except ValueError:
raise ValidationError("Phonenumber must be numeric!")
# check for conflicts with the same number # check for conflicts with the same number
if ( if (
DectRegistration.objects.filter(camp=self.camp, number=self.number) DectRegistration.objects.filter(camp=self.camp, number=self.number)