mirror of
https://github.com/OpenBankProject/API-Manager.git
synced 2026-02-06 12:46:54 +00:00
fix webui save function
This commit is contained in:
parent
23f75ad841
commit
945cf02814
@ -28,7 +28,7 @@ $(document).ready(function($) {
|
||||
$.post('methodrouting/delete/method', {
|
||||
'method_routing_id': method_routing_id
|
||||
}, function (response) {
|
||||
t.next().show().fadeOut(1000);
|
||||
t.parent().parent().parent().remove();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -85,7 +85,7 @@
|
||||
</div>
|
||||
<div class="col-sm-12 col-sm-2">
|
||||
<div class="form-group">
|
||||
<button class="btn btn-primary btn-green forSave">Save</button>
|
||||
<button class="btn btn-primary btn-green forSave">Save</button><span style="display: none;margin-left: 5px;background-color:#00cc00">saved.</span>
|
||||
<button class="btn btn-primary btn-red forDelete">Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -5,7 +5,8 @@ URLs for config app
|
||||
|
||||
from django.conf.urls import url
|
||||
|
||||
from .views import IndexView, methodrouting_save, methodrouting_delete
|
||||
#from .views import IndexView, methodrouting_save, methodrouting_delete
|
||||
from methodrouting.views import IndexView, methodrouting_save, methodrouting_delete
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$',
|
||||
|
||||
@ -10,20 +10,11 @@ from django.contrib import messages
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.views.generic import FormView
|
||||
from obp.api import API, APIError
|
||||
from utils.ErrorHandler import exception_handle, error_once_only
|
||||
from .forms import MethodRoutingForm
|
||||
from django.urls import reverse_lazy
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
def error_once_only(request, err):
|
||||
"""
|
||||
Just add the error once
|
||||
:param request:
|
||||
:param err:
|
||||
:return:
|
||||
"""
|
||||
storage = messages.get_messages(request)
|
||||
if str(err) not in [str(m.message) for m in storage]:
|
||||
messages.error(request, err)
|
||||
|
||||
class IndexView(LoginRequiredMixin, FormView):
|
||||
"""Index view for config"""
|
||||
@ -38,16 +29,22 @@ class IndexView(LoginRequiredMixin, FormView):
|
||||
|
||||
try:
|
||||
response = api.get(urlpath)
|
||||
if 'code' in response and response['code'] >= 400:
|
||||
error_once_only(self.request, response['message'])
|
||||
else:
|
||||
msg = 'Submission successfully!'
|
||||
messages.success(self.request, msg)
|
||||
except APIError as err:
|
||||
messages.error(self.request, Exception("OBP-API server is not running or do not response properly. "
|
||||
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)))
|
||||
except BaseException as err:
|
||||
messages.error(self.request, (Exception("Unknown Error. Details:" + str(err))))
|
||||
error_once_only(self.request, (Exception("Unknown Error. Details:" + str(err))))
|
||||
else:
|
||||
context.update(response)
|
||||
return context
|
||||
|
||||
@exception_handle
|
||||
@csrf_exempt
|
||||
def methodrouting_save(request):
|
||||
method_name = request.POST.get('method_name')
|
||||
@ -66,42 +63,21 @@ def methodrouting_save(request):
|
||||
'method_routing_id':method_routing_id
|
||||
}
|
||||
|
||||
if method_routing_id!="":
|
||||
method_routing_id = "/"+method_routing_id
|
||||
|
||||
api = API(request.session.get('obp'))
|
||||
try:
|
||||
if(""==method_routing_id): # if method_routing_id=="". we will create a new method routing .
|
||||
urlpath = '/management/method_routings'
|
||||
result = api.post(urlpath, payload=payload)
|
||||
else: # if method_routing_id not empty. we will update the current method routing ..
|
||||
urlpath = '/management/method_routings/{}'.format(method_routing_id)
|
||||
result = api.put(urlpath, payload=payload)
|
||||
except APIError as err:
|
||||
error_once_only(request, APIError(Exception("OBP-API server is not running or do not response properly. "
|
||||
"Please check OBP-API server. Details: " + str(err))))
|
||||
except Exception as err:
|
||||
error_once_only(request, "Unknown Error. Details: " + str(err))
|
||||
if 'code' in result and result['code'] >= 400:
|
||||
error_once_only(request, result['message'])
|
||||
msg = 'Submission successfully!'
|
||||
messages.success(request, msg)
|
||||
return JsonResponse({'state': True})
|
||||
|
||||
urlpath = '/management/method_routings{}'.format(method_routing_id)
|
||||
result = api.put(urlpath, payload=payload)
|
||||
return result
|
||||
|
||||
@exception_handle
|
||||
@csrf_exempt
|
||||
def methodrouting_delete(request):
|
||||
method_routing_id = request.POST.get('method_routing_id')
|
||||
|
||||
api = API(request.session.get('obp'))
|
||||
|
||||
try:
|
||||
urlpath = '/management/method_routings/{}'.format(method_routing_id)
|
||||
result = api.delete(urlpath)
|
||||
except APIError as err:
|
||||
error_once_only(request, APIError(Exception("OBP-API server is not running or do not response properly. "
|
||||
"Please check OBP-API server. Details: " + str(err))))
|
||||
except Exception as err:
|
||||
error_once_only(request, "Unknown Error. Details: " + str(err))
|
||||
if 'code' in result and result['code'] >= 400:
|
||||
error_once_only(request, result['message'])
|
||||
msg = 'Submission successfully!'
|
||||
messages.success(request, msg)
|
||||
return JsonResponse({'state': True})
|
||||
urlpath = '/management/method_routings/{}'.format(method_routing_id)
|
||||
result = api.delete(urlpath)
|
||||
return result
|
||||
33
apimanager/utils/ErrorHandler.py
Normal file
33
apimanager/utils/ErrorHandler.py
Normal file
@ -0,0 +1,33 @@
|
||||
from django.contrib import messages
|
||||
import functools
|
||||
from obp.api import API, APIError
|
||||
from django.http import JsonResponse
|
||||
|
||||
def error_once_only(request, err):
|
||||
"""
|
||||
Just add the error once
|
||||
:param request:
|
||||
:param err:
|
||||
:return:
|
||||
"""
|
||||
storage = messages.get_messages(request)
|
||||
if str(err) not in [str(m.message) for m in storage]:
|
||||
messages.error(request, err)
|
||||
|
||||
def exception_handle(fn):
|
||||
@functools.wraps(fn)
|
||||
def wrapper(request, *args, **kwargs):
|
||||
try:
|
||||
result = fn(request, *args, **kwargs)
|
||||
if 'code' in result and result['code'] >= 400:
|
||||
error_once_only(request, result['message'])
|
||||
else:
|
||||
msg = 'Submission successfully!'
|
||||
messages.success(request, msg)
|
||||
except APIError as err:
|
||||
error_once_only(request, APIError(Exception("OBP-API server is not running or do not response properly. "
|
||||
"Please check OBP-API server. Details: " + str(err))))
|
||||
except Exception as err:
|
||||
error_once_only(request, "Unknown Error. Details: " + str(err))
|
||||
return JsonResponse({'state': True})
|
||||
return wrapper
|
||||
0
apimanager/utils/__init__.py
Normal file
0
apimanager/utils/__init__.py
Normal file
Loading…
Reference in New Issue
Block a user