From 305ac7023917e69634047af84692dc96a81446bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= <fpeters@entrouvert.com>
Date: Tue, 19 May 2020 14:42:57 +0200
Subject: [PATCH] admin: set forms/workflows breadcrumb in _q_traverse (#43080)

---
 wcs/admin/forms.py          | 14 ++++++--------
 wcs/admin/mail_templates.py |  1 -
 wcs/admin/workflows.py      | 14 ++++++--------
 3 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/wcs/admin/forms.py b/wcs/admin/forms.py
index 3abe90faf..59c14ec8f 100644
--- a/wcs/admin/forms.py
+++ b/wcs/admin/forms.py
@@ -24,7 +24,7 @@ import time
 
 from django.utils.six import BytesIO, StringIO
 
-from quixote import get_response, redirect
+from quixote import get_publisher, get_response, redirect
 from quixote.directory import Directory, AccessControlled
 from quixote.html import TemplateIO, htmltext
 
@@ -1479,9 +1479,7 @@ class FormDefPage(Directory):
 
 
 class NamedDataSourcesDirectoryInForms(NamedDataSourcesDirectory):
-    def _q_traverse(self, path):
-        get_response().breadcrumb.append(('forms/', _('Forms')))
-        return super(NamedDataSourcesDirectoryInForms, self)._q_traverse(path)
+    pass
 
 
 class FormsDirectory(AccessControlled, Directory):
@@ -1512,8 +1510,11 @@ class FormsDirectory(AccessControlled, Directory):
     def html_top(self, title):
         return html_top('forms', title)
 
+    def _q_traverse(self, path):
+        get_response().breadcrumb.append(('forms/', _('Forms')))
+        return super()._q_traverse(path)
+
     def _q_index(self):
-        get_response().breadcrumb.append( ('forms/', _('Forms')) )
         self.html_top(title = _('Forms'))
         r = TemplateIO(html=True)
         get_response().add_javascript(['jquery.js', 'widget_list.js'])
@@ -1580,7 +1581,6 @@ class FormsDirectory(AccessControlled, Directory):
         return r.getvalue()
 
     def new(self):
-        get_response().breadcrumb.append( ('forms/', _('Forms')) )
         get_response().breadcrumb.append( ('new', _('New')) )
         if Role.count() == 0:
             return template.error_page('forms', _('You first have to define roles.'))
@@ -1606,7 +1606,6 @@ class FormsDirectory(AccessControlled, Directory):
         return r.getvalue()
 
     def _q_lookup(self, component):
-        get_response().breadcrumb.append( ('forms/', _('Forms')) )
         return self.formdef_page_class(component)
 
     def p_import(self):
@@ -1627,7 +1626,6 @@ class FormsDirectory(AccessControlled, Directory):
             except ValueError:
                 pass
 
-        get_response().breadcrumb.append( ('forms/', _('Forms')) )
         get_response().breadcrumb.append( ('import', _('Import')) )
         self.html_top(title=_(self.import_title))
         r = TemplateIO(html=True)
diff --git a/wcs/admin/mail_templates.py b/wcs/admin/mail_templates.py
index 82547a3df..3fb6b01b6 100644
--- a/wcs/admin/mail_templates.py
+++ b/wcs/admin/mail_templates.py
@@ -30,7 +30,6 @@ class MailTemplatesDirectory(Directory):
     do_not_call_in_templates = True
 
     def _q_traverse(self, path):
-        get_response().breadcrumb.append(('workflows/', _('Workflows')))
         get_response().breadcrumb.append(('mail-templates/', _('Mail Templates')))
         return super(MailTemplatesDirectory, self)._q_traverse(path)
 
diff --git a/wcs/admin/workflows.py b/wcs/admin/workflows.py
index a42509550..197b83c8d 100644
--- a/wcs/admin/workflows.py
+++ b/wcs/admin/workflows.py
@@ -27,7 +27,7 @@ from django.utils import six
 from django.utils.encoding import force_bytes
 from django.utils.six import StringIO
 
-from quixote import redirect, get_publisher
+from quixote import redirect, get_publisher, get_response
 from quixote.directory import Directory
 from quixote.html import TemplateIO, htmltext
 
@@ -1801,9 +1801,7 @@ class WorkflowPage(Directory):
 
 
 class NamedDataSourcesDirectoryInWorkflows(NamedDataSourcesDirectory):
-    def _q_traverse(self, path):
-        get_response().breadcrumb.append(('workflows/', _('Workflows')))
-        return super(NamedDataSourcesDirectoryInWorkflows, self)._q_traverse(path)
+    pass
 
 
 class WorkflowsDirectory(Directory):
@@ -1817,8 +1815,11 @@ class WorkflowsDirectory(Directory):
     def html_top(self, title):
         return html_top('workflows', title)
 
+    def _q_traverse(self, path):
+        get_response().breadcrumb.append(('workflows', _('Workflows')))
+        return super()._q_traverse(path)
+
     def _q_index(self):
-        get_response().breadcrumb.append( ('workflows/', _('Workflows')) )
         self.html_top(title = _('Workflows'))
         r = TemplateIO(html=True)
 
@@ -1893,7 +1894,6 @@ class WorkflowsDirectory(Directory):
         return r.getvalue()
 
     def new(self):
-        get_response().breadcrumb.append( ('workflows/', _('Workflows')) )
         get_response().breadcrumb.append( ('new', _('New')) )
         workflow_ui = WorkflowUI(None)
 
@@ -1916,7 +1916,6 @@ class WorkflowsDirectory(Directory):
         return r.getvalue()
 
     def _q_lookup(self, component):
-        get_response().breadcrumb.append( ('workflows/', _('Workflows')) )
         return WorkflowPage(component, html_top=self.html_top)
 
     def p_import(self):
@@ -1937,7 +1936,6 @@ class WorkflowsDirectory(Directory):
             except ValueError:
                 pass
 
-        get_response().breadcrumb.append( ('workflows/', _('Workflows')) )
         get_response().breadcrumb.append( ('import', _('Import')) )
         self.html_top(title=_('Import Workflow'))
         r = TemplateIO(html=True)
-- 
2.27.0.rc0

