Added config app

And removed old api_config app
This commit is contained in:
Sebastian Henschel 2017-06-10 16:00:20 +02:00
parent 0d0a64038a
commit 01970caaa8
16 changed files with 125 additions and 82 deletions

View File

@ -1,5 +0,0 @@
from django.apps import AppConfig
class ApiConfigConfig(AppConfig):
name = 'api_config'

View File

@ -1,3 +0,0 @@
.api-config input[type="text"] {
width: 100%;
}

View File

@ -1,35 +0,0 @@
{% extends "base.html" %}
{% load static %}
{% block content %}
<div class="api-config">
<h1>API Config</h1>
<div class="alert alert-warning">
There is no live data here!
</div>
<form>
<div class="form-group">
<label for="config-versions-disabled" class="control-label">Versions Disabled</label><br />
<input type="text" name="config-versions-disabled" id="config-versions-disabled" aria-label="versions-disabled" disabled="disabled" value="{{ config.versions_disabled }}" />
</div>
<div class="form-group">
<label for="config-functions-disabled" class="control-label">Functions Disabled</label><br />
<input type="text" name="config-functions-disabled" id="config-functions-disabled" aria-label="functions-disabled" disabled="disabled" value="{{ config.functions_disabled }}" />
</div>
<div class="form-group">
<label for="config-host" class="control-label">Host</label><br />
<input type="text" name="config-host" id="config-host" aria-label="host" disabled="disabled" value="{{ config.host }}" />
</div>
</form>
</div>
{% endblock %}
{% block extracss %}
<link href="{% static 'api_config/css/api_config.css' %}" rel="stylesheet">
{% endblock extracss %}

View File

@ -1,7 +0,0 @@
from django.conf.urls import url
from .views import IndexView
urlpatterns = [
url(r'^$', IndexView.as_view(), name='api-config-index'),
]

View File

@ -1,26 +0,0 @@
# -*- coding: utf-8 -*-
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import TemplateView
CONFIG = {
'versions_disabled': ', '.join(['1.4.0', '2.0.0']),
'functions_disabled': ', '.join([
'getBank', 'getBanks', 'getAccounts', 'getAccount',
'getTransactions', 'getTransaction'
]),
'host': 'http://127.0.0.1:8080',
}
class IndexView(LoginRequiredMixin, TemplateView):
template_name = "api_config/index.html"
def get_context_data(self, **kwargs):
context = super(IndexView, self).get_context_data(**kwargs)
context.update({
'config': CONFIG,
})
return context

View File

@ -50,7 +50,7 @@ INSTALLED_APPS = [
'users',
'customers',
'metrics',
#'api_config',
'config',
]
MIDDLEWARE = [

View File

@ -15,5 +15,5 @@ urlpatterns = [
url(r'^users/', include('users.urls')),
url(r'^customers/', include('customers.urls')),
url(r'^metrics/', include('metrics.urls')),
#url(r'^api_config/', include('api_config.urls')),
url(r'^config/', include('config.urls')),
]

View File

@ -35,10 +35,8 @@
<li{% if metrics_index_url in request.path %} class="active"{% endif %}><a href="{{ metrics_index_url }}">Metrics</a></li>
{% url "customers-create" as customers_create_url %}
<li{% if customers_create_url in request.path %} class="active"{% endif %}><a href="{{ customers_create_url }}">Customers</a></li>
{% comment %}
{% url "api-config-index" as api_config_index_url %}
<li{% ifequal request.path api_config_index_url %} class="active" {% endifequal %}><a href="{{ api_config_index_url }}">API Config</a></li>
{% endcomment %}
{% url "config-index" as config_index_url %}
<li{% ifequal request.path config_index_url %} class="active" {% endifequal %}><a href="{{ config_index_url }}">Config</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>

12
apimanager/config/apps.py Normal file
View File

@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
"""
App config for config app
"""
from django.apps import AppConfig
class ConfigConfig(AppConfig):
"""Config for config"""
name = 'config'

View File

@ -0,0 +1,10 @@
#config pre {
overflow: auto;
word-wrap: normal;
white-space: pre;
}
#config .string { color: green; }
#config .number { color: darkorange; }
#config .boolean { color: blue; }
#config .null { color: magenta; }
#config .key { color: red; }

View File

@ -0,0 +1,25 @@
$(document).ready(function($) {
function syntaxHighlight(json) {
if (typeof json != 'string') {
json = JSON.stringify(json, undefined, 2);
}
json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
var cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
} else {
cls = 'string';
}
} else if (/true|false/.test(match)) {
cls = 'boolean';
} else if (/null/.test(match)) {
cls = 'null';
}
return '<span class="' + cls + '">' + match + '</span>';
});
}
$('#config-json').html((syntaxHighlight(ConfigJson)));
});

View File

@ -0,0 +1,27 @@
{% extends 'base.html' %}
{% load static %}
{% block page_title %}{{ block.super }} / Users{% endblock page_title %}
{% block content %}
<div id="config">
<h1>Config</h1>
<p>The configuration of the API</p>
<pre id="config-json">
</pre>
</div>
{% endblock %}
{% block extrajs %}
<script type="text/javascript" src="{% static 'config/js/config.js' %}"></script>
<script type="text/javascript">
ConfigJson = {{ config_json|safe }};
</script>
{% endblock extrajs %}
{% block extracss %}
<link href="{% static 'config/css/config.css' %}" rel="stylesheet">
{% endblock extracss %}

14
apimanager/config/urls.py Normal file
View File

@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
"""
URLs for config app
"""
from django.conf.urls import url
from .views import IndexView
urlpatterns = [
url(r'^$',
IndexView.as_view(),
name='config-index'),
]

View File

@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
"""
Views of config app
"""
import json
from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import FormView, TemplateView, View
from base.api import api, APIError
class IndexView(LoginRequiredMixin, TemplateView):
"""Index view for config"""
template_name = "config/index.html"
def get_context_data(self, **kwargs):
context = super(IndexView, self).get_context_data(**kwargs)
try:
urlpath = '/config'
config = api.get(self.request, urlpath)
except APIError as err:
messages.error(self.request, err)
config = {}
context.update({
'config_json': json.dumps(config, indent=4),
})
return context