|
@@ -17,40 +17,40 @@ _templates_root = 'rapid/widgets/'
|
|
|
|
|
|
class RapidReadOnly(widgets.Widget):
|
|
|
def render(self, name, value, attrs=None):
|
|
|
- hidden = '<input type="hidden" name="%s" value="%s" ' % (name, value)
|
|
|
+ hidden = '<input type="hidden" name="%s" value="%s" ' % (name, value if value else "")
|
|
|
for a in attrs.keys():
|
|
|
hidden += '%s="%s" ' % (a, attrs[a])
|
|
|
hidden += '>'
|
|
|
return '<span class="data-value">%s</span>%s\n' % (force_text(value), hidden)
|
|
|
|
|
|
def value_from_datadict(self, data, files, name):
|
|
|
- return data[name]
|
|
|
-
|
|
|
-
|
|
|
-class RapidRelationReadOnly(widgets.Widget):
|
|
|
- def __init__(self, model, *args, **kwargs):
|
|
|
- super(RapidRelationReadOnly, self).__init__(*args, **kwargs)
|
|
|
- self.model = ModelData(model)
|
|
|
+ return data.get(name)
|
|
|
|
|
|
- def render(self, name, value, attrs=None):
|
|
|
- hidden = '<input type="hidden" name="%s" value="%s" ' % (name, value)
|
|
|
- for a in attrs.keys():
|
|
|
- hidden += '%s="%s" ' % (a, attrs[a])
|
|
|
- hidden += '>'
|
|
|
- if hasattr(value, '__iter__'):
|
|
|
- obj = self.model.default_manager().filter(pk__in=value)
|
|
|
- ret = ''
|
|
|
- for o in obj:
|
|
|
- ret += '<span class="data-value multiple">%s</span>\n' % force_text(o)
|
|
|
- ret += hidden
|
|
|
- return ret
|
|
|
- else:
|
|
|
- obj = self.model.default_manager().get(pk=value)
|
|
|
- return '<span class="data-value">%s</span>%s\n' % (force_text(obj), hidden)
|
|
|
|
|
|
- def value_from_datadict(self, data, files, name):
|
|
|
- return data.get(name)
|
|
|
+def getRapidReadonlyRelation(model, originator):
|
|
|
+ class RapidRelationReadOnly(widgets.Widget):
|
|
|
+ def render(self, name, value, attrs=None):
|
|
|
+ hidden = '<input type="hidden" name="%s" value="%s" ' % (name, value if value else "")
|
|
|
+ for a in attrs.keys():
|
|
|
+ hidden += '%s="%s" ' % (a, attrs[a])
|
|
|
+ hidden += '>'
|
|
|
+ if hasattr(value, '__iter__'):
|
|
|
+ obj = model.default_manager().filter(pk__in=value)
|
|
|
+ ret = ''
|
|
|
+ for o in obj:
|
|
|
+ ret += '<span class="data-value multiple">%s</span>\n' % force_text(o)
|
|
|
+ ret += hidden
|
|
|
+ return ret
|
|
|
+ else:
|
|
|
+ if value:
|
|
|
+ obj = model.default_manager().get(pk=value)
|
|
|
+ else:
|
|
|
+ obj = ""
|
|
|
+ return '<span class="data-value">%s</span>%s\n' % (force_text(obj), hidden)
|
|
|
|
|
|
+ def value_from_datadict(self, data, files, name):
|
|
|
+ return originator
|
|
|
+ return RapidRelationReadOnly
|
|
|
|
|
|
class RapidSelector(widgets.Select):
|
|
|
"""
|
|
@@ -152,7 +152,6 @@ def rapid_dependent_widget(model_data, form, has_instance, is_mutiple):
|
|
|
'form': form,
|
|
|
'present': has_instance,
|
|
|
})
|
|
|
- # import pdb; pdb.set_trace()
|
|
|
t = loader.get_template(_templates_root + ('multipleDependent.html' if
|
|
|
is_mutiple else 'singleDependent.html'))
|
|
|
return t.render(c)
|