mirror of
https://github.com/OpenBankProject/API-Manager.git
synced 2026-02-06 16:46:57 +00:00
commit
6fcebdcfeb
@ -21,6 +21,31 @@ def get_banks(request):
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
return []
|
||||
def get_consumers(request):
|
||||
api = API(request.session.get('obp'))
|
||||
try:
|
||||
urlpath = '/management/consumers'
|
||||
result = api.get(urlpath)
|
||||
if 'consumers' in result:
|
||||
return [consumer['consumer_id'] for consumer in sorted(result['consumers'], key=lambda d: d['consumer_id'])]
|
||||
else:
|
||||
return []
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
return []
|
||||
|
||||
def get_api_versions(request):
|
||||
api = API(request.session.get('obp'))
|
||||
try:
|
||||
urlpath = '/api/versions'
|
||||
result = api.get(urlpath)
|
||||
if 'scanned_api_versions' in result:
|
||||
return [apiversion['apiShortVersion'] for apiversion in sorted(result['scanned_api_versions'], key=lambda d: d['apiShortVersion'])]
|
||||
else:
|
||||
return []
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
return []
|
||||
|
||||
class HomeView(TemplateView):
|
||||
"""View for home page"""
|
||||
|
||||
@ -38,7 +38,7 @@ class MetricsForm(forms.Form):
|
||||
'class': FORM_CONTROL,
|
||||
}
|
||||
),
|
||||
initial=100,
|
||||
initial=1000,
|
||||
required=False,
|
||||
)
|
||||
offset = forms.IntegerField(
|
||||
@ -69,25 +69,15 @@ class APIMetricsForm(MetricsForm):
|
||||
('POST', 'POST'),
|
||||
('PUT', 'PUT'),
|
||||
)
|
||||
VERSION = (
|
||||
('', _('Any')),
|
||||
('v1.2', '1.2'),
|
||||
('v1.2.1', '1.2.1'),
|
||||
('v1.3.0', '1.3.0'),
|
||||
('v1.4.0', '1.4.0'),
|
||||
('v2.0.0', '2.0.0'),
|
||||
('v2.1.0', '2.1.0'),
|
||||
('v2.2.0', '2.2.0'),
|
||||
('v3.0.0', '3.0.0'),
|
||||
)
|
||||
|
||||
consumer_id = forms.CharField(
|
||||
consumer_id = forms.ChoiceField(
|
||||
label=_('Consumer ID'),
|
||||
widget=forms.TextInput(
|
||||
widget=forms.Select(
|
||||
attrs={
|
||||
'class': FORM_CONTROL,
|
||||
}
|
||||
),
|
||||
choices=[],
|
||||
required=False,
|
||||
)
|
||||
user_id = forms.CharField(
|
||||
@ -107,7 +97,7 @@ class APIMetricsForm(MetricsForm):
|
||||
'class': FORM_CONTROL,
|
||||
}
|
||||
),
|
||||
initial='',
|
||||
initial='false',
|
||||
required=False,
|
||||
)
|
||||
app_name = forms.CharField(
|
||||
@ -150,17 +140,17 @@ class APIMetricsForm(MetricsForm):
|
||||
)
|
||||
implemented_in_version = forms.ChoiceField(
|
||||
label=_('Implemented In Version'),
|
||||
choices=VERSION,
|
||||
#choices=VERSION,
|
||||
widget=forms.Select(
|
||||
attrs={
|
||||
'class': FORM_CONTROL,
|
||||
}
|
||||
),
|
||||
initial='',
|
||||
choices=[],
|
||||
#initial='',
|
||||
required=False,
|
||||
)
|
||||
|
||||
|
||||
class ConnectorMetricsForm(MetricsForm):
|
||||
# override from_date until API returns values without given date
|
||||
from_date = forms.DateTimeField(
|
||||
|
||||
@ -21,6 +21,7 @@ from obp.api import API, APIError, LOGGER
|
||||
from .forms import APIMetricsForm, ConnectorMetricsForm, MonthlyMetricsSummaryForm, CustomSummaryForm
|
||||
from pylab import *
|
||||
from django.core.cache import cache
|
||||
from base.views import get_consumers, get_api_versions
|
||||
import traceback
|
||||
try:
|
||||
# Python 2
|
||||
@ -180,6 +181,32 @@ class APIMetricsView(MetricsView):
|
||||
template_name = 'metrics/api.html'
|
||||
api_urlpath = '/management/metrics'
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.api = API(request.session.get('obp'))
|
||||
return super(APIMetricsView, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_form(self, *args, **kwargs):
|
||||
form = super(APIMetricsView, self).get_form(*args, **kwargs)
|
||||
# Cannot add api in constructor: super complains about unknown kwarg
|
||||
form.api = self.api
|
||||
fields = form.fields
|
||||
try:
|
||||
fields['consumer_id'].choices = self.api.get_consumer_id_choices()
|
||||
#fields['apiShortVersion'].choices = self.api.get_api_version_choices()
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
except Exception as err:
|
||||
messages.error(self.request, err)
|
||||
return form
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(APIMetricsView, self).get_context_data(**kwargs)
|
||||
context.update({
|
||||
'consumer_id': get_consumers(self.request)
|
||||
#'API_VERSION': get_api_versions(self.request)
|
||||
})
|
||||
return context
|
||||
|
||||
|
||||
class APISummaryPartialFunctionView(APIMetricsView):
|
||||
template_name = 'metrics/api_summary_partial_function.html'
|
||||
|
||||
@ -160,6 +160,22 @@ class API(object):
|
||||
for bank in sorted(result['banks'], key=lambda d: d['id']) :
|
||||
choices.append((bank['id'], bank['id']))
|
||||
return choices
|
||||
def get_consumer_id_choices(self):
|
||||
"""Gets a list of Consumer ids and consumer ids as used by form choices"""
|
||||
choices = [('', _('Choose ...'))]
|
||||
result = self.get('/management/consumers')
|
||||
for consumer in sorted(result['consumers'], key=lambda d: d['consumer_id']) :
|
||||
choices.append((consumer['consumer_id'], consumer['consumer_id']))
|
||||
return choices
|
||||
|
||||
def get_api_version_choices(self):
|
||||
"""Gets a list of APIs Version and APIs Version as used by form choices"""
|
||||
choices = [('', _('Choose ...'))]
|
||||
result = self.get('/api/versions')
|
||||
for apiversion in sorted(result['scanned_api_versions'], key=lambda d: d['apiShortVersion']) :
|
||||
choices.append((apiversion['apiShortVersion'], apiversion['apiShortVersion']))
|
||||
return choices
|
||||
|
||||
|
||||
def get_user_id_choices(self):
|
||||
"""Gets a list of user ids and usernames as used by form choices"""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user