Changes between Initial Version and Version 1 of ValidationHelperFunctionsProposal


Ignore:
Timestamp:
Sep 11, 2007, 11:45:18 AM (17 years ago)
Author:
amitu
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ValidationHelperFunctionsProposal

    v1 v1  
     1=== Validation Helpers For newform ===
     2
     3Please read this [http://groups.google.com/group/django-developers/browse_thread/thread/86618e7a09a13da0 thread] to get some background.
     4
     5== assure(expression, message) ==
     6
     7This will raise !ValidationError(message) if expression evaluates to false.
     8
     9== assure_false(expression, msg) ==
     10
     11This will raise !ValidationError(msg) if expression evalautes to true.
     12
     13== assure_almost_equal(first, second, msg, delta=0.1) ==
     14
     15Tests if first and second differ by less than delta, raise !ValidationError(msg) otherwise.
     16
     17== assure_not_almost_equal(first, second, msg, delat=0.1) ==
     18
     19Tests if first and second are further than delta apart, otherwise raises !ValidationError(msg).
     20
     21== assure_exception(exception, msg, callable, *args, **kw) ==
     22
     23Calls calls the callable: callable(*args, **kw) and raises !ValidationError if callable did not raise the exception. exception can optionally be a sequence contains more than one exceptions, in this case !ValidationError will be raised if either no exception was raised by the callable or exception not in the list was raised.
     24
     25== assure_no_exception(exception, msg, callable, *args, **kw) ==
     26
     27Calls calls the callable: callable(*args, **kw) and raises !ValidationError if callable did not raise the exception. exception can optionally be a sequence contains more than one exceptions, in this case !ValidationError will be raised if callable raised an exception that is an isntance of any exception class in the sequence.
     28
     29== assure_valid_email(data, msg) ==
     30
     31Will raise !ValdationError(msg) if data is not a valid email. This may be helpful when taking comma separated email addresses as input for example.
     32
     33== assure_valid_slug(data, msg) ==
     34
     35Will raise !ValidationError(msg) if data is not a valid slug. This may be helpful when generating slug based on other fields for example.
     36
     37== assure_valid_* ==
     38
     39(assure_valid_int, assure_valid_float, assure_valid_url, etc)
     40
     41Other validation shortcuts for django defined fields. This will be simpler than importing the regex from appropriate django module, and calling .match on it. Such functions are helpful when the field value is not being validated on as such, but when intermediate strings derived from field values are being validated.
     42
     43== assure_date_before(date, future_date, msg) ==
     44
     45This will raise !ValidationError(msg) if date is not before future_date.
     46
     47== assure_date_in_range(date, first_date, second_date, msg) ==
     48
     49This will raise !ValidationError(msg) if date is not withing first_date and second_date.
Back to Top