Permalink
Browse files

Adding support for checkbox.

  • Loading branch information...
1 parent cf04264 commit f9436b6754c2d5198404c4eeb79807204cc8d030 @ext committed Apr 24, 2012
Showing with 22 additions and 1 deletion.
  1. +22 −1 slideshow/settings.py
View
@@ -333,11 +333,31 @@ class ItemTextArea(Item):
def __init__(self, *args, **kwargs):
Item.__init__(self, *args, **kwargs)
- self.value = ''
def __str__(self):
return '<textarea name="{group}.{name}">{value}</textarea>'.format(**self._values())
+class ItemCheckbox(Item):
+ default = False
+
+ def __init__(self, *args, **kwargs):
+ Item.__init__(self, *args, **kwargs)
+
+ def set(self, value, rollback=False):
+ if isinstance(value, basestring):
+ value = value.lower() == 'on'
+ Item.set(self, value, rollback)
+
+ def _values(self):
+ checked = ''
+ if self._value: checked = 'checked="checked"'
+ d = Item._values(self)
+ d['checked'] = checked
+ return d
+
+ def __str__(self):
+ return '<input name="{group}.{name}" type="checkbox" {checked} />'.format(**self._values())
+
itemfactory = {
'directory': ItemDirectory,
'file': ItemFile,
@@ -350,6 +370,7 @@ def __str__(self):
'static': ItemStatic,
'filelist': ItemFilelist,
'textarea': ItemTextArea,
+ 'checkbox': ItemCheckbox,
}
for k,v in itemfactory.items():

0 comments on commit f9436b6

Please sign in to comment.