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

Source Code for Module omeroweb.webadmin.custom_widgets

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