Skip to content

Commit

Permalink
update default Widget.render to render a plain text input
Browse files Browse the repository at this point in the history
  • Loading branch information
ervandew committed Jan 19, 2012
1 parent 0ddbdf8 commit c95d838
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions blingalytics/widgets.py
Expand Up @@ -44,7 +44,7 @@ class ValidationError(Exception):
class Widget(object): class Widget(object):
""" """
Base widget implementation. Base widget implementation.
All widgets should derive from this class. Generally, a widget class will All widgets should derive from this class. Generally, a widget class will
define its own clean and render methods, as well as whatever related define its own clean and render methods, as well as whatever related
functionality it requires. functionality it requires.
Expand Down Expand Up @@ -86,7 +86,7 @@ def clean(self, user_input):
Basic user input cleaning example. Subclasses will generally override Basic user input cleaning example. Subclasses will generally override
this clean method to implement their own validation and parsing of the this clean method to implement their own validation and parsing of the
HTML form input. HTML form input.
The clean method of a subclass needs to handle the required option, The clean method of a subclass needs to handle the required option,
either by calling this method using super or implementing its own either by calling this method using super or implementing its own
version. If the widget is required, an empty user input should raise a version. If the widget is required, an empty user input should raise a
Expand All @@ -102,9 +102,16 @@ def clean(self, user_input):


def render(self): def render(self):
""" """
Renders the widget to HTML. Subclasses must implement this themselves. Renders the widget to HTML. Default implementation is to render a text input.
""" """
raise NotImplementedError value = self.default() if callable(self.default) else self.default
return INPUT % {
'form_name': self.form_name,
'form_label': self.label,
'form_class': self._form_class('bl_input'),
'form_type': 'text',
'form_attrs': 'value="%s" %s' % (value if value is not None else '', self.extra_attrs),
}


class Checkbox(Widget): class Checkbox(Widget):
""" """
Expand Down

0 comments on commit c95d838

Please sign in to comment.