Adding a check-filter to request.values.get() function

Issue #35 invalid
Akash Sinha created an issue

In request.values.get('param', 0) function if the param value is None, it returns the default value i.e 0 here. What if we could also apply a check that if param value doesn't lie in a specified range, in that case also it may return the default one.

Something like this request.values.get('param', 0, ValueAtLeast(0)) So in above if the param value is -1, then also function should return the value 0.

Comments (1)

  1. Thomas Waldmann repo owner

    How can a param value be None? request.values is a dict key -> value and all values are unicode, right?

    If you say their value is None, are you referring to the return value of .get('param')? This is returning None if it could not find 'param' key in the dict (so None is the default). If you use .get('param', 0), you specify that you want 0 as default.

    As that is specified standard behaviour of dict.get() (same for dict-like objects), we won't change that.

    Maybe we can solve that problem with form validation with flatland.

  2. Log in to comment