Before Release 27 March
This commit is contained in:
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"python.analysis.typeCheckingMode": "basic"
|
||||||
|
}
|
||||||
@@ -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',
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -59,6 +57,6 @@ class DeviceSerializer(serializers.ModelSerializer):
|
|||||||
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
|
||||||
@@ -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]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user