misc: remove unused validate-expression API (#86827)
gitea/wcs/pipeline/head This commit looks good Details

This commit is contained in:
Frédéric Péters 2024-02-11 12:24:03 +01:00
parent 8b2cd7d0e5
commit ee6543f463
4 changed files with 0 additions and 69 deletions

View File

@ -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': ''}

View File

@ -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 ''

View File

@ -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');

View File

@ -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()),