newfunctions server version CFDI checks and model Bitacora

This commit is contained in:
fjrodriguez
2023-02-09 09:12:49 -06:00
parent a59de70f54
commit 814412e9bf
9 changed files with 157 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
from django.shortcuts import render
from django.shortcuts import render,redirect
from django.contrib.auth import logout
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
@@ -13,6 +13,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from .models import sistemas_por_cliente, DeviceHistory,Device
from .serializers import DeviceSerializer
from .permissions import HasAuthorizationHeader
from .models import Sistema
from django.utils import timezone
import re
@@ -22,6 +23,26 @@ from datetime import timedelta
from django.contrib.sessions.models import Session
from django.http.response import HttpResponse
import os
import mimetypes
def download_version_FromServer(request):
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
print('BASE_DIR',BASE_DIR)
filename = 'CFDI.zip'
filepath = f'{BASE_DIR }/downloadSystems/{filename}'
#path = open(filepath, 'r')
with open(filepath, 'rb') as path:
mime_type, _ = mimetypes.guess_type(filepath)
print(mime_type)
response = HttpResponse(path.read(),content_type=mime_type)
response['Content-Disposition']= f'attachment; filename={filename}'
return response#redirect('index')
def get_logged_in_users():
sessions = Session.objects.filter(expire_date__gte=timezone.now())
@@ -89,9 +110,9 @@ class RegisterDeviceView(APIView):
return Response(serializer.data, status=status.HTTP_200_OK)
else:
return Response({'Error':f'{serializer.errors}','isError':True}, status=status.HTTP_200_OK)
except Exception as e:
except Exception as ex:
return Response(
{'Error':f'{e}','isError':True}
{'Error':f'{ex}','isError':True}
, status=status.HTTP_200_OK)
@@ -115,9 +136,9 @@ class AuthenticateDeviceView(APIView):
return Response(
{'Error':f'{device_data.serializer.errors}','isError':True}
, status=status.HTTP_200_OK)
except Exception as e:
except Exception as ex:
return Response(
{'Error':f'{e}','isError':True}
{'Error':f'{ex}','isError':True}
, status=status.HTTP_200_OK)
@@ -127,4 +148,37 @@ class LogoutView(APIView):
def post(self, request):
logout(request)
return Response({'OK':'Dispositivo desautenticado'},status=200)
return Response({'OK':'Dispositivo desautenticado'},status=200)
class CheckVersionView(APIView):
authentication_classes = (TokenAuthentication,)
permission_classes = (IsAuthenticated,HasAuthorizationHeader,)
def post(self, request,*args, **kwargs):
try:
version = request.data.get('version')
client_version = [int(x) for x in version.split(".")]
print('client_version: ',client_version)
try:
ver = Sistema.objects.get(nombre_sistema="CFDI")
server_version = [int(x) for x in ver.version.split(".")]
except Exception as e:
return Response({'success':True, 'actualizar':False})
print('server_version', server_version)
result=False
#for i in range(len(client_version)):
for cont, ele in enumerate(client_version):
if client_version[cont] < server_version[cont]:
print('server verion is grater')
result = True
break
else:
result= False
print('equal')
return Response({'success':True, 'actualizar':result})
except Exception as ex:
return Response({'Error':f'{ex}','isError':True})