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:
parent
8da8ac65c7
commit
e02e912c5d
|
@ -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..
|
||||
|
|
37
src/phonebook/migrations/0002_auto_20200310_1902.py
Normal file
37
src/phonebook/migrations/0002_auto_20200310_1902.py
Normal 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
|
||||
),
|
||||
),
|
||||
]
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue