Ticket #5620: newforms_xmlfield.diff
File newforms_xmlfield.diff, 1.9 KB (added by , 16 years ago) |
---|
-
db/models/fields/__init__.py
1157 1157 self.schema_path = schema_path 1158 1158 Field.__init__(self, verbose_name, name, **kwargs) 1159 1159 1160 def formfield(self, **kwargs): 1161 defaults = {'form_class': forms.XMLField} 1162 defaults.update(kwargs) 1163 return super(XMLField, self).formfield(**defaults) 1164 1160 1165 def get_manipulator_field_objs(self): 1161 1166 return [curry(oldforms.XMLLargeTextField, schema_path=self.schema_path)] 1162 1167 -
newforms/fields.py
32 32 'RegexField', 'EmailField', 'FileField', 'ImageField', 'URLField', 33 33 'BooleanField', 'NullBooleanField', 'ChoiceField', 'MultipleChoiceField', 34 34 'ComboField', 'MultiValueField', 'FloatField', 'DecimalField', 35 'SplitDateTimeField', 'IPAddressField', 'FilePathField', 35 'SplitDateTimeField', 'IPAddressField', 'FilePathField', 'XMLField' 36 36 ) 37 37 38 38 # These values, if given to to_python(), will trigger the self.required check. … … 782 782 783 783 def __init__(self, *args, **kwargs): 784 784 super(IPAddressField, self).__init__(ipv4_re, *args, **kwargs) 785 786 class XMLField(CharField): 787 """ 788 A field that validates XML content against a RelaxNG schema 789 """ 790 def __init__(self, schema_path): 791 self.schema_path = schema_path 792 793 def clean(self, value): 794 from django.core.validators import RelaxNGCompact, ValidationError as OldValidationError 795 validator = RelaxNGCompact(self.schema_path) 796 try: 797 validator(value, "") # second arg isn't used but is required 798 except OldValidationError, e: 799 raise ValidationError(e.messages) 800 return value