filter 2 page remove from filter page
This commit is contained in:
@@ -3,12 +3,24 @@ from .models import Clientes
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
class ClienteForm(forms.ModelForm):
|
class ClienteForm(forms.ModelForm):
|
||||||
fecha_baja = forms.DateField(
|
|
||||||
|
fecha_baja = forms.DateField(
|
||||||
required=False,
|
required=False,
|
||||||
initial=datetime.now(),
|
initial=datetime.now(),
|
||||||
input_formats=["%Y-%m-%d"],
|
input_formats=["%Y-%m-%d"],
|
||||||
widget=forms.DateInput(attrs={'type':'date'},format="%Y-%m-%d")
|
widget=forms.DateInput(attrs={'type':'date'},format="%Y-%m-%d")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Clientes
|
model = Clientes
|
||||||
fields = ('RFC','Nombre','Activo','fecha_baja')
|
fields = ('RFC','Nombre','Activo','fecha_baja')
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
super(ClienteForm,self).clean()
|
||||||
|
Activo = self.cleaned_data.get("Activo")
|
||||||
|
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"])
|
||||||
|
return self.cleaned_data
|
||||||
@@ -37,7 +37,7 @@ class Clientes(models.Model):
|
|||||||
Nombre = models.CharField(max_length=100)
|
Nombre = models.CharField(max_length=100)
|
||||||
|
|
||||||
|
|
||||||
Activo = models.BooleanField(default=True)
|
Activo = models.BooleanField(default=False)
|
||||||
fecha_baja = models.DateField(blank=True,null=True)
|
fecha_baja = models.DateField(blank=True,null=True)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -47,6 +47,6 @@ class Clientes(models.Model):
|
|||||||
year = today.year
|
year = today.year
|
||||||
return Timbres.objects.filter(rfcc=self.RFC, created_at__year=str(year),created_at__month=str(month)).count()
|
return Timbres.objects.filter(rfcc=self.RFC, created_at__year=str(year),created_at__month=str(month)).count()
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ('RFC',)
|
ordering = ('-Activo','RFC',)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -91,8 +91,8 @@ def timbres_cliente(request, RFC):
|
|||||||
tipo = request.GET.get('tipo',None)
|
tipo = request.GET.get('tipo',None)
|
||||||
|
|
||||||
|
|
||||||
filters = {key:value for (key,value) in dict(request.GET).items() if value !=None}
|
filters = {key:value[0] for (key,value) in dict(request.GET).items() if value !=[""]}
|
||||||
|
filters.pop('page', '')
|
||||||
if tipo:
|
if tipo:
|
||||||
lista = lista.filter(Q(tipo__icontains=search))
|
lista = lista.filter(Q(tipo__icontains=search))
|
||||||
|
|
||||||
@@ -113,12 +113,15 @@ def timbres_cliente(request, RFC):
|
|||||||
|
|
||||||
conteo = lista.count()
|
conteo = lista.count()
|
||||||
perPage = conteo // 2
|
perPage = conteo // 2
|
||||||
|
if perPage == 0 :
|
||||||
|
perPage = conteo
|
||||||
lista =pageFunc(page,lista,perPage)
|
lista =pageFunc(page,lista,perPage)
|
||||||
|
|
||||||
context ={
|
context ={
|
||||||
'lista':lista,
|
'lista':lista,
|
||||||
'conteo':conteo,
|
'conteo':conteo,
|
||||||
'RFC':RFC
|
'RFC':RFC,
|
||||||
|
'filters':filters
|
||||||
}
|
}
|
||||||
return render(request, 'Clientes/timbres_cliente.html', context)
|
return render(request, 'Clientes/timbres_cliente.html', context)
|
||||||
|
|
||||||
|
|||||||
@@ -11,13 +11,11 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="{{form.RFC.name}}"><strong> {{form.RFC.label|capfirst}} </strong></label>
|
<label for="{{form.RFC.name}}"><strong> {{form.RFC.label|capfirst}} </strong></label>
|
||||||
{% render_field form.RFC id+="add" id+=form.RFC.name placeholder=form.RFC.label class="form-control" type="text" autocomplete="off" %}
|
{% render_field form.RFC id+="add" id+=form.RFC.name placeholder=form.RFC.label class="form-control" type="text" autocomplete="off" %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="{{form.Nombre.name}}"><strong> {{form.Nombre.label|capfirst}} </strong></label>
|
<label for="{{form.Nombre.name}}"><strong> {{form.Nombre.label|capfirst}} </strong></label>
|
||||||
{% render_field form.Nombre id+="add" id+=form.Nombre.name placeholder=form.Nombre.label class="form-control" type="text" autocomplete="off" %}
|
{% render_field form.Nombre id+="add" id+=form.Nombre.name placeholder=form.Nombre.label class="form-control" type="text" autocomplete="off" %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group form-check">
|
<div class="form-group form-check">
|
||||||
{% render_field form.Activo class+="form-checkbox" type="checkbox" %}
|
{% render_field form.Activo class+="form-checkbox" type="checkbox" %}
|
||||||
<label class="form-check-label" for="{{form.Activo.label}}">Activo</label>
|
<label class="form-check-label" for="{{form.Activo.label}}">Activo</label>
|
||||||
@@ -32,6 +30,7 @@
|
|||||||
|
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
window.addEventListener("load", (event)=>{
|
window.addEventListener("load", (event)=>{
|
||||||
if(!id_Activo.checked){
|
if(!id_Activo.checked){
|
||||||
id_fecha_baja.setAttribute('required','')
|
id_fecha_baja.setAttribute('required','')
|
||||||
|
|||||||
@@ -20,17 +20,27 @@ Timbres disponibles Comercio Digital: {{saldo.saldo}}
|
|||||||
</th>
|
</th>
|
||||||
<th>Nombre</th>
|
<th>Nombre</th>
|
||||||
<th>Totales Mes {{fecha|date:"F"}}</th>
|
<th>Totales Mes {{fecha|date:"F"}}</th>
|
||||||
|
<th>Estado</th>
|
||||||
<th scope="col">actions</th>
|
<th scope="col">actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for obj in lista %}
|
{% for obj in lista %}
|
||||||
<tr class="">
|
<tr class="{% if not obj.Activo %}table-danger{% endif %}">
|
||||||
<td>
|
<td>
|
||||||
<a href="{% url 'update_cliente' obj.pk %}">{{obj.RFC}}</a>
|
<a href="{% url 'update_cliente' obj.pk %}">{{obj.RFC}}</a>
|
||||||
</td>
|
</td>
|
||||||
<td>{{obj.Nombre}}</td>
|
<td>{{obj.Nombre}} </td>
|
||||||
<td>{{obj.timbres_mes_count}}</td>
|
<td>{{obj.timbres_mes_count}}</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
{% if obj.Activo %}
|
||||||
|
Activo
|
||||||
|
{% else %}
|
||||||
|
Inactivo
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
|
||||||
<td>
|
<td>
|
||||||
{% if request.user.is_staff %}
|
{% if request.user.is_staff %}
|
||||||
<a href="{% url 'timbres_cliente' obj.RFC %}" class="btn btn-info">Ver Timbres</a>
|
<a href="{% url 'timbres_cliente' obj.RFC %}" class="btn btn-info">Ver Timbres</a>
|
||||||
|
|||||||
@@ -6,6 +6,15 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>Timbres <strong>{{RFC}}</strong> </h1>
|
<h1>Timbres <strong>{{RFC}}</strong> </h1>
|
||||||
<h2>Timbres totales: <strong></strong>{{conteo}}</strong></h2>
|
<h2>Timbres totales: <strong></strong>{{conteo}}</strong></h2>
|
||||||
|
<span class="navbar-text mr-2">
|
||||||
|
{% if filters.datepicker%}
|
||||||
|
De fecha: <strong>"{{filters.datepicker}}"</strong>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if filters.datepickerFin %}
|
||||||
|
A fecha: <strong>"{{filters.datepickerFin}}"</strong>
|
||||||
|
{% endif %}
|
||||||
|
</span>
|
||||||
|
|
||||||
<br><br>
|
<br><br>
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,9 @@
|
|||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
{% include 'sidebar.html' %}
|
{% include 'sidebar.html' %}
|
||||||
<h1>{% block titlePage %}{% endblock titlePage %}</h1>
|
<h1>{% block titlePage %}{% endblock titlePage %}</h1>
|
||||||
|
{% include 'partials/messages.html' %}
|
||||||
{% block content %}{% endblock content %}
|
{% block content %}{% endblock content %}
|
||||||
|
|
||||||
{% include 'paginator.html' %}
|
{% include 'paginator.html' %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
|
||||||
{% if lista.has_other_pages %}
|
{% if lista.has_other_pages %}
|
||||||
|
|
||||||
<nav>
|
<nav>
|
||||||
<ul class="pagination justify-content-center">
|
<ul class="pagination justify-content-center">
|
||||||
{% if lista.has_previous %}
|
{% if lista.has_previous %}
|
||||||
@@ -17,7 +19,7 @@
|
|||||||
{% if lista.number == p %}
|
{% if lista.number == p %}
|
||||||
<li class="page-item"><a class="page-link" style="color: red;" href="#">{{ p }}</a></li>
|
<li class="page-item"><a class="page-link" style="color: red;" href="#">{{ p }}</a></li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li class="page-item"><a class="page-link" href="?page={{ p }}">{{ p }}</a></li>
|
<li class="page-item"><a class="page-link" href="?page={{ p }}{% for i,v in filters.items %}&{{i}}={{v}}{% endfor%}">{{ p }}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
|||||||
13
Templates/partials/messages.html
Normal file
13
Templates/partials/messages.html
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{% if form.errors %}
|
||||||
|
{% for field in form %}
|
||||||
|
{% for error in field.errors %}
|
||||||
|
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||||
|
<strong>-{{field.name}}</strong><br>
|
||||||
|
<strong>{{ error|escape }}</strong> <br>
|
||||||
|
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
Reference in New Issue
Block a user