From 8154294a0fb0134a13676642d13e525901d6bc97 Mon Sep 17 00:00:00 2001 From: Boulder Sprinters Date: Fri, 17 Nov 2006 06:47:43 +0000 Subject: boulder-oracle-sprint: Merged to [4077] of trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@4083 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/forms/tests.py | 226 ++++++++++++++++++++++++++++++----- 1 file changed, 199 insertions(+), 27 deletions(-) (limited to 'tests') diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py index 5402f654e9..c4dd7074a5 100644 --- a/tests/regressiontests/forms/tests.py +++ b/tests/regressiontests/forms/tests.py @@ -1,4 +1,5 @@ -""" +# -*- coding: utf-8 -*- +r""" >>> from django.newforms import * >>> import datetime >>> import re @@ -17,6 +18,11 @@ u'' +# Note that doctest in Python 2.4 (and maybe 2.5?) doesn't support non-ascii +# characters in output, so we're displaying the repr() here. +>>> w.render('email', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'}) +u'' + You can also pass 'attrs' to the constructor: >>> w = TextInput(attrs={'class': 'fun'}) >>> w.render('email', '') @@ -55,6 +61,9 @@ u'' >>> w.render('email', '', attrs={'class': 'special'}) u'' +>>> w.render('email', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'}) +u'' + # HiddenInput Widget ############################################################ >>> w = HiddenInput() @@ -81,6 +90,14 @@ u'' >>> w.render('email', '', attrs={'class': 'special'}) u'' +>>> w.render('email', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'}) +u'' + +'attrs' passed to render() get precedence over those passed to the constructor: +>>> w = HiddenInput(attrs={'class': 'pretty'}) +>>> w.render('email', '', attrs={'class': 'special'}) +u'' + # FileInput Widget ############################################################ >>> w = FileInput() @@ -102,10 +119,8 @@ u'' >>> w.render('email', 'foo@example.com') u'' -'attrs' passed to render() get precedence over those passed to the constructor: ->>> w = HiddenInput(attrs={'class': 'pretty'}) ->>> w.render('email', '', attrs={'class': 'special'}) -u'' +>>> w.render('email', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'}) +u'' # Textarea Widget ############################################################# @@ -133,6 +148,9 @@ u'' >>> w.render('msg', '', attrs={'class': 'special'}) u'' +>>> w.render('msg', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'}) +u'' + # CheckboxInput Widget ######################################################## >>> w = CheckboxInput() @@ -236,6 +254,9 @@ If 'choices' is passed to both the constructor and render(), then they'll both b +>>> w.render('email', 'ŠĐĆŽćžšđ', choices=[('ŠĐĆŽćžšđ', 'ŠĐabcĆŽćžšđ'), ('ćžšđ', 'abcćžšđ')]) +u'' + # SelectMultiple Widget ####################################################### >>> w = SelectMultiple() @@ -340,6 +361,120 @@ If 'choices' is passed to both the constructor and render(), then they'll both b +>>> w.render('nums', ['ŠĐĆŽćžšđ'], choices=[('ŠĐĆŽćžšđ', 'ŠĐabcĆŽćžšđ'), ('ćžšđ', 'abcćžšđ')]) +u'' + +# RadioSelect Widget ########################################################## + +>>> w = RadioSelect() +>>> print w.render('beatle', 'J', choices=(('J', 'John'), ('P', 'Paul'), ('G', 'George'), ('R', 'Ringo'))) + + +If the value is None, none of the options are checked: +>>> print w.render('beatle', None, choices=(('J', 'John'), ('P', 'Paul'), ('G', 'George'), ('R', 'Ringo'))) + + +If the value corresponds to a label (but not to an option value), none of the options are checked: +>>> print w.render('beatle', 'John', choices=(('J', 'John'), ('P', 'Paul'), ('G', 'George'), ('R', 'Ringo'))) + + +The value is compared to its str(): +>>> print w.render('num', 2, choices=[('1', '1'), ('2', '2'), ('3', '3')]) + +>>> print w.render('num', '2', choices=[(1, 1), (2, 2), (3, 3)]) + +>>> print w.render('num', 2, choices=[(1, 1), (2, 2), (3, 3)]) + + +The 'choices' argument can be any iterable: +>>> def get_choices(): +... for i in range(5): +... yield (i, i) +>>> print w.render('num', 2, choices=get_choices()) + + +You can also pass 'choices' to the constructor: +>>> w = RadioSelect(choices=[(1, 1), (2, 2), (3, 3)]) +>>> print w.render('num', 2) + + +If 'choices' is passed to both the constructor and render(), then they'll both be in the output: +>>> print w.render('num', 2, choices=[(4, 4), (5, 5)]) + + +The render() method returns a RadioFieldRenderer object, whose str() is a