magic-removal: Began simplification of AdminBoundManipulator. Changed admin/change_form template to add 'opts' to template context.

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2082 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-01-21 04:06:26 +00:00
parent 39fec03db6
commit 4f6f777bc7
2 changed files with 12 additions and 20 deletions

View File

@ -5,24 +5,24 @@
{% for js in bound_manipulator.javascript_imports %}{% include_admin_script js %}{% endfor %}
{% endblock %}
{% block coltype %}{{ bound_manipulator.coltype }}{% endblock %}
{% block bodyclass %}{{ app_label }}-{{ bound_manipulator.object_name.lower }} change-form{% endblock %}
{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %}
{% block userlinks %}<a href="../../../doc/">{% trans 'Documentation' %}</a> / <a href="../../../password_change/">{% trans 'Change password' %}</a> / <a href="../../../logout/">{% trans 'Log out' %}</a>{% endblock %}
{% block breadcrumbs %}{% if not is_popup %}
<div class="breadcrumbs">
<a href="../../../">{% trans "Home" %}</a> &rsaquo;
<a href="../">{{ bound_manipulator.verbose_name_plural|capfirst }}</a> &rsaquo;
{% if add %}{% trans "Add" %} {{ bound_manipulator.verbose_name }}{% else %}{{ bound_manipulator.original|striptags|truncatewords:"18" }}{% endif %}
<a href="../">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
{% if add %}{% trans "Add" %} {{ opts.verbose_name }}{% else %}{{ bound_manipulator.original|striptags|truncatewords:"18" }}{% endif %}
</div>
{% endif %}{% endblock %}
{% block content %}<div id="content-main">
{% if change %}{% if not is_popup %}
<ul class="object-tools"><li><a href="history/" class="historylink">{% trans "History" %}</a></li>
{% if bound_manipulator.has_absolute_url %}<li><a href="/r/{{ bound_manipulator.content_type_id }}/{{ object_id }}/" class="viewsitelink">{% trans "View on site" %}</a></li>{% endif%}
{% if bound_manipulator.has_absolute_url %}<li><a href="/r/{{ opts.get_content_type_id }}/{{ object_id }}/" class="viewsitelink">{% trans "View on site" %}</a></li>{% endif%}
</ul>
{% endif %}{% endif %}
<form {{ bound_manipulator.form_enc_attrib }} action="{{ form_url }}" method="post">{% block form_top %}{% endblock %}
{% if is_popup %}<input type="hidden" name="_popup" value="1">{% endif %}
{% if bound_manipulator.save_on_top %}{% submit_row bound_manipulator %}{% endif %}
{% if opts.admin.save_on_top %}{% submit_row bound_manipulator %}{% endif %}
{% if form.error_dict %}
<p class="errornote">
{% blocktrans count form.error_dict.items|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}

View File

@ -153,22 +153,13 @@ class AdminBoundManipulator(BoundManipulator):
self.auto_populated_fields = [f for f in self.opts.fields if f.prepopulate_from]
self.javascript_imports = get_javascript_imports(self.opts, self.auto_populated_fields, self.ordered_objects, field_sets);
self.coltype = self.ordered_objects and 'colMS' or 'colM'
self.has_absolute_url = hasattr(model, 'get_absolute_url')
self.form_enc_attrib = self.opts.has_field_type(models.FileField) and 'enctype="multipart/form-data" ' or ''
self.first_form_field_id = self.bound_field_sets[0].bound_field_lines[0].bound_fields[0].form_fields[0].get_id();
self.ordered_object_pk_names = [o.pk.name for o in self.ordered_objects]
opts = self.opts
self.save_on_top = opts.admin.save_on_top
self.save_as = opts.admin.save_as
self.content_type_id = opts.get_content_type_id()
self.verbose_name_plural = opts.verbose_name_plural
self.verbose_name = opts.verbose_name
self.object_name = opts.object_name
self.save_as = self.opts.admin.save_as
self.verbose_name = self.opts.verbose_name
def get_ordered_object_pk(self, ordered_obj):
for name in self.ordered_object_pk_names:
@ -176,15 +167,16 @@ class AdminBoundManipulator(BoundManipulator):
return str(getattr(ordered_obj, name))
return ""
def render_change_form(model, manipulator, app_label, context, add=False, change=False, show_delete=False, form_url=''):
def render_change_form(model, manipulator, context, add=False, change=False, show_delete=False, form_url=''):
opts = model._meta
app_label = opts.app_label
extra_context = {
'add': add,
'change': change,
'bound_manipulator': AdminBoundManipulator(model, manipulator, context['form']),
'has_delete_permission': context['perms'][app_label][opts.get_delete_permission()],
'form_url': form_url,
'app_label': app_label,
'opts': opts,
}
context.update(extra_context)
return render_to_response(["admin/%s/%s/change_form" % (app_label, opts.object_name.lower() ),
@ -266,7 +258,7 @@ def add_stage(request, app_label, model_name, show_delete=False, form_url='', po
if object_id_override is not None:
c['object_id'] = object_id_override
return render_change_form(model, manipulator, app_label, c, add=True)
return render_change_form(model, manipulator, c, add=True)
add_stage = staff_member_required(add_stage)
def change_stage(request, app_label, model_name, object_id):
@ -354,7 +346,7 @@ def change_stage(request, app_label, model_name, object_id):
'original': manipulator.original_object,
'is_popup': request.REQUEST.has_key('_popup'),
})
return render_change_form(model, manipulator, app_label, c, change=True)
return render_change_form(model, manipulator, c, change=True)
change_stage = staff_member_required(change_stage)
def _nest_help(obj, depth, val):