Cambios de Device model
This commit is contained in:
@@ -71,9 +71,9 @@ class Device(models.Model):
|
||||
username=username_
|
||||
)
|
||||
return obj
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.pk:
|
||||
print(self.client,self.device_name, self.ip_address, self.macAddress)
|
||||
obj = self.generate_unique_username(self.client,self.device_name, self.ip_address, self.macAddress)
|
||||
self.username= obj
|
||||
token= Token.objects.create(user=obj)
|
||||
|
||||
@@ -5,6 +5,7 @@ from .views import (
|
||||
#CVB
|
||||
SistemasXCliente_ListView,
|
||||
SistemasXCliente_DetailView,
|
||||
UsersConnectedList,
|
||||
|
||||
#DRF APIViews
|
||||
RegisterDeviceView,
|
||||
@@ -17,4 +18,5 @@ urlpatterns = [
|
||||
path('registerPC/',RegisterDeviceView.as_view(),name='register_PC'),
|
||||
path('authenticatePC/',AuthenticateDeviceView.as_view(), name="authenticateDevice"),
|
||||
path('logout/', LogoutView.as_view(), name='logout_sistemas'),
|
||||
path('usuariosConectados/', UsersConnectedList.as_view(), name='lista_usuarios'),
|
||||
]
|
||||
@@ -8,22 +8,76 @@ from rest_framework.response import Response
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework import status, permissions
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib import messages
|
||||
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 django.utils import timezone
|
||||
import re
|
||||
|
||||
class SistemasXCliente_ListView(ListView):
|
||||
from rest_framework.authtoken.models import Token
|
||||
from django.utils import timezone
|
||||
from datetime import timedelta
|
||||
|
||||
from django.contrib.sessions.models import Session
|
||||
|
||||
def get_logged_in_users():
|
||||
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.all()
|
||||
|
||||
# Get a list of logged-in user ids
|
||||
uid_list = [token.user_id for token in tokens]
|
||||
|
||||
# Get the logged-in users
|
||||
users = User.objects.filter(id__in=uid_list)
|
||||
for user,session in zip(users,sessions):
|
||||
user.session_data = session.get_decoded()
|
||||
user.session_expire = session.expire_date
|
||||
return users
|
||||
|
||||
class UsersConnectedList(UserPassesTestMixin,LoginRequiredMixin,ListView):
|
||||
model = User
|
||||
template_name= 'Sistemas/Usuarios/lista.html'
|
||||
|
||||
def get_queryset(self):
|
||||
return get_logged_in_users()
|
||||
|
||||
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
|
||||
|
||||
class SistemasXCliente_ListView(UserPassesTestMixin,LoginRequiredMixin, ListView):
|
||||
model = sistemas_por_cliente
|
||||
paginate_by = 5
|
||||
template_name = 'Sistemas/Xclientes/lista.html'
|
||||
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
|
||||
|
||||
class SistemasXCliente_DetailView(DetailView):
|
||||
class SistemasXCliente_DetailView(UserPassesTestMixin,LoginRequiredMixin, DetailView):
|
||||
model = sistemas_por_cliente
|
||||
template_name= 'Sistemas/Xclientes/detail.html'
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
'''
|
||||
========================= API Views
|
||||
'''
|
||||
|
||||
class RegisterDeviceView(APIView):
|
||||
permissions_classes = (permissions.AllowAny,)
|
||||
|
||||
@@ -44,7 +98,7 @@ class RegisterDeviceView(APIView):
|
||||
|
||||
class AuthenticateDeviceView(APIView):
|
||||
authentication_classes= [TokenAuthentication]
|
||||
permissions_classes=[IsAuthenticated]
|
||||
permissions_classes=[IsAuthenticated, HasAuthorizationHeader]
|
||||
|
||||
def get(self, request):
|
||||
try:
|
||||
@@ -66,6 +120,7 @@ class AuthenticateDeviceView(APIView):
|
||||
{'Error':f'{e}','isError':True}
|
||||
, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class LogoutView(APIView):
|
||||
authentication_classes = (TokenAuthentication,)
|
||||
permission_classes = (IsAuthenticated,HasAuthorizationHeader,)
|
||||
|
||||
33
Templates/Sistemas/Usuarios/lista.html
Normal file
33
Templates/Sistemas/Usuarios/lista.html
Normal file
@@ -0,0 +1,33 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block title %}
|
||||
| Sistemas
|
||||
{% endblock title %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
<table class="table">
|
||||
<thead class="thead-dark">
|
||||
<tr>
|
||||
<th scope="col">Usuario</th>
|
||||
<th scope="col">Expira</th>
|
||||
<th scope="col"></th>
|
||||
<th scope="col"></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{% for user in object_list %}
|
||||
<tr>
|
||||
<th scope="row">{{user.username}}</th>
|
||||
<td>Session expire at: {{ user.session_expire }}</td>
|
||||
<td>-</td>
|
||||
<td><a href="#" class="btn btn-info">Detalles</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
{% endblock content %}
|
||||
@@ -6,8 +6,84 @@
|
||||
|
||||
|
||||
{% block content %}
|
||||
<style>
|
||||
@import url('https://fonts.googleapis.com/css?family=Assistant');
|
||||
|
||||
body {
|
||||
background: #eee;
|
||||
font-family: Assistant, sans-serif
|
||||
}
|
||||
|
||||
.cell-1 {
|
||||
border-collapse: separate;
|
||||
border-spacing: 0 4em;
|
||||
background: #ffffff;
|
||||
border-bottom: 5px solid transparent;
|
||||
/*background-color: gold;*/
|
||||
background-clip: padding-box;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
thead {
|
||||
background: #dddcdc;
|
||||
}
|
||||
|
||||
|
||||
.table-elipse {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#demo {
|
||||
-webkit-transition: all 0.3s ease-in-out;
|
||||
-moz-transition: all 0.3s ease-in-out;
|
||||
-o-transition: all 0.3s 0.1s ease-in-out;
|
||||
transition: all 0.3s ease-in-out;
|
||||
}
|
||||
|
||||
.row-child {
|
||||
background-color: rgb(113, 178, 238);
|
||||
color: rgb(0, 0, 0);
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
|
||||
<h1>{{object.cliente}}</h1>
|
||||
{{object.id_sistema}} <br>
|
||||
{{object.num_licencias}}
|
||||
|
||||
<div class="table-responsive table-borderless">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-center">Num. Licencias contratadas</th>
|
||||
<th>Sistema</th>
|
||||
<th>-</th>
|
||||
<th>Estatus</th>
|
||||
<th>-</th>
|
||||
<th>-</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-body">
|
||||
<tr class="cell-1" data-toggle="collapse" data-target="#demo">
|
||||
<td class="text-center">{{object.num_licencias}}</td>
|
||||
<td>{{object.id_sistema}}</td>
|
||||
<td>-</td>
|
||||
<td><span class="badge badge-{% if object.cliente.Activo %}success{%else%}danger{% endif %}">{% if object.cliente.Activo %}Activo{%else%}Inactivo{% endif %}</span></td>
|
||||
<td>-</td>
|
||||
<td>click me</td>
|
||||
<td class="table-elipse" data-toggle="collapse" data-target="#demo"><i class="fa fa-ellipsis-h text-black-50"></i></td>
|
||||
</tr>
|
||||
{% for sistema in object.id_sistema.device_set.all %}
|
||||
<tr id="demo" class="collapse cell-1 row-child">
|
||||
<td class="text-center" colspan="1"><i class="fa fa-angle-up"></i></td>
|
||||
<td colspan="1">Dispositivo: <strong>{{sistema}}</strong> </td>
|
||||
<td colspan="3"></td>
|
||||
<td colspan="1">-</td>
|
||||
<td colspan="2">-</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.14.6/dist/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.2.1/dist/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"></script>
|
||||
<script>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user