mirror of
https://github.com/OpenBankProject/API-Manager.git
synced 2026-02-06 10:59:00 +00:00
API collection list and create page
This commit is contained in:
parent
7b6f607b18
commit
bdf930c0c8
0
apimanager/apicollectionlist/__init__.py
Normal file
0
apimanager/apicollectionlist/__init__.py
Normal file
5
apimanager/apicollectionlist/apps.py
Normal file
5
apimanager/apicollectionlist/apps.py
Normal file
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class CustomersConfig(AppConfig):
|
||||
name = 'customers_list'
|
||||
0
apimanager/apicollectionlist/forms.py
Normal file
0
apimanager/apicollectionlist/forms.py
Normal file
@ -0,0 +1,18 @@
|
||||
#apicollectionlist div {
|
||||
margin: 5px 0;
|
||||
}
|
||||
|
||||
/* The actual popup (appears on top) */
|
||||
.popuptext {
|
||||
width: 250px;
|
||||
background-color: #555;
|
||||
color: #fff;
|
||||
text-align: left;
|
||||
border-radius: 6px;
|
||||
padding: 8px 0;
|
||||
z-index: 1;
|
||||
/*bottom: 125%;*/
|
||||
top:100%
|
||||
left: 50%;
|
||||
margin-left: -80px;
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
$(document).ready(function($) {
|
||||
$('#info').click(function() {
|
||||
alert("Hello World")
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,43 @@
|
||||
{% extends 'base.html' %} {% load static %} {% load i18n %}
|
||||
{% block page_title %} {{ block.super }} / {% trans "Customer List" %}{% endblock page_title %} {% block content %}
|
||||
<div id="apicollectionlist">
|
||||
<h1>{% trans "My API Collection List" %}</h1>
|
||||
<form class="form-inline" method="get">
|
||||
<input type="submit" class="btn btn-default" value ='{% trans "Export CSV" %}' onclick="javascript: form.action='{% url 'export-csv-apicollection' %}';">
|
||||
</form>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover tablesorter" id="apicollectionlist" aria-describedby="apicollectionlist list">
|
||||
<thead>
|
||||
<th scope="col">{% trans "API Collection Id" %}</th>
|
||||
<th scope="col">{% trans "User Id" %}</th>
|
||||
<th scope="col">{% trans "API Collection Name" %}</th>
|
||||
<th scope="col">{% trans "More info" %}</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for apicollection in apicollections_list %}
|
||||
|
||||
{% url 'apicollection_update' apicollection.api_collection_id apicollection.user_id as url_apicollection_update %}
|
||||
<tr id="{{ apicollection.api_collection_id }}">
|
||||
<td>{{ apicollection.api_collection_id }}</td>
|
||||
<td>{{ apicollection.user_id }}</td>
|
||||
<td>{{ apicollection.api_collection_name }}</td>
|
||||
<td>
|
||||
<div class="popuptext">
|
||||
<ul>
|
||||
<li>{% trans "Other Info" %}:
|
||||
<ul>
|
||||
<li>{{apicollection.is_sharable}}</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
<td><a href="{{ url_apicollection_update }}" class="btn btn-primary">{% trans "View" %}</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %} {% block extrajs %} {% endblock extrajs %} {% block extracss %}
|
||||
<link href="{% static 'customerlist/css/customerlist.css' %}" rel="stylesheet"> {% endblock extracss %}
|
||||
16
apimanager/apicollectionlist/urls.py
Normal file
16
apimanager/apicollectionlist/urls.py
Normal file
@ -0,0 +1,16 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
URLs for Api Collection list app
|
||||
"""
|
||||
|
||||
from django.conf.urls import url
|
||||
from .views import ApiCollectionListView, ExportCsvView
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$',
|
||||
ApiCollectionListView.as_view(),
|
||||
name='apicollection-list'),
|
||||
url(r'^export_csv$',
|
||||
ExportCsvView.as_view(),
|
||||
name='export-csv-apicollection')
|
||||
]
|
||||
74
apimanager/apicollectionlist/views.py
Normal file
74
apimanager/apicollectionlist/views.py
Normal file
@ -0,0 +1,74 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Views of Api Collection list app
|
||||
"""
|
||||
import datetime
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
import json
|
||||
from django.urls import reverse_lazy
|
||||
from django.http import HttpResponse
|
||||
from django.views.generic import FormView,TemplateView, View
|
||||
from apicollections.views import IndexView
|
||||
from obp.api import API, APIError
|
||||
import csv
|
||||
|
||||
|
||||
|
||||
class ApiCollectionListView(IndexView, LoginRequiredMixin, FormView ):
|
||||
template_name = "apicollectionlist/apicollectionlist.html"
|
||||
success_url = '/apicollections/list'
|
||||
|
||||
def get_apicollections(self, context):
|
||||
api = API(self.request.session.get('obp'))
|
||||
try:
|
||||
apicollections_list = []
|
||||
urlpath = '/my/api-collections'
|
||||
result = api.get(urlpath)
|
||||
if 'api_collections' in result:
|
||||
apicollections_list.extend(result['api_collections'])
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
return []
|
||||
except Exception as inst:
|
||||
messages.error(self.request, "Unknown Error {}".format(type(inst).__name__))
|
||||
return []
|
||||
|
||||
return apicollections_list
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(IndexView, self).get_context_data(**kwargs)
|
||||
apicollections_list = self.get_apicollections(context)
|
||||
context.update({
|
||||
'apicollections_list': apicollections_list,
|
||||
})
|
||||
return context
|
||||
|
||||
class ExportCsvView(LoginRequiredMixin, View):
|
||||
"""View to export the user to csv"""
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
api = API(self.request.session.get('obp'))
|
||||
try:
|
||||
apicollections_list = []
|
||||
urlpath = '/my/api-collections'
|
||||
result = api.get(urlpath)
|
||||
if 'api_collections' in result:
|
||||
apicollections_list.extend(result['api_collections'])
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
except Exception as inst:
|
||||
messages.error(self.request, "Unknown Error {}".format(type(inst).__name__))
|
||||
response = HttpResponse(content_type = 'text/csv')
|
||||
response['Content-Disposition'] = 'attachment;filename= ApiCollections'+ str(datetime.datetime.now())+'.csv'
|
||||
writer = csv.writer(response)
|
||||
writer.writerow(["api_collection_id","user_id","api_collection_name","is_sharable","description"])
|
||||
for user in apicollections_list:
|
||||
writer.writerow([user['api_collection_id'],user['user_id'], user['api_collection_name'], user["is_sharable"],
|
||||
user["description"]])
|
||||
return response
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
{% block page_title %}{{ block.super }} / API Collections{% endblock page_title %}
|
||||
|
||||
{% block content %}
|
||||
<h1>{% trans "API Collections" %}</h1>
|
||||
<h1>{% trans "My API Collections" %}</h1>
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
<label class="form-group">{% trans "API Collection Id" %}:</label> <br>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Views of config app
|
||||
Views of API Collection app
|
||||
"""
|
||||
|
||||
import json
|
||||
@ -16,7 +16,7 @@ from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
|
||||
class IndexView(LoginRequiredMixin, FormView):
|
||||
"""Index view for config"""
|
||||
"""Index view for API Collection"""
|
||||
template_name = "apicollections/index.html"
|
||||
form_class = ApiCollectionsForm
|
||||
success_url = reverse_lazy('apicollections-index')
|
||||
@ -97,9 +97,7 @@ class DetailView(LoginRequiredMixin, FormView):
|
||||
else:
|
||||
api_collection_endpoints=response['api_collection_endpoints']
|
||||
except APIError as err:
|
||||
error_once_only(self.request, Exception("OBP-API server is not running or do not response properly. "
|
||||
"Please check OBP-API server. "
|
||||
"Details: " + str(err)))
|
||||
messages.error(self.request, result['message'])
|
||||
except BaseException as err:
|
||||
error_once_only(self.request, (Exception("Unknown Error. Details:" + str(err))))
|
||||
else:
|
||||
@ -115,8 +113,7 @@ class DeleteCollectionEndpointView(LoginRequiredMixin, FormView):
|
||||
"""Deletes api collection endpoint from API"""
|
||||
api = API(self.request.session.get('obp'))
|
||||
try:
|
||||
urlpath = '/my/api-collections-ids/{}/api-collection-endpoints/{}'\
|
||||
.format(kwargs['api_collection_id'],kwargs['operation_id'])
|
||||
urlpath = '/my/api-collections-ids/{}/api-collection-endpoints/{}'.format(kwargs['api_collection_id'],kwargs['operation_id'])
|
||||
result = api.delete(urlpath)
|
||||
if result is not None and 'code' in result and result['code']>=400:
|
||||
messages.error(request, result['message'])
|
||||
@ -127,7 +124,6 @@ class DeleteCollectionEndpointView(LoginRequiredMixin, FormView):
|
||||
messages.error(request, err)
|
||||
except:
|
||||
messages.error(self.request, 'Unknown Error')
|
||||
|
||||
redirect_url = reverse('my-api-collection-detail',kwargs={"api_collection_id":kwargs['api_collection_id']})
|
||||
return HttpResponseRedirect(redirect_url)
|
||||
|
||||
|
||||
@ -68,7 +68,8 @@ INSTALLED_APPS = [
|
||||
'methodrouting',
|
||||
'connectormethod',
|
||||
'dynamicendpoints',
|
||||
'apicollections'
|
||||
'apicollections',
|
||||
'apicollectionlist'
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
||||
@ -53,6 +53,7 @@ urlpatterns += i18n_patterns(
|
||||
url(r'^connectormethod/', include('connectormethod.urls')),
|
||||
url(r'^dynamicendpoints/', include('dynamicendpoints.urls')),
|
||||
url(r'^apicollections/', include('apicollections.urls')),
|
||||
url(r'^apicollections/list', include('apicollectionlist.urls')),
|
||||
)
|
||||
#prefix_default_language=False,
|
||||
#)+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
@ -75,7 +75,7 @@
|
||||
<li {% if product_list_url in request.path %} class="active" {% endif %}><a href="{{ product_list_url }}">{% trans "Product List" %}</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
{% url "config-index" as config_index_url %} {% url "webui-index" as webui_props_index_url %} {% url "methodrouting-index" as methodrouting_index_url %} {% url "connectormethod" as connectormethod_url %} {% url "dynamicendpoints-index" as dynamic_endpoints_index_url %} {% url "apicollections-index" as api_collections_index_url %}
|
||||
{% url "config-index" as config_index_url %} {% url "webui-index" as webui_props_index_url %} {% url "methodrouting-index" as methodrouting_index_url %} {% url "connectormethod" as connectormethod_url %} {% url "dynamicendpoints-index" as dynamic_endpoints_index_url %} {% url "apicollections-index" as api_collections_index_url %} {% url "apicollection-list" as api_collections_list_url %}
|
||||
<li class="dropdown{% if config_index_url in request.path %} active{% endif %}">
|
||||
<a href="#" data-toggle="dropdown" class="dropdown-toggle">{% trans "Configurations" %}</a>
|
||||
<ul class="dropdown-menu">
|
||||
@ -91,6 +91,7 @@
|
||||
</li>
|
||||
<hr class="dropdown-hr">
|
||||
<li {% if api_collections_index_url in request.path %} class="active" {% endif %}><a href="{{ api_collections_index_url }}">{% trans "My API Collections" %}</a></li>
|
||||
<li {% if api_collections_list_url in request.path %} class="active" {% endif %}><a href="{{ api_collections_list_url }}">{% trans "My API Collection List" %}</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
{% if SHOW_API_TESTER %}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user