From f99a66a709dc093b0ecaff97a2c98df5c0544c1f Mon Sep 17 00:00:00 2001 From: Sage Abdullah Date: Mon, 2 Sep 2024 10:29:42 +0100 Subject: [PATCH] Use grid and simplify the template for documents edit view --- .../templates/wagtaildocs/documents/edit.html | 65 ++++++++----------- wagtail/documents/views/documents.py | 8 +++ 2 files changed, 34 insertions(+), 39 deletions(-) diff --git a/wagtail/documents/templates/wagtaildocs/documents/edit.html b/wagtail/documents/templates/wagtaildocs/documents/edit.html index fa4c81f8f8..be336640ee 100644 --- a/wagtail/documents/templates/wagtaildocs/documents/edit.html +++ b/wagtail/documents/templates/wagtaildocs/documents/edit.html @@ -1,46 +1,33 @@ {% extends "wagtailadmin/generic/edit.html" %} {% load i18n wagtailadmin_tags %} -{% block main_content %} -
- -
-
- {% csrf_token %} - -
    - {% for field in form %} - {% if field.name == 'file' %} -
  • {% include "wagtaildocs/documents/_file_field.html" %}
  • - {% elif field.is_hidden %} - {{ field }} - {% else %} -
  • {% formattedfield field %}
  • - {% endif %} - {% endfor %} -
  • - - {% if can_delete %} - {% trans "Delete document" %} - {% endif %} -
  • -
-
-
-
-
- {% if document.file %} -
{% trans "Filesize" %}
-
{% if filesize %}{{ filesize|filesizeformat }}{% else %}{% trans "File not found" %}{% endif %}
+{% block fields %} +
+
+ + {% for field in form %} + {% if field.name == 'file' %} + {% include "wagtaildocs/documents/_file_field.html" %} + {% elif field.is_hidden %} + {{ field }} + {% else %} + {% formattedfield field %} {% endif %} - -
{% trans "Usage" %}
-
- {% with usage_count_val=document.get_usage.count %} - {% blocktrans trimmed with usage_count=usage_count_val|intcomma count usage_count_val=usage_count_val %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %} - {% endwith %} -
-
+ {% endfor %}
+ +
+ {% if document.file %} +
{% trans "Filesize" %}
+
{% if filesize %}{{ filesize|filesizeformat }}{% else %}{% trans "File not found" %}{% endif %}
+ {% endif %} + +
{% trans "Usage" %}
+
+ {% with usage_count_val=document.get_usage.count %} + {% blocktrans trimmed with usage_count=usage_count_val|intcomma count usage_count_val=usage_count_val %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %} + {% endwith %} +
+
{% endblock %} diff --git a/wagtail/documents/views/documents.py b/wagtail/documents/views/documents.py index e24a40d91b..9058288952 100644 --- a/wagtail/documents/views/documents.py +++ b/wagtail/documents/views/documents.py @@ -4,6 +4,7 @@ from django.contrib.admin.utils import quote from django.core.exceptions import PermissionDenied from django.http.response import HttpResponse as HttpResponse from django.utils.functional import cached_property +from django.utils.http import urlencode from django.utils.translation import gettext as _ from django.utils.translation import gettext_lazy, ngettext @@ -196,6 +197,7 @@ class EditView(generic.EditView): delete_url_name = "wagtaildocs:delete" header_icon = "doc-full-inverse" context_object_name = "document" + delete_item_label = gettext_lazy("Delete document") _show_breadcrumbs = True @cached_property @@ -230,6 +232,12 @@ class EditView(generic.EditView): def get_success_url(self): return self.next_url or super().get_success_url() + def get_delete_url(self): + delete_url = super().get_delete_url() + if self.next_url: + delete_url += "?" + urlencode({"next": self.next_url}) + return delete_url + def render_to_response(self, context, **response_kwargs): if self.object.is_stored_locally(): # Give error if document file doesn't exist