mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-04-30 13:55:41 +00:00
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 4m12s
- Updated the `reverse_dhivehi_string` function to correct the range for combining characters. - Added new device handling in the health check view and integrated the `add_new_devices_to_omada` task. - Improved date handling in `CreateTemporaryUserView` to ensure proper string conversion. - Enhanced OTP sending by converting mobile numbers to strings. - Implemented MAC address validation in the `Device` model using a custom validator. - Removed unnecessary fields from the `CreateDeviceSerializer`. - Normalized MAC address format in the `DeviceListCreateAPIView`. - Updated the `djangopasswordlessknox` package to improve code consistency and readability. - Added migration to enforce MAC address validation in the database.
43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
from django.db import models
|
|
from django.utils import timezone
|
|
from api.models import User
|
|
import regex
|
|
from django.core.exceptions import ValidationError
|
|
|
|
|
|
def validate_mac_address(value):
|
|
if not regex.match(r"^([0-9A-Fa-f]{2}-){5}[0-9A-Fa-f]{2}$", value):
|
|
raise ValidationError(
|
|
"This field accepts a valid MAC address in the format XX-XX-XX-XX-XX-XX using '-' as the separator."
|
|
)
|
|
return value
|
|
|
|
|
|
class Device(models.Model):
|
|
name = models.CharField(max_length=255)
|
|
mac = models.CharField(
|
|
max_length=255,
|
|
validators=[
|
|
validate_mac_address,
|
|
],
|
|
)
|
|
has_a_pending_payment = models.BooleanField(default=False)
|
|
reason_for_blocking = models.CharField(max_length=255, null=True, blank=True)
|
|
is_active = models.BooleanField(default=False)
|
|
registered = models.BooleanField(default=False)
|
|
blocked = models.BooleanField(default=False)
|
|
blocked_by = models.CharField(
|
|
max_length=255,
|
|
choices=[("ADMIN", "Admin"), ("PARENT", "Parent")],
|
|
default="PARENT",
|
|
)
|
|
expiry_date = models.DateTimeField(null=True, blank=True)
|
|
created_at = models.DateTimeField(default=timezone.now)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
user = models.ForeignKey(
|
|
User, on_delete=models.SET_NULL, null=True, blank=True, related_name="devices"
|
|
)
|
|
|
|
def __str__(self):
|
|
return self.name
|