From a6f0920f39f3fd8bc976c4de28946aed49fc3b60 Mon Sep 17 00:00:00 2001 From: danielmarv Date: Sat, 19 Oct 2024 20:05:50 +0300 Subject: [PATCH 1/6] First commit --- legal_db/templates/legal_db/case/index.html | 64 ++++++++++++++++----- legal_db/views.py | 16 +++++- 2 files changed, 64 insertions(+), 16 deletions(-) diff --git a/legal_db/templates/legal_db/case/index.html b/legal_db/templates/legal_db/case/index.html index 0eb0957..1163d39 100644 --- a/legal_db/templates/legal_db/case/index.html +++ b/legal_db/templates/legal_db/case/index.html @@ -27,17 +27,17 @@

Contribute

{% include "legal_db/partials/_search.html" %}
- {% for tag in tags %} - - {% endfor %} + {% for tag in tags %} + + {% endfor %}
@@ -45,17 +45,29 @@

Contribute

- - + + - + {% for case in cases %} - +
CountryCase name + + Country + + + + Case name + + LicenseYear of resolution + + Year of resolution + +
{{ case.country.name }}{{ case.name }} {{ case.name }} {% if not case.license %} Unknown {% else %} {{ case.license }} {% endif %} @@ -68,6 +80,28 @@

Contribute

+ + {% endblock %} diff --git a/legal_db/views.py b/legal_db/views.py index ba06639..5fe6d68 100644 --- a/legal_db/views.py +++ b/legal_db/views.py @@ -4,6 +4,8 @@ from django.shortcuts import redirect, render from django.views.generic import DetailView, ListView, TemplateView from taggit.models import Tag +from django.core.paginator import Paginator +from django.db.models import Q from .forms import CaseForm, LinkForm, LinkFormset, ScholarshipForm, SearchForm from .models import FAQ, Case, Link, Scholarship @@ -24,6 +26,7 @@ def get_context_data(self, **kwargs): class CaseListView(ListView): template_name = "legal_db/case/index.html" context_object_name = "cases" + paginate_by = 10 # Number of cases per page def get_queryset(self): """ @@ -49,11 +52,18 @@ def get_queryset(self): lookups = build_filters(attributes, keywords) qs = qs.filter(lookups) + tags = self.request.GET.getlist("tags[]") if tags: qs = qs.filter(tags__name__in=tags) - return qs.order_by("country", "name") + + sort_by = self.request.GET.get('sort', 'name') + direction = self.request.GET.get('direction', 'asc') + if direction == 'desc': + sort_by = '-' + sort_by + + return qs.order_by(sort_by) def get_context_data(self, **kwargs): """ @@ -67,6 +77,10 @@ def get_context_data(self, **kwargs): tags.append({"name": tag, "checked": checked}) context["tags"] = tags context["form"] = SearchForm(self.request.GET) + + context["current_sort"] = self.request.GET.get('sort', 'name') + context["direction"] = self.request.GET.get('direction', 'asc') + return context From 434e03e5888c00e007fef7f261b4614150b24d6d Mon Sep 17 00:00:00 2001 From: danielmarv Date: Sat, 19 Oct 2024 21:39:30 +0300 Subject: [PATCH 2/6] commit --- legal_db/templates/legal_db/case/index.html | 28 ++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/legal_db/templates/legal_db/case/index.html b/legal_db/templates/legal_db/case/index.html index 1163d39..b52c895 100644 --- a/legal_db/templates/legal_db/case/index.html +++ b/legal_db/templates/legal_db/case/index.html @@ -2,6 +2,32 @@ {% load static %} {% block body_content %} +
{% include "legal_db/partials/_breadcrumb.html" %} @@ -97,7 +123,7 @@

Contribute

{% endfor %} {% if page_obj.has_next %} -
  • Next
  • +
  • Next
  • Last »
  • {% endif %} From 87dba3dbaa075a51d10d52132a01f71a61751dd1 Mon Sep 17 00:00:00 2001 From: webbunivAdmin Date: Sat, 19 Oct 2024 21:41:06 +0300 Subject: [PATCH 3/6] commit --- legal_db/templates/legal_db/case/index.html | 1 - 1 file changed, 1 deletion(-) diff --git a/legal_db/templates/legal_db/case/index.html b/legal_db/templates/legal_db/case/index.html index b52c895..ce363ea 100644 --- a/legal_db/templates/legal_db/case/index.html +++ b/legal_db/templates/legal_db/case/index.html @@ -26,7 +26,6 @@ background-color: #333; border-color: #333; } -
    From bd5d809cff7d626a35b631c9d0b255313d550ceb Mon Sep 17 00:00:00 2001 From: Daniel Ntege Date: Wed, 23 Oct 2024 18:00:59 +0300 Subject: [PATCH 4/6] electifying the requested changes --- legal_db/templates/legal_db/case/index.html | 60 +++++++-------------- legal_db/views.py | 2 +- 2 files changed, 19 insertions(+), 43 deletions(-) diff --git a/legal_db/templates/legal_db/case/index.html b/legal_db/templates/legal_db/case/index.html index ce363ea..8debfca 100644 --- a/legal_db/templates/legal_db/case/index.html +++ b/legal_db/templates/legal_db/case/index.html @@ -2,31 +2,7 @@ {% load static %} {% block body_content %} - +
    {% include "legal_db/partials/_breadcrumb.html" %} @@ -53,16 +29,16 @@

    Contribute

    {% for tag in tags %} - - {% endfor %} + + {% endfor %}
    @@ -106,24 +82,24 @@

    Contribute

    -
    {% endblock %} diff --git a/legal_db/views.py b/legal_db/views.py index fa2bc70..6b11b03 100644 --- a/legal_db/views.py +++ b/legal_db/views.py @@ -26,12 +26,11 @@ def get_context_data(self, **kwargs): class CaseListView(ListView): template_name = "legal_db/case/index.html" context_object_name = "cases" - paginate_by = 5 + paginate_by = 8 def get_queryset(self): """ - Get only rows with PUBLISHED status and filtered by user input and - tags. + Get only rows with PUBLISHED status and filtered by user input and tags. """ qs = Case.objects.filter(status=Case.Status.PUBLISHED).only( "country", "name", "license", "decision_year" @@ -52,14 +51,12 @@ def get_queryset(self): lookups = build_filters(attributes, keywords) qs = qs.filter(lookups) - tags = self.request.GET.getlist("tags[]") if tags: qs = qs.filter(tags__name__in=tags) - - sort_by = self.request.GET.get('sort', 'name') - direction = self.request.GET.get('direction', 'asc') + sort_by = self.request.GET.get('sort', 'name') + direction = self.request.GET.get('direction', 'asc') if direction == 'desc': sort_by = '-' + sort_by @@ -67,20 +64,43 @@ def get_queryset(self): def get_context_data(self, **kwargs): """ - Append search form and tags marking the selected ones. + Append search form, tags marking the selected ones, and customized pagination range. """ context = super().get_context_data(**kwargs) selected_tags = self.request.GET.getlist("tags[]") tags = [] for tag in Tag.objects.exclude(case=None).order_by("name"): - checked = True if tag.name in selected_tags else False + checked = tag.name in selected_tags tags.append({"name": tag, "checked": checked}) context["tags"] = tags context["form"] = SearchForm(self.request.GET) context["current_sort"] = self.request.GET.get('sort', 'name') context["direction"] = self.request.GET.get('direction', 'asc') - + + page_obj = context["page_obj"] + paginator = page_obj.paginator + current_page = page_obj.number + total_pages = paginator.num_pages + + start_page = max(current_page - 2, 1) + end_page = min(current_page + 2, total_pages) + + page_range = [] + if start_page > 1: + page_range.append(1) + if start_page > 2: + page_range.append("...") + + page_range.extend(range(start_page, end_page + 1)) + + if end_page < total_pages: + if end_page < total_pages - 1: + page_range.append("...") + page_range.append(total_pages) + + context["custom_page_range"] = page_range + return context