magic-removal: Removed AdminBoundManipulator

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2095 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-01-21 06:23:16 +00:00
parent 8e1e0adfc7
commit 43d6bef62b
3 changed files with 17 additions and 41 deletions

View File

@ -4,7 +4,7 @@
<script type="text/javascript" src="../../../jsi18n/"></script> <script type="text/javascript" src="../../../jsi18n/"></script>
{% for js in javascript_imports %}{% include_admin_script js %}{% endfor %} {% for js in javascript_imports %}{% include_admin_script js %}{% endfor %}
{% endblock %} {% 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 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 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 %} {% block breadcrumbs %}{% if not is_popup %}
@ -22,13 +22,13 @@
{% endif %}{% endif %} {% endif %}{% endif %}
<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post">{% block form_top %}{% endblock %} <form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post">{% block form_top %}{% endblock %}
{% if is_popup %}<input type="hidden" name="_popup" value="1">{% endif %} {% if is_popup %}<input type="hidden" name="_popup" value="1">{% 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 %} {% if form.error_dict %}
<p class="errornote"> <p class="errornote">
{% blocktrans count form.error_dict.items|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %} {% blocktrans count form.error_dict.items|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
</p> </p>
{% endif %} {% endif %}
{% for bound_field_set in bound_manipulator.bound_field_sets %} {% for bound_field_set in bound_field_sets %}
<fieldset class="module aligned {{ bound_field_set.classes }}"> <fieldset class="module aligned {{ bound_field_set.classes }}">
{% if bound_field_set.name %}<h2>{{ bound_field_set.name }}</h2>{% endif %} {% if bound_field_set.name %}<h2>{{ bound_field_set.name }}</h2>{% endif %}
{% for bound_field_line in bound_field_set %} {% for bound_field_line in bound_field_set %}
@ -41,7 +41,7 @@
{% endfor %} {% endfor %}
{% block after_field_sets %}{% endblock %} {% block after_field_sets %}{% endblock %}
{% if change %} {% if change %}
{% if opts.get_ordered_objects %} {% if ordered_objects %}
<fieldset class="module"><h2>{% trans "Ordering" %}</h2> <fieldset class="module"><h2>{% trans "Ordering" %}</h2>
<div class="form-row{% if form.order_.errors %} error{% endif %} "> <div class="form-row{% if form.order_.errors %} error{% endif %} ">
{% if form.order_.errors %}{{ form.order_.html_error_list }}{% endif %} {% if form.order_.errors %}{{ form.order_.html_error_list }}{% endif %}
@ -49,27 +49,16 @@
</div></fieldset> </div></fieldset>
{% endif %} {% endif %}
{% 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 %} {% block after_related_objects %}{% endblock %}
{% submit_row bound_manipulator %} {% submit_row %}
{% if add %} {% if add %}
<script type="text/javascript">document.getElementById("{{ bound_manipulator.first_form_field_id }}").focus();</script> <script type="text/javascript">document.getElementById("{{ first_form_field_id }}").focus();</script>
{% endif %} {% endif %}
{% if auto_populated_fields %} {% if auto_populated_fields %}
<script type="text/javascript"> <script type="text/javascript">
{% auto_populated_field_script auto_populated_fields change %} {% auto_populated_field_script auto_populated_fields change %}
</script> </script>
{% endif %} {% endif %}
{% if change %}
{% if opts.get_ordered_objects %}
{% if form.order_objects %}<ul id="orderthese">
{% for object in form.order_objects %}
<li id="p{% object_pk bound_manipulator object %}">
<span id="handlep{% object_pk bound_manipulator object %}">{{ object|truncatewords:"5" }}</span>
</li>
{% endfor %}
</ul>{% endif %}
{% endif %}
{% endif %}
</form></div> </form></div>
{% endblock %} {% endblock %}

View File

@ -21,7 +21,7 @@ def include_admin_script(script_path):
return '<script type="text/javascript" src="%s%s"></script>' % (settings.ADMIN_MEDIA_PREFIX, script_path) return '<script type="text/javascript" src="%s%s"></script>' % (settings.ADMIN_MEDIA_PREFIX, script_path)
include_admin_script = register.simple_tag(include_admin_script) include_admin_script = register.simple_tag(include_admin_script)
def submit_row(context, bound_manipulator): def submit_row(context):
opts = context['opts'] opts = context['opts']
change = context['change'] change = context['change']
is_popup = context['is_popup'] is_popup = context['is_popup']
@ -230,7 +230,3 @@ def admin_field_line(context, argument_val):
'class_names': " ".join(class_names), 'class_names': " ".join(class_names),
} }
admin_field_line = register.inclusion_tag('admin/field_line', takes_context=True)(admin_field_line) 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)

View File

@ -156,37 +156,28 @@ class AdminBoundFieldSet(object):
def __len__(self): def __len__(self):
return len(self.bound_field_lines) 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=''): def render_change_form(model, manipulator, context, add=False, change=False, form_url=''):
opts = model._meta opts = model._meta
app_label = opts.app_label app_label = opts.app_label
auto_populated_fields = [f for f in opts.fields if f.prepopulate_from] auto_populated_fields = [f for f in opts.fields if f.prepopulate_from]
field_sets = opts.admin.get_field_sets(opts) 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 = { extra_context = {
'add': add, 'add': add,
'change': change, 'change': change,
'bound_manipulator': AdminBoundManipulator(model, manipulator, context['form']),
'has_delete_permission': context['perms'][app_label][opts.get_delete_permission()], 'has_delete_permission': context['perms'][app_label][opts.get_delete_permission()],
'has_file_field': opts.has_field_type(models.FileField), 'has_file_field': opts.has_field_type(models.FileField),
'has_absolute_url': hasattr(model, 'get_absolute_url'), 'has_absolute_url': hasattr(model, 'get_absolute_url'),
'auto_populated_fields': auto_populated_fields, '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), '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, 'form_url': form_url,
'opts': opts, 'opts': opts,
} }