Ticket #2383: multi_delete.diff

File multi_delete.diff, 9.6 KB (added by jay@…, 18 years ago)
  • django/contrib/admin/media/css/global.css

     
    135135.object-tools a.viewsitelink:hover, .object-tools a.golink:hover { background:#5b80b2 url(../img/admin/tooltag-arrowright_over.gif) top right no-repeat; }
    136136.object-tools a.addlink { background:#999 url(../img/admin/tooltag-add.gif) top right no-repeat; padding-right:28px; }
    137137.object-tools a.addlink:hover { background:#5b80b2 url(../img/admin/tooltag-add_over.gif) top right no-repeat; }
     138.object-tools a.deletelink { background:#999 url(../img/admin/tooltag-delete.gif) top right no-repeat; padding-right:28px; }
     139.object-tools a.deletelink:hover { background:#5b80b2 url(../img/admin/tooltag-delete_over.gif) top right no-repeat; }
    138140
    139141/* OBJECT HISTORY */
    140142table#change-history { width:100%; }
  • django/contrib/admin/templatetags/admin_list.py

     
    6868    }
    6969pagination = register.inclusion_tag('admin/pagination.html')(pagination)
    7070
    71 def result_headers(cl):
     71def result_headers(cl, user):
    7272    lookup_opts = cl.lookup_opts
    7373
    7474    for i, field_name in enumerate(lookup_opts.admin.list_display):
     
    102102                       "sortable": True,
    103103                       "url": cl.get_query_string({ORDER_VAR: i, ORDER_TYPE_VAR: new_order_type}),
    104104                       "class_attrib": (th_classes and ' class="%s"' % ' '.join(th_classes) or '')}
     105    delete_permission = '%s.%s' % (cl.model._meta.app_label, cl.opts.get_delete_permission())
     106    if user.get_all_permissions().__contains__(delete_permission):
     107        yield{"text":"Delete?"}
    105108
    106 def items_for_result(cl, result):
     109def items_for_result(cl, result, user):
    107110    first = True
    108111    pk = cl.lookup_opts.pk.attname
    109112    for field_name in cl.lookup_opts.admin.list_display:
     
    175178                (table_tag, row_class, url, (cl.is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %r); return false;"' % result_id or ''), result_repr, table_tag))
    176179        else:
    177180            yield ('<td%s>%s</td>' % (row_class, result_repr))
     181    delete_permision = '%s.%s' % (cl.model._meta.app_label, cl.opts.get_delete_permission())
     182    if user.get_all_permissions().__contains__(delete_permision):
     183        yield('<td><input type="checkbox" name="%s" /></td>' % result_id)
    178184
    179 def results(cl):
     185def results(cl, user):
    180186    for res in cl.result_list:
    181         yield list(items_for_result(cl,res))
     187        yield list(items_for_result(cl,res, user))
    182188
    183 def result_list(cl):
     189def result_list(cl, user):
    184190    return {'cl': cl,
    185             'result_headers': list(result_headers(cl)),
    186             'results': list(results(cl))}
     191            'result_headers': list(result_headers(cl, user)),
     192            'results': list(results(cl, user))}
    187193result_list = register.inclusion_tag("admin/change_list_results.html")(result_list)
    188194
    189195def date_hierarchy(cl):
  • django/contrib/admin/urls.py

     
    3131    # Add/change/delete/history
    3232    ('^([^/]+)/([^/]+)/$', 'django.contrib.admin.views.main.change_list'),
    3333    ('^([^/]+)/([^/]+)/add/$', 'django.contrib.admin.views.main.add_stage'),
     34    ('^([^/]+)/([^/]+)/delete/$', 'django.contrib.admin.views.main.delete_checked'),
    3435    ('^([^/]+)/([^/]+)/(.+)/history/$', 'django.contrib.admin.views.main.history'),
    3536    ('^([^/]+)/([^/]+)/(.+)/delete/$', 'django.contrib.admin.views.main.delete_stage'),
    3637    ('^([^/]+)/([^/]+)/(.+)/$', 'django.contrib.admin.views.main.change_stage'),
  • django/contrib/admin/views/main.py

     
    8181            myappend('_' + item)
    8282    return "".join(res)
    8383
    84 def get_javascript_imports(opts, auto_populated_fields, field_sets):
     84def get_javascript_imports(opts, auto_populated_fields, field_sets, has_delete_permission):
    8585# Put in any necessary JavaScript imports.
    8686    js = ['js/core.js', 'js/admin/RelatedObjectLookups.js']
    8787    if auto_populated_fields:
     
    9292        js.extend(['js/getElementsBySelector.js', 'js/dom-drag.js' , 'js/admin/ordering.js'])
    9393    if opts.admin.js:
    9494        js.extend(opts.admin.js)
     95    if has_delete_permission:
     96        js.extend(['js/admin/delete.js'])
    9597    seen_collapse = False
    9698    for field_set in field_sets:
    9799        if not seen_collapse and 'collapse' in field_set.classes:
     
    209211        'auto_populated_fields': auto_populated_fields,
    210212        'bound_field_sets': bound_field_sets,
    211213        'first_form_field_id': first_form_field_id,
    212         'javascript_imports': get_javascript_imports(opts, auto_populated_fields, field_sets),
     214        'javascript_imports': get_javascript_imports(opts, auto_populated_fields, field_sets, context['perms'][app_label][opts.get_delete_permission()]),
    213215        'ordered_objects': ordered_objects,
    214216        'inline_related_objects': inline_related_objects,
    215217        'form_url': form_url,
     
    731733
    732734def change_list(request, app_label, model_name):
    733735    model = models.get_model(app_label, model_name)
     736    opts = model._meta
     737    auto_populated_fields = [f for f in opts.fields if f.prepopulate_from]
     738    field_sets = opts.admin.get_field_sets(opts)
    734739    if model is None:
    735740        raise Http404, "App %r, model %r, not found" % (app_label, model_name)
    736741    if not request.user.has_perm(app_label + '.' + model._meta.get_change_permission()):
     
    752757        'cl': cl,
    753758    })
    754759    c.update({'has_add_permission': c['perms'][app_label][cl.opts.get_add_permission()]}),
     760    c.update({'has_delete_permission': c['perms'][app_label][cl.opts.get_delete_permission()]}),
     761    c.update({'javascript_imports': get_javascript_imports(opts, auto_populated_fields, field_sets, c['perms'][app_label][opts.get_delete_permission()])}),
    755762    return render_to_response(['admin/%s/%s/change_list.html' % (app_label, cl.opts.object_name.lower()),
    756763                               'admin/%s/change_list.html' % app_label,
    757764                               'admin/change_list.html'], context_instance=c)
    758765change_list = staff_member_required(never_cache(change_list))
     766
     767def delete_checked(request, app_name, model_name):
     768    if request.POST:
     769        model = models.get_model(app_name, model_name)
     770        for item in request.POST:
     771            ob = model.objects.get(id=item)
     772            ob.delete()
     773        return HttpResponseRedirect('/admin/%s/%s/' % (app_name, model_name))
     774    else:
     775        return HttpResponseRedirect('/admin/%s/%s/' % (app_name, model_name))
     776   
  • django/contrib/admin/templates/admin/change_list.html

     
    11{% extends "admin/base_site.html" %}
    2 {% load adminmedia admin_list i18n %}
     2{% load adminmedia admin_list i18n admin_modify %}
     3{% block extrahead %}{{ block.super }}
     4<script type="text/javascript" src="../../../jsi18n/"></script>
     5{% for js in javascript_imports %}{% include_admin_script js %}{% endfor %}
     6{% endblock %}
    37{% block stylesheet %}{% admin_media_prefix %}css/changelists.css{% endblock %}
    48{% block bodyclass %}change-list{% endblock %}
    59{% block userlinks %}<a href="../../doc/">{% trans 'Documentation' %}</a> / <a href="../../password_change/">{% trans 'Change password' %}</a> / <a href="../../logout/">{% trans 'Log out' %}</a>{% endblock %}
     
    711{% block coltype %}flex{% endblock %}
    812{% block content %}
    913<div id="content-main">
    10 {% if has_add_permission %}
    11 <ul class="object-tools"><li><a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink">{% blocktrans with cl.opts.verbose_name|escape as name %}Add {{ name }}{% endblocktrans %}</a></li></ul>
    12 {% endif %}
     14<ul class="object-tools">
     15        {% if has_add_permission %}
     16                <li>
     17                        <a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink">{% blocktrans with cl.opts.verbose_name|escape as name %}Add {{ name }}{% endblocktrans %}</a>
     18                </li>
     19        {% endif %}
     20        {% if has_delete_permission %}
     21                <li>
     22                        <a href="#" onclick="javascript: delete_checked();" class="deletelink">{% blocktrans with cl.opts.verbose_name|escape as name %}Delete checked {{ name }}{% endblocktrans %}</a>
     23                </li>
     24        {% endif %}
     25</ul>
    1326<div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist">
    1427{% block search %}{% search_form cl %}{% endblock %}
    1528{% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %}
    1629{% block filters %}{% filters cl %}{% endblock %}
    17 {% block result_list %}{% result_list cl %}{% endblock %}
     30{% block result_list %}{% result_list cl user %}{% endblock %}
    1831{% block pagination %}{% pagination cl %}{% endblock %}
    1932</div>
    2033</div>
  • django/contrib/admin/templates/admin/change_list_results.html

     
    11{% if results %}
     2<form name="delete_checked_form" method="POST" action="delete/">
    23<table cellspacing="0">
    34<thead>
    45<tr>
     
    1415{% endfor %}
    1516</tbody>
    1617</table>
     18</form>
    1719{% endif %}
Back to Top