Skip to content

Commit

Permalink
Add condition for deleted models
Browse files Browse the repository at this point in the history
  • Loading branch information
Tammo-Feldmann committed Nov 15, 2023
1 parent 70408ab commit 225140a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions app/admin_ui/views/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,21 @@ class ChangeHistoryList(SingleTableView):
template_name = "api_app/canonical/change_history.html"

def get(self, request, *args, **kwargs):
messages.error(
self.request,
(
f"""The published version of this {self.kwargs['model']} has been deleted and is no longer viewable on
the CASEI UI. You can only view the past versions in the {self.kwargs['model']} history."""
),
# display message for deleted models
is_deleted = (
Change.objects.related_drafts(self.kwargs[self.pk_url_kwarg])
.filter(status=Change.Statuses.PUBLISHED, action=Change.Actions.DELETE)
.exists()
)
if is_deleted:
messages.error(
self.request,
(
f"""The published version of this {self.kwargs['model']} has been deleted
and is no longer viewable on the CASEI UI. You can only view the past versions
in the {self.kwargs['model']} history."""
),
)

return super().get(request, *args, **kwargs)

Expand Down

0 comments on commit 225140a

Please sign in to comment.