From 03ddb739f95d6cd1f1bb6d7853fca9ba62c7d28f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= <zebuline@entrouvert.com>
Date: Thu, 3 Sep 2020 11:42:23 +0200
Subject: [PATCH 2/3] wscall: use a django template for detail page

---
 wcs/admin/wscalls.py                     | 49 ++----------------------
 wcs/templates/wcs/backoffice/wscall.html | 33 ++++++++++++++++
 2 files changed, 36 insertions(+), 46 deletions(-)
 create mode 100644 wcs/templates/wcs/backoffice/wscall.html

diff --git a/wcs/admin/wscalls.py b/wcs/admin/wscalls.py
index 48fd9c90..febcecc3 100644
--- a/wcs/admin/wscalls.py
+++ b/wcs/admin/wscalls.py
@@ -91,52 +91,9 @@ class NamedWsCallPage(Directory):
 
     def _q_index(self):
         html_top('wscalls', title=self.wscall.name)
-        r = TemplateIO(html=True)
-
-        r += htmltext('<div id="appbar">')
-        r += htmltext('<h2>%s - ') % _('Webservice Call')
-        r += self.wscall.name
-        r += htmltext('</h2>')
-        r += htmltext('<span class="actions">')
-        r += htmltext('<a href="delete" rel="popup">%s</a>') % _('Delete')
-        r += htmltext('<a href="edit">%s</a>') % _('Edit')
-        r += htmltext('</span>')
-        r += htmltext('</div>')
-
-        if self.wscall.description:
-            r += htmltext('<div class="bo-block">')
-            r += self.wscall.description
-            r += htmltext('</div>')
-
-        if self.wscall.request:
-            r += htmltext('<div class="bo-block">')
-            r += htmltext('<h3>%s</h3>') % _('Parameters')
-            r += htmltext('<ul>')
-            if self.wscall.request.get('url'):
-                r += htmltext('<li>%s %s</li>') % (
-                        _('URL:'),
-                        self.wscall.request.get('url'))
-            if self.wscall.request.get('request_signature_key'):
-                r += htmltext('<li>%s %s</li>') % (
-                        _('Request Signature Key:'),
-                        self.wscall.request.get('request_signature_key'))
-            if self.wscall.request.get('qs_data'):
-                r += htmltext('<li>%s<ul>') % _('Query string data:')
-                for k, v in self.wscall.request.get('qs_data').items():
-                    r += htmltext('<li>%s %s</li>') % (_('%s:') % k, v)
-                r += htmltext('</ul></li>')
-            r += htmltext('<li>%s %s</li>') % (
-                    _('Method:'),
-                    'POST' if self.wscall.request.get('method') == 'POST' else 'GET')
-            if self.wscall.request.get('post_data'):
-                r += htmltext('<li>%s<ul>') % _('POST data:')
-                for k, v in self.wscall.request.get('post_data').items():
-                    r += htmltext('<li>%s %s</li>') % (_('%s:') % k, v)
-                r += htmltext('</ul></li>')
-            r += htmltext('</ul>')
-            r += htmltext('</div>')
-
-        return r.getvalue()
+        return template.QommonTemplateResponse(
+            templates=['wcs/backoffice/wscall.html'],
+            context={'view': self, 'wscall': self.wscall})
 
     def edit(self):
         form = self.wscall_ui.get_form()
diff --git a/wcs/templates/wcs/backoffice/wscall.html b/wcs/templates/wcs/backoffice/wscall.html
new file mode 100644
index 00000000..75c91a35
--- /dev/null
+++ b/wcs/templates/wcs/backoffice/wscall.html
@@ -0,0 +1,33 @@
+{% load i18n %}
+
+{% block body %}
+<div id="appbar">
+<h2>{% trans "Webservice Call" %} - {{ wscall.name }}</h2>
+<span class="actions">
+  <a href="delete" rel="popup">{% trans "Delete" %}</a>
+  <a href="edit">{% trans "Edit" %}</a>
+</span>
+</div>
+
+{% if wscall.description %}
+<div class="bo-block">{{ wscall.description }}</div>
+{% endif %}
+
+<div class="bo-block">
+<h3>{% trans "Parameters" %}</h3>
+<ul>
+  {% if wscall.request.url %}<li>{% trans "URL:" %} {{ wscall.request.url }}</li>{% endif %}
+  {% if wscall.request.request_signature_key %}<li>{% trans "Request Signature Key:" %} {{ wscall.request.request_signature_key }}</li>{% endif %}
+  {% if wscall.request.qs_data %}
+  <li>{% trans "Query string data:" %}
+      <ul>
+        {% for k, v in wscall.request.qs_data.items %}
+          <li>{% blocktrans %}{{ k }}:{% endblocktrans %} {{ v }}</li>
+        {% endfor %}
+      </ul>
+    </li>
+  {% endif %}
+  <li>{% trans "Method:" %} {% if wscall.request.method == 'POST' %}POST{% else %}GET{% endif %}</li>
+</ul>
+</div>
+{% endblock %}
-- 
2.28.0

