Skip to content

Commit

Permalink
Make _validate always have option state argument. Minor tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
paj committed Jul 12, 2010
1 parent 5c7e4de commit 2dfcfeb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion tw2/forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
SingleSelectField, MultipleSelectField, RadioButtonList, CheckBoxList,
RadioButtonTable, CheckBoxTable, GridLayout, RowLayout, TableForm, ListForm,
TableFieldSet, ListFieldSet, FormPage, FileValidator,
LabelField, LinkField, InputField)
LabelField, LinkField, InputField, SelectionField)
19 changes: 9 additions & 10 deletions tw2/forms/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def prepare(self):
super(PasswordField, self).prepare()
self.safe_modify('attrs')
self.attrs['value'] = None
def _validate(self, value):
value = super(PasswordField, self)._validate(value)
def _validate(self, value, state=None):
value = super(PasswordField, self)._validate(value, state)
return value or twc.EmptyField


Expand Down Expand Up @@ -80,9 +80,9 @@ class FileField(InputField):
type = "file"
validator = FileValidator

def _validate(self, value):
def _validate(self, value, state=None):
try:
return super(FileField, self)._validate(value)
return super(FileField, self)._validate(value, state)
except twc.ValidationError:
self.value = None
raise
Expand Down Expand Up @@ -113,15 +113,14 @@ class LinkField(twc.Widget):
template = "tw2.forms.templates.link_field"
link = twc.Variable('Link target', default='')
text = twc.Variable('Link text', default='')
css_class = twc.Param('Css Class Name', default=None, attribute=True, view_name='class')
value = twc.Variable("value to replace $ with in the link/text")
value = twc.Variable("Value to replace $ with in the link/text")
validator = twc.BlankValidator

def prepare(self):
super(LinkField, self).prepare()
self.safe_modify('attrs')
self.attrs['href'] = self.link.replace('$', str(self.value or ''))
self.text = self.text.replace('$', str(self.value)) if self.value else ''
self.attrs['href'] = self.link.replace('$', unicode(self.value or ''))
self.text = self.text.replace('$', unicode(self.value or ''))


class Button(InputField):
Expand Down Expand Up @@ -240,14 +239,14 @@ def prepare(self):
self.options = options
self.grouped_options = grouped_options or [(None, options)]

def _validate(self, value):
def _validate(self, value, state=None):
"""
To redisplay correctly on error, selection fields must have the
:attr:`item_validator` applies to their value. This function does this
in a way that will never raise an exception, before calling the main
validator.
"""
value = super(SelectionField, self)._validate(value)
value = super(SelectionField, self)._validate(value, state)
if self.multiple:
if isinstance(value, basestring):
value = [value,]
Expand Down

0 comments on commit 2dfcfeb

Please sign in to comment.