Liberacion
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,5 @@
|
||||
#archvi .env#
|
||||
.env
|
||||
# Django #
|
||||
*.log
|
||||
*.pot
|
||||
|
||||
@@ -13,7 +13,7 @@ from django.core.files.storage import FileSystemStorage
|
||||
from django.core.mail import send_mail
|
||||
from django.shortcuts import render,redirect
|
||||
from django.contrib import messages
|
||||
from django.http import HttpResponse,JsonResponse,QueryDict
|
||||
from django.http import HttpResponse,JsonResponse
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
||||
from django.db.models import Q
|
||||
@@ -207,11 +207,8 @@ def index(request):
|
||||
clientes_list =pageFunc(page,clientes_list,50)
|
||||
current_query_dict = request.GET.copy()
|
||||
current_query_dict.pop('page', None)
|
||||
|
||||
current_query_params = current_query_dict.urlencode()
|
||||
|
||||
|
||||
|
||||
current_query_params = current_query_dict.urlencode()
|
||||
|
||||
context = {
|
||||
'lista':clientes_list,
|
||||
|
||||
@@ -78,16 +78,16 @@ class Suspension_Modulos_Permisos_ClienteAdmin(admin.ModelAdmin):
|
||||
super().save_model(request, obj, form, change)
|
||||
|
||||
for modulo in obj.suspensionmodulo_set.all():
|
||||
print(modulo, 'permisos',modulo.modulo.permisos.all())
|
||||
#print(modulo, 'permisos',modulo.modulo.permisos.all())
|
||||
for permiso in modulo.modulo.permisos.all():
|
||||
print('borrar?',permiso.delete)
|
||||
#print('borrar?',permiso.delete)
|
||||
|
||||
permObj,created=SuspensionPermiso.objects.get_or_create(
|
||||
supension_modPermP=obj,
|
||||
suspension_modulo=modulo.modulo,
|
||||
permiso=permiso,
|
||||
)
|
||||
print(permObj,created)
|
||||
#print(permObj,created)
|
||||
if permiso.delete:
|
||||
print('borrar')
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ from django import forms
|
||||
from django.forms import inlineformset_factory
|
||||
from .models import ClientesA24, Suspension_Modulos_Permisos_Cliente,SuspensionModulo,SuspensionPermiso,Modulo
|
||||
from datetime import datetime
|
||||
from django.utils.html import format_html
|
||||
|
||||
|
||||
class ClienteForm_IMMEX(forms.ModelForm):
|
||||
fecha_baja = forms.DateField(
|
||||
@@ -21,10 +23,16 @@ class ClienteForm_IMMEX(forms.ModelForm):
|
||||
fecha_baja = self.cleaned_data.get("fecha_baja")
|
||||
|
||||
if Activo and fecha_baja:
|
||||
self._errors['fecha_baja'] = self.error_class(["El parametro activo no puede estar seleccionado si hay fecha de baja"])
|
||||
self.errors['fecha_baja'] = self.error_class(["El parametro activo no puede estar seleccionado si hay fecha de baja"])
|
||||
return self.cleaned_data
|
||||
|
||||
|
||||
class SuspensionModulosPermisosClienteForm(forms.ModelForm):
|
||||
button_field = forms.CharField(
|
||||
widget=forms.TextInput(attrs={'id':'add-sistema-cliente','type': 'button', 'value': 'Agregar Sistema-Cliente', "class":"btn btn-info"}),
|
||||
required=False,
|
||||
label=''
|
||||
)
|
||||
class Meta:
|
||||
model = Suspension_Modulos_Permisos_Cliente
|
||||
fields = '__all__'
|
||||
@@ -47,7 +55,7 @@ SuspensionModuloFormSet = inlineformset_factory(
|
||||
SuspensionModulo,
|
||||
form=SuspensionModuloForm,
|
||||
extra=5,
|
||||
can_delete=False,
|
||||
can_delete=True,
|
||||
)
|
||||
|
||||
#se usa "SuspensionModuloFormSet2" en el UpdateView para pasar el Extra igual a cero
|
||||
|
||||
@@ -9,7 +9,7 @@ router.register(r'modulos',views.ModulosListCreateAPIView)
|
||||
router.register(r'permisosA24',views.Permisos_A24_ModelViewSet)
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.Sistemas_xCliente_IMMEX_ListView.as_view(), name='sistemasXcli_IMMEX'),
|
||||
path('lista/', views.Sistemas_xCliente_IMMEX_ListView.as_view(), name='sistemasXcli_IMMEX'),
|
||||
path('create_sistema/',views.Sistemas_xCliente_IMMEX_CreateView.as_view(), name='create_sistemaIMMEX'),
|
||||
path('create_Cliente/', views.ClientesIMMEX_CreateView.as_view(), name='ClientesIMMEX_Create'),
|
||||
path('checkRfcA24/', views.Check_IMMEX_RFC.as_view(), name='checkRfcA24' ),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Imports de Django
|
||||
from django.shortcuts import render
|
||||
from django.http import Http404
|
||||
from django.http import Http404,JsonResponse
|
||||
from django.urls import reverse_lazy, reverse
|
||||
from django.core.mail import send_mail
|
||||
from django.views.generic.edit import CreateView
|
||||
@@ -72,6 +72,29 @@ class Sistemas_xCliente_IMMEX_CreateView(UserPassesTestMixin,LoginRequiredMixin,
|
||||
if not res:
|
||||
messages.error(self.request, 'Lo sentimos. La página que buscas no está disponible o no cuentas con los permisos.')
|
||||
return res
|
||||
|
||||
def form_valid(self, form):
|
||||
response = super().form_valid(form)
|
||||
if self.request.headers.get('X-Requested-With') == 'XMLHttpRequest':
|
||||
|
||||
data = {
|
||||
'id':self.object.id,
|
||||
'nombre':self.object.id_sistema.nombre_sistema,
|
||||
'cliente':self.object.cliente.Nombre,
|
||||
'version':self.object.id_sistema.version
|
||||
}
|
||||
|
||||
return JsonResponse(data,status=status.HTTP_200_OK)
|
||||
|
||||
return response
|
||||
|
||||
def form_invalid(self,form):
|
||||
response = super().form_invalid(form)
|
||||
if self.request.headers.get('X-Requested-With') == 'XMLHttpRequest':
|
||||
errors = form.errors.as_text()
|
||||
return JsonResponse({'errors':f'{errors}'},status=200,content_type='application/json')
|
||||
else:
|
||||
return response
|
||||
|
||||
class ClientesIMMEX_CreateView(CreateView):
|
||||
model = ClientesA24
|
||||
|
||||
@@ -64,8 +64,7 @@ class SuspensionPermisosClienteCreateView(LoginRequiredMixin,UserPassesTestMixin
|
||||
context = self.get_context_data()
|
||||
modulo_formset = context['modulo_formset']
|
||||
permiso_formset = context['permiso_formset']
|
||||
|
||||
|
||||
|
||||
if modulo_formset.is_valid() and permiso_formset.is_valid():
|
||||
self.object = form.save() # Guardamos el objeto principal
|
||||
|
||||
@@ -79,24 +78,7 @@ class SuspensionPermisosClienteCreateView(LoginRequiredMixin,UserPassesTestMixin
|
||||
supension_modPermP=self.object,
|
||||
suspension_modulo=modulo.modulo,
|
||||
permiso=permiso,
|
||||
)
|
||||
|
||||
# permiso_formset.instance= self.object
|
||||
# permiso_formset.save()
|
||||
|
||||
# for permiso in self.object.suspensionpermiso_set.all():
|
||||
# # print(permiso.permiso,'iud',permiso.supension_modPermP.id)
|
||||
# # print(permiso.supension_modPermP,permiso.suspension_modulo)
|
||||
# suspension_modulo = self.object.suspensionmodulo_set.filter(
|
||||
# supension_modPerm_id=self.object,
|
||||
# # suspension_modulo = SuspensionModulo.objects.filter(supension_modPerm_id=self.object,
|
||||
# modulo__permisos__in=[permiso.permiso]
|
||||
# ).first()
|
||||
# #print('suspMod',(suspension_modulo))
|
||||
|
||||
# permiso.suspension_modulo=suspension_modulo.modulo
|
||||
# permiso.save()
|
||||
|
||||
)
|
||||
|
||||
return super().form_valid(form)
|
||||
else:
|
||||
@@ -119,54 +101,62 @@ class SuspensionPermisosCliente_UpdateView(LoginRequiredMixin,UserPassesTestMixi
|
||||
context = super().get_context_data(**kwargs)
|
||||
if self.request.POST:
|
||||
context['modulo_formset'] = SuspensionModuloFormSet(self.request.POST, instance=self.object)
|
||||
context['permiso_formset'] = SuspensionPermisoFormSet(self.request.POST,instance=self.object)
|
||||
|
||||
|
||||
context['permiso_formset'] = SuspensionPermisoFormSet(self.request.POST,instance=self.object)
|
||||
else:
|
||||
context['modulo_formset'] = SuspensionModuloFormSet2(instance=self.object)
|
||||
|
||||
|
||||
context['permiso_formset'] = SuspensionPermisoFormSet(instance=self.object)
|
||||
for form in context['permiso_formset'].forms:
|
||||
form.fields['modulo_extra'].widget = forms.HiddenInput()
|
||||
form.fields['modulo_extra'].queryset = SuspensionModulo.objects.none()
|
||||
form.fields['suspension_modulo'].queryset = Modulo.objects.all()
|
||||
#form.fields['suspension_modulo'].widget = forms.HiddenInput()
|
||||
#form.fields['permiso'].widget.attrs['disabled'] = True
|
||||
|
||||
|
||||
|
||||
for permiso_formset in context['permiso_formset'].forms:
|
||||
permiso_formset.fields['modulo_extra'].widget = forms.HiddenInput()
|
||||
permiso_formset.fields['modulo_extra'].queryset = SuspensionModulo.objects.none()
|
||||
permiso_formset.fields['suspension_modulo'].queryset = Modulo.objects.all()
|
||||
#permiso_formset.fields['suspension_modulo'].widget = forms.HiddenInput()
|
||||
#permiso_formset.fields['permiso'].widget.attrs['disabled'] = True
|
||||
|
||||
|
||||
context['form'].fields['sistema_cliente'].widget = forms.HiddenInput()
|
||||
context['form'].fields['button_field'].widget = forms.HiddenInput()
|
||||
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
context = self.get_context_data()
|
||||
modulo_formset = context['modulo_formset']
|
||||
permiso_formset = context['permiso_formset']
|
||||
print('permiupdate',permiso_formset.is_valid())
|
||||
#print('permiupdate',permiso_formset.is_valid())
|
||||
if form.is_valid() and modulo_formset.is_valid() and permiso_formset.is_valid():
|
||||
self.object = form.save()
|
||||
modulo_formset.instance = self.object
|
||||
|
||||
modulo_formset.save()
|
||||
print('MODULOS',self.object.suspensionmodulo_set.all().values())
|
||||
|
||||
modulo_formset.instance = self.object
|
||||
modulo_formset.save()
|
||||
|
||||
#print('MODULOS',(modulo_formset.instance.suspensionmodulo_set.all()))
|
||||
#Guardamos SuspensionModulo
|
||||
permiso_formset.instance= self.object
|
||||
permiso_formset.save()
|
||||
for permiso in self.object.suspensionpermiso_set.all():
|
||||
print('permiso:',permiso.permiso,'iud',permiso.supension_modPermP.id)
|
||||
print('MODULO PERMISO:',permiso.suspension_modulo)
|
||||
suspension_modulo = self.object.suspensionmodulo_set.filter(
|
||||
supension_modPerm_id=self.object,
|
||||
# suspension_modulo = SuspensionModulo.objects.filter(supension_modPerm_id=self.object,
|
||||
modulo__permisos__in=[permiso.permiso]
|
||||
).first()
|
||||
if not suspension_modulo == None:
|
||||
print('suspMod',(suspension_modulo))
|
||||
print()
|
||||
permiso.suspension_modulo=suspension_modulo.modulo
|
||||
permiso.save()
|
||||
else:
|
||||
permiso.delete()
|
||||
|
||||
|
||||
modulos_a_eliminar = [form1.cleaned_data['modulo'] for form1 in modulo_formset.forms \
|
||||
if hasattr(form1, 'cleaned_data') and form1.cleaned_data.get('DELETE')
|
||||
]
|
||||
#print('modulos_a_eliminar',modulos_a_eliminar)
|
||||
modulos_a_mantener = modulo_formset.instance.suspensionmodulo_set.exclude(modulo__in=modulos_a_eliminar)
|
||||
|
||||
#print('modulos_a_mantener',modulos_a_mantener)
|
||||
for modulo in modulos_a_mantener:
|
||||
for permiso in modulo.modulo.permisos.all():
|
||||
permObj,created=SuspensionPermiso.objects.get_or_create(
|
||||
supension_modPermP=self.object,
|
||||
suspension_modulo=modulo.modulo,
|
||||
permiso=permiso,
|
||||
)
|
||||
|
||||
# Eliminamos los permisos asociados a los módulos que se van a eliminar
|
||||
if modulos_a_eliminar:
|
||||
permisos_a_eliminar = SuspensionPermiso.objects.filter(suspension_modulo__in=modulos_a_eliminar)
|
||||
permisos_a_eliminar.delete()
|
||||
|
||||
return super().form_valid(form)
|
||||
else:
|
||||
return self.render_to_response(self.get_context_data(form=form))
|
||||
return self.render_to_response(self.get_context_data(form=form))
|
||||
|
||||
32
Templates/IMMEX/modulos/add_SistemaXCliente_Script.html
Normal file
32
Templates/IMMEX/modulos/add_SistemaXCliente_Script.html
Normal file
@@ -0,0 +1,32 @@
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", ()=>{
|
||||
document.querySelector('#add-sistema-cliente').addEventListener('click', function() {
|
||||
let parentWidth = window.innerWidth;
|
||||
let parentHeight = window.innerHeight;
|
||||
|
||||
let childWidth = 800;
|
||||
let childHeight = 600;
|
||||
let left =(parentWidth - childWidth);
|
||||
let top = (parentHeight - childHeight);
|
||||
|
||||
let popupWin = window.open("{% url 'create_sistemaIMMEX' %}", "createSistemaXCliente_popup", "width=" + childWidth + ",height=" + childHeight + ",left=" + left + ",top=" + top);
|
||||
popupWin.focus();
|
||||
});
|
||||
|
||||
|
||||
window.addEventListener('message', (event)=>{
|
||||
let response = event.data.data;
|
||||
let windowName = event.data.windowName;
|
||||
|
||||
if(windowName==='createSistemaXCliente'){
|
||||
|
||||
let option = '<option value="' + response.id + '" selected>'+response.cliente+', ' + response.nombre + '</option>';
|
||||
document.querySelector('#id_sistema_cliente').insertAdjacentHTML('beforeend', option);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
</script>
|
||||
@@ -4,7 +4,9 @@
|
||||
{% block title %}Add Cliente IMMEX {% endblock title %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Crear Módulo/Permisos</h2>
|
||||
<h2>Editar Módulo/Permisos</h2>
|
||||
<p><strong>Cliente:</strong>{{object.sistema_cliente}}</p>
|
||||
<hr>
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
@@ -36,4 +38,7 @@
|
||||
|
||||
<button type="submit" class="btn btn-outline-success">Guardar</button>
|
||||
</form>
|
||||
{% endblock %}
|
||||
{% block scripts %}
|
||||
{% include 'IMMEX/modulos/add_SistemaXCliente_Script.html' %}
|
||||
{% endblock %}
|
||||
@@ -33,4 +33,11 @@
|
||||
|
||||
<button type="submit" class="btn btn-outline-success">Guardar</button>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
{% include 'IMMEX/modulos/add_SistemaXCliente_Script.html' %}
|
||||
|
||||
{% endblock scripts %}
|
||||
@@ -31,6 +31,7 @@
|
||||
{% block scripts %}
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", ()=>{
|
||||
console.log('edit_cliente.html',window.name)
|
||||
if(window.name ==='popupWin')
|
||||
{
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
{% block content %}
|
||||
<h1>Create a new Sistema IMMEX por cliente</h1>
|
||||
<form method="post">
|
||||
<form method="post" id="sistemaXCliente-form">
|
||||
|
||||
{% csrf_token %}
|
||||
{% if form.non_field_errors %}
|
||||
@@ -63,6 +63,43 @@
|
||||
{% block scripts %}
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
console.log('SISTEMA X CLIENTE', window.name);
|
||||
|
||||
if(window.name==='createSistemaXCliente_popup'){
|
||||
document.querySelector('#sistemaXCliente-form').addEventListener('submit',(event)=>{
|
||||
event.preventDefault();
|
||||
let form = event.target;
|
||||
let url = `{% url 'create_sistemaIMMEX' %}`;
|
||||
let data = new FormData(form);
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open('POST',url);
|
||||
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||
xhr.onreadystatechange = ()=>{
|
||||
if(xhr.readyState===XMLHttpRequest.DONE){
|
||||
if(xhr.status===200){
|
||||
let response = JSON.parse(xhr.responseText);
|
||||
if(response.errors){
|
||||
alert(response.errors);
|
||||
|
||||
}else{
|
||||
window.opener.postMessage({data:response, windowName:'createSistemaXCliente'}, window.location.origin);
|
||||
|
||||
window.close();
|
||||
|
||||
}
|
||||
|
||||
}else{
|
||||
console.error('Request error', xhr.statusText);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
xhr.send(data);
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/*add Sistema*/
|
||||
document.querySelector('#add-sistema-btn').addEventListener('click', function() {
|
||||
let parentWidth = window.innerWidth;
|
||||
@@ -92,11 +129,12 @@
|
||||
popupWin.focus();
|
||||
});
|
||||
|
||||
|
||||
|
||||
window.addEventListener('message', function(event) {
|
||||
let response = event.data.data;
|
||||
|
||||
|
||||
let windowName = event.data.windowName;
|
||||
|
||||
if(windowName==='clientWindow'){
|
||||
let id_cliente = response.id;
|
||||
let Nombre = response.Nombre;
|
||||
|
||||
@@ -10,61 +10,48 @@
|
||||
<div class="collapse navbar-collapse" id="navbarTogglerDemo03">
|
||||
<ul class="navbar-nav mr-auto mt-2 mt-lg-0">
|
||||
|
||||
<li class="nav-item dropdown {% if request_path == '/' %}active{% endif %}">
|
||||
<li class="nav-item dropdown {% if 'cliente' in request_path or request_path == '/' %}active border py-1 px-1 {% endif %}">
|
||||
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
Timbres/Clientes
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
|
||||
<a class="dropdown-item" href="/">Timbres x Cliente</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item" href="{% url 'add_cliente' %}">Agregar Cliente</a>
|
||||
|
||||
<a class="dropdown-item" href="#">---</a>
|
||||
<a class="dropdown-item" href="{% url 'add_cliente' %}">Agregar Cliente</a>
|
||||
</div>
|
||||
</li>
|
||||
{% comment %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">Contacts</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">List</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">#</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">List</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">List</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link disabled" href="#">Disabled</a>
|
||||
</li>
|
||||
|
||||
{% endcomment %}
|
||||
|
||||
<li class="nav-item {% if 'sistemas' in request_path %}active border{% endif %}">
|
||||
<a class="nav-link" href="/sistemas" >Sistemas CFDI</a>
|
||||
</li>
|
||||
<li class="nav-item {% if 'IMMEX/' in request_path %}active border{% endif %}">
|
||||
<a class="nav-link" href="{% url 'sistemasXcli_IMMEX' %}" >Sistemas IMMEX</a>
|
||||
</li>
|
||||
<li class="nav-item {% if 'sistemas' in request_path %}active border{% endif %}">
|
||||
<a class="nav-link" href="/sistemas" >Sistemas CFDI</a>
|
||||
</li>
|
||||
|
||||
<li class="nav-item dropdown {% if 'IMMEX' in request_path %}active border py-1 px-1 {% endif %}">
|
||||
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
IMMEX
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
|
||||
|
||||
<a class="dropdown-item" href="{% url 'sistemasXcli_IMMEX' %}">Sistemas</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
{% for group in request.user.groups.all %}
|
||||
{% if group.name == 'admin_soft' %}
|
||||
<a class="dropdown-item" href="{% url 'permisos-clientesModulos' %}">Modulos - Permisos</a>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
{% for group in request.user.groups.all %}
|
||||
{% if group.name == 'admin_soft' %}
|
||||
<li class="nav-item {% if 'IMMEX/permisos-clientes' in request_path %}active border{% endif %}">
|
||||
<a class="nav-link" href="{% url 'permisos-clientesModulos' %}" >Modulos-Permisos</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% if request.user.is_superuser %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/admin" target="_blank">Admin site</a>
|
||||
</li>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
||||
{% include "partials/search_form.html" %}
|
||||
|
||||
<li class="navbar-text mr-2 nav-item dropdown">
|
||||
@@ -73,8 +60,7 @@
|
||||
</a>
|
||||
<div class="dropdown-menu dropleft" aria-labelledby="navbarDropdown">
|
||||
<form method="post" action="{% url 'account_logout' %}">
|
||||
{% csrf_token %}
|
||||
|
||||
{% csrf_token %}
|
||||
<button type="submit" class="dropdown-item">Cerrar sesión</button>
|
||||
</form>
|
||||
<div class="dropdown-divider"></div>
|
||||
|
||||
Reference in New Issue
Block a user