From b7a897eebbd4797c58b004eda7c6a30f9971eac2 Mon Sep 17 00:00:00 2001 From: Jason Pellerin Date: Mon, 4 Dec 2006 20:29:44 +0000 Subject: [multi-db] Merged trunk to [4000]. Some tests still failing. git-svn-id: http://code.djangoproject.com/svn/django/branches/multiple-db-support@4156 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/newforms/__init__.py | 3 +- django/newforms/fields.py | 125 ++++++++++++++++++++++++++++++++++++++------ django/newforms/forms.py | 106 ++++++++++++++++++++++++++++++------- django/newforms/widgets.py | 76 +++++++++++++++++++++++++-- 4 files changed, 269 insertions(+), 41 deletions(-) (limited to 'django/newforms') diff --git a/django/newforms/__init__.py b/django/newforms/__init__.py index f0eca9a950..2a472d7b39 100644 --- a/django/newforms/__init__.py +++ b/django/newforms/__init__.py @@ -2,8 +2,6 @@ Django validation and HTML form handling. TODO: - Validation not tied to a particular field - widgets (except type='checkbox', which is special)" + input_type = None # Subclasses must define this. def render(self, name, value, attrs=None): if value is None: value = '' - final_attrs = dict(self.attrs, type='text', name=name) + final_attrs = dict(self.attrs, type=self.input_type, name=name) if attrs: final_attrs.update(attrs) if value != '': final_attrs['value'] = value # Only add the 'value' attribute if a value is non-empty. return u'' % flatatt(final_attrs) +class TextInput(Input): + input_type = 'text' + +class PasswordInput(Input): + input_type = 'password' + +class HiddenInput(Input): + input_type = 'hidden' + +class FileInput(Input): + input_type = 'file' + class Textarea(Widget): def render(self, name, value, attrs=None): if value is None: value = '' @@ -41,3 +66,48 @@ class CheckboxInput(Widget): final_attrs.update(attrs) if value: final_attrs['checked'] = 'checked' return u'' % flatatt(final_attrs) + +class Select(Widget): + def __init__(self, attrs=None, choices=()): + # choices can be any iterable + self.attrs = attrs or {} + self.choices = choices + + def render(self, name, value, attrs=None, choices=()): + if value is None: value = '' + final_attrs = dict(self.attrs, name=name) + if attrs: + final_attrs.update(attrs) + output = [u'') + return u'\n'.join(output) + +class SelectMultiple(Widget): + requires_data_list = True + def __init__(self, attrs=None, choices=()): + # choices can be any iterable + self.attrs = attrs or {} + self.choices = choices + + def render(self, name, value, attrs=None, choices=()): + if value is None: value = [] + final_attrs = dict(self.attrs, name=name) + if attrs: + final_attrs.update(attrs) + output = [u'') + return u'\n'.join(output) + +class RadioSelect(Widget): + pass + +class CheckboxSelectMultiple(Widget): + pass -- cgit v1.3