From 7e2f6699b10b8f071883d49965ecb75d267ed839 Mon Sep 17 00:00:00 2001 From: i701 Date: Sun, 8 Jun 2025 15:23:18 +0500 Subject: [PATCH] Refactor imports in admin.py and update MAC address handling in views.py to improve code clarity and error handling --- api/admin.py | 3 --- devices/views.py | 9 ++++++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/admin.py b/api/admin.py index 0c19531..5266c7d 100644 --- a/api/admin.py +++ b/api/admin.py @@ -1,8 +1,5 @@ -from typing import Any from django.contrib import admin from django.contrib.auth.admin import UserAdmin as BaseUserAdmin -from django.forms.models import ModelForm -from django.http.request import HttpRequest from api.models import User, Atoll, Island, TemporaryUser from django.contrib.auth.models import Permission diff --git a/devices/views.py b/devices/views.py index 7bc4701..c6a568f 100644 --- a/devices/views.py +++ b/devices/views.py @@ -1,4 +1,5 @@ -from attr import dataclass +from dataclasses import dataclass +from xmlrpc.client import Boolean from rest_framework import generics, status from rest_framework.response import Response from django_filters.rest_framework import DjangoFilterBackend @@ -56,7 +57,7 @@ class DeviceListCreateAPIView( {"message": "Device with this mac address already exists."}, status=400 ) mac_details = get_mac_address_details(mac) - if mac_details.vendor == "Unknown": + if not mac_details.ok: return Response({"message": "MAC address vendor not found."}, status=400) mac = re.sub(NORMALIZE_MAC_REGEX, "-", mac).upper() @@ -154,6 +155,7 @@ class MacResponse: mac_address: str vendor: str detail: str | None = None + ok: Boolean = True def get_mac_address_details(mac: str) -> MacResponse: @@ -167,6 +169,7 @@ def get_mac_address_details(mac: str) -> MacResponse: mac_address=json_data.get("mac_address", mac), vendor=json_data.get("vendor", ""), detail=json_data.get("detail"), + ok=json_data.get("ok", True), ) else: - return MacResponse(mac_address=mac, vendor="Unknown", detail=None) + return MacResponse(mac_address=mac, vendor="Unknown", detail=None, ok=False)