diff --git a/apimanager/methodrouting/models.py b/apimanager/methodrouting/models.py deleted file mode 100644 index 535610f..0000000 --- a/apimanager/methodrouting/models.py +++ /dev/null @@ -1,56 +0,0 @@ -from django.db import models -from django.conf import settings - -class MethodRouting(models.Model): - - method = models.CharField( - max_length=255, - verbose_name="Operation id ", - help_text="Test endpoint opreation id", - blank=True, - null=True - ) - - bank_id_pattern = models.CharField( - max_length=255, - verbose_name="bank_id_pattern id ", - help_text="bank_id_pattern", - blank=True, - null=True - ) - - parameters = models.CharField( - max_length=255, - verbose_name="parameters ", - help_text="parameters", - blank=True, - null=True - ) - - value = models.CharField( - max_length=255, - verbose_name="value", - help_text="value", - blank=True, - null=True, - ) - - select2 = models.CharField( - max_length=255, - verbose_name="select2", - help_text="select2", - blank=True, - null=True, - ) - - select1 = models.CharField( - max_length=255, - verbose_name="select1", - help_text="select1", - blank=True, - null=True, - ) - - class Meta: - verbose_name = 'Test Profile Operation' - verbose_name_plural = 'Test Profile Operation' diff --git a/apimanager/methodrouting/static/methodrouting/js/methodrouting.js b/apimanager/methodrouting/static/methodrouting/js/methodrouting.js index afa5308..b16334d 100644 --- a/apimanager/methodrouting/static/methodrouting/js/methodrouting.js +++ b/apimanager/methodrouting/static/methodrouting/js/methodrouting.js @@ -1,45 +1,19 @@ $(document).ready(function($) { - function syntaxHighlight(json) { - if (typeof json != 'string') { - json = JSON.stringify(json, undefined, 2); - } - json = json.replace(/&/g, '&').replace(//g, '>'); - 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 '' + match + ''; - }); - } - - $('#config-json').html((syntaxHighlight(ConfigJson))); - - $('.runner button.forSave').click(function() { + $('.runner button#forSave').click(function() { var t = $(this); var runner = $(this).parent().parent().parent(); - select1 = $(runner).find('#select1').val(); - select2 = $(runner).find('#select2').val(); - method = $(runner).find('#method_name').innerHTML; + method_name = $(runner).find('#method_name').html(); + connector_name = $(runner).find('#connector_name').val(); bank_id_pattern = $(runner).find('textarea[name="bank_id_pattern"]').val(); + is_bank_id_exact_match = $(runner).find('#is_bank_id_exact_match').val(); parameters = $(runner).find('textarea[name="parameters"]').val(); - $.post('/methodrouting/save/method', { - 'method': method, - 'value': value, - 'select1': select1, - 'select2': select2, + $.post('methodrouting/save/method', { + 'method_name': method_name, + 'connector_name': connector_name, 'bank_id_pattern': bank_id_pattern, - 'parameters': parameters, - 'csrfmiddlewaretoken': window.CSRF + 'is_bank_id_exact_match': is_bank_id_exact_match, + 'parameters': parameters }, function (response) { t.next().show().fadeOut(1000); }); diff --git a/apimanager/methodrouting/templates/methodrouting/index.html b/apimanager/methodrouting/templates/methodrouting/index.html index 7051a46..3e8557f 100644 --- a/apimanager/methodrouting/templates/methodrouting/index.html +++ b/apimanager/methodrouting/templates/methodrouting/index.html @@ -1,77 +1,72 @@ {% extends 'base.html' %} {% load static %} - {% block page_title %}{{ block.super }} / Users{% endblock page_title %} +{% block extrajs %} + +{% endblock extrajs %} +{% block extracss %} + +{% endblock extracss %} {% block content %} -
-
-

Method Routing

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+

Method Routing

+ +
+
+
-
- {% csrf_token %} - {% for method_routhing in method_routhings %} +
+
+
+
+
+
+
+
+
+
+
+
+
+ {% for method_routhing in method_routhings %} +
-
-
-
{{ method_routhing.method_name }}
-
-
- -
-
- -
-
- -
-
- -
-
-
- -
+
+
+ {{ method_routhing.method_name }}
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
- {% endfor %} - -
-
-{% endblock %} - -{% block extrajs %} - - -{% endblock extrajs %} - - -{% block extracss %} - -{% endblock extracss %} +
+ {% endfor %} +{% endblock %} \ No newline at end of file diff --git a/apimanager/methodrouting/views.py b/apimanager/methodrouting/views.py index 7121212..426cf8d 100644 --- a/apimanager/methodrouting/views.py +++ b/apimanager/methodrouting/views.py @@ -12,7 +12,7 @@ from django.views.generic import FormView from obp.api import API, APIError from .forms import MethodRoutingForm from django.urls import reverse_lazy -from .models import MethodRouting +from django.views.decorators.csrf import csrf_exempt def error_once_only(request, err): """ @@ -31,10 +31,6 @@ class IndexView(LoginRequiredMixin, FormView): form_class = MethodRoutingForm success_url = reverse_lazy('methodrouting-index') - def dispatch(self, request, *args, **kwargs): - self.api = API(request.session.get('obp')) - return super(IndexView, self).dispatch(request, *args, **kwargs) - def get_context_data(self, **kwargs): context = super(IndexView, self).get_context_data(**kwargs) method_routhings=json.loads("""{ @@ -214,69 +210,36 @@ class IndexView(LoginRequiredMixin, FormView): context.update({'method_routhings': method_routhings["method_routings"]}) return context - def get_form(self, *args, **kwargs): - form = super(IndexView, self).get_form(*args, **kwargs) - # Cannot add api in constructor: super complains about unknown kwarg - fields = form.fields - form.api = self.api - try: - fields['method_routing_body'].initial = "" - except APIError as err: - messages.error(self.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: - messages.error(self.request, "Unknown Error. Details: "+ str(err)) - - return form - - def form_valid(self, form): - try: - data = form.cleaned_data - urlpath = '/management/method_routings' - payload = json.loads(data["method_routing_body"]) - result = self.api.post(urlpath, payload=payload) - except APIError as err: - error_once_only(self.request, APIError(Exception("OBP-API server is not running or do not response properly. " - "Please check OBP-API server. Details: " + str(err)))) - return super(IndexView, self).form_invalid(form) - except Exception as err: - error_once_only(self.request, "Unknown Error. Details: "+ str(err)) - return super(IndexView, self).form_invalid(form) - if 'code' in result and result['code']>=400: - error_once_only(self.request, result['message']) - return super(IndexView, self).form_valid(form) - msg = 'Submission successfully!' - messages.success(self.request, msg) - return super(IndexView, self).form_valid(form) +@csrf_exempt def methodrouting_save(request): - method = request.POST.get('method') - value = request.POST.get('value') - select1 = request.POST.get('select1') - select2 = request.POST.get('select2') + method_name = request.POST.get('method_name') + connector_name = request.POST.get('connector_name') bank_id_pattern = request.POST.get('bank_id_pattern') + is_bank_id_exact_match = request.POST.get('is_bank_id_exact_match') parameters = request.POST.get('parameters') - #if not re.match("^{.*}$", json_body): - # json_body = "{{{}}}".format(json_body) - - data = { - 'method' : method, - 'value': value, - 'select1': select1, - 'select2': select2, + payload = { + 'method_name' : method_name, + 'connector_name': connector_name, + 'is_bank_id_exact_match': bool(is_bank_id_exact_match), 'bank_id_pattern':bank_id_pattern, - 'parameters':parameters + 'parameters':eval(parameters) } - profile_list = MethodRouting.objects.update_or_create( - method=method, - value=value, - select1=select1, - select2=select2, - bank_id_pattern=bank_id_pattern, - parameters=parameters - ) + api = API(request.session.get('obp')) + try: + urlpath = '/management/method_routings' + result = api.post(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}) \ No newline at end of file