Skip to content

Commit

Permalink
Merge pull request #4496 from freelawproject/add-ordering-key
Browse files Browse the repository at this point in the history
feat(opinion): Add ordering key
  • Loading branch information
flooie authored Dec 17, 2024
2 parents a83812b + e5e9828 commit 9951ee8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
10 changes: 5 additions & 5 deletions cl/opinion_page/templates/opinion.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h3><span>Admin</span></h3>
class="btn btn-primary btn-xs">Cluster</a>
{% endif %}
{% if perms.search.change_opinion %}
{% for sub_opinion in cluster.sub_opinions.all|dictsort:"type" %}
{% for sub_opinion in cluster.sub_opinions.all %}
<a href="{% url 'admin:search_opinion_change' sub_opinion.pk %}"
class="btn btn-primary btn-xs">{{ sub_opinion.get_type_display|cut:"Opinion" }} opinion</a>
{% endfor %}
Expand Down Expand Up @@ -359,7 +359,7 @@ <h3>{{ cluster.docket.court }}</h3>
Download Original <span class="caret"></span>
</button>
<ul class="dropdown-menu">
{% for sub_opinion in cluster.sub_opinions.all|dictsort:"type" %}
{% for sub_opinion in cluster.sub_opinions.all %}
{% if sub_opinion.local_path %}
<li>
<a href="{{ sub_opinion.local_path.url }}"
Expand All @@ -370,7 +370,7 @@ <h3>{{ cluster.docket.court }}</h3>
</li>
{% endif %}
{% endfor %}
{% for sub_opinion in cluster.sub_opinions.all|dictsort:"type" %}
{% for sub_opinion in cluster.sub_opinions.all %}
{% if sub_opinion.download_url %}
{% if forloop.counter == 1 %}
<li role="separator" class="divider"></li>
Expand Down Expand Up @@ -408,7 +408,7 @@ <h4>Summary of Opinion</h4>
{# Only display tabs and make panels if more than one sub-opinion. #}
{% if opinion_count > 1 %}
<ul class="nav nav-tabs v-offset-below-1" role="tablist">
{% for sub_opinion in cluster.sub_opinions.all|dictsort:"type" %}
{% for sub_opinion in cluster.sub_opinions.all %}
<li role="presentation" {% if forloop.first %}class="active"{% endif %}>
<a href="#{{ sub_opinion.type }}{{ forloop.counter }}"
aria-controls="{{ sub_opinion.type }}{{ forloop.counter }}"
Expand All @@ -420,7 +420,7 @@ <h4>Summary of Opinion</h4>
{% endif %}

<div class="tab-content">
{% for sub_opinion in cluster.sub_opinions.all|dictsort:"type" %}
{% for sub_opinion in cluster.sub_opinions.all %}
<div {% if opinion_count > 1 %}
role="tabpanel"
class="tab-pane {% if forloop.first %}active{% endif %}"
Expand Down
11 changes: 10 additions & 1 deletion cl/opinion_page/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
Court,
Docket,
DocketEntry,
Opinion,
OpinionCluster,
Parenthetical,
RECAPDocument,
Expand Down Expand Up @@ -796,7 +797,15 @@ async def view_opinion_old(
unbound form.
"""
# Look up the court, cluster, title and note information
cluster: OpinionCluster = await aget_object_or_404(OpinionCluster, pk=pk)
cluster: OpinionCluster = await aget_object_or_404(
OpinionCluster.objects.prefetch_related(
Prefetch(
"sub_opinions",
queryset=Opinion.objects.order_by("ordering_key"),
)
),
pk=pk,
)
title = ", ".join(
[
s
Expand Down
9 changes: 8 additions & 1 deletion cl/search/api_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from http import HTTPStatus

import waffle
from django.db.models import Prefetch
from rest_framework import pagination, permissions, response, viewsets
from rest_framework.exceptions import NotFound
from rest_framework.pagination import PageNumberPagination
Expand Down Expand Up @@ -220,7 +222,12 @@ class OpinionClusterViewSet(LoggingMixin, viewsets.ModelViewSet):
"date_modified",
]
queryset = OpinionCluster.objects.prefetch_related(
"sub_opinions", "panel", "non_participating_judges", "citations"
Prefetch(
"sub_opinions", queryset=Opinion.objects.order_by("ordering_key")
),
"panel",
"non_participating_judges",
"citations",
).order_by("-id")


Expand Down
1 change: 0 additions & 1 deletion cl/search/tests/tests_es_opinion.py
Original file line number Diff line number Diff line change
Expand Up @@ -2274,7 +2274,6 @@ def test_uses_exact_version_for_case_name_field(self) -> None:
class RelatedSearchTest(
ESIndexTestCase, CourtTestCase, PeopleTestCase, SearchTestCase, TestCase
):

@classmethod
def setUpTestData(cls) -> None:
super().setUpTestData()
Expand Down

0 comments on commit 9951ee8

Please sign in to comment.