From f675b93788367b97a53ec50445579dc0c3853a2b Mon Sep 17 00:00:00 2001 From: Wilson Gaturu Date: Tue, 23 Apr 2024 23:18:30 +0300 Subject: [PATCH 1/4] refactors court views; adds court class detail view --- peachjam/migrations/0126_courtclass_slug.py | 27 ++ .../migrations/0127_alter_courtclass_slug.py | 18 ++ .../0128_courtclass_show_listing_page.py | 18 ++ peachjam/models/judgment.py | 6 + .../peachjam/_court_class_month_list.html | 9 + .../peachjam/_court_class_years_list.html | 9 + peachjam/templates/peachjam/_court_list.html | 4 + .../peachjam/_court_months_list.html | 37 +++ .../_court_registries_months_list.html | 9 + .../_court_registries_years_list.html | 9 + .../templates/peachjam/_court_years_list.html | 36 +++ .../peachjam/court_class_detail.html | 8 + peachjam/templates/peachjam/court_detail.html | 40 ++- .../peachjam/court_registry_detail.html | 20 +- peachjam/urls.py | 18 ++ peachjam/views/courts.py | 256 +++++++++--------- peachjam/views/generic_views.py | 2 +- 17 files changed, 378 insertions(+), 148 deletions(-) create mode 100644 peachjam/migrations/0126_courtclass_slug.py create mode 100644 peachjam/migrations/0127_alter_courtclass_slug.py create mode 100644 peachjam/migrations/0128_courtclass_show_listing_page.py create mode 100644 peachjam/templates/peachjam/_court_class_month_list.html create mode 100644 peachjam/templates/peachjam/_court_class_years_list.html create mode 100644 peachjam/templates/peachjam/_court_months_list.html create mode 100644 peachjam/templates/peachjam/_court_registries_months_list.html create mode 100644 peachjam/templates/peachjam/_court_registries_years_list.html create mode 100644 peachjam/templates/peachjam/_court_years_list.html create mode 100644 peachjam/templates/peachjam/court_class_detail.html diff --git a/peachjam/migrations/0126_courtclass_slug.py b/peachjam/migrations/0126_courtclass_slug.py new file mode 100644 index 000000000..7da4de2b0 --- /dev/null +++ b/peachjam/migrations/0126_courtclass_slug.py @@ -0,0 +1,27 @@ +# Generated by Django 3.2.24 on 2024-04-23 08:26 + +from django.db import migrations, models +from django.utils.text import slugify + + +def create_slug(apps, schema_editor): + CourtClass = apps.get_model("peachjam", "CourtClass") + for court_class in CourtClass.objects.all(): + court_class.slug = slugify(court_class.name) + court_class.save() + + +class Migration(migrations.Migration): + dependencies = [ + ("peachjam", "0125_judgment_auto_assign_title"), + ] + + operations = [ + migrations.AddField( + model_name="courtclass", + name="slug", + field=models.SlugField(default="", max_length=255, verbose_name="slug"), + preserve_default=False, + ), + migrations.RunPython(create_slug, migrations.RunPython.noop), + ] diff --git a/peachjam/migrations/0127_alter_courtclass_slug.py b/peachjam/migrations/0127_alter_courtclass_slug.py new file mode 100644 index 000000000..8e81dfbcc --- /dev/null +++ b/peachjam/migrations/0127_alter_courtclass_slug.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.24 on 2024-04-23 08:34 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("peachjam", "0126_courtclass_slug"), + ] + + operations = [ + migrations.AlterField( + model_name="courtclass", + name="slug", + field=models.SlugField(max_length=255, unique=True, verbose_name="slug"), + ), + ] diff --git a/peachjam/migrations/0128_courtclass_show_listing_page.py b/peachjam/migrations/0128_courtclass_show_listing_page.py new file mode 100644 index 000000000..583815408 --- /dev/null +++ b/peachjam/migrations/0128_courtclass_show_listing_page.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.24 on 2024-04-23 08:54 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("peachjam", "0127_alter_courtclass_slug"), + ] + + operations = [ + migrations.AddField( + model_name="courtclass", + name="show_listing_page", + field=models.BooleanField(default=False), + ), + ] diff --git a/peachjam/models/judgment.py b/peachjam/models/judgment.py index f0948ce74..c3059ead3 100644 --- a/peachjam/models/judgment.py +++ b/peachjam/models/judgment.py @@ -74,7 +74,9 @@ def __str__(self): class CourtClass(models.Model): name = models.CharField(_("name"), max_length=100, null=False, unique=True) description = models.TextField(_("description"), null=True, blank=True) + slug = models.SlugField(_("slug"), max_length=255, null=False, unique=True) order = models.IntegerField(_("order"), null=True, blank=True) + show_listing_page = models.BooleanField(null=False, default=False) class Meta: ordering = ( @@ -87,6 +89,10 @@ class Meta: def __str__(self): return self.name + def save(self, *args, **kwargs): + self.slug = slugify(self.name) + return super().save(*args, **kwargs) + class Court(models.Model): name = models.CharField(_("name"), max_length=255, null=False, unique=True) diff --git a/peachjam/templates/peachjam/_court_class_month_list.html b/peachjam/templates/peachjam/_court_class_month_list.html new file mode 100644 index 000000000..ffd1eb461 --- /dev/null +++ b/peachjam/templates/peachjam/_court_class_month_list.html @@ -0,0 +1,9 @@ +{% extends "peachjam/_court_months_list.html" %} +{% load i18n %} +{% block all_months_link %} + {% trans 'All months' %} +{% endblock %} +{% block month_link %} + {{ m|date:"F" }} +{% endblock %} diff --git a/peachjam/templates/peachjam/_court_class_years_list.html b/peachjam/templates/peachjam/_court_class_years_list.html new file mode 100644 index 000000000..5dcf5b24d --- /dev/null +++ b/peachjam/templates/peachjam/_court_class_years_list.html @@ -0,0 +1,9 @@ +{% extends "peachjam/_court_years_list.html" %} +{% load i18n %} +{% block all_years_link %} + {% trans 'All years' %} +{% endblock %} +{% block year_link %} + {{ y.year }} +{% endblock %} diff --git a/peachjam/templates/peachjam/_court_list.html b/peachjam/templates/peachjam/_court_list.html index ae64bb421..3bc56ea97 100644 --- a/peachjam/templates/peachjam/_court_list.html +++ b/peachjam/templates/peachjam/_court_list.html @@ -12,6 +12,10 @@

{{ court_class }}

{% endfor %} + {% if court_class.show_listing_page %} + View All + {% endif %} {% else %}
{% trans 'No courts found.' %}
{% endif %} diff --git a/peachjam/templates/peachjam/_court_months_list.html b/peachjam/templates/peachjam/_court_months_list.html new file mode 100644 index 000000000..5c274baa2 --- /dev/null +++ b/peachjam/templates/peachjam/_court_months_list.html @@ -0,0 +1,37 @@ +{% load i18n %} +{% if months and years %} +
+ +
+ {% block all_months_link %} + {% trans 'All months' %} + {% endblock %} +
+ +
+ +{% endif %} diff --git a/peachjam/templates/peachjam/_court_registries_months_list.html b/peachjam/templates/peachjam/_court_registries_months_list.html new file mode 100644 index 000000000..ec3e591d5 --- /dev/null +++ b/peachjam/templates/peachjam/_court_registries_months_list.html @@ -0,0 +1,9 @@ +{% extends "peachjam/_court_months_list.html" %} +{% load i18n %} +{% block all_months_link %} + {% trans 'All months' %} +{% endblock %} +{% block month_link %} + {{ m|date:"F" }} +{% endblock %} diff --git a/peachjam/templates/peachjam/_court_registries_years_list.html b/peachjam/templates/peachjam/_court_registries_years_list.html new file mode 100644 index 000000000..c46766aab --- /dev/null +++ b/peachjam/templates/peachjam/_court_registries_years_list.html @@ -0,0 +1,9 @@ +{% extends "peachjam/_court_years_list.html" %} +{% load i18n %} +{% block all_years_link %} + {% trans 'All months' %} +{% endblock %} +{% block year_link %} + {{ y.year }} +{% endblock %} diff --git a/peachjam/templates/peachjam/_court_years_list.html b/peachjam/templates/peachjam/_court_years_list.html new file mode 100644 index 000000000..54fa081d1 --- /dev/null +++ b/peachjam/templates/peachjam/_court_years_list.html @@ -0,0 +1,36 @@ +{% load i18n %} +{% if years %} +
+ +
+ {% block all_years_link %} + {% trans 'All years' %} + {% endblock %} +
+ +
+ +{% endif %} diff --git a/peachjam/templates/peachjam/court_class_detail.html b/peachjam/templates/peachjam/court_class_detail.html new file mode 100644 index 000000000..70d5578ef --- /dev/null +++ b/peachjam/templates/peachjam/court_class_detail.html @@ -0,0 +1,8 @@ +{% extends 'peachjam/court_detail.html' %} +{% load i18n %} +{% block year_list %} + {% include "peachjam/_court_class_years_list.html" %} +{% endblock %} +{% block month_list %} + {% include "peachjam/_court_class_month_list.html" %} +{% endblock %} diff --git a/peachjam/templates/peachjam/court_detail.html b/peachjam/templates/peachjam/court_detail.html index 4cbc2e3f6..5eed9cbdb 100644 --- a/peachjam/templates/peachjam/court_detail.html +++ b/peachjam/templates/peachjam/court_detail.html @@ -1,6 +1,6 @@ {% extends 'peachjam/layouts/document_list.html' %} {% load i18n %} -{% block title %}{{ formatted_court_name }}{% endblock %} +{% block title %}{{ page_title }}{% endblock %} {% block breadcrumbs %}
@@ -23,13 +39,17 @@ {% endwith %} {% endblock %} {% block page-header %} -

{{ formatted_court_name }}

+

{{ page_title }}

{% include 'peachjam/_document_count.html' %} - {% include 'peachjam/_registries.html' %} - {% include 'peachjam/_years_list.html' %} - {% if months %} - {% include 'peachjam/_months_list.html' %} - {% endif %} + {% block court_list %} + {% include 'peachjam/_registries.html' %} + {% endblock %} + {% block year_list %} + {% include 'peachjam/_court_years_list.html' %} + {% endblock %} + {% block month_list %} + {% include 'peachjam/_court_months_list.html' %} + {% endblock %} {% endblock %} {% block content %} {% if grouped_documents %} diff --git a/peachjam/templates/peachjam/court_registry_detail.html b/peachjam/templates/peachjam/court_registry_detail.html index 2722c6e29..2c5247f49 100644 --- a/peachjam/templates/peachjam/court_registry_detail.html +++ b/peachjam/templates/peachjam/court_registry_detail.html @@ -1,18 +1,8 @@ {% extends 'peachjam/court_detail.html' %} {% load i18n %} -{% block title %}{{ formatted_court_name }}{% endblock %} -{% block breadcrumbs %} -
- -
+{% block year_list %} + {% include "peachjam/_court_registries_years_list.html" %} +{% endblock %} +{% block month_list %} + {% include "peachjam/_court_registries_months_list.html" %} {% endblock %} diff --git a/peachjam/urls.py b/peachjam/urls.py index 269bae934..677027791 100644 --- a/peachjam/urls.py +++ b/peachjam/urls.py @@ -36,6 +36,9 @@ ArticleYearArchiveView, AuthorDetailView, BookListView, + CourtClassDetailView, + CourtClassMonthView, + CourtClassYearView, CourtDetailView, CourtMonthView, CourtRegistryDetailView, @@ -93,6 +96,21 @@ name="author", ), path("judgments/", JudgmentListView.as_view(), name="judgment_list"), + path( + "judgments/court-class//", + CourtClassDetailView.as_view(), + name="court_class", + ), + path( + "judgments/court-class///", + CourtClassYearView.as_view(), + name="court_class_year", + ), + path( + "judgments/court-class////", + CourtClassMonthView.as_view(), + name="court_class_month", + ), path( "judgments//", CourtDetailView.as_view(), diff --git a/peachjam/views/courts.py b/peachjam/views/courts.py index 48d881f4c..c73bb7aaa 100644 --- a/peachjam/views/courts.py +++ b/peachjam/views/courts.py @@ -1,69 +1,36 @@ from itertools import groupby +from django.http import Http404 from django.shortcuts import get_object_or_404 -from django.urls import reverse from django.utils.dates import MONTHS from peachjam.helpers import chunks, lowercase_alphabet -from peachjam.models import Court, CourtRegistry, Judgment +from peachjam.models import Court, CourtClass, CourtRegistry, Judgment from peachjam.views.generic_views import FilteredDocumentListView -class CourtDetailView(FilteredDocumentListView): - """List View class for filtering a court's judgments. - - This view may be restricted to a specific year. - """ +class BaseJudgmentFilterView(FilteredDocumentListView): + """Base List View class for filtering judgments.""" model = Judgment - template_name = "peachjam/court_detail.html" navbar_link = "judgments" - queryset = Judgment.objects.prefetch_related("labels") - - def get_base_queryset(self): - qs = super().get_base_queryset().filter(court=self.court) - if "year" in self.kwargs: - qs = qs.filter(date__year=self.kwargs["year"]) - - if "month" in self.kwargs: - qs = qs.filter(date__month=self.kwargs["month"]) + queryset = Judgment.objects.prefetch_related("judges", "labels") - return qs + def base_view_name(self): + return "Judgments" - def get_queryset(self): - self.court = get_object_or_404(Court, code=self.kwargs["code"]) - return super().get_queryset() + def page_title(self): + return self.base_view_name() def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context["doc_type"] = "Judgment" - context["court"] = self.court - context["formatted_court_name"] = self.formatted_court_name() - context["registry_label_plural"] = CourtRegistry.model_label_plural - context["registries"] = self.court.registries.exclude( - judgments__isnull=True - ) # display registries with judgments only - context["registry_groups"] = list(chunks(context["registries"], 2)) + context["page_title"] = self.page_title() if not self.form.cleaned_data.get("alphabet"): context["grouped_documents"] = self.grouped_judgments(context["documents"]) - if "year" in self.kwargs: - context["year"] = self.kwargs["year"] - - if "month" in self.kwargs and self.kwargs["month"] in set(range(1, 13)): - context["month"] = MONTHS[self.kwargs["month"]] - context[ - "formatted_court_name" - ] = f"{context['formatted_court_name']} - {context['month']} {self.kwargs['year']}" - else: - context[ - "formatted_court_name" - ] = f"{context['formatted_court_name']} - {self.kwargs['year']}" - - self.populate_months(context) - self.populate_years(context) self.populate_facets(context) @@ -110,37 +77,10 @@ def populate_facets(self, context): "order_outcomes": order_outcomes, } - def formatted_court_name(self): - return self.court.name - def populate_years(self, context): - years = self.queryset.filter(court=self.court).dates( + context["years"] = self.get_base_queryset(exclude=["year", "month"]).dates( "date", "year", order="DESC" ) - context["years"] = [ - { - "url": reverse("court_year", args=[self.court.code, year.year]), - "year": year.year, - } - for year in years - ] - context["all_years_url"] = reverse("court", args=[self.court.code]) - - def populate_months(self, context): - year = self.kwargs["year"] - months = self.queryset.filter(court=self.court, date__year=year).dates( - "date", "month", order="ASC" - ) - context["months"] = [ - { - "url": reverse("court_month", args=[self.court.code, year, item.month]), - "month": MONTHS[item.month], - } - for item in months - ] - context["all_months_url"] = reverse( - "court_year", args=[self.court.code, self.kwargs["year"]] - ) def grouped_judgments(self, documents): """Group the judgments by month and return a list of dicts with the month name and judgments for that month""" @@ -150,78 +90,150 @@ def grouped_judgments(self, documents): return [{"key": key, "judgments": list(group)} for key, group in groups] -class CourtYearView(CourtDetailView): +class CourtDetailView(BaseJudgmentFilterView): + template_name = "peachjam/court_detail.html" + + @property + def court(self): + return get_object_or_404(Court, code=self.kwargs.get("code")) + + def base_view_name(self): + return self.court.name + + def get_base_queryset(self, exclude=None): + qs = super().get_base_queryset(exclude=exclude).filter(court=self.court) + return qs + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["court"] = self.court + context["registry_label_plural"] = CourtRegistry.model_label_plural + context["registries"] = self.court.registries.exclude( + judgments__isnull=True + ) # display registries with judgments only + context["registry_groups"] = list(chunks(context["registries"], 2)) + return context + + +class YearMixin: + @property + def year(self): + return self.kwargs["year"] + + def page_title(self): + return f"{super().page_title()} - {self.year}" + + def get_base_queryset(self, exclude=None): + qs = super().get_base_queryset() + if exclude is None: + exclude = [] + if "year" not in exclude: + qs = qs.filter(date__year=self.kwargs["year"]) + return qs + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["year"] = self.year + self.populate_months(context) + return context + + def populate_months(self, context): + context["months"] = self.get_base_queryset(exclude=["month"]).dates( + "date", "month", order="ASC" + ) + + +class CourtYearView(YearMixin, CourtDetailView): pass -class CourtMonthView(CourtDetailView): +class MonthMixin: + @property + def month(self): + if self.kwargs["month"] not in set(range(1, 13)): + raise Http404("Invalid month") + return self.kwargs["month"] + + def page_title(self): + return f"{super().page_title()} {MONTHS[self.month]}" + + def get_base_queryset(self, exclude=None): + if exclude is None: + exclude = [] + qs = super().get_base_queryset(exclude=exclude) + if "month" not in exclude: + qs = qs.filter(date__month=self.month) + return qs + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["month"] = MONTHS[self.month] + return context + + +class CourtMonthView(MonthMixin, CourtYearView): pass -class CourtRegistryDetailView(CourtDetailView): - queryset = Judgment.objects.prefetch_related("judges", "labels") +class RegistryMixin: template_name = "peachjam/court_registry_detail.html" - def get_base_queryset(self): - return super().get_base_queryset().filter(registry=self.registry) + def base_view_name(self): + return self.registry.name - def get_queryset(self): - self.court = get_object_or_404(Court, code=self.kwargs["code"]) - self.registry = get_object_or_404( - CourtRegistry, code=self.kwargs["registry_code"] - ) - return super().get_queryset() + @property + def registry(self): + return get_object_or_404(CourtRegistry, code=self.kwargs.get("registry_code")) + + def get_base_queryset(self, *args, **kwargs): + return super().get_base_queryset(*args, **kwargs).filter(registry=self.registry) def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context["registry"] = self.registry return context - def formatted_court_name(self): - return self.registry.name - def populate_years(self, context): - years = self.queryset.filter(registry=self.registry).dates( - "date", "year", order="DESC" - ) - context["years"] = [ - { - "url": reverse( - "court_registry_year", - args=[self.court.code, self.registry.code, year.year], - ), - "year": year.year, - } - for year in years - ] - context["all_years_url"] = reverse( - "court_registry", args=[self.court.code, self.registry.code] - ) +class CourtRegistryDetailView(RegistryMixin, CourtDetailView): + pass - def populate_months(self, context): - year = self.kwargs["year"] - months = self.queryset.filter(registry=self.registry, date__year=year).dates( - "date", "month", order="ASC" - ) - context["months"] = [ - { - "url": reverse( - "court_registry_month", - args=[self.court.code, self.registry.code, year, item.month], - ), - "month": MONTHS[item.month], - } - for item in months - ] - context["all_months_url"] = reverse( - "court_registry_year", - args=[self.court.code, self.registry.code, self.kwargs["year"]], + +class CourtRegistryYearView(RegistryMixin, CourtYearView): + pass + + +class CourtRegistryMonthView(RegistryMixin, CourtMonthView): + pass + + +class CourtClassDetailView(BaseJudgmentFilterView): + template_name = "peachjam/court_class_detail.html" + + def base_view_name(self): + return self.court_class.name + + @property + def court_class(self): + return get_object_or_404(CourtClass, slug=self.kwargs["court_class"]) + + def get_base_queryset(self, exclude=None): + return ( + super() + .get_base_queryset(exclude=exclude) + .filter(court__court_class=self.court_class) ) + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["court_class"] = self.court_class + context["registries"] = Court.objects.filter(court_class=self.court_class) + context["registry_groups"] = list(chunks(context["registries"], 2)) + return context + -class CourtRegistryYearView(CourtRegistryDetailView): +class CourtClassYearView(YearMixin, CourtClassDetailView): pass -class CourtRegistryMonthView(CourtRegistryDetailView): +class CourtClassMonthView(MonthMixin, CourtClassYearView): pass diff --git a/peachjam/views/generic_views.py b/peachjam/views/generic_views.py index 5ff7da9aa..0be56bee4 100644 --- a/peachjam/views/generic_views.py +++ b/peachjam/views/generic_views.py @@ -34,7 +34,7 @@ class DocumentListView(ListView): "nature", "work", "jurisdiction", "locality" ) - def get_base_queryset(self): + def get_base_queryset(self, *args, **kwargs): qs = self.queryset if self.queryset is not None else self.model.objects return qs.filter(published=True) From 5a22f268319ae03de1a2e8baf83f7c0ff50a6100 Mon Sep 17 00:00:00 2001 From: Wilson Gaturu Date: Wed, 24 Apr 2024 13:22:42 +0300 Subject: [PATCH 2/4] fixes court view mixins --- peachjam/models/judgment.py | 6 +++ .../peachjam/_court_class_month_list.html | 10 ++-- .../peachjam/_court_class_years_list.html | 10 ++-- peachjam/templates/peachjam/_court_list.html | 4 +- .../peachjam/_court_months_list.html | 15 +++--- .../_court_registries_months_list.html | 10 ++-- .../_court_registries_years_list.html | 10 ++-- .../templates/peachjam/_court_years_list.html | 15 +++--- peachjam/tests/test_views.py | 18 ++----- peachjam/views/courts.py | 47 ++++++++++++++----- 10 files changed, 87 insertions(+), 58 deletions(-) diff --git a/peachjam/models/judgment.py b/peachjam/models/judgment.py index c3059ead3..b46c9d178 100644 --- a/peachjam/models/judgment.py +++ b/peachjam/models/judgment.py @@ -89,6 +89,9 @@ class Meta: def __str__(self): return self.name + def get_absolute_url(self): + return reverse("court_class", args=[self.slug]) + def save(self, *args, **kwargs): self.slug = slugify(self.name) return super().save(*args, **kwargs) @@ -134,6 +137,9 @@ class Meta: def __str__(self): return self.name + def get_absolute_url(self): + return reverse("court", args=[self.code]) + class CourtRegistryManager(models.Manager): def get_queryset(self): diff --git a/peachjam/templates/peachjam/_court_class_month_list.html b/peachjam/templates/peachjam/_court_class_month_list.html index ffd1eb461..7d45f7598 100644 --- a/peachjam/templates/peachjam/_court_class_month_list.html +++ b/peachjam/templates/peachjam/_court_class_month_list.html @@ -1,9 +1,11 @@ {% extends "peachjam/_court_months_list.html" %} {% load i18n %} -{% block all_months_link %} - {% trans 'All months' %} -{% endblock %} {% block month_link %} {{ m|date:"F" }} {% endblock %} +{% block month_option %} + +{% endblock %} diff --git a/peachjam/templates/peachjam/_court_class_years_list.html b/peachjam/templates/peachjam/_court_class_years_list.html index 5dcf5b24d..e6ef9c082 100644 --- a/peachjam/templates/peachjam/_court_class_years_list.html +++ b/peachjam/templates/peachjam/_court_class_years_list.html @@ -1,9 +1,11 @@ {% extends "peachjam/_court_years_list.html" %} {% load i18n %} -{% block all_years_link %} - {% trans 'All years' %} -{% endblock %} {% block year_link %} {{ y.year }} {% endblock %} +{% block year_option %} + +{% endblock %} diff --git a/peachjam/templates/peachjam/_court_list.html b/peachjam/templates/peachjam/_court_list.html index 3bc56ea97..5b54502da 100644 --- a/peachjam/templates/peachjam/_court_list.html +++ b/peachjam/templates/peachjam/_court_list.html @@ -13,8 +13,8 @@

{{ court_class }}

{% endfor %} {% if court_class.show_listing_page %} - View All + {% trans 'View all' %} {% endif %} {% else %}
{% trans 'No courts found.' %}
diff --git a/peachjam/templates/peachjam/_court_months_list.html b/peachjam/templates/peachjam/_court_months_list.html index 5c274baa2..0d4472fc9 100644 --- a/peachjam/templates/peachjam/_court_months_list.html +++ b/peachjam/templates/peachjam/_court_months_list.html @@ -4,10 +4,8 @@ class="pl-0 mt-2 mb-3 align-items-center d-none d-lg-flex">
- {% block all_months_link %} - {% trans 'All months' %} - {% endblock %} + {% trans 'All months' %}
    {% for m in months %} @@ -29,9 +27,12 @@ {% trans 'All months' %} {% for m in months %} - + {% block month_option %} + + {% endblock %} {% endfor %} {% endif %} diff --git a/peachjam/templates/peachjam/_court_registries_months_list.html b/peachjam/templates/peachjam/_court_registries_months_list.html index ec3e591d5..9e5726e97 100644 --- a/peachjam/templates/peachjam/_court_registries_months_list.html +++ b/peachjam/templates/peachjam/_court_registries_months_list.html @@ -1,9 +1,11 @@ {% extends "peachjam/_court_months_list.html" %} {% load i18n %} -{% block all_months_link %} - {% trans 'All months' %} -{% endblock %} {% block month_link %} {{ m|date:"F" }} {% endblock %} +{% block month_option %} + +{% endblock %} diff --git a/peachjam/templates/peachjam/_court_registries_years_list.html b/peachjam/templates/peachjam/_court_registries_years_list.html index c46766aab..5c07f69b9 100644 --- a/peachjam/templates/peachjam/_court_registries_years_list.html +++ b/peachjam/templates/peachjam/_court_registries_years_list.html @@ -1,9 +1,11 @@ {% extends "peachjam/_court_years_list.html" %} {% load i18n %} -{% block all_years_link %} - {% trans 'All months' %} -{% endblock %} {% block year_link %} {{ y.year }} {% endblock %} +{% block year_option %} + +{% endblock %} diff --git a/peachjam/templates/peachjam/_court_years_list.html b/peachjam/templates/peachjam/_court_years_list.html index 54fa081d1..1341923a2 100644 --- a/peachjam/templates/peachjam/_court_years_list.html +++ b/peachjam/templates/peachjam/_court_years_list.html @@ -3,10 +3,8 @@
    - {% block all_years_link %} - {% trans 'All years' %} - {% endblock %} + {% trans 'All years' %}
      {% for y in years %} @@ -28,9 +26,12 @@ {% trans 'All years' %} {% for y in years %} - + {% block year_option %} + + {% endblock %} {% endfor %} {% endif %} diff --git a/peachjam/tests/test_views.py b/peachjam/tests/test_views.py index c77ab2d17..fe91e57b2 100644 --- a/peachjam/tests/test_views.py +++ b/peachjam/tests/test_views.py @@ -55,13 +55,8 @@ def test_court_listing(self): "Ababacar and Ors vs Senegal [2018] ECOWASCJ 17 (29 June 2018)", documents, ) - self.assertEqual( - response.context["years"], - [ - {"url": "/judgments/ECOWASCJ/2018/", "year": 2018}, - {"url": "/judgments/ECOWASCJ/2016/", "year": 2016}, - ], - ) + self.assertContains(response, "/judgments/ECOWASCJ/2018/") + self.assertContains(response, "/judgments/ECOWASCJ/2016/") self.assertNotIn("years", response.context["facet_data"], [2016, 2018]) def test_court_year_listing(self): @@ -79,13 +74,8 @@ def test_court_year_listing(self): documents, ) self.assertEqual(response.context["year"], 2016) - self.assertEqual( - response.context["years"], - [ - {"url": "/judgments/ECOWASCJ/2018/", "year": 2018}, - {"url": "/judgments/ECOWASCJ/2016/", "year": 2016}, - ], - ) + self.assertContains(response, "/judgments/ECOWASCJ/2018/") + self.assertContains(response, "/judgments/ECOWASCJ/2016/") self.assertNotIn("years", response.context["facet_data"], [2016, 2018]) def test_judgment_detail(self): diff --git a/peachjam/views/courts.py b/peachjam/views/courts.py index c73bb7aaa..665528595 100644 --- a/peachjam/views/courts.py +++ b/peachjam/views/courts.py @@ -1,15 +1,18 @@ +from functools import cached_property from itertools import groupby from django.http import Http404 from django.shortcuts import get_object_or_404 +from django.urls import reverse from django.utils.dates import MONTHS +from django.utils.text import gettext_lazy as _ from peachjam.helpers import chunks, lowercase_alphabet from peachjam.models import Court, CourtClass, CourtRegistry, Judgment from peachjam.views.generic_views import FilteredDocumentListView -class BaseJudgmentFilterView(FilteredDocumentListView): +class FilteredJudgmentView(FilteredDocumentListView): """Base List View class for filtering judgments.""" model = Judgment @@ -17,7 +20,7 @@ class BaseJudgmentFilterView(FilteredDocumentListView): queryset = Judgment.objects.prefetch_related("judges", "labels") def base_view_name(self): - return "Judgments" + return _("Judgments") def page_title(self): return self.base_view_name() @@ -90,10 +93,10 @@ def grouped_judgments(self, documents): return [{"key": key, "judgments": list(group)} for key, group in groups] -class CourtDetailView(BaseJudgmentFilterView): +class CourtDetailView(FilteredJudgmentView): template_name = "peachjam/court_detail.html" - @property + @cached_property def court(self): return get_object_or_404(Court, code=self.kwargs.get("code")) @@ -112,6 +115,7 @@ def get_context_data(self, **kwargs): judgments__isnull=True ) # display registries with judgments only context["registry_groups"] = list(chunks(context["registries"], 2)) + context["all_years_url"] = self.court.get_absolute_url() return context @@ -144,7 +148,12 @@ def populate_months(self, context): class CourtYearView(YearMixin, CourtDetailView): - pass + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["all_months_url"] = reverse( + "court_year", args=[self.court.code, self.year] + ) + return context class MonthMixin: @@ -181,7 +190,7 @@ class RegistryMixin: def base_view_name(self): return self.registry.name - @property + @cached_property def registry(self): return get_object_or_404(CourtRegistry, code=self.kwargs.get("registry_code")) @@ -191,6 +200,7 @@ def get_base_queryset(self, *args, **kwargs): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context["registry"] = self.registry + context["all_years_url"] = self.registry.get_absolute_url() return context @@ -198,21 +208,26 @@ class CourtRegistryDetailView(RegistryMixin, CourtDetailView): pass -class CourtRegistryYearView(RegistryMixin, CourtYearView): - pass +class CourtRegistryYearView(YearMixin, CourtRegistryDetailView): + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["all_months_url"] = reverse( + "court_registry_year", args=[self.court.code, self.registry.code, self.year] + ) + return context -class CourtRegistryMonthView(RegistryMixin, CourtMonthView): +class CourtRegistryMonthView(MonthMixin, CourtRegistryYearView): pass -class CourtClassDetailView(BaseJudgmentFilterView): +class CourtClassDetailView(FilteredJudgmentView): template_name = "peachjam/court_class_detail.html" def base_view_name(self): return self.court_class.name - @property + @cached_property def court_class(self): return get_object_or_404(CourtClass, slug=self.kwargs["court_class"]) @@ -227,12 +242,20 @@ def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context["court_class"] = self.court_class context["registries"] = Court.objects.filter(court_class=self.court_class) + context["registry_label_plural"] = _("Courts") context["registry_groups"] = list(chunks(context["registries"], 2)) + context["all_years_url"] = self.court_class.get_absolute_url() + return context class CourtClassYearView(YearMixin, CourtClassDetailView): - pass + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["all_months_url"] = reverse( + "court_class_year", args=[self.court_class.slug, self.year] + ) + return context class CourtClassMonthView(MonthMixin, CourtClassYearView): From 512482f39502951f96dc5717bc8e92a2f951e711 Mon Sep 17 00:00:00 2001 From: Greg Kempe Date: Thu, 25 Apr 2024 09:32:23 +0200 Subject: [PATCH 3/4] use flow-columns for registry list as well as courts also increase padding between groups --- peachjam/static/stylesheets/_global.scss | 9 +++++---- peachjam/templates/peachjam/_court_list.html | 4 ++-- peachjam/templates/peachjam/_registries.html | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/peachjam/static/stylesheets/_global.scss b/peachjam/static/stylesheets/_global.scss index 5333f20c4..138394e6d 100644 --- a/peachjam/static/stylesheets/_global.scss +++ b/peachjam/static/stylesheets/_global.scss @@ -18,7 +18,8 @@ main { flex-grow: 1; } -.courts__column-wrapper { +// newspaper-like dynamic columns +.flow-columns { columns: 3 auto; @include media-breakpoint-down(lg) { @@ -28,10 +29,10 @@ main { @include media-breakpoint-down(sm) { columns: 1; } -} -.courts__item { - break-inside: avoid; + .flow-columns-group { + break-inside: avoid; + } } mark { diff --git a/peachjam/templates/peachjam/_court_list.html b/peachjam/templates/peachjam/_court_list.html index 5b54502da..082468e8c 100644 --- a/peachjam/templates/peachjam/_court_list.html +++ b/peachjam/templates/peachjam/_court_list.html @@ -1,8 +1,8 @@ {% load peachjam i18n %} {% if court_classes %} -
      +
      {% for court_class in court_classes %} -
      +

      {{ court_class }}

      {% if court_class.courts.all %}
        diff --git a/peachjam/templates/peachjam/_registries.html b/peachjam/templates/peachjam/_registries.html index 1277913a0..0aa50f1cd 100644 --- a/peachjam/templates/peachjam/_registries.html +++ b/peachjam/templates/peachjam/_registries.html @@ -1,15 +1,15 @@ {% load i18n %} {% if registries %}

        {{ registry_label_plural }}

        -
        +
        {% for group in registry_groups %} -
        +
          {% for r in group %} {% if r.code == registry.code %}
        • {{ r.name }}
        • {% else %} -
        • +
        • {{ r.name }}
        • {% endif %} From c6694425284b2317dfd096b6d107e77463ec75fd Mon Sep 17 00:00:00 2001 From: Wilson Gaturu Date: Thu, 25 Apr 2024 12:34:45 +0300 Subject: [PATCH 4/4] changes all judgments button position --- peachjam/templates/peachjam/_court_list.html | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/peachjam/templates/peachjam/_court_list.html b/peachjam/templates/peachjam/_court_list.html index 082468e8c..f32ec9b42 100644 --- a/peachjam/templates/peachjam/_court_list.html +++ b/peachjam/templates/peachjam/_court_list.html @@ -4,6 +4,11 @@ {% for court_class in court_classes %}

          {{ court_class }}

          + {% if court_class.show_listing_page %} + + {% endif %} {% if court_class.courts.all %}
            {% for court in court_class.courts.all %} @@ -12,10 +17,6 @@

            {{ court_class }}

            {% endfor %}
          - {% if court_class.show_listing_page %} - {% trans 'View all' %} - {% endif %} {% else %}
          {% trans 'No courts found.' %}
          {% endif %}