Login

Snippets by limodou

Snippet List

convert plain text to html

Convert plain text to html. For example: text="""aabhttp://www.example.com http://www.example.com http://www.example.com <<< [<aaaa></aaaa>] """ print plaintext2html(text) It can convert url text to html href. And it also can convert space to &nbsp;. So if you paste python code, the indent will not lost at all. Default it'll convert \t to 4 spaces.

  • text
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