validate mesh node address
This commit is contained in:
parent
320ae7b4c9
commit
e3afa4b2ea
2 changed files with 38 additions and 1 deletions
30
src/c3nav/mesh/migrations/0011_meshnode_address_validate.py
Normal file
30
src/c3nav/mesh/migrations/0011_meshnode_address_validate.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
# Generated by Django 4.2.1 on 2023-11-10 17:53
|
||||
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("mesh", "0010_otaupdate_otaupdaterecipient"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="meshnode",
|
||||
name="address",
|
||||
field=models.CharField(
|
||||
max_length=17,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
validators=[
|
||||
django.core.validators.RegexValidator(
|
||||
code="invalid_macaddress",
|
||||
message="Must be a lower-case mac address",
|
||||
regex="^([a-f0-9]{2}:){5}[a-f0-9]{2}$",
|
||||
)
|
||||
],
|
||||
verbose_name="mac address",
|
||||
),
|
||||
),
|
||||
]
|
|
@ -7,6 +7,7 @@ from operator import attrgetter
|
|||
from typing import Any, Mapping, Optional, Self
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.validators import RegexValidator
|
||||
from django.db import NotSupportedError, models
|
||||
from django.db.models import Q, UniqueConstraint
|
||||
from django.utils import timezone
|
||||
|
@ -199,7 +200,13 @@ class MeshNode(models.Model):
|
|||
"""
|
||||
A nesh node. Any node.
|
||||
"""
|
||||
address = models.CharField(_('mac address'), max_length=17, primary_key=True)
|
||||
address = models.CharField(_('mac address'), max_length=17, primary_key=True,
|
||||
validators=[RegexValidator(
|
||||
regex='^([a-f0-9]{2}:){5}[a-f0-9]{2}$',
|
||||
message='Must be a lower-case mac address',
|
||||
code='invalid_macaddress'
|
||||
)])
|
||||
|
||||
name = models.CharField(_('name'), max_length=32, null=True, blank=True)
|
||||
first_seen = models.DateTimeField(_('first seen'), auto_now_add=True)
|
||||
uplink = models.ForeignKey('MeshUplink', models.PROTECT, null=True,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue