def _get_value(self, value): # Fetch the value from the list or dict values = self.field.allowed_values if isinstance(values, list): return smart_unicode(value) else: return smart_unicode(values[value])
def render(self, name, value, attrs=None): if value is None: value = "" final_attrs = self.build_attrs(attrs, type=self.input_type, name=name) if value != "": final_attrs["value"] = smart_unicode(value) return u"<input%s />" % flatatt(final_attrs)
def clean(self, value): super(CharField, self).clean(value) value = smart_unicode(value) if value in EMPTY_VALUES: return u'' if len(value) > self.max_length: raise ValidationError(_(u'Value can only be up to %d characters long') % self.max_length) if len(value) < self.min_length: raise ValidationError(_(u'Value must be at least %d characters long') % self.min_length) return value
def clean(self, value): super(RegexField, self).clean(value) if value in EMPTY_VALUES: value = u'' value = smart_unicode(value) if value == u'': return value if self.max_length is not None and len(value) > self.max_length: raise ValidationError(_(u'Value must have has at most %d characters.') % self.max_length) if self.min_length is not None and len(value) < self.min_length: raise ValidationError(_(u'Value must have at least %d characters.') % self.min_length) if not self.regex.search(value): raise ValidationError(self.error_message) return value
def render(self, name, value, attrs=None): if value is None: value = "" # default value final_attrs = self.build_attrs(attrs, name=name) return u"<textarea" + flatatt(final_attrs) + u">" + smart_unicode(value) + u"</textarea>"