From 47e89c2f9706bfb835b5e9950a20f80ce1e37f8b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= <fpeters@entrouvert.com>
Date: Thu, 28 Mar 2019 17:53:02 +0100
Subject: [PATCH] manager: change manager_form_template to only be about the
 form (#31874)

---
 .../templates/combo/ajax_cell_form.html       |  1 -
 combo/manager/templates/combo/cell_form.html  | 25 +-----------------
 .../combo/manager_edit_cell_block.html        | 26 +++++++++++++++++++
 combo/manager/templatetags/cells.py           |  2 +-
 combo/manager/views.py                        |  8 +++++-
 5 files changed, 35 insertions(+), 27 deletions(-)
 delete mode 100644 combo/manager/templates/combo/ajax_cell_form.html
 create mode 100644 combo/manager/templates/combo/manager_edit_cell_block.html

diff --git a/combo/manager/templates/combo/ajax_cell_form.html b/combo/manager/templates/combo/ajax_cell_form.html
deleted file mode 100644
index 572164d0..00000000
--- a/combo/manager/templates/combo/ajax_cell_form.html
+++ /dev/null
@@ -1 +0,0 @@
-{{form.as_p}}
diff --git a/combo/manager/templates/combo/cell_form.html b/combo/manager/templates/combo/cell_form.html
index 4f81ef12..572164d0 100644
--- a/combo/manager/templates/combo/cell_form.html
+++ b/combo/manager/templates/combo/cell_form.html
@@ -1,24 +1 @@
-{% load i18n %}
-{% block cell-form %}
-<form action="{{ url }}" method="post" data-label-url="{% url 'combo-manager-page-get-additional-label' page_pk=page.id cell_reference=cell.get_reference %}">
-{% csrf_token %}
-{% if form %}
-  <div class="cell-form">
-  {{ form.as_p }}
-  </div>
-{% else %}
-  <p>{% trans "There are no options for this cell." %}</p>
-{% endif %}
-{% endblock %}
-<div class="buttons">
-{% block cell-buttons %}
-<a rel="popup" href="{% url 'combo-manager-page-delete-cell' page_pk=page.id cell_reference=cell.get_reference %}">{% trans 'Delete' %}</a> |
-<a rel="popup" href="{% url 'combo-manager-page-visibility-cell' page_pk=page.id cell_reference=cell.get_reference %}">{% trans 'Visibility' %}</a> |
-<a rel="popup" href="{% url 'combo-manager-page-options-cell' page_pk=page.id cell_reference=cell.get_reference %}">{% trans 'Options' %}</a> |
-<a class="close-button" href="#">{% trans 'Close' %}</a>
-{% if form %}
-<button class="save submit-button">{% trans 'Save' %}</button>
-{% endif %}
-{% endblock %}
-</div>
-</form>
+{{form.as_p}}
diff --git a/combo/manager/templates/combo/manager_edit_cell_block.html b/combo/manager/templates/combo/manager_edit_cell_block.html
new file mode 100644
index 00000000..337d7a38
--- /dev/null
+++ b/combo/manager/templates/combo/manager_edit_cell_block.html
@@ -0,0 +1,26 @@
+{% load i18n %}
+{% block cell-form %}
+<form action="{{ url }}" method="post" data-label-url="{% url 'combo-manager-page-get-additional-label' page_pk=page.id cell_reference=cell.get_reference %}">
+{% csrf_token %}
+{% if form %}
+  <div class="cell-form">
+    {% block cell-form-content %}
+      {% include cell.manager_form_template %}
+    {% endblock %}
+  </div>
+{% else %}
+  <p>{% trans "There are no options for this cell." %}</p>
+{% endif %}
+{% endblock %}
+<div class="buttons">
+{% block cell-buttons %}
+<a rel="popup" href="{% url 'combo-manager-page-delete-cell' page_pk=page.id cell_reference=cell.get_reference %}">{% trans 'Delete' %}</a> |
+<a rel="popup" href="{% url 'combo-manager-page-visibility-cell' page_pk=page.id cell_reference=cell.get_reference %}">{% trans 'Visibility' %}</a> |
+<a rel="popup" href="{% url 'combo-manager-page-options-cell' page_pk=page.id cell_reference=cell.get_reference %}">{% trans 'Options' %}</a> |
+<a class="close-button" href="#">{% trans 'Close' %}</a>
+{% if form %}
+<button class="save submit-button">{% trans 'Save' %}</button>
+{% endif %}
+{% endblock %}
+</div>
+</form>
diff --git a/combo/manager/templatetags/cells.py b/combo/manager/templatetags/cells.py
index bd429dcb..3f95a6d7 100644
--- a/combo/manager/templatetags/cells.py
+++ b/combo/manager/templatetags/cells.py
@@ -29,7 +29,7 @@ def cell_form(context, cell):
     else:
         context['form'] = None
     context['cell'] = cell
-    cell_form_template = template.loader.get_template(cell.manager_form_template)
+    cell_form_template = template.loader.get_template('combo/manager_edit_cell_block.html')
     with context.push():
         context = context.flatten()
         context.update(cell.get_extra_manager_context())
diff --git a/combo/manager/views.py b/combo/manager/views.py
index 7fa45241..cca2a79a 100644
--- a/combo/manager/views.py
+++ b/combo/manager/views.py
@@ -352,7 +352,13 @@ page_add_cell = PageAddCellView.as_view()
 
 
 class PageEditCellView(UpdateView):
-    template_name = 'combo/ajax_cell_form.html'
+    def get_template_names(self):
+        return [self.template_name or self.object.manager_form_template]
+
+    def get_context_data(self, **kwargs):
+        context = super(PageEditCellView, self).get_context_data(**kwargs)
+        context['cell'] = self.get_object()
+        return context
 
     def get_object(self, queryset=None):
         page_pk = self.kwargs.get('page_pk')
-- 
2.20.1

