from django import forms from django.forms import * from django.utils.functional import curry from django.utils.html import escape from django.conf import settings ### OVERRIDEN FORM FIELDS class TextField(forms.TextField): input_type = "text" def __init__(self, *args, **kwargs): try: self.html_attributes = kwargs.pop('html_attributes') except KeyError, e: self.html_attributes = {} forms.TextField.__init__(self, *args, **kwargs) def render(self, data): if data is None: data = '' if isinstance(data, unicode): data = data.encode(settings.DEFAULT_CHARSET) fa = self.html_attributes.copy() fa['type'] = self.input_type fa['id'] = self.get_id() fa['name'] = self.field_name fa['value'] = escape(data) if not fa.has_key('size'): fa['size'] = self.length if self.maxlength: fa['maxlength'] = self.maxlength css_classes = 'v%s%s' % (self.__class__.__name__, self.is_required and ' required' or '') if fa.has_key('class'): fa['class'] = '%s %s' % (css_classes, fa['class']) else: fa['class'] = css_classes attributes = ' '.join(['%s="%s"' % attr for attr in fa.items()]) buffer = '' % attributes return buffer class LargeTextField(forms.LargeTextField): def __init__(self, *args, **kwargs): try: self.html_attributes = kwargs.pop('html_attributes') except KeyError, e: self.html_attributes = {} forms.LargeTextField.__init__(self, *args, **kwargs) def render(self, data): if data is None: data = '' if isinstance(data, unicode): data = data.encode(settings.DEFAULT_CHARSET) fa = self.html_attributes.copy() fa['id'] = self.get_id() fa['name'] = self.field_name if not fa.has_key('rows'): fa['rows'] = self.rows if not fa.has_key('cols'): fa['cols'] = self.cols css_classes = 'v%s%s' % (self.__class__.__name__, self.is_required and ' required' or '') if fa.has_key('class'): fa['class'] = '%s %s' % (css_classes, fa['class']) else: fa['class'] = css_classes attributes = ' '.join(['%s="%s"' % attr for attr in fa.items()]) buffer = '
' % \ (attributes, escape(data)) return buffer