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.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'rest_framework', 'rest_framework',
'rest_framework.authtoken', 'rest_framework.authtoken',
'allauth', 'allauth',
'allauth.account', 'allauth.account',
'allauth.socialaccount', 'allauth.socialaccount',

View File

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

View File

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