Permalink
Browse files

overhauled widget system to better better represent different kinds o…

…f empty values. see CHANGELOG
  • Loading branch information...
1 parent 3f8050c commit e358662c8295437356a23d69f37bd90ead4c42f9 Tim Parkin committed Feb 16, 2010
View
@@ -2,6 +2,24 @@
Changlelog
==========
+0.9.0-alpha
+-----------
+
+ * Updated documentation
+ * Added better defaults for schema types
+ * Updated JQuery in testish
+ * Overhauled the missing/empty strategies
+ In order to allow a user to represent both an empty string and a None value
+ at the same time, a few updates had to be made to how the widgets worked.
+ Hopefully most of these will be backward comptaible but we can't assure this
+ without a lot of checking. We now have a none_value attribute which
+ represents the value that is shown to a user to represent None. We also have
+ the old empty attribute which is used if the widget produces data which
+ matches the none_value. Have a look in testish for InputNoneValue for an
+ example and also InputDateNoneValue. Another example is
+ SelectChoiceWithEmptyString which shows how to allow both '' and None to be
+ selected.
+
0.8.8
-----
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1,6 +1,6 @@
<%page args="field" />
<div class="password">
- <input id="${field.cssname}" type="password" name="${field.name}.password" value="${field.value['password'][0]}" />
+ <input id="${field.cssname}" type="password" name="${field.name}.input" value="${field.value['input'][0]}" />
</div>
<div class="confirm">
% if field.widget.confirm_label:
@@ -1,7 +1,7 @@
<%page args="field" />
<select id="${field.cssname}" name="${field.name}">
%if field.widget.none_option:
- <option value="${field.widget.get_none_option_value(field)}">${field.widget.none_option[1]}</option>
+ <option value="${field.widget.none_value}">${field.widget.none_option[1]}</option>
%endif
%for option in field.widget.get_options(field):
<option value="${option[0]}" ${field.widget.selected(option,field)|n}>${option[1]}</option>
@@ -1,7 +1,7 @@
<%page args="field" />
<select id="${field.cssname}" name="${field.name}.select">
%if field.widget.none_option:
- <option value="${field.widget.get_none_option_value(field)}">${field.widget.none_option[1]}</option>
+ <option value="${field.widget.none_value}">${field.widget.none_option[1]}</option>
%endif
%for option in field.widget.get_options(field):
<option value="${option[0]}"${field.widget.selected(option,field)|n}>${option[1]}</option>
@@ -289,59 +289,13 @@ def unittest_Float(self, formdef):
def form_Boolean(request):
"""
- A simple form with a single boolean field
+ A simple form with a single boolean field, defaults to a RadioChoice widget. Add a required validator if you want a checkbox widget.
"""
schema = schemaish.Structure()
schema.add('myBooleanField', schemaish.Boolean())
form = formish.Form(schema, 'form')
return form
-def functest_Boolean(self):
- sel = self.selenium
- sel.open("/Boolean")
-
- sel.click("form-action")
- sel.wait_for_page_to_load("30000")
- self.failUnless(sel.is_text_present("{'myBooleanField': None}"))
-
- sel.type("form-myBooleanField", "a")
- sel.click("form-action")
- sel.wait_for_page_to_load("30000")
- self.failUnless(sel.is_text_present("u'a' should be either True or False"))
-
- sel.type("form-myBooleanField", "t")
- sel.click("form-action")
- sel.wait_for_page_to_load("30000")
- self.failUnless(sel.is_text_present("u't' should be either True or False"))
-
- sel.type("form-myBooleanField", "True")
- sel.click("form-action")
- sel.wait_for_page_to_load("30000")
- self.failUnless(sel.is_text_present("{'myBooleanField': True}"))
-
- sel.type("form-myBooleanField", "False")
- sel.click("form-action")
- sel.wait_for_page_to_load("30000")
- self.failUnless(sel.is_text_present("{'myBooleanField': False}"))
-
- return
-
-def unittest_Boolean(self, formdef):
- # Test no data
- f = formdef(None)
- self.assertIdHasValue(f, 'form-myBooleanField', '')
- # Test None data
- f = formdef(None)
- testdata = {'myBooleanField': None}
- f.defaults = testdata
- self.assertIdHasValue(f, 'form-myBooleanField', '')
- self.assertRoundTrip(f, testdata)
- # Test sample data
- f = formdef(None)
- testdata = {'myBooleanField': True}
- f.defaults = testdata
- self.assertIdHasValue(f, 'form-myBooleanField', 'True')
- self.assertRoundTrip(f, testdata)
def form_BooleanWithDefaults(request):
"""
@@ -438,7 +392,6 @@ def form_File(request):
schema = schemaish.Structure()
schema.add('myFile', schemaish.File())
form = formish.Form(schema, 'form')
- form['myFile'].widget = formish.FileUpload(filestore=CachedTempFilestore())
return form
def functest_File(self):
@@ -474,6 +427,28 @@ def form_Input(request):
form['inputStrip'].widget = formish.Input(strip=True)
return form
+def form_InputNoneValue(request):
+ """
+ Simple input field with a strip parameter and a substitue none_value (allows user to return a None and an empty string). Notice use of schema default value.
+ """
+ schema = schemaish.Structure()
+ schema.add('inputStrip', schemaish.String(default=''))
+
+ form = formish.Form(schema, 'form')
+ form['inputStrip'].widget = formish.Input(strip=True, none_value='BANG')
+ return form
+
+def form_InputDateNoneValue(request):
+ """
+ Simple input field with a strip parameter and a substitue none_value (allows user to return a None and an empty string). Notice use of schema default value.
+ """
+ schema = schemaish.Structure()
+ schema.add('inputStrip', schemaish.Date(default=datetime.date(1900,1,1)))
+
+ form = formish.Form(schema, 'form')
+ form['inputStrip'].widget = formish.Input(empty=datetime.date(1900,1,1),roundtrip_empty=True)
+ return form
+
def form_Hidden(request):
"""
Hidden Field with a visible friend..
@@ -573,15 +548,27 @@ def form_Required(request):
form = formish.Form(schema, 'form')
return form
+
+
def form_CheckboxRequired(request):
"""
+ Simple Boolean Checkbox with a required validator. Add an empty value if you want to force the user to add a tick
+ """
+ schema = schemaish.Structure()
+ schema.add('checkbox', schemaish.Boolean(validator=validatish.Required()))
+
+ form = formish.Form(schema, 'form')
+ return form
+
+def form_CheckboxRequiredWithEmptyValue(request):
+ """
Simple Boolean Checkbox
"""
schema = schemaish.Structure()
- schema.add('checkbox', schemaish.Boolean(validator=validatish.Equal(True)))
+ schema.add('checkbox', schemaish.Boolean(validator=validatish.Required()))
form = formish.Form(schema, 'form')
- form['checkbox'].widget = formish.Checkbox()
+ form['checkbox'].widget = formish.Checkbox(empty=None)
return form
def form_RadioChoiceRequired(request):
@@ -926,6 +913,18 @@ def form_SelectChoiceNoneOption(request):
form['mySelect'].widget = formish.SelectChoice(options,none_option=(None, '--select--'))
return form
+def form_SelectChoiceWithEmptyString(request):
+ """
+ A select choice which includes an empty string and a none value
+ """
+ schema = schemaish.Structure()
+ schema.add('mySelect', schemaish.String())
+ options = [('','empty string'),('b','b'),('c','c')]
+
+ form = formish.Form(schema, 'form')
+ form['mySelect'].widget = formish.SelectChoice(options, none_value='BANG')
+ return form
+
def form_SelectChoiceCallableOptions(request):
"""
Passing in a callable list of options
@@ -26,7 +26,7 @@
<h3>Simple Widgets</h3>
<%
-ids = ['Input','Hidden','Password','CheckedPassword','TextAreaSimple','TextAreaColsAndRows','TextAreaStrip']
+ids = ['Input','InputNoneValue','InputDateNoneValue','Hidden','Password','CheckedPassword','TextAreaSimple','TextAreaColsAndRows','TextAreaStrip']
links(ids)
%>
@@ -45,14 +45,14 @@
<h3>Validation Examples</h3>
<%
-ids = ['Required', 'RadioChoiceRequired','CheckboxRequired','MinLength','MaxLength','MinMaxLength','MinLengthCheckboxMultiChoice','MinRange','MaxRange','MinMaxRange','PlainText','OneOf','All','Any','ReCAPTCHA','ValidationOnSequenceItem','ValidationOnSequence','ValidationOnSequenceItemTextArea','RequiredStringAndFile']
+ids = ['Required', 'RadioChoiceRequired','CheckboxRequired','CheckboxRequiredWithEmptyValue','MinLength','MaxLength','MinMaxLength','MinLengthCheckboxMultiChoice','MinRange','MaxRange','MinMaxRange','PlainText','OneOf','All','Any','ReCAPTCHA','ValidationOnSequenceItem','ValidationOnSequence','ValidationOnSequenceItemTextArea','RequiredStringAndFile']
links(ids)
%>
<h3>Select Widgets</h3>
<%
-ids = ['SelectChoice','SelectChoiceNoneOption','SelectChoiceCallableOptions','SelectWithOtherChoice','RadioChoice','RadioChoiceNoneOption','RadioChoiceNoneOptionNoneDefault','RadioChoiceCallableOptions','RadioChoiceWithDefaults','SelectChoiceDate','SelectChoiceSequenceInteger']
+ids = ['SelectChoice','SelectChoiceNoneOption','SelectChoiceWithEmptyString','SelectChoiceCallableOptions','SelectWithOtherChoice','RadioChoice','RadioChoiceNoneOption','RadioChoiceNoneOptionNoneDefault','RadioChoiceCallableOptions','RadioChoiceWithDefaults','SelectChoiceDate','SelectChoiceSequenceInteger']
links(ids)
%>
@@ -147,8 +147,10 @@ def test_integer_type(self):
# check scmea matches
self.assert_(form.structure.attr is schema_flat)
# Does the form produce an int and a string
+ print 'RPpre', repr(request.POST['a'])
self.assertEquals(form.validate(request), {'a': 3, 'b': '4'})
# Does the convert request to data work
+ print 'RP', repr(request.POST['a'])
self.assertEqual( form.widget.from_request_data(form, request.POST) , {'a': 3, 'b': '4'})
# Does the convert data to request work
self.assert_( form.widget.to_request_data(form, {'a': 3, 'b': '4'} ) == reqr)
Oops, something went wrong.

0 comments on commit e358662

Please sign in to comment.