Python django.forms() Examples

The following are 1 code examples for showing how to use django.forms(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may want to check out the right sidebar which shows the related API usage.

You may also want to check out all available functions/classes of the module django , or try the search function .

Example 1
Project: Dailyfresh-B2C   Author: BeanWei   File: utils.py    License: Apache License 2.0 6 votes vote down vote up
def raw_validation(error):
    """
    Deconstruct a django.forms.ValidationError into a primitive structure
    eg, plain dicts and lists.
    """
    if isinstance(error, ValidationError):
        if hasattr(error, 'error_dict'):
            error = error.error_dict
        elif not hasattr(error, 'message'):
            error = error.error_list
        else:
            error = error.message

    if isinstance(error, dict):
        return {key: raw_validation(value) for key, value in error.items()}
    elif isinstance(error, list):
        return [raw_validation(value) for value in error]
    else:
        return error