Package omeroweb :: Package webadmin :: Module custom_widgets
[hide private]
[frames] | no frames]

Source Code for Module omeroweb.webadmin.custom_widgets

 1  #!/usr/bin/env python 
 2  # -*- coding: utf-8 -*- 
 3  from django.forms.widgets import RadioSelect, RadioInput, RadioFieldRenderer 
 4  from django.utils.encoding import force_unicode 
 5   
6 -class DefaultGroupRadioInput(RadioInput):
7 """ 8 An object used by RadioFieldRenderer that represents a single 9 <input type='radio'>. 10 """ 11
12 - def __init__(self, name, value, attrs, choice, index):
13 self.name, self.value = name, value 14 self.attrs = attrs 15 self.choice_value = force_unicode(choice[0]) 16 self.choice_label = force_unicode(choice[1]) 17 # self.index = index 18 self.index = choice[0]
19
20 -class DefaultGroupRadioFieldRenderer(RadioFieldRenderer):
21 """ 22 An object used by RadioSelect to enable customization of radio widgets. 23 """ 24
25 - def __iter__(self):
26 for i, choice in enumerate(self.choices): 27 yield DefaultGroupRadioInput(self.name, self.value, self.attrs.copy(), choice, i)
28
29 - def __getitem__(self, idx):
30 choice = self.choices[idx] # Let the IndexError propogate 31 return DefaultGroupRadioInput(self.name, self.value, self.attrs.copy(), choice, idx)
32
33 -class DefaultGroupRadioSelect(RadioSelect):
34 renderer = DefaultGroupRadioFieldRenderer
35