Skip to content

Commit

Permalink
Merge pull request #1472 from laws-africa/admin-help
Browse files Browse the repository at this point in the history
Help button in admin
  • Loading branch information
actlikewill authored Aug 29, 2023
2 parents 95231fb + 5b822f8 commit b11230e
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 3 deletions.
24 changes: 21 additions & 3 deletions peachjam/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@
User = get_user_model()


class BaseAdmin(admin.ModelAdmin):
"""Base admin class for Peachjam. Includes some common fields and methods
for all models.
"""

def changelist_view(self, request, extra_context=None):
resp = super().changelist_view(request, extra_context)
if hasattr(self, "help_topic"):
resp.context_data["help_topic"] = self.help_topic
return resp


class ImportExportMixin(BaseImportExportMixin):
def import_action(self, request, *args, **kwargs):
resp = super().import_action(request, *args, **kwargs)
Expand Down Expand Up @@ -310,7 +322,7 @@ def _save_m2m(self):
self.instance.update_text_content()


class DocumentAdmin(admin.ModelAdmin):
class DocumentAdmin(BaseAdmin):
form = DocumentForm
inlines = [DocumentTopicInline, SourceFileInline, AlternativeNameInline]
list_display = (
Expand Down Expand Up @@ -673,6 +685,7 @@ def save(self, *args, **kwargs):


class JudgmentAdmin(ImportExportMixin, DocumentAdmin):
help_topic = "judgments/upload-a-judgment"
form = JudgmentAdminForm
resource_class = JudgmentResource
inlines = [
Expand Down Expand Up @@ -916,7 +929,8 @@ def get_form(self, request, obj=None, **kwargs):


@admin.register(CourtRegistry)
class CourtRegistryAdmin(admin.ModelAdmin):
class CourtRegistryAdmin(BaseAdmin):
help_topic = "site_admin/add-court-registries"
readonly_fields = ("code",)
list_display = ("name", "code")

Expand Down Expand Up @@ -950,11 +964,15 @@ class JudgeAdmin(admin.ModelAdmin):
search_fields = ("name",)


@admin.register(MatterType)
class MatterTypeAdmin(BaseAdmin):
help_topic = "site_admin/add-matter-types"


admin.site.register(
[
CitationLink,
Attorney,
MatterType,
CourtClass,
AttachedFileNature,
CitationProcessing,
Expand Down
23 changes: 23 additions & 0 deletions peachjam/migrations/0101_peachjamsettings_help_link.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.19 on 2023-08-24 06:09

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("peachjam", "0100_sourcefile_file_as_pdf"),
]

operations = [
migrations.AddField(
model_name="peachjamsettings",
name="help_link",
field=models.URLField(
blank=True,
default="https://liieditors.docs.laws.africa/",
null=True,
verbose_name="help link",
),
),
]
6 changes: 6 additions & 0 deletions peachjam/models/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ class PeachJamSettings(SingletonModel):
pocket_law_repo = models.CharField(
verbose_name=_("Pocket Law repo"), max_length=1024, null=True, blank=True
)
help_link = models.URLField(
_("help link"),
default="https://liieditors.docs.laws.africa/",
null=True,
blank=True,
)

class Meta:
verbose_name = verbose_name_plural = _("site settings")
Expand Down
9 changes: 9 additions & 0 deletions peachjam/templates/admin/change_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "admin/change_form.html" %}
{% load i18n %}
{% block extra_actions %}
{% if PEACHJAM_SETTINGS.help_link and adminform.model_admin.help_topic %}
<a target="_blank"
href="{{ PEACHJAM_SETTINGS.help_link }}{{ adminform.model_admin.help_topic }}"
class="btn btn-block btn-info">{% trans 'Help' %}</a>
{% endif %}
{% endblock %}
13 changes: 13 additions & 0 deletions peachjam/templates/admin/change_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends 'admin/change_list.html' %}
{% load i18n %}
{% block object-tools-items %}
{{ block.super }}
{% if PEACHJAM_SETTINGS.help_link and help_topic %}
<a class="btn btn-info"
target="_blank"
href="{{ PEACHJAM_SETTINGS.help_link }}{{ help_topic }}">
<i class="fa fa-question-circle"></i>
{% trans 'Help' %}
</a>
{% endif %}
{% endblock %}

0 comments on commit b11230e

Please sign in to comment.