Added document detail view

This commit is contained in:
Roberto Rosario
2011-02-03 22:46:51 -04:00
parent e275b58fd8
commit 5854a1ce50
6 changed files with 72 additions and 22 deletions
+10
View File
@@ -56,6 +56,11 @@ class DetailSelectMultiple(forms.widgets.SelectMultiple):
return mark_safe(output + u'</ul>\n')
class PlainWidget(forms.widgets.Widget):
def render(self, name, value, attrs=None):
return mark_safe(u'%s' % value)
class DetailForm(forms.ModelForm):
def __init__(self, extra_fields=None, *args, **kwargs):
super(DetailForm, self).__init__(*args, **kwargs)
@@ -66,6 +71,11 @@ class DetailForm(forms.ModelForm):
#TODO: Add others result types <=> Field types
if isinstance(result, models.query.QuerySet):
self.fields[extra_field['field']]=forms.ModelMultipleChoiceField(queryset=result, label=label)
else:
self.fields[extra_field['field']]=forms.CharField(
label=extra_field['label'],
initial=getattr(self.instance, extra_field['field'], None),
widget=PlainWidget)
for field_name, field in self.fields.items():
if isinstance(field.widget, forms.widgets.SelectMultiple):
+3 -2
View File
@@ -1,7 +1,6 @@
{% extends "base.html" %}
{% load i18n %}
{% load styling %}
{% load generic_views_helpers %}
{% block title %} :: {% with "true" as read_only %}{% with "true" as striptags %}{% include "calculate_form_title.html" %}{% endwith %}{% endwith %}{% endblock %}
{% block javascript %}
@@ -49,6 +48,7 @@
{% with subtemplate.extra_columns as extra_columns %}
{% with subtemplate.hide_object as hide_object %}
{% with subtemplate.main_object as main_object %}
{% with subtemplate.hide_link as hide_link %}
<div class="content">
{% include subtemplate.name %}
</div>
@@ -57,6 +57,7 @@
{% endwith %}
{% endwith %}
{% endwith %}
{% endwith %}
{% endfor %}