Skip to content

Commit

Permalink
EREGCSC-2729 - Usable and consistent admin lists (#1411)
Browse files Browse the repository at this point in the history
* EREGCSC-2729-Usable-consistant-admin-list

* modify public_resources admin panel

* add custom_admin.css

* update the css path

* fix ruff

* add the css to internal links and internal files

* update to remove annotation for categories

* fix ruff

* update internal files to display category name with out annoitation

* remove static file dir not needed

* update base.py

* update files

* add to the README file and fix the extra method that was not needed

* update readme file

* feat: on admin panel list display, only link unique fields

* chore: update wording of README info

* Update README.md

---------

Co-authored-by: Caleb Godwin <[email protected]>
Co-authored-by: Phil Reese <[email protected]>
Co-authored-by: Phil Reese <[email protected]>
  • Loading branch information
4 people authored Sep 13, 2024
1 parent 675e79b commit 645c8c8
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 13 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ This data is not maintained and should not be relied on for any purpose other th

`make local.clean` will remove the local environment completely, useful when you want to start fresh.

## Update CSS for admin site

To change the styling of the admin site, add custom style rules to `solution/ui/regulations/css/admin/custom_admin.css`.

To see the changes on the admin site, run `make local.collectstatic`. This will update/create the CSS files in the `solution/static-assets/css/admin` directory.

You will need to restart the local environment to see the changes. The Makefile will automatically move those files to the correct location where `STATIC_ROOT` is defined. This is the location where Django will look for static files.

## Testing eRegs

#### Testing setup
Expand Down
18 changes: 13 additions & 5 deletions solution/backend/resources/admin/internal_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class InternalLinkForm(AbstractInternalResourceForm):
class InternalLinkAdmin(AbstractInternalResourceAdmin):
admin_priority = 20
form = InternalLinkForm
list_display = ["date", "document_id", "title", "category", "updated_at", "approved"]
list_display_links = ["date", "document_id", "title", "category", "updated_at", "approved"]
list_display = ["date", "document_id", "title", "category__name", "updated_at", "approved"]
list_display_links = ["date", "document_id", "title", "updated_at"]
search_fields = ["date", "document_id", "title", "summary"]

fieldsets = [
Expand All @@ -47,6 +47,11 @@ class InternalLinkAdmin(AbstractInternalResourceAdmin):
}),
]

class Media:
css = {
'all': ('css/admin/custom_admin.css',)
}

# Override the URL field's help_text for internal links specifically
def get_form(self, request, obj=None, **kwargs):
form = super().get_form(request, obj, **kwargs)
Expand All @@ -63,10 +68,9 @@ class InternalFileForm(AbstractInternalResourceForm):
class InternalFileAdmin(AbstractInternalResourceAdmin):
admin_priority = 21
form = InternalFileForm
list_display = ["date", "document_id", "title", "category", "updated_at", "approved"]
list_display_links = ["date", "document_id", "title", "category", "updated_at", "approved"]
list_display = ["date", "document_id", "title", "category__name", "updated_at", "approved"]
list_display_links = ["date", "document_id", "title", "updated_at"]
search_fields = ["date", "document_id", "title", "summary"]
ordering = ["date", "document_id", "category", "updated_at"]
readonly_fields = ["download_file", "file_name", "file_type"]

fieldsets = [
Expand All @@ -87,6 +91,10 @@ class InternalFileAdmin(AbstractInternalResourceAdmin):
}),
]

class Media:
css = {
'all': ('css/admin/custom_admin.css',)
}
# TODO: use presigned URL to upload to S3 directly, bypassing API Gateway restrictions
# Easy to follow how to: https://www.hacksoft.io/blog/direct-to-s3-file-upload-with-django
# Most of these methods will be rewritten then.
Expand Down
20 changes: 14 additions & 6 deletions solution/backend/resources/admin/public_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class PublicLinkForm(AbstractPublicResourceForm):
class PublicLinkAdmin(AbstractPublicResourceAdmin):
admin_priority = 10
form = PublicLinkForm
list_display = ["date", "document_id", "title", "category", "updated_at", "approved"]
list_display_links = ["date", "document_id", "title", "category", "updated_at", "approved"]
list_display = ["date", "document_id", "title", "category__name", "updated_at", "approved"]
list_display_links = ["date", "document_id", "title", "updated_at"]
search_fields = ["date", "document_id", "title", "url"]

fieldsets = [
Expand All @@ -52,6 +52,11 @@ class PublicLinkAdmin(AbstractPublicResourceAdmin):
}),
]

class Media:
css = {
'all': ('css/admin/custom_admin.css',)
}


class FederalRegisterLinkForm(AbstractPublicResourceForm):
resource_groups = forms.ModelMultipleChoiceField(
Expand Down Expand Up @@ -81,11 +86,9 @@ class FederalRegisterLinkAdmin(AbstractPublicResourceAdmin):
admin_priority = 11
form = FederalRegisterLinkForm
list_display = ["date", "document_id", "title", "in_groups", "docket_numbers", "document_number",
"category", "action_type", "updated_at", "approved"]
list_display_links = ["date", "document_id", "title", "in_groups", "docket_numbers", "document_number",
"category", "action_type", "updated_at", "approved"]
"action_type", "updated_at", "approved"]
list_display_links = ["date", "document_id", "title", "docket_numbers", "document_number", "updated_at"]
search_fields = ["date", "document_id", "title", "docket_numbers", "document_number", "url"]

fieldsets = [
("Basics", {
"fields": ["url", "title"],
Expand All @@ -105,6 +108,11 @@ class FederalRegisterLinkAdmin(AbstractPublicResourceAdmin):
}),
]

class Media:
css = {
'all': ('css/admin/custom_admin.css',)
}

def in_groups(self, obj):
groups = ", ".join([str(i) for i in obj.resource_groups.all()])
return f"{groups[:20]}..." if len(groups) > 20 else groups
Expand Down
2 changes: 1 addition & 1 deletion solution/backend/resources/admin/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class AbstractResourceAdmin(CustomAdminMixin, admin.ModelAdmin):
actions = [actions.mark_approved, actions.mark_not_approved, actions.extract_text]
filter_horizontal = ["cfr_citations", "subjects"]
empty_value_display = "NONE"
ordering = ["-updated_at", "date", "document_id", "category", "-created_at"]
ordering = ["-updated_at"]

list_filter = [
"approved",
Expand Down
2 changes: 1 addition & 1 deletion solution/static-assets/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pyopenssl>=24,<25
Werkzeug==0.15.5
boto3
django-debug-toolbar
django>=5.0.7
django>=5.1
requests
djangorestframework
psycopg2-binary
Expand Down
4 changes: 4 additions & 0 deletions solution/ui/regulations/css/admin/custom_admin.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
table#result_list tbody tr td {
/* Allow wrapping on all columns*/
white-space: normal !important;
}

0 comments on commit 645c8c8

Please sign in to comment.