Changeset 4163
- Timestamp:
- 12/05/06 14:08:27 (2 years ago)
- Files:
-
- django/trunk/django/newforms/forms.py (modified) (5 diffs)
- django/trunk/django/newforms/util.py (modified) (2 diffs)
- django/trunk/django/newforms/widgets.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/newforms/forms.py
r4160 r4163 7 7 from fields import Field 8 8 from widgets import TextInput, Textarea, HiddenInput 9 from util import ErrorDict, ErrorList, ValidationError9 from util import StrAndUnicode, ErrorDict, ErrorList, ValidationError 10 10 11 11 NON_FIELD_ERRORS = '__all__' … … 33 33 return type.__new__(cls, name, bases, attrs) 34 34 35 class Form( object):35 class Form(StrAndUnicode): 36 36 "A collection of Fields, plus their associated data." 37 37 __metaclass__ = DeclarativeFieldsMetaclass … … 44 44 self.__errors = None # Stores the errors after clean() has been called. 45 45 46 def __ str__(self):46 def __unicode__(self): 47 47 return self.as_table() 48 48 … … 156 156 return self.clean_data 157 157 158 class BoundField( object):158 class BoundField(StrAndUnicode): 159 159 "A Field plus data" 160 160 def __init__(self, form, field, name): … … 163 163 self.name = name 164 164 165 def __ str__(self):165 def __unicode__(self): 166 166 "Renders this field as an HTML widget." 167 167 # Use the 'widget' attribute on the field to determine which type django/trunk/django/newforms/util.py
r4077 r4163 1 # Default encoding for input byte strings. 2 DEFAULT_ENCODING = 'utf-8' # TODO: First look at django.conf.settings, then fall back to this. 1 from django.conf import settings 3 2 4 3 def smart_unicode(s): … … 6 5 s = unicode(str(s)) 7 6 elif not isinstance(s, unicode): 8 s = unicode(s, DEFAULT_ENCODING)7 s = unicode(s, settings.DEFAULT_CHARSET) 9 8 return s 9 10 class StrAndUnicode(object): 11 """ 12 A class whose __str__ returns its __unicode__ as a bytestring 13 according to settings.DEFAULT_CHARSET. 14 15 Useful as a mix-in. 16 """ 17 def __str__(self): 18 return self.__unicode__().encode(settings.DEFAULT_CHARSET) 10 19 11 20 class ErrorDict(dict): django/trunk/django/newforms/widgets.py
r4148 r4163 9 9 ) 10 10 11 from util import smart_unicode11 from util import StrAndUnicode, smart_unicode 12 12 from django.utils.html import escape 13 13 from itertools import chain … … 147 147 return u'\n'.join(output) 148 148 149 class RadioInput( object):149 class RadioInput(StrAndUnicode): 150 150 "An object used by RadioFieldRenderer that represents a single <input type='radio'>." 151 151 def __init__(self, name, value, attrs, choice, index): … … 155 155 self.index = index 156 156 157 def __ str__(self):157 def __unicode__(self): 158 158 return u'<label>%s %s</label>' % (self.tag(), self.choice_label) 159 159 … … 169 169 return u'<input%s />' % flatatt(final_attrs) 170 170 171 class RadioFieldRenderer( object):171 class RadioFieldRenderer(StrAndUnicode): 172 172 "An object used by RadioSelect to enable customization of radio widgets." 173 173 def __init__(self, name, value, attrs, choices): … … 179 179 yield RadioInput(self.name, self.value, self.attrs.copy(), choice, i) 180 180 181 def __ str__(self):181 def __unicode__(self): 182 182 "Outputs a <ul> for this set of radio fields." 183 183 return u'<ul>\n%s\n</ul>' % u'\n'.join([u'<li>%s</li>' % w for w in self])
