From bd45d3af1a242db5439152434754c5d5988bb7d4 Mon Sep 17 00:00:00 2001
From: James Graham <J.Graham@software.ac.uk>
Date: Thu, 28 Feb 2019 10:14:08 +0000
Subject: [PATCH] Add api url to data source detail page - #66

---
 .../templates/datasources/datasource/detail.html       | 10 +++++++---
 datasources/views/datasource.py                        |  6 ++++++
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/datasources/templates/datasources/datasource/detail.html b/datasources/templates/datasources/datasource/detail.html
index 67152ed..d2a4c82 100644
--- a/datasources/templates/datasources/datasource/detail.html
+++ b/datasources/templates/datasources/datasource/detail.html
@@ -104,12 +104,16 @@
                 </td>
             </tr>
             <tr>
-                <td>URL</td>
+                <td>Licence</td>
+                <td>{{ datasource.licence.name }}</td>
+            </tr>
+            <tr>
+                <td>External API URL</td>
                 <td>{{ datasource.url }}</td>
             </tr>
             <tr>
-                <td>Licence</td>
-                <td>{{ datasource.licence.name }}</td>
+                <td>Pedasi API URL</td>
+                <td>{{ api_url }}</td>
             </tr>
         </tbody>
     </table>
diff --git a/datasources/views/datasource.py b/datasources/views/datasource.py
index dbc90b4..717dc4f 100644
--- a/datasources/views/datasource.py
+++ b/datasources/views/datasource.py
@@ -44,6 +44,12 @@ class DataSourceDetailView(DetailView):
         except (KeyError, ValueError):
             messages.error(self.request, 'This data source is not configured correctly.  Please notify the owner.')
 
+        context['api_url'] = (
+            'https://' if self.request.is_secure() else 'http://' +
+            self.request.get_host() +
+            '/api/datasources/{0}/data/'.format(self.object.pk)
+        )
+
         return context
 
 
-- 
GitLab