diff --git a/tests/api/test_all.py b/tests/api/test_all.py index 9451c08b4..7247af4fc 100644 --- a/tests/api/test_all.py +++ b/tests/api/test_all.py @@ -125,33 +125,6 @@ def test_tracking_code(pub, auth, admin_user): resp = get_url('/api/code/%s' % code.id, status=404) -def test_validate_expression(pub): - resp = get_app(pub).get('/api/validate-expression?expression=hello') - assert resp.json == {'klass': None, 'msg': ''} - resp = get_app(pub).get('/api/validate-expression?expression=[hello]') - assert resp.json == {'klass': None, 'msg': ''} - resp = get_app(pub).get('/api/validate-expression?expression==[hello') - assert resp.json['klass'] == 'error' - assert resp.json['msg'].startswith('syntax error') - resp = get_app(pub).get('/api/validate-expression?expression==[hello]') - assert resp.json['klass'] == 'warning' - assert resp.json['msg'].startswith('Make sure you want a Python expression,') - resp = get_app(pub).get('/api/validate-expression?expression==hello[0]') - assert resp.json == {'klass': None, 'msg': ''} - resp = get_app(pub).get('/api/validate-expression?expression==hello[\'plop\']') - assert resp.json == {'klass': None, 'msg': ''} - # django with unicode - resp = get_app(pub).get('/api/validate-expression?expression={{hello+%C3%A9l%C3%A9phant}}') - assert resp.json['klass'] == 'error' - assert resp.json['msg'].startswith('syntax error in Django template: Could not parse the remainder') - # broken ezt - resp = get_app(pub).get('/api/validate-expression?expression=[for]') - assert resp.json == { - 'klass': 'error', - 'msg': 'syntax error in ezt template: wrong number of arguments at line 1 and column 1', - } - - def test_validate_condition(pub): resp = get_app(pub).get('/api/validate-condition?type=python&value_python=hello') assert resp.json == {'klass': None, 'msg': ''} diff --git a/wcs/api.py b/wcs/api.py index 1c2f3b8ac..3fb5e0256 100644 --- a/wcs/api.py +++ b/wcs/api.py @@ -18,7 +18,6 @@ import base64 import copy import datetime import json -import re import time import urllib.parse @@ -64,7 +63,6 @@ from .backoffice.management import ManagementDirectory from .backoffice.submission import SubmissionDirectory from .qommon import _, misc from .qommon.errors import AccessForbiddenError, TraversalError, UnknownNameIdAccessForbiddenError -from .qommon.form import ComputedExpressionWidget from .qommon.template import Template, TemplateError @@ -1464,21 +1462,6 @@ def geocoding(request, *args, **kwargs): return HttpResponse(misc.urlopen(url).read(), content_type='application/json') -def validate_expression(request, *args, **kwargs): - expression = request.GET.get('expression') - hint = {'klass': None, 'msg': ''} - try: - ComputedExpressionWidget.validate(expression) - except ValidationError as e: - hint['klass'] = 'error' - hint['msg'] = str(e) - else: - if expression and re.match(r'^=.*\[[a-zA-Z_]\w*\]', expression): - hint['klass'] = 'warning' - hint['msg'] = _('Make sure you want a Python expression, not a simple template string.') - return JsonResponse(hint) - - def validate_condition(request, *args, **kwargs): condition = {} condition['type'] = request.GET.get('type') or '' diff --git a/wcs/qommon/static/js/qommon.admin.js b/wcs/qommon/static/js/qommon.admin.js index 457e17560..baee96be3 100644 --- a/wcs/qommon/static/js/qommon.admin.js +++ b/wcs/qommon/static/js/qommon.admin.js @@ -127,30 +127,6 @@ $(function() { }); }); - /* hints on the computed expression widget */ - var validation_timeout_id = 0; - $('input[data-validation-url]').on('change focus input', function() { - var val = $(this).val(); - var $widget = $(this).parents('.ComputedExpressionWidget'); - var validation_url = $(this).data('validation-url'); - clearTimeout(validation_timeout_id); - validation_timeout_id = setTimeout(function() { - $.ajax({ - url: validation_url, - data: {expression: val}, - dataType: 'json', - success: function(data) { - $widget.removeClass('hint-warning'); - $widget.removeClass('hint-error'); - if (data.klass) { - $widget.addClass('hint-' + data.klass); - } - $widget.prop('title', data.msg); - } - })}, 250); - return false; - }); - $('div[data-validation-url]').each(function(idx, elem) { var $widget = $(this); var widget_name = $widget.find('input').attr('name'); diff --git a/wcs/urls.py b/wcs/urls.py index 34d3ebc8c..1726c7328 100644 --- a/wcs/urls.py +++ b/wcs/urls.py @@ -50,7 +50,6 @@ urlpatterns = [ name='api-export-import-object-redirect', ), path('api/validate-condition', api.validate_condition, name='api-validate-condition'), - path('api/validate-expression', api.validate_expression, name='api-validate-expression'), path('api/reverse-geocoding', api.reverse_geocoding, name='api-reverse-geocoding'), path('api/geocoding', api.geocoding, name='api-geocoding'), path('api/statistics/', statistics_views.IndexView.as_view()),