changes for sistemas

This commit is contained in:
fjrodriguez
2023-03-09 09:40:17 -06:00
parent c84ef13d33
commit 5b5e79f430
7 changed files with 108 additions and 89 deletions

View File

@@ -0,0 +1,18 @@
# Generated by Django 4.1.3 on 2023-03-07 16:28
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('Clientes', '0015_alter_timbres_rfcc'),
('Sistemas', '0013_alter_bitacoraerrores_options'),
]
operations = [
migrations.AlterUniqueTogether(
name='sistemas_por_cliente',
unique_together={('id_sistema', 'cliente')},
),
]

View File

@@ -38,13 +38,11 @@ class sistemas_por_cliente(models.Model):
id_sistema= models.ForeignKey(Sistema, related_name='sistema_spc', on_delete=models.CASCADE)
cliente = models.ForeignKey(Clientes, related_name='cliente_spc', on_delete=models.CASCADE)
num_licencias= models.IntegerField(default=1)
def __str__(self):
return f'{self.cliente.Nombre}'
class Meta:
ordering= ('-cliente','id_sistema')
unique_together = ('id_sistema', 'cliente')
class DeviceManager(BaseUserManager):
def generate_unique_username(self,client, device_name, ip_address):

View File

@@ -73,9 +73,9 @@ class UploadZipVersionView(APIView):
messages.error(self.request, f'El archivo {fileN} no es .zip')
return redirect('uploadZipViewHTML')
version = request.POST.get('version')
sistema = request.POST.get('sistema')
print('version',version, ' sistema',sistema)
except KeyError:
sistema = request.POST.get('sistema')
except KeyError as ker:
BitacoraErrores.objects.create(level=2, message=f'keyError Try: {str(ker)}', traceback=traceback.format_exc(), view='Sistemas.UploadZipVersionView')
return Response({'error':'Zip file is required'},status=status.HTTP_400_BAD_REQUEST)
try:
versionSistema = Sistema.objects.get(id=sistema)
@@ -100,18 +100,15 @@ class UploadZipVersionView(APIView):
@authentication_classes([TokenAuthentication])
@permission_classes([IsAuthenticated])
def download_version_FromServer(request):
""""""
"""dw"""
try:
sys= request.GET.get('sys')
sys= request.GET.get('sys')
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if sys:
filename=f'{sys}.zip'
else:
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)
response = HttpResponse(path.read(),content_type=mime_type)
@@ -122,6 +119,7 @@ def download_version_FromServer(request):
return HttpResponse(status=204)
class UsersConnectedList(UserPassesTestMixin,LoginRequiredMixin,ListView):
"""CV"""
model = User
template_name= 'Sistemas/Usuarios/lista.html'
@@ -139,7 +137,7 @@ class UsersConnectedList(UserPassesTestMixin,LoginRequiredMixin,ListView):
sessions = Session.objects.filter(expire_date__gte=timezone.now())
# Get all non-expired tokens
#tokens = Token.objects.filter(created__gte=timezone.now() - timedelta(hours=1))
#tokens = Token.objects.filter(created__gte=timezone.now() - timedelta(hours=1))
tokens = Token.objects.all()
# Get a list of logged-in user ids
@@ -147,13 +145,12 @@ class UsersConnectedList(UserPassesTestMixin,LoginRequiredMixin,ListView):
# Get the logged-in users
users = User.objects.filter(id__in=uid_list)
for user,session in zip(users,sessions):
for user,session in zip(users,sessions):
user.session_data = session.get_decoded()
user.session_expire = session.expire_date
return users
class SistemasXCliente_ListView(UserPassesTestMixin,LoginRequiredMixin, ListView):
model = sistemas_por_cliente
paginate_by = 20
template_name = 'Sistemas/Xclientes/lista.html'
@@ -179,12 +176,11 @@ class SistemasBitacora_ListView(UserPassesTestMixin,LoginRequiredMixin, ListView
class SistemasXCliente_DetailView(UserPassesTestMixin,LoginRequiredMixin, DetailView):
model = sistemas_por_cliente
template_name= 'Sistemas/Xclientes/detail.html'
def test_func(self):
def test_func(self):
res = self.request.user.groups.filter(name= 'admin_soft')
if not res:
messages.error(self.request, f'Lo sentimos. La página que buscas no está disponible, no cuentas con los permisos.')
return res
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
sistemas_por_cliente = self.object
@@ -213,7 +209,9 @@ class Sistema_CreateView(CreateView):
'version': self.object.version,
}
return JsonResponse(data)
def form_invalid(self, form):
errors =form.errors.as_text()
return JsonResponse({'errors': f'{errors}'}, status=200)
'''
========================= API Views
'''