From 76465e348b12b67fb45529b9af9abb7ecb3a5555 Mon Sep 17 00:00:00 2001 From: Francisco Rodriguez Date: Sun, 27 Nov 2022 11:05:35 -0700 Subject: [PATCH] index and paginator added --- Admin/settings.py | 2 +- Clientes/views.py | 19 ++++++++++-- Templates/Clientes/index.html | 31 +++++++++++++++++++ Templates/base.html | 56 +++++++++++++++++++++++++++++++++++ Templates/paginator.html | 38 ++++++++++++++++++++++++ Templates/sidebar.html | 44 +++++++++++++++++++++++++++ 6 files changed, 186 insertions(+), 4 deletions(-) create mode 100644 Templates/Clientes/index.html create mode 100644 Templates/base.html create mode 100644 Templates/paginator.html create mode 100644 Templates/sidebar.html diff --git a/Admin/settings.py b/Admin/settings.py index 7278a7d..a5afc12 100644 --- a/Admin/settings.py +++ b/Admin/settings.py @@ -12,7 +12,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent SECRET_KEY = 'django-insecure-5*mm&uf5zq@t6nrs_5z8-_qtyapm^3&yz^wqqkc_a!v(!ulj-^' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = False +DEBUG = True ALLOWED_HOSTS = ['*'] diff --git a/Clientes/views.py b/Clientes/views.py index baa921f..7d3a950 100644 --- a/Clientes/views.py +++ b/Clientes/views.py @@ -2,9 +2,24 @@ from django.shortcuts import render from django.http import HttpResponse from django.contrib.auth.decorators import login_required from .models import Timbres +from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger + @login_required def index(request): - return HttpResponse('hello') + timbres_list = Timbres.objects.all() + page = request.GET.get('page', 1) + paginator = Paginator(timbres_list, 1) + + try: + timbres = paginator.page(page) + except PageNotAnInteger: + timbres = paginator.page(1) + except EmptyPage: + timbres = paginator.page(paginator.num_pages) + context = { + 'timbres':timbres, + } + return render(request,'Clientes/index.html',context) def add_timbre(request): @@ -24,8 +39,6 @@ def add_timbre(request): 'tipo':tipo, 'rfcp':rfcp } - p = Timbres.objects.all() - p.delete() try: obj = Timbres.objects.create(**obj) return HttpResponse('ok') diff --git a/Templates/Clientes/index.html b/Templates/Clientes/index.html new file mode 100644 index 0000000..02be319 --- /dev/null +++ b/Templates/Clientes/index.html @@ -0,0 +1,31 @@ +{% extends "base.html" %} + + +{% block content %} + + + + + + + + + + {% for obj in timbres %} + + + + + + {% endfor %} + +
UUID + + RFC Cliente + actions
{{obj.uuid}}{{obj.rfcc}} + {% if request.user.is_staff %} + View + {% endif %} +
+{% endblock content %} + \ No newline at end of file diff --git a/Templates/base.html b/Templates/base.html new file mode 100644 index 0000000..5b03a0c --- /dev/null +++ b/Templates/base.html @@ -0,0 +1,56 @@ + + + + + + + + + + + + {% block title %}{% endblock title %} + + + + {% include 'sidebar.html' %} +
+

{% block titlePage %}{% endblock titlePage %}

+ +
+ {% comment %} + {% include "Profiles/partials/messages.html" %} + {% endcomment %} +
+ + {% block content %} + + {% endblock content %} + + {% include 'paginator.html' %} +
+ + + + + + + + {% block scripts %} + + {% endblock scripts %} + + \ No newline at end of file diff --git a/Templates/paginator.html b/Templates/paginator.html new file mode 100644 index 0000000..76f6d01 --- /dev/null +++ b/Templates/paginator.html @@ -0,0 +1,38 @@ +{% if timbres.has_other_pages %} + +{% endif %} + \ No newline at end of file diff --git a/Templates/sidebar.html b/Templates/sidebar.html new file mode 100644 index 0000000..a8b292b --- /dev/null +++ b/Templates/sidebar.html @@ -0,0 +1,44 @@ + \ No newline at end of file