From 43d6bef62b2b73bb26f0da85fe3b8cede8afa166 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Sat, 21 Jan 2006 06:23:16 +0000 Subject: [PATCH] magic-removal: Removed AdminBoundManipulator git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2095 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- .../admin/templates/admin/change_form.html | 25 +++++------------ .../admin/templatetags/admin_modify.py | 6 +---- django/contrib/admin/views/main.py | 27 +++++++------------ 3 files changed, 17 insertions(+), 41 deletions(-) diff --git a/django/contrib/admin/templates/admin/change_form.html b/django/contrib/admin/templates/admin/change_form.html index 784938059a..8133217a24 100644 --- a/django/contrib/admin/templates/admin/change_form.html +++ b/django/contrib/admin/templates/admin/change_form.html @@ -4,7 +4,7 @@ {% for js in javascript_imports %}{% include_admin_script js %}{% endfor %} {% endblock %} -{% block coltype %}{% if opts.get_ordered_objects %}colMS{% else %}colM{% endif %}{% endblock %} +{% block coltype %}{% if ordered_objects %}colMS{% else %}colM{% endif %}{% endblock %} {% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %} {% block userlinks %}{% trans 'Documentation' %} / {% trans 'Change password' %} / {% trans 'Log out' %}{% endblock %} {% block breadcrumbs %}{% if not is_popup %} @@ -22,13 +22,13 @@ {% endif %}{% endif %}
{% block form_top %}{% endblock %} {% if is_popup %}{% endif %} -{% if opts.admin.save_on_top %}{% submit_row bound_manipulator %}{% endif %} +{% if opts.admin.save_on_top %}{% submit_row %}{% endif %} {% if form.error_dict %}

{% blocktrans count form.error_dict.items|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}

{% endif %} -{% for bound_field_set in bound_manipulator.bound_field_sets %} +{% for bound_field_set in bound_field_sets %}
{% if bound_field_set.name %}

{{ bound_field_set.name }}

{% endif %} {% for bound_field_line in bound_field_set %} @@ -41,7 +41,7 @@ {% endfor %} {% block after_field_sets %}{% endblock %} {% if change %} - {% if opts.get_ordered_objects %} + {% if ordered_objects %}

{% trans "Ordering" %}

{% if form.order_.errors %}{{ form.order_.html_error_list }}{% endif %} @@ -49,27 +49,16 @@
{% endif %} {% endif %} -{% for related_object in bound_manipulator.inline_related_objects %}{% edit_inline related_object %}{% endfor %} +{% for related_object in inline_related_objects %}{% edit_inline related_object %}{% endfor %} {% block after_related_objects %}{% endblock %} -{% submit_row bound_manipulator %} +{% submit_row %} {% if add %} - + {% endif %} {% if auto_populated_fields %} {% endif %} -{% if change %} - {% if opts.get_ordered_objects %} - {% if form.order_objects %}
    - {% for object in form.order_objects %} -
  • - {{ object|truncatewords:"5" }} -
  • - {% endfor %} -
{% endif %} - {% endif %} -{% endif %} {% endblock %} diff --git a/django/contrib/admin/templatetags/admin_modify.py b/django/contrib/admin/templatetags/admin_modify.py index 1faf3fb9e6..8d5cbb24a8 100644 --- a/django/contrib/admin/templatetags/admin_modify.py +++ b/django/contrib/admin/templatetags/admin_modify.py @@ -21,7 +21,7 @@ def include_admin_script(script_path): return '' % (settings.ADMIN_MEDIA_PREFIX, script_path) include_admin_script = register.simple_tag(include_admin_script) -def submit_row(context, bound_manipulator): +def submit_row(context): opts = context['opts'] change = context['change'] is_popup = context['is_popup'] @@ -230,7 +230,3 @@ def admin_field_line(context, argument_val): 'class_names': " ".join(class_names), } admin_field_line = register.inclusion_tag('admin/field_line', takes_context=True)(admin_field_line) - -def object_pk(bound_manip, ordered_obj): - return bound_manip.get_ordered_object_pk(ordered_obj) -object_pk = register.simple_tag(object_pk) diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py index 1cac88dec5..3833202a35 100644 --- a/django/contrib/admin/views/main.py +++ b/django/contrib/admin/views/main.py @@ -156,37 +156,28 @@ class AdminBoundFieldSet(object): def __len__(self): return len(self.bound_field_lines) -class AdminBoundManipulator(object): - def __init__(self, model, manipulator, field_mapping): - self.model = model - self.opts = model._meta - self.inline_related_objects = self.opts.get_followed_related_objects(manipulator.follow) - self.original = getattr(manipulator, 'original_object', None) - self.bound_field_sets = [field_set.bind(field_mapping, self.original, AdminBoundFieldSet) - for field_set in self.opts.admin.get_field_sets(self.opts)] - 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.opts.get_ordered_objects()] - - def get_ordered_object_pk(self, ordered_obj): - for name in self.ordered_object_pk_names: - if hasattr(ordered_obj, name): - return str(getattr(ordered_obj, name)) - return "" - def render_change_form(model, manipulator, context, add=False, change=False, form_url=''): opts = model._meta app_label = opts.app_label auto_populated_fields = [f for f in opts.fields if f.prepopulate_from] field_sets = opts.admin.get_field_sets(opts) + original = getattr(manipulator, 'original_object', None) + bound_field_sets = [field_set.bind(context['form'], original, AdminBoundFieldSet) for field_set in field_sets] + first_form_field_id = bound_field_sets[0].bound_field_lines[0].bound_fields[0].form_fields[0].get_id(); + ordered_objects = opts.get_ordered_objects() + inline_related_objects = opts.get_followed_related_objects(manipulator.follow) extra_context = { 'add': add, 'change': change, - 'bound_manipulator': AdminBoundManipulator(model, manipulator, context['form']), 'has_delete_permission': context['perms'][app_label][opts.get_delete_permission()], 'has_file_field': opts.has_field_type(models.FileField), 'has_absolute_url': hasattr(model, 'get_absolute_url'), 'auto_populated_fields': auto_populated_fields, + 'bound_field_sets': bound_field_sets, + 'first_form_field_id': first_form_field_id, 'javascript_imports': get_javascript_imports(opts, auto_populated_fields, field_sets), + 'ordered_objects': ordered_objects, + 'inline_related_objects': inline_related_objects, 'form_url': form_url, 'opts': opts, }