From ee54386fd5dfd009a7c880efde6c6da7973d12d0 Mon Sep 17 00:00:00 2001 From: i701 Date: Sun, 27 Jul 2025 14:59:08 +0500 Subject: [PATCH] =?UTF-8?q?feat(devices):=20enhance=20device=20naming=20to?= =?UTF-8?q?=20include=20user=20details=20and=20enforce=20name=20length=20l?= =?UTF-8?q?imit=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- billing/views.py | 5 +++-- devices/views.py | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/billing/views.py b/billing/views.py index f0c27b8..1b129b6 100644 --- a/billing/views.py +++ b/billing/views.py @@ -183,6 +183,7 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView): devices = payment.devices.all() data = request.data user = request.user + user_details = f"{user.first_name.capitalize() if user.first_name else ''} {user.last_name.capitalize() if user.last_name else ''} {user.mobile}" # type: ignore omada_client = Omada() if payment.paid: return Response( @@ -218,7 +219,7 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView): device_list.append( { "mac": device.mac, - "name": device.name, + "name": f"{user_details} - {device.name}", } ) if device.registered: @@ -261,7 +262,7 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView): device_list.append( { "mac": device.mac, - "name": device.name, + "name": f"{user_details} - {device.name}", } ) if device.registered: diff --git a/devices/views.py b/devices/views.py index 7f13afc..ff3adb7 100644 --- a/devices/views.py +++ b/devices/views.py @@ -67,6 +67,15 @@ class DeviceListCreateAPIView( return DeviceSerializer def create(self, request, *args, **kwargs): + user = request.user + name = request.data.get("name", None) + user_details = f"{user.first_name.capitalize() if user.first_name else ''} {user.last_name.capitalize() if user.last_name else ''} {user.mobile}" # type: ignore + omada_device_name = f"{user_details} - {name}" if name else user_details + if len(omada_device_name) > 64: + return Response( + {"message": "Device name is too long."}, + status=400, + ) mac = request.data.get("mac", None) MAC_REGEX = re.compile(r"^([0-9A-Fa-f]{2}([.:-]?)){5}[0-9A-Fa-f]{2}$") NORMALIZE_MAC_REGEX = re.compile(r"[^0-9A-Fa-f]")