[PATCH v2 2/3] templates: Add API status to about page

Daniel Axtens dja at axtens.net
Mon Feb 13 07:26:38 AEDT 2017


Hi Stephen,

Looks good to me.

Reviewed-by: Daniel Axtens <dja at axtens.net>

Regards,
Daniel

Stephen Finucane <stephen at that.guru> writes:

> This is useful given that these APIs can be disabled, and likely will
> be for deployments where django-rest-framework is not available.
>
> The version is currently hardcoded, but this will be resolved in a
> future change.
>
> Signed-off-by: Stephen Finucane <stephen at that.guru>
> ---
>  patchwork/templates/patchwork/about.html | 53 +++++++++++++++++++++++++++++---
>  patchwork/tests/test_about.py            | 21 +++++++++++++
>  patchwork/views/about.py                 |  9 +++++-
>  3 files changed, 77 insertions(+), 6 deletions(-)
>
> diff --git a/patchwork/templates/patchwork/about.html b/patchwork/templates/patchwork/about.html
> index ed0c421..e087f7c 100644
> --- a/patchwork/templates/patchwork/about.html
> +++ b/patchwork/templates/patchwork/about.html
> @@ -4,11 +4,54 @@
>  {% block heading %}About Patchwork{% endblock %}
>  
>  {% block body %}
> -<h1>About Patchwork</h1>
> +<div class="container">
> +  <h1>About Patchwork</h1>
>  
> -<p>Patchwork is free software, and is available from the
> -<a href="http://jk.ozlabs.org/projects/patchwork/">Patchwork website</a>.</p>
> +  <p>Patchwork is free software, and is available from the <a
> +     href="http://jk.ozlabs.org/projects/patchwork/">Patchwork website</a>.
> +     Documentation is available on <a
> +     href="http://patchwork.readthedocs.io/">Read the Docs</a>.</p>
>  
> -<p>Patchwork is built on the <a href="http://djangoproject.com/">Django</a>
> -web framework.</p>
> +  <p>Patchwork is built on the <a href="https://djangoproject.com/">Django</a>
> +  web framework using <a href="https://getbootstrap.com/">Bootstrap</a>.</p>
> +
> +  <div class="panel panel-default">
> +    <div class="panel-heading">
> +      <h3 class="panel-title">Version</h3>
> +    </div>
> +    <ul class="list-group">
> +      <li class="list-group-item">
> +        <p>2.0.0-pre</p>
> +      </li>
> +    </ul>
> +  </div>
> +
> +  <div class="panel panel-default">
> +    <div class="panel-heading">
> +      <h3 class="panel-title">API Status</h3>
> +    </div>
> +    <ul class="list-group">
> +      <li class="list-group-item">
> +        REST
> +        <span class="glyphicon glyphicon-question-sign" title="The REST
> +          API"></span>
> +        {% if enabled_apis.rest %}
> +        <span class="label label-success pull-right">enabled</span>
> +        {% else %}
> +        <span class="label label-warning pull-right">disabled</span>
> +        {% endif %}
> +      </li>
> +      <li class="list-group-item">
> +        XML-RPC
> +        <span class="glyphicon glyphicon-question-sign" title="The XML-RPC
> +          API"></span>
> +        {% if enabled_apis.xmlrpc %}
> +        <span class="label label-success pull-right">enabled</span>
> +        {% else %}
> +        <span class="label label-warning pull-right">disabled</span>
> +        {% endif %}
> +      </li>
> +    </ul>
> +  </div>
> +</div>
>  {% endblock %}
> diff --git a/patchwork/tests/test_about.py b/patchwork/tests/test_about.py
> index 2175641..0ced799 100644
> --- a/patchwork/tests/test_about.py
> +++ b/patchwork/tests/test_about.py
> @@ -19,6 +19,7 @@
>  
>  from django.core.urlresolvers import reverse
>  from django.test import TestCase
> +from django.test.utils import override_settings
>  
>  
>  class AboutViewTest(TestCase):
> @@ -30,3 +31,23 @@ class AboutViewTest(TestCase):
>  
>              response = self.client.get(requested_url)
>              self.assertRedirects(response, redirect_url, 301)
> +
> +    @override_settings(ENABLE_XMLRPC=False)
> +    def test_disabled_xmlrpc(self):
> +        response = self.client.get(reverse('about'))
> +        self.assertFalse(response.context['enabled_apis']['xmlrpc'])
> +
> +    @override_settings(ENABLE_XMLRPC=True)
> +    def test_enabled_xmlrpc(self):
> +        response = self.client.get(reverse('about'))
> +        self.assertTrue(response.context['enabled_apis']['xmlrpc'])
> +
> +    @override_settings(ENABLE_REST_API=False)
> +    def test_disabled_rest(self):
> +        response = self.client.get(reverse('about'))
> +        self.assertFalse(response.context['enabled_apis']['rest'])
> +
> +    @override_settings(ENABLE_REST_API=True)
> +    def test_enabled_rest(self):
> +        response = self.client.get(reverse('about'))
> +        self.assertTrue(response.context['enabled_apis']['rest'])
> diff --git a/patchwork/views/about.py b/patchwork/views/about.py
> index 86ef952..1cbc362 100644
> --- a/patchwork/views/about.py
> +++ b/patchwork/views/about.py
> @@ -25,7 +25,14 @@ from django.shortcuts import render
>  
>  
>  def about(request):
> -    return render(request, 'patchwork/about.html')
> +    context = {
> +        'enabled_apis': {
> +            'rest': settings.ENABLE_REST_API,
> +            'xmlrpc': settings.ENABLE_XMLRPC,
> +         }
> +    }
> +
> +    return render(request, 'patchwork/about.html', context)
>  
>  
>  def redirect(request):
> -- 
> 2.7.4
>
> _______________________________________________
> Patchwork mailing list
> Patchwork at lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/patchwork


More information about the Patchwork mailing list