Skip to content

Commit

Permalink
Merge pull request #2180 from laws-africa/core-docs
Browse files Browse the repository at this point in the history
prevent creation of core documents in admin, and better errors if one…
  • Loading branch information
longhotsummer authored Nov 21, 2024
2 parents bc62ce7 + ef79c16 commit 9762bc5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion peachjam/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ class PeachJamSettingsAdmin(admin.ModelAdmin):
"document_jurisdictions",
)

def has_add_permission(self, request):
return False

def changelist_view(self, request, extra_context=None):
# redirect to edit the singleton
return redirect("admin:peachjam_peachjamsettings_change", pj_settings().pk)
Expand Down Expand Up @@ -844,7 +847,9 @@ def fixup(item):

@admin.register(CoreDocument)
class CoreDocumentAdmin(DocumentAdmin):
pass
def has_add_permission(self, request):
# this is prevented because there is no view that handles a CoreDocument
return False


@admin.register(GenericDocument)
Expand Down
4 changes: 4 additions & 0 deletions peachjam/views/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ def dispatch(self, request, *args, **kwargs):

return view.dispatch(request, *args, **kwargs)

raise Exception(
f"The document type {obj.doc_type} does not have a view registered."
)


@method_decorator(add_slash_to_frbr_uri(), name="setup")
class DocumentSourceView(DetailView):
Expand Down

0 comments on commit 9762bc5

Please sign in to comment.