Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paginated legislation listing #1901

Merged
merged 50 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
e800fc0
adds paginated legislation listing
actlikewill Jul 9, 2024
754a0b4
adds children dropdown
actlikewill Jul 12, 2024
dadf2d8
changes liiweb legislation template
actlikewill Jul 12, 2024
2a07642
uses htmx for facets
actlikewill Jul 12, 2024
2ade5bc
bring legislation features into base _document_table
longhotsummer Jul 15, 2024
8ecb05a
caret and collapse for children
longhotsummer Jul 15, 2024
05520ad
grouping
longhotsummer Jul 15, 2024
6ef34ca
Merge pull request #1904 from laws-africa/doc-table
actlikewill Jul 15, 2024
5bacb67
common grouping mechanism for courts
longhotsummer Jul 15, 2024
df6219b
fix latest_expression_only for legislation view
longhotsummer Jul 15, 2024
8440f35
htmx included in app.ts
longhotsummer Jul 15, 2024
1816f3d
Merge pull request #1905 from laws-africa/grouping
longhotsummer Jul 15, 2024
6c6cbb2
sorting for document filter table
longhotsummer Jul 15, 2024
2dc98f2
doc-table sorting
longhotsummer Jul 15, 2024
1bf4be9
sort is possible with alphabet filter
longhotsummer Jul 15, 2024
77c1872
adds facet values
actlikewill Jul 15, 2024
c5a42e5
Merge branch 'listing' into sort
longhotsummer Jul 15, 2024
0751fbd
sorting
longhotsummer Jul 15, 2024
10e9e4e
fix tests
longhotsummer Jul 16, 2024
749fbba
Merge pull request #1906 from laws-africa/sort
longhotsummer Jul 16, 2024
b5b36e2
adds _document_table_form; updates court facets
actlikewill Jul 16, 2024
d54de55
fix filtering; don't duplicate form; progress bar
longhotsummer Jul 16, 2024
a9a96c3
unify document listing layouts; search beside doc count
longhotsummer Jul 16, 2024
765405c
intcomma for doc counts
longhotsummer Jul 16, 2024
c278969
default sorting
longhotsummer Jul 16, 2024
8c4a8d5
fix sorting bug
longhotsummer Jul 16, 2024
0cb5a7a
Merge pull request #1907 from laws-africa/tweaks
longhotsummer Jul 16, 2024
dbe13b6
make help_link easier to set
longhotsummer Jul 16, 2024
acfaa66
adds facet clear
actlikewill Jul 16, 2024
c3fdd81
set default sort
longhotsummer Jul 16, 2024
ac648da
spacing on mobile
longhotsummer Jul 16, 2024
a9c4c14
make offcanvas filters work
longhotsummer Jul 16, 2024
f8f4881
move filters back and forth
longhotsummer Jul 16, 2024
6790de6
adds support for taxonomies
actlikewill Jul 16, 2024
3f6b421
Merge pull request #1908 from laws-africa/offcanvas
longhotsummer Jul 16, 2024
114c767
fixes heading template
actlikewill Jul 16, 2024
eafdb8b
adds distinct for judges and attorneys filters
actlikewill Jul 16, 2024
f487acb
lawlibrary legislation notice
longhotsummer Jul 16, 2024
5120661
prefetch labels
longhotsummer Jul 16, 2024
162445d
simplify prefetch for legislation
longhotsummer Jul 16, 2024
d055402
uses get_queryset method to calculate facets
actlikewill Jul 16, 2024
6917286
adds get variant queryset
actlikewill Jul 16, 2024
a07a22a
adds repealed legislation warning
actlikewill Jul 17, 2024
97cd21e
prefetch labels
longhotsummer Jul 17, 2024
19eabff
fix ES-based listing views
longhotsummer Jul 17, 2024
81dd89d
extracted strings for translation
longhotsummer Jul 17, 2024
ccd6c7b
adds doc index facets; clear all button
actlikewill Jul 17, 2024
3a6b266
hide filter controls in pocketlaw
longhotsummer Jul 17, 2024
5463a38
guard against htmx race conditions
longhotsummer Jul 18, 2024
1b11d49
translation
longhotsummer Jul 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lawlibrary/views/legislation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@


class LegislationListView(BaseLegislationListView):
def get_queryset(self):
return super().get_queryset().filter(locality=None)
def get_base_queryset(self):
return super().get_base_queryset().filter(locality=None)


class LocalityLegislationView(BaseLocalityLegislationView):
Expand Down
143 changes: 51 additions & 92 deletions liiweb/templates/liiweb/legislation_list.html
Original file line number Diff line number Diff line change
@@ -1,97 +1,56 @@
{% extends "peachjam/layouts/main.html" %}
{% extends 'peachjam/layouts/document_list.html' %}
{% load i18n %}
{% block title %}
{% trans 'Legislation' %}
{% endblock %}
{% block page-content %}
{% block breadcrumbs %}{% endblock %}
{% block entity-profile %}
{% if entity_profile %}
<div class="mt-3">{% include 'peachjam/_entity_profile.html' %}</div>
{% endif %}
{% endblock %}
<section class="pb-5">
<div class="container">
{% block page-heading %}
<h1 class="my-4">{% trans 'Legislation' %}</h1>
{% include "peachjam/_help_button.html" with link="legislation/" %}
{% endblock %}
longhotsummer marked this conversation as resolved.
Show resolved Hide resolved
{% block legislation-nav %}
<nav class="nav nav-tabs scroll-xs mb-3 border-bottom">
<li class="nav-item">
<a class="nav-link {% if view.variant == 'current' %}active{% endif %}"
href="{% url 'legislation_list' %}">
{% block current_tab_title %}
{% trans 'Current legislation' %}
{% endblock %}
</a>
</li>
<li class="nav-item">
<a class="nav-link {% if view.variant == 'recent' %}active{% endif %}"
href="{% url 'legislation_list_recent' %}">
{% block recent_tab_title %}
{% trans 'Recent legislation' %}
{% endblock %}
</a>
</li>
<li class="nav-item">
<a class="nav-link {% if view.variant == 'subleg' %}active{% endif %}"
href="{% url 'legislation_list_subsidiary' %}">
{% block sublegislation_tab_title %}{{ PEACHJAM_SETTINGS.subleg_label }}{% endblock %}
</a>
</li>
<li class="nav-item">
<a class="nav-link {% if view.variant == 'uncommenced' %}active{% endif %}"
href="{% url 'legislation_list_uncommenced' %}">
{% block uncommenced_tab_title %}
{% trans 'Uncommenced legislation' %}
{% endblock %}
</a>
</li>
<li class="nav-item">
<a class="nav-link {% if view.variant == 'repealed' %}active{% endif %}"
href="{% url 'legislation_list_repealed' %}">
{% block repealed_tab_title %}
{% trans 'Repealed legislation' %}
{% endblock %}
</a>
</li>
<li class="nav-item">
<a class="nav-link {% if view.variant == 'all' %}active{% endif %}"
href="{% url 'legislation_list_all' %}">
{% trans 'All legislation' %}
</a>
</li>
</nav>
{% endblock %}
{% if view.variant == 'repealed' %}
<div class="alert alert-danger">{% trans 'You are viewing repealed legislation which is no longer in force.' %}</div>
{% endif %}
longhotsummer marked this conversation as resolved.
Show resolved Hide resolved
<div data-vue-component="LegislationTable"
data-initial-sort="{{ legislation_list_sort }}"
{% if not doc_table_citations %}data-hide-citations="true"{% endif %}>
{% comment %}
This ensures that peachjam has links to scrape. This content is replaced when the javacript LegislationTable
component runs.
{% endcomment %}
<ul>
{% for item in legislation_table %}
<li>
<a href="{{ item.work_frbr_uri }}">{{ item.title }}</a>
{% if item.children %}
<ul>
{% for kid in item.children %}
<li>
<a href="{{ kid.work_frbr_uri }}">{{ kid.title }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
</ul>
</div>
{{ legislation_table|json_script:"legislation-table" }}
</div>
</section>
{% block page-title %}
<h1 class="my-4">{% trans 'Legislation' %}</h1>
{% endblock %}
{% block nav-tabs %}
<nav class="nav nav-tabs scroll-xs mb-3 border-bottom">
<li class="nav-item">
<a class="nav-link {% if view.variant == 'current' %}active{% endif %}"
href="{% url 'legislation_list' %}">
{% block current_tab_title %}
{% trans 'Current legislation' %}
{% endblock %}
</a>
</li>
<li class="nav-item">
<a class="nav-link {% if view.variant == 'recent' %}active{% endif %}"
href="{% url 'legislation_list_recent' %}">
{% block recent_tab_title %}
{% trans 'Recent legislation' %}
{% endblock %}
</a>
</li>
<li class="nav-item">
<a class="nav-link {% if view.variant == 'subleg' %}active{% endif %}"
href="{% url 'legislation_list_subsidiary' %}">
{% block sublegislation_tab_title %}{{ PEACHJAM_SETTINGS.subleg_label }}{% endblock %}
</a>
</li>
<li class="nav-item">
<a class="nav-link {% if view.variant == 'uncommenced' %}active{% endif %}"
href="{% url 'legislation_list_uncommenced' %}">
{% block uncommenced_tab_title %}
{% trans 'Uncommenced legislation' %}
{% endblock %}
</a>
</li>
<li class="nav-item">
<a class="nav-link {% if view.variant == 'repealed' %}active{% endif %}"
href="{% url 'legislation_list_repealed' %}">
{% block repealed_tab_title %}
{% trans 'Repealed legislation' %}
{% endblock %}
</a>
</li>
<li class="nav-item">
<a class="nav-link {% if view.variant == 'all' %}active{% endif %}"
href="{% url 'legislation_list_all' %}">
{% trans 'All legislation' %}
</a>
</li>
</nav>
{% endblock %}
44 changes: 23 additions & 21 deletions liiweb/views/legislation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@
from django.utils.translation import gettext_lazy as _
from django.views.generic import TemplateView

from peachjam.helpers import chunks, get_language
from peachjam.helpers import chunks
from peachjam.models import JurisdictionProfile, Legislation, Locality, pj_settings
from peachjam_api.serializers import LegislationSerializer
from peachjam.views import FilteredDocumentListView


class LegislationListView(TemplateView):
class LegislationListView(FilteredDocumentListView):
template_name = "liiweb/legislation_list.html"
variant = "current"
navbar_link = "legislation"
model = Legislation
queryset = Legislation.objects.prefetch_related(
"taxonomies", "taxonomies__topic", "work"
)
latest_expression_only = True
extra_context = {"doc_table_citations": True, "legislation_list_sort": "title"}
longhotsummer marked this conversation as resolved.
Show resolved Hide resolved

def get_queryset(self):
qs = (
self.model.objects.exclude(published=False)
.distinct("work_frbr_uri")
.order_by("work_frbr_uri", "-date", "language__pk")
.preferred_language(get_language(self.request))
)
return qs
def get_template_names(self):
if self.request.htmx:
return ["peachjam/faceted_doc_table.html"]
return ["liiweb/legislation_list.html"]

def filter_queryset(self, qs):
if self.variant == "all":
Expand All @@ -48,17 +48,13 @@ def filter_queryset(self, qs):
datetime.date.today() - timedelta(days=365)
).isoformat()
)
qs = super().filter_queryset(qs)

return qs

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

qs = self.filter_queryset(self.get_queryset())
qs = qs.prefetch_related("taxonomies", "taxonomies__topic", "work")
qs = self.add_children(qs)

context["legislation_table"] = LegislationSerializer(qs, many=True).data
self.add_children(context["documents"])

site_jurisdictions = pj_settings().document_jurisdictions.all()
if site_jurisdictions.count() == 1:
Expand All @@ -69,6 +65,14 @@ def get_context_data(self, **kwargs):
context["entity_profile"] = jurisdiction_profile.entity_profile.first()
context["entity_profile_title"] = jurisdiction_profile.jurisdiction.name

context["doc_table_toggle"] = True
context["doc_table_show_doc_type"] = False
context["doc_table_show_court"] = False
context["doc_table_show_author"] = False
context["doc_table_show_jurisdiction"] = False

context["documents"] = self.group_documents(context["documents"])

return context

def add_children(self, queryset):
Expand All @@ -78,18 +82,16 @@ def add_children(self, queryset):
)

children = defaultdict(list)
children_qs = self.get_queryset().filter(
children_qs = self.get_base_queryset().filter(
parent_work_id__in=parents, repealed=False, metadata_json__principal=True
)
# group children by parent
for child in children_qs:
children[child.parent_work_id].append(child)

# fold in children
qs = list(queryset)
for parent in qs:
for parent in queryset:
parent.children = children.get(parent.work_id, [])
return qs


class LocalityLegislationView(TemplateView):
Expand Down
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"eslint-plugin-standard": "^4.0.1",
"eslint-plugin-vue": "^8.5.0",
"flag-icons": "^6.6.6",
"htmx.org": "^2.0.1",
"i18next": "^22.0.6",
"i18next-parser": "^6.5.0",
"lodash.debounce": "^4.0.8",
Expand Down
4 changes: 4 additions & 0 deletions peachjam/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def filter_queryset(self, queryset, exclude=None):
registries = self.params.getlist("registries")
attorneys = self.params.getlist("attorneys")
outcomes = self.params.getlist("outcomes")
q = self.params.getlist("q")

queryset = self.order_queryset(queryset, exclude)

Expand Down Expand Up @@ -140,6 +141,9 @@ def filter_queryset(self, queryset, exclude=None):
if outcomes and exclude != "outcomes":
queryset = queryset.filter(outcomes__name__in=outcomes).distinct()

if q and exclude != "q":
longhotsummer marked this conversation as resolved.
Show resolved Hide resolved
queryset = queryset.filter(title__icontains=q[0])

return queryset

def order_queryset(self, queryset, exclude=None):
Expand Down
50 changes: 0 additions & 50 deletions peachjam/js/components/LegislationTable/TableRow.vue

This file was deleted.

Loading
Loading