From 20d3d9f27991b95fd03b7d80945ef9719f9537aa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= <zebuline@entrouvert.com>
Date: Tue, 26 Oct 2021 10:53:30 +0200
Subject: [PATCH] wcs: custom title for current forms cell (#57966)

---
 combo/apps/wcs/forms.py                          |  2 ++
 .../0041_current_forms_custom_title.py           | 16 ++++++++++++++++
 combo/apps/wcs/models.py                         |  1 +
 .../wcs/templates/combo/wcs/current_forms.html   |  2 +-
 .../wcs/templates/combo/wcs/user_all_forms.html  |  2 +-
 .../wcs/templates/combo/wcs/user_done_forms.html |  2 +-
 tests/test_wcs.py                                | 16 +++++++++++++++-
 7 files changed, 37 insertions(+), 4 deletions(-)
 create mode 100644 combo/apps/wcs/migrations/0041_current_forms_custom_title.py

diff --git a/combo/apps/wcs/forms.py b/combo/apps/wcs/forms.py
index 55bfe6c9..c14c96b3 100644
--- a/combo/apps/wcs/forms.py
+++ b/combo/apps/wcs/forms.py
@@ -163,6 +163,7 @@ class WcsCurrentFormsCellForm(WcsFormsMixin, forms.ModelForm):
     field_order = [
         'wcs_site',
         'categories',
+        'custom_title',
         'current_forms',
         'done_forms',
         'include_drafts',
@@ -173,6 +174,7 @@ class WcsCurrentFormsCellForm(WcsFormsMixin, forms.ModelForm):
         model = WcsCurrentFormsCell
         fields = [
             'wcs_site',
+            'custom_title',
             'current_forms',
             'done_forms',
             'include_drafts',
diff --git a/combo/apps/wcs/migrations/0041_current_forms_custom_title.py b/combo/apps/wcs/migrations/0041_current_forms_custom_title.py
new file mode 100644
index 00000000..2c4fe913
--- /dev/null
+++ b/combo/apps/wcs/migrations/0041_current_forms_custom_title.py
@@ -0,0 +1,16 @@
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('wcs', '0040_cards_limit'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='wcscurrentformscell',
+            name='custom_title',
+            field=models.CharField(blank=True, max_length=150, verbose_name='Custom Title'),
+        ),
+    ]
diff --git a/combo/apps/wcs/models.py b/combo/apps/wcs/models.py
index d468194d..526443c0 100644
--- a/combo/apps/wcs/models.py
+++ b/combo/apps/wcs/models.py
@@ -462,6 +462,7 @@ class WcsCurrentFormsCell(CategoriesAndWcsSiteValidityMixin, CategoriesFiltering
     loading_message = _('Loading forms...')
 
     categories = JSONField(_('Categories'), blank=True, default=dict)
+    custom_title = models.CharField(_('Custom Title'), max_length=150, blank=True)
     current_forms = models.BooleanField(_('Current Forms'), default=True)
     done_forms = models.BooleanField(_('Done Forms'), default=False)
     include_drafts = models.BooleanField(_('Include drafts'), default=False)
diff --git a/combo/apps/wcs/templates/combo/wcs/current_forms.html b/combo/apps/wcs/templates/combo/wcs/current_forms.html
index a79e46e7..95f52a76 100644
--- a/combo/apps/wcs/templates/combo/wcs/current_forms.html
+++ b/combo/apps/wcs/templates/combo/wcs/current_forms.html
@@ -1,6 +1,6 @@
 {% load i18n %}
 {% block cell-content %}
-<h2>{% trans 'Current Forms' %}</h2>
+<h2>{{ cell.custom_title|default:_('Current Forms') }}</h2>
 {% if forms %}
 {% for slug, forms in current_forms.items %}
   <div class="links-list current-forms-{{ slug }} current-forms list-of-forms">
diff --git a/combo/apps/wcs/templates/combo/wcs/user_all_forms.html b/combo/apps/wcs/templates/combo/wcs/user_all_forms.html
index 113e0fb4..7a4f2b28 100644
--- a/combo/apps/wcs/templates/combo/wcs/user_all_forms.html
+++ b/combo/apps/wcs/templates/combo/wcs/user_all_forms.html
@@ -1,6 +1,6 @@
 {% load i18n %}
 {% block cell-content %}
-<h2>{% trans 'All Forms' %}</h2>
+<h2>{{ cell.custom_title|default:_('All Forms') }}</h2>
 {% if forms %}
 {% for slug, forms in user_forms.items %}
   <div class="links-list user-forms-{{ slug }} user-all-forms list-of-forms">
diff --git a/combo/apps/wcs/templates/combo/wcs/user_done_forms.html b/combo/apps/wcs/templates/combo/wcs/user_done_forms.html
index cfb99aca..9b98a64f 100644
--- a/combo/apps/wcs/templates/combo/wcs/user_done_forms.html
+++ b/combo/apps/wcs/templates/combo/wcs/user_done_forms.html
@@ -1,6 +1,6 @@
 {% load i18n %}
 {% block cell-content %}
-<h2>{% trans 'Done Forms' %}</h2>
+<h2>{{ cell.custom_title|default:_('Done Forms') }}</h2>
 {% if forms %}
 {% for slug, forms in user_forms.items %}
   <div class="links-list user-forms-{{ slug }} list-of-forms">
diff --git a/tests/test_wcs.py b/tests/test_wcs.py
index c6cdb6a6..efe6497b 100644
--- a/tests/test_wcs.py
+++ b/tests/test_wcs.py
@@ -632,7 +632,7 @@ def test_current_forms_cell_render(mock_send, context):
         == '/api/user/forms/?status=done&include-accessible=on&limit=100&sort=desc'
     )
 
-    # check empty messages
+    # check empty messages and title
     with mock.patch('combo.apps.wcs.models.requests.get') as requests_get:
         mock_json = mock.Mock(status_code=200)
         requests_get.return_value = mock_json
@@ -640,13 +640,27 @@ def test_current_forms_cell_render(mock_send, context):
         cell.done_forms = False
         cell.include_drafts = False
         result = cell.render(context)
+        assert '<h2>Current Forms</h2>' in result
         assert 'There are no current forms.' in result
+        cell.custom_title = 'Foo bar'
+        result = cell.render(context)
+        assert '<h2>Foo bar</h2>' in result
+        cell.custom_title = ''
         cell.done_forms = True
         result = cell.render(context)
+        assert '<h2>All Forms</h2>' in result
         assert 'There are no forms.' in result
+        cell.custom_title = 'Foo bar'
+        result = cell.render(context)
+        assert '<h2>Foo bar</h2>' in result
+        cell.custom_title = ''
         cell.current_forms = False
         result = cell.render(context)
+        assert '<h2>Done Forms</h2>' in result
         assert 'There are no done forms' in result
+        cell.custom_title = 'Foo bar'
+        result = cell.render(context)
+        assert '<h2>Foo bar</h2>' in result
 
 
 @mock.patch('combo.apps.wcs.utils.requests.send', side_effect=mocked_requests_send)
-- 
2.33.0

