Login

Tag "validator"

Snippet List

CleanCharField

I was about to start an online community but every time you allow people to post something as a comment you never know what they come up to, especially regarding profanities. So I come up with this idea, I put together some code from the old style form validators and the new newform style, plus some code to sanitize HTML from snippet number [169](http://www.djangosnippets.org/snippets/169/), and the final result is a CharField that only accept values without swear words, profanities, curses and bad html. Cheers.

  • validator
  • newforms
  • forms
  • html
  • sanitize
  • profanities
Read More
Author: DvD
  • -2
  • 0

Self-referencing Foreign Key Infinite Loop

Make sure we don't create an infinite loop with a self-referencing foreign key. Many times I have needed category models that reference themselves, providing a flexible way to make children categories, grandchildren categories, etc. If you chain the slugs (or even ids) there's a chance you could end up with an infinite loop. Assumes a required, unique slug field ('slug') and an optional self-referencing foreign key ('parent'). All_data doesn't give you the object's ID, so we will find it via the unique slug. If either is not present we pass -- if there's no parent chosen it's not a problem, and if there is no slug present the submission will fail on that validation instead. It is worth noting that if the user changes the slug field on submission AND picks a bad parent it will not be caught. Infinite loop cases: 1. A references A 2. A tries to reference B, which is currently referencing A

  • validator
  • foreignkey
Read More

SAS70 Compliant Password Validator

Validator to verify a password is SAS70 compliant: greater than or equal to eight characters, and contains at least three out of the four characters( Uppercase, Lowercase, Number, Special Character ).

  • validator
Read More

Validator for data

This module is not aimed to replace the newforms, but I would like manually write html code, and just need a pure validate module, so I write this, and many things may be similar with newforms. So if you like me would only need a pure validator module, you can use it. And it has some different features from newforms: 1. Support validator_list parameter, so you could use it just like the old manipuator class 2. Supply easy method, such as `validate_and_save()`, so you can pass a request object, and get a tuple result `(flag, obj_or_error)`, if the `flag` is `True`, then the next value is an object; and if the `flag` is `False`, then the next value is error message. 3. Each field has a `validate_and_get` method, and it'll validate first and then return the result, maybe an object or error message. Just like above. 4. SplitDateTimeField is somewhat different from the newforms. For example:: c = SplitDateTimeField('date', 'time') print c.validate_and_get({'date':'2006/11/30', 'time':'12:13'}) So the first parameter is DateField's field_name, and the second parameter is TimeField's field_name. 5. Add yyyy/mm/dd date format support 6. Support default value of a field. You can add a default value for a field, if this field is not required, and the value is *empty*, Validator will return the default value. This module is new, so many things could be changed.

  • validator
Read More

5 snippets posted so far.