Skip to content

Commit

Permalink
Merge pull request #4226 from freelawproject/enable-territories-in-se…
Browse files Browse the repository at this point in the history
…arch-ui

feat(UI): Update state court picker
  • Loading branch information
mlissner authored Jul 23, 2024
2 parents 57ebc40 + 324a3f9 commit 8c7f674
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 34 deletions.
32 changes: 31 additions & 1 deletion cl/custom_filters/templatetags/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from django.utils.safestring import SafeString, mark_safe
from elasticsearch_dsl import AttrDict, AttrList

from cl.search.models import Docket, DocketEntry
from cl.search.models import Court, Docket, DocketEntry

register = template.Library()

Expand Down Expand Up @@ -243,3 +243,33 @@ def get_highlight(result: AttrDict | dict[str, any], field: str) -> any:
original_value = result.get(field, "")

return render_string_or_list(hl_value) if hl_value else original_value


@register.filter
def group_courts(courts: list[Court], num_columns: int) -> list:
"""Divide courts in equal groupings while keeping related courts together
:param courts: Courts to group.
:param num_columns: Number of groups wanted
:return: The courts grouped together
"""

column_len = len(courts) // num_columns
remainder = len(courts) % num_columns

groups = []
start = 0
for index in range(num_columns):
# Calculate the end index for this chunk
end = start + column_len + (1 if index < remainder else 0)

# Find the next COLR as a starting point (Court of last resort)
COLRs = [Court.TERRITORY_SUPREME, Court.STATE_SUPREME]
while end < len(courts) and courts[end].jurisdiction not in COLRs:
end += 1

# Create the column and add it to result
groups.append(courts[start:end])
start = end

return groups
25 changes: 6 additions & 19 deletions cl/lib/search_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ def merge_form_with_courts(
}
bap_bundle = []
b_bundle = []
state_bundle: List = []
state_bundles = []
states = []
territories = []
for court in courts:
if court.jurisdiction == Court.FEDERAL_APPELLATE:
court_tabs["federal"].append(court)
Expand All @@ -247,15 +247,9 @@ def merge_form_with_courts(
else:
b_bundle.append(court)
elif court.jurisdiction in Court.STATE_JURISDICTIONS:
# State courts get bundled by supreme courts
if court.jurisdiction == Court.STATE_SUPREME:
# Whenever we hit a state supreme court, we append the
# previous bundle and start a new one.
if state_bundle:
state_bundles.append(state_bundle)
state_bundle = [court]
else:
state_bundle.append(court)
states.append(court)
elif court.jurisdiction in Court.TERRITORY_JURISDICTIONS:
territories.append(court)
elif court.jurisdiction in [
Court.FEDERAL_SPECIAL,
Court.COMMITTEE,
Expand All @@ -265,18 +259,11 @@ def merge_form_with_courts(
]:
court_tabs["special"].append(court)

# append the final state bundle after the loop ends. Hack?
state_bundles.append(state_bundle)

# Put the bankruptcy bundles in the courts dict
if bap_bundle:
court_tabs["bankruptcy_panel"] = [bap_bundle]
court_tabs["bankruptcy"] = [b_bundle]

# Divide the state bundles into the correct partitions
court_tabs["state"].append(state_bundles[:17])
court_tabs["state"].append(state_bundles[17:34])
court_tabs["state"].append(state_bundles[34:])
court_tabs["state"] = [states, territories]

return court_tabs, court_count_human, court_count

Expand Down
36 changes: 22 additions & 14 deletions cl/search/templates/includes/jurisdiction_picker_modal.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% load partition_util %}
{% load extras %}

<div class="modal" id="court-picker" role="dialog" aria-hidden="true">
<div class="modal-dialog" id="modal-court-picker">
Expand Down Expand Up @@ -166,24 +167,31 @@ <h3 class="bottom inline">
{% endif %}

{% if v == SEARCH_TYPES.OPINION or v == SEARCH_TYPES.PEOPLE %}
<div class="tab-pane" id="tab-state">
<div class="row">
{% for col_bundle in courts.state %}
<div class="col-sm-4">
{% for court_bundle in col_bundle %}
{% for court in court_bundle %}
{% if court.jurisdiction == 'S' %}
{% include "includes/court_checkbox.html" %}
{% else %}
{% include "includes/court_checkbox.html" with indent=True %}
{% endif %}
{% endfor %}
<div class="tab-pane" id="tab-state">
{% for group in courts.state %}
{% if forloop.counter == 1 %}
<h3 class="bottom inline">State Courts</h3>
{% elif forloop.counter == 2 %}
<hr>
<h3 class="bottom inline">U.S. Territory Courts</h3>
{% endif %}
<div class="row">
{% for col_bundle in group|group_courts:3 %}
<div class="col-sm-4">
{% for court in col_bundle %}
{% if court.jurisdiction == 'S' %}
{% include "includes/court_checkbox.html" %}
{% else %}
{% include "includes/court_checkbox.html" with indent=True %}
{% endif %}
{% endfor %}
</div>
{% endfor %}
</div>
{% endfor %}
{% endfor %}
</div>
</div>
{% endif %}

{% if v != SEARCH_TYPES.ORAL_ARGUMENT %}
<div class="tab-pane" id="tab-special">
{# Regroup into closed/open courts #}
Expand Down

0 comments on commit 8c7f674

Please sign in to comment.