Removed Sobol's automatic use of eventlet. Adjusted imports project-wide to conform...
[philo.git] / philo / forms / fields.py
1 from django import forms
2 from django.core.exceptions import ValidationError
3 from django.utils import simplejson as json
4
5 from philo.validators import json_validator
6
7
8 __all__ = ('JSONFormField',)
9
10
11 class JSONFormField(forms.Field):
12         default_validators = [json_validator]
13         
14         def clean(self, value):
15                 if value == '' and not self.required:
16                         return None
17                 try:
18                         return json.loads(value)
19                 except Exception, e:
20                         raise ValidationError(u'JSON decode error: %s' % e)