Skip to content

Commit

Permalink
Merge branch 'main' into 4752-document-webhooks-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
albertisfu committed Jan 3, 2025
2 parents fffbfad + 4f3d429 commit 0511430
Show file tree
Hide file tree
Showing 10 changed files with 334 additions and 114 deletions.
19 changes: 19 additions & 0 deletions cl/assets/templates/admin/docket_change_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends "admin/change_form.html" %}

{% block object-tools-items %}
{% if docket_entries_url %}
<li>
<a class="historylink" href="{{ docket_entries_url }}">
View Docket Entries
</a>
</li>
{% endif %}
{% if docket_alerts_url %}
<li>
<a class="historylink" href="{{ docket_alerts_url }}">
View Docket Alerts
</a>
</li>
{% endif %}
{{ block.super }}
{% endblock object-tools-items %}
19 changes: 19 additions & 0 deletions cl/assets/templates/admin/user_change_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends "admin/change_form.html" %}

{% block object-tools-items %}
{% if proxy_events_url %}
<li>
<a class="historylink" href="{{ proxy_events_url }}">
View UserProxy Events
</a>
</li>
{% endif %}
{% if profile_events_url %}
<li>
<a class="historylink" href="{{ profile_events_url }}">
View UserProfile Events
</a>
</li>
{% endif %}
{{ block.super }}
{% endblock object-tools-items %}
32 changes: 32 additions & 0 deletions cl/lib/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from typing import Any, Type
from urllib.parse import urlencode

from django.contrib.contenttypes.admin import GenericTabularInline
from django.db.models import Model
from django.urls import reverse

from cl.lib.models import Note

Expand All @@ -13,3 +18,30 @@ class Media:
class NotesInline(GenericTabularInline):
model = Note
extra = 1


def build_admin_url(
model_class: Type[Model],
query_params: dict[str, Any] | None = None,
) -> str:
"""
Construct a URL for a given model's admin view, optionally appending query parameters.
:param model_class: The Django model class for which the admin URL will be built.
:param query_params: A dictionary of query parameters to append to the URL (e.g. {"docket": 123}).
:return: A string representing the fully constructed admin URL, including any query parameters.
Example usage:
>>> from cl.search.models import DocketEntry
>>> build_admin_url(DocketEntry, {"docket": "1234"})
'/admin/search/docketentry/?docket=1234'
"""
query_params = query_params or {}
app_label = model_class._meta.app_label
model_name = model_class._meta.model_name
# "admin:app_label_modelname_changelist" is the standard naming for admin changelist
entries_changelist_url = reverse(
f"admin:{app_label}_{model_name}_changelist"
)
encoded_query_params = urlencode(query_params)
return f"{entries_changelist_url}?{encoded_query_params}"
48 changes: 26 additions & 22 deletions cl/package-lock.json

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

26 changes: 11 additions & 15 deletions cl/recap/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ class ProcessingQueueAdmin(CursorPaginatorAdmin):
"pacer_case_id",
"document_number",
"attachment_number",
"date_created",
)
list_filter = ("status",)
list_filter = ("status", "date_created")
search_help_text = "Search ProcessingQueues by pacer_case_id or court__pk."
search_fields = (
"pacer_case_id",
"court__pk",
Expand All @@ -41,15 +43,8 @@ class ProcessingQueueAdmin(CursorPaginatorAdmin):

@admin.register(PacerFetchQueue)
class PacerFetchQueueAdmin(CursorPaginatorAdmin):
list_display = (
"__str__",
"court",
"request_type",
)
list_filter = (
"status",
"request_type",
)
list_display = ("__str__", "court", "request_type", "date_created")
list_filter = ("status", "request_type", "date_created")
readonly_fields = (
"date_created",
"date_modified",
Expand Down Expand Up @@ -94,14 +89,15 @@ def reprocess_failed_epq(modeladmin, request, queryset):

@admin.register(EmailProcessingQueue)
class EmailProcessingQueueAdmin(CursorPaginatorAdmin):
list_display = (
"__str__",
"status",
)
list_filter = ("status",)
list_display = ("__str__", "status", "date_created")
list_filter = ("status", "date_created")
actions = [reprocess_failed_epq]
raw_id_fields = ["uploader", "court"]
exclude = ["recap_documents", "filepath"]
readonly_fields = (
"date_created",
"date_modified",
)


admin.site.register(FjcIntegratedDatabase)
75 changes: 65 additions & 10 deletions cl/search/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
from django.db.models import QuerySet
from django.http import HttpRequest

from cl.alerts.admin import DocketAlertInline
from cl.alerts.models import DocketAlert
from cl.lib.admin import build_admin_url
from cl.lib.cloud_front import invalidate_cloudfront
from cl.lib.models import THUMBNAIL_STATUSES
from cl.lib.string_utils import trunc
from cl.recap.management.commands.delete_document_from_ia import delete_from_ia
from cl.search.models import (
BankruptcyInformation,
Expand Down Expand Up @@ -88,7 +90,14 @@ class OpinionClusterAdmin(CursorPaginatorAdmin):

@admin.register(Court)
class CourtAdmin(admin.ModelAdmin):
list_display = ("full_name", "short_name", "position", "in_use", "pk")
list_display = (
"full_name",
"short_name",
"position",
"in_use",
"pk",
"jurisdiction",
)
list_filter = (
"jurisdiction",
"in_use",
Expand Down Expand Up @@ -215,17 +224,36 @@ class RECAPDocumentInline(admin.StackedInline):
@admin.register(DocketEntry)
class DocketEntryAdmin(CursorPaginatorAdmin):
inlines = (RECAPDocumentInline,)
search_help_text = (
"Search DocketEntries by Docket ID or RECAP sequence number."
)
search_fields = (
"docket__id",
"recap_sequence_number",
)
list_display = (
"get_pk",
"get_trunc_description",
"date_filed",
"time_filed",
"entry_number",
"recap_sequence_number",
"pacer_sequence_number",
)
raw_id_fields = ("docket", "tags")
readonly_fields = (
"date_created",
"date_modified",
)
list_filter = ("date_filed", "date_created", "date_modified")

@admin.display(description="Docket entry")
def get_pk(self, obj):
return obj.pk

class DocketEntryInline(admin.TabularInline):
model = DocketEntry
extra = 1
raw_id_fields = ("tags",)
@admin.display(description="Description")
def get_trunc_description(self, obj):
return trunc(obj.description, 35, ellipsis="...")


@admin.register(OriginatingCourtInformation)
Expand All @@ -238,17 +266,25 @@ class OriginatingCourtInformationAdmin(admin.ModelAdmin):

@admin.register(Docket)
class DocketAdmin(CursorPaginatorAdmin):
change_form_template = "admin/docket_change_form.html"
prepopulated_fields = {"slug": ["case_name"]}
inlines = (
DocketEntryInline,
BankruptcyInformationInline,
DocketAlertInline,
list_display = (
"__str__",
"pacer_case_id",
"docket_number",
)
search_help_text = "Search dockets by PK, PACER case ID, or Docket number."
search_fields = ("pk", "pacer_case_id", "docket_number")
inlines = (BankruptcyInformationInline,)
readonly_fields = (
"date_created",
"date_modified",
"view_count",
)
autocomplete_fields = (
"court",
"appeal_from",
)
raw_id_fields = (
"panel",
"tags",
Expand All @@ -259,6 +295,25 @@ class DocketAdmin(CursorPaginatorAdmin):
"parent_docket",
)

def change_view(self, request, object_id, form_url="", extra_context=None):
"""Add links to pre-filtered related admin pages."""
extra_context = extra_context or {}
query_params = {"docket": object_id}

extra_context["docket_entries_url"] = build_admin_url(
DocketEntry,
query_params,
)

extra_context["docket_alerts_url"] = build_admin_url(
DocketAlert,
query_params,
)

return super().change_view(
request, object_id, form_url, extra_context=extra_context
)


@admin.register(OpinionsCited)
class OpinionsCitedAdmin(CursorPaginatorAdmin):
Expand Down
Loading

0 comments on commit 0511430

Please sign in to comment.