Before Release 27 March

This commit is contained in:
fjrodriguez
2023-03-24 15:32:05 -06:00
parent 4af3b42372
commit 17795193d3
4 changed files with 17 additions and 17 deletions

View File

@@ -0,0 +1,3 @@
{
"python.analysis.typeCheckingMode": "basic"
}

View File

@@ -26,10 +26,8 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'allauth',
'allauth.account',
'allauth.socialaccount',

View File

@@ -2,7 +2,7 @@
from rest_framework import serializers
from .models import Device, Sistema, sistemas_por_cliente
from Clientes.models import Clientes
from django.db.models import Q
from django.db.models import Q
class SistemaPrimaryKeyRelatedField(serializers.PrimaryKeyRelatedField):
def to_internal_value(self,data):
@@ -38,11 +38,9 @@ class DeviceSerializer(serializers.ModelSerializer):
mac_address = self.context['request'].data.get('macAddress')
sistema = validated_data['sistema']
client = validated_data['client']
existing_devices = Device.objects.filter(
Q(sistema=sistema)& Q(client=client)& Q(macAddress=mac_address)
Q(sistema=sistema)& Q(client=client)& Q(macAddress__icontains=mac_address)
)
if existing_devices.exists():
# A device with the same macAddress already exists for the given sistema and client
# Get the number of existing devices and add 1 to create a new suffix
@@ -51,14 +49,14 @@ class DeviceSerializer(serializers.ModelSerializer):
validated_data['macAddress']= mac_address
return super().create(validated_data)
def validate(self, data):
sistema = data.get('sistema', None)
client = data.get('client', None)
try:
sistemaxCli = sistemas_por_cliente.objects.get(id_sistema=sistema,cliente=client)
sistemaxCli = sistemas_por_cliente.objects.get(id_sistema=sistema,cliente=client)
except sistemas_por_cliente.DoesNotExist:
raise serializers.ValidationError('No existe licencia para este sistema y/o cliente')
if sistemaxCli.num_licencias <= Device.objects.filter(sistema=sistemaxCli.id_sistema).count():
raise serializers.ValidationError('No existe licencia para este sistema y/o cliente')
if sistemaxCli.num_licencias <= Device.objects.filter(sistema=sistemaxCli.id_sistema, client=client).count():
raise serializers.ValidationError(f"No hay licencias disponibles para este sistema:{sistema} y cliente:{client}")
return data

View File

@@ -217,6 +217,7 @@ class Sistema_CreateView(CreateView):
'''
class GetDeviceToken(APIView):
"""Recobra el Token DRF del Device"""
authentication_classes= [TokenAuthentication]
permissions_classes=[IsAuthenticated, HasAuthorizationHeader]
def post(self,request):
@@ -229,7 +230,7 @@ class GetDeviceToken(APIView):
ip_address=data.get('ip_address'),
sistema= sis.id,#data.get('sistema'),
macAddress=data.get('macAddress')
).first()
).first()
if device is not None:
token = {"token":str(device.token)}
else:
@@ -242,11 +243,10 @@ class GetDeviceToken(APIView):
traceback=traceback.format_exc(),
view='Sistemas.GetDeviceToken'
)
return Response(
{'Error':f'{ex}','isError':True}
, status=status.HTTP_200_OK)
return Response({'Error':f'{ex}','isError':True}, status=status.HTTP_200_OK)
class RegisterDeviceView(APIView):
"""Registra al Device"""
permissions_classes = (permissions.AllowAny,)
def post(self,request):
@@ -260,11 +260,12 @@ class RegisterDeviceView(APIView):
except Exception as ex:
BitacoraErrores.objects.create(level=2, message=str(ex), traceback=traceback.format_exc(),
view='Sistemas.RegisterDeviceView')
return Response(
{'Error':f'{ex}','isError':True}
, status=status.HTTP_200_OK)
return Response({'Error':f'{ex}','isError':True}
, status=status.HTTP_200_OK
)
class AuthenticateDeviceView(APIView):
"""Autentica al device"""
authentication_classes= [TokenAuthentication]
permissions_classes=[IsAuthenticated, HasAuthorizationHeader]