diff --git a/src/phonebook/dectutils.py b/src/phonebook/dectutils.py index 7be4eff4..957fb330 100644 --- a/src/phonebook/dectutils.py +++ b/src/phonebook/dectutils.py @@ -9,14 +9,16 @@ class DectUtils: """ DECT_MATRIX = { - "2": ["A", "B", "C"], - "3": ["D", "E", "F"], - "4": ["G", "H", "I"], - "5": ["J", "K", "L"], - "6": ["M", "N", "O"], - "7": ["P", "Q", "R", "S"], - "8": ["T", "U", "V"], - "9": ["W", "X", "Y", "Z"], + "0": ["0"], + "1": ["1"], + "2": ["2", "A", "B", "C"], + "3": ["3", "D", "E", "F"], + "4": ["4", "G", "H", "I"], + "5": ["5", "J", "K", "L"], + "6": ["6", "M", "N", "O"], + "7": ["7", "P", "Q", "R", "S"], + "8": ["8", "T", "U", "V"], + "9": ["9", "W", "X", "Y", "Z"], } def __init__(self): @@ -32,11 +34,6 @@ class DectUtils: """ 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 for letter in self.DECT_MATRIX[numbers[0]]: # if we have more digits.. diff --git a/src/phonebook/migrations/0002_auto_20200310_1902.py b/src/phonebook/migrations/0002_auto_20200310_1902.py new file mode 100644 index 00000000..90e39808 --- /dev/null +++ b/src/phonebook/migrations/0002_auto_20200310_1902.py @@ -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 + ), + ), + ] diff --git a/src/phonebook/models.py b/src/phonebook/models.py index 79f78911..3e4147cf 100644 --- a/src/phonebook/models.py +++ b/src/phonebook/models.py @@ -29,18 +29,18 @@ class DectRegistration(CampRelatedModel): ) 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( max_length=9, 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( 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( @@ -65,6 +65,12 @@ class DectRegistration(CampRelatedModel): 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. """ + # 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 if ( DectRegistration.objects.filter(camp=self.camp, number=self.number)