summaryrefslogtreecommitdiff
path: root/postgresqleu/util/request.py
diff options
context:
space:
mode:
authorMagnus Hagander2023-07-13 15:24:13 +0000
committerMagnus Hagander2023-07-13 15:24:13 +0000
commite83cd018f524822ac3896fe2b0a3aef1b248315b (patch)
treedd798f90440e61bcc49459c35658b4aa37c5e204 /postgresqleu/util/request.py
parentb9a98e32c6fa05c874dfb4025005ca4c974e2990 (diff)
Add support for negative integers to get_int_or_error
Diffstat (limited to 'postgresqleu/util/request.py')
-rw-r--r--postgresqleu/util/request.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/postgresqleu/util/request.py b/postgresqleu/util/request.py
index 878763d5..b7729676 100644
--- a/postgresqleu/util/request.py
+++ b/postgresqleu/util/request.py
@@ -1,14 +1,20 @@
from django.http import Http404
-def get_int_or_error(reqmap, paramname, default=None):
+def get_int_or_error(reqmap, paramname, default=None, allow_negative=False):
if paramname not in reqmap:
if default:
return default
raise Http404("Parameter {} missing".format(paramname))
p = reqmap.get(paramname)
+ if allow_negative and p.startswith('-'):
+ p = p[1:]
+ negative = -1
+ else:
+ negative = 1
+
if not p.isnumeric():
raise Http404("Parameter {} is not an integer".format(paramname))
- return int(p)
+ return int(p) * negative