id,summary,reporter,owner,description,type,status,priority,milestone,component,version,severity,resolution,keywords,cc,branch,changelog,apichanges,internalchanges 12426,Add as_int and as_bool methods to the Request class,Ryan J Ollos,Ryan J Ollos,"comment:5:ticket:12325 suggested adding `as_int` and `as_bool` methods to the `Request` class. This was discussed further a bit later in the ticket. `as_int` and `as_bool` in `trac.util` do not raise exceptions. Perhaps we should be somewhat consistent with the interface of those functions. We could add two pairs of methods with the following behaviors: * `as_int(self, name, default=None, min=None, max=None)` * Return `default` if `name` not in dict * Return `default` if exception raised converting `self[name]` to an int * `getint(self, name, default=None, min=None, max=None)` * Return `default` if `name` not in dict * Raise `HTTPBadRequest` if exception is raised converting `self[name]` to an int `get_int` would be a better name, but `getint` is more consistent with `getfirst` and `getlist`. Also it seems reasonable to expect that a `get` method might raise an exception.",enhancement,closed,normal,1.2,web frontend,,normal,fixed,,,,,"* Added `as_bool` to `_RequestArgs`, which converts the value to a boolean or returns a default if an exception is raised. * Added `as_int` to `_RequestArgs`, which converts the value to an int or returns a default if an exception is raised. * Added `getbool` to `_RequestArgs`, which gets the value as a boolean or raises an `HTTPBadRequest` exception on invalid input. * Added `getint` to `_RequestArgs`, which gets the value as an integer or raises an `HTTPBadRequest` exception on invalid input. * Added `require` to `_RequestArgs`, which raises an `HTTPBadRequest` exception if the parameter is not in the dictionary.",