Skip to content

Commit

Permalink
Merge pull request #1478 from nationalarchives/FCL-322-court-year-ran…
Browse files Browse the repository at this point in the history
…ges-are-off-by-one-in-the-sitemap

[FCL-322] Fix for court years being off by one in the sitemap
  • Loading branch information
jacksonj04 authored Sep 26, 2024
2 parents c4d2898 + 9c2ea33 commit 70a7960
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
16 changes: 6 additions & 10 deletions config/views/sitemaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from django.http import Http404
from django.urls import reverse
from django.views.generic.base import TemplateResponseMixin, TemplateView
from ds_caselaw_utils import courts

from judgments.models.court_dates import CourtDates
from judgments.utils import api_client


Expand All @@ -31,11 +31,11 @@ def get_context_data(self, **kwargs) -> dict[str, Any]:
context["maps"] = [self.request.build_absolute_uri(reverse(map)) for map in map_url_names]

# Dynamically append a sitemap for each court
for court in courts.get_listable_courts():
for year in range(court.start_year, court.end_year):
for court in CourtDates.objects.all():
for year in range(court.start_year, court.end_year + 1):
context["maps"].append(
self.request.build_absolute_uri(
reverse("sitemap_court", kwargs={"code": court.canonical_param, "year": year})
reverse("sitemap_court", kwargs={"code": court.param, "year": year})
)
)

Expand Down Expand Up @@ -83,12 +83,8 @@ def get_context_data(self, **kwargs) -> dict[str, Any]:
context = super().get_context_data(**kwargs)

context["items"] = [
{
"url": self.request.build_absolute_uri(
reverse("court_or_tribunal", kwargs={"param": court.canonical_param})
)
}
for court in courts.get_listable_courts()
{"url": self.request.build_absolute_uri(reverse("court_or_tribunal", kwargs={"param": court.param}))}
for court in CourtDates.objects.all()
]

return context
Expand Down
9 changes: 9 additions & 0 deletions judgments/management/commands/recalculate_court_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ def _get_year_of_first_document_in_order(self, canonical_court_param, order, doc
api_client, SearchParameters(court=canonical_court_param, order=order)
)

if len(search_response.results) == 0:
self.stdout.write(
self.style.WARNING(
f"Could not find document for court {canonical_court_param}, \
falling back to config value of {fallback}"
)
)
return fallback

first_document = search_response.results[0]

if first_document.date:
Expand Down

0 comments on commit 70a7960

Please sign in to comment.