On the way there...
[auf_rh_dae.git] / project / dae / widgets.py
CommitLineData
4718c21c 1from django.utils.safestring import mark_safe
661da766 2from django.forms.widgets import Select, TextInput
4718c21c
BS
3
4
5class ReadOnlyChoiceWidget(Select):
6 def render(self, name, value, attrs=None, choices=()):
6bec5651
BS
7 try:
8 key = long(value)
9 except ValueError:
10 key = ''
4718c21c 11 return mark_safe(
661da766
BS
12 '%(display)s</span><input type="hidden" '
13 'name="%(name)s" id="%(name)s" value="%(value)s" />' % {
6bec5651 14 'display': dict(self.choices)[key],
4718c21c
BS
15 'name': name,
16 'value': value,
17 })
661da766
BS
18
19
20class ReadOnlyWidget(TextInput):
21 def render(self, name, value, attrs=None):
22 return mark_safe(
23 '%(display)s<input id="%(name)s" type="hidden" '
24 'name="%(name)s" value="%(value)s" />' % {
25 'display': value,
26 'name': name,
27 'value': value,
28 })