Ticket #2383: multi_delete.diff
File multi_delete.diff, 9.6 KB (added by , 18 years ago) |
---|
-
django/contrib/admin/media/css/global.css
135 135 .object-tools a.viewsitelink:hover, .object-tools a.golink:hover { background:#5b80b2 url(../img/admin/tooltag-arrowright_over.gif) top right no-repeat; } 136 136 .object-tools a.addlink { background:#999 url(../img/admin/tooltag-add.gif) top right no-repeat; padding-right:28px; } 137 137 .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; } 138 140 139 141 /* OBJECT HISTORY */ 140 142 table#change-history { width:100%; } -
django/contrib/admin/templatetags/admin_list.py
68 68 } 69 69 pagination = register.inclusion_tag('admin/pagination.html')(pagination) 70 70 71 def result_headers(cl ):71 def result_headers(cl, user): 72 72 lookup_opts = cl.lookup_opts 73 73 74 74 for i, field_name in enumerate(lookup_opts.admin.list_display): … … 102 102 "sortable": True, 103 103 "url": cl.get_query_string({ORDER_VAR: i, ORDER_TYPE_VAR: new_order_type}), 104 104 "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?"} 105 108 106 def items_for_result(cl, result ):109 def items_for_result(cl, result, user): 107 110 first = True 108 111 pk = cl.lookup_opts.pk.attname 109 112 for field_name in cl.lookup_opts.admin.list_display: … … 175 178 (table_tag, row_class, url, (cl.is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %r); return false;"' % result_id or ''), result_repr, table_tag)) 176 179 else: 177 180 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) 178 184 179 def results(cl ):185 def results(cl, user): 180 186 for res in cl.result_list: 181 yield list(items_for_result(cl,res ))187 yield list(items_for_result(cl,res, user)) 182 188 183 def result_list(cl ):189 def result_list(cl, user): 184 190 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))} 187 193 result_list = register.inclusion_tag("admin/change_list_results.html")(result_list) 188 194 189 195 def date_hierarchy(cl): -
django/contrib/admin/urls.py
31 31 # Add/change/delete/history 32 32 ('^([^/]+)/([^/]+)/$', 'django.contrib.admin.views.main.change_list'), 33 33 ('^([^/]+)/([^/]+)/add/$', 'django.contrib.admin.views.main.add_stage'), 34 ('^([^/]+)/([^/]+)/delete/$', 'django.contrib.admin.views.main.delete_checked'), 34 35 ('^([^/]+)/([^/]+)/(.+)/history/$', 'django.contrib.admin.views.main.history'), 35 36 ('^([^/]+)/([^/]+)/(.+)/delete/$', 'django.contrib.admin.views.main.delete_stage'), 36 37 ('^([^/]+)/([^/]+)/(.+)/$', 'django.contrib.admin.views.main.change_stage'), -
django/contrib/admin/views/main.py
81 81 myappend('_' + item) 82 82 return "".join(res) 83 83 84 def get_javascript_imports(opts, auto_populated_fields, field_sets ):84 def get_javascript_imports(opts, auto_populated_fields, field_sets, has_delete_permission): 85 85 # Put in any necessary JavaScript imports. 86 86 js = ['js/core.js', 'js/admin/RelatedObjectLookups.js'] 87 87 if auto_populated_fields: … … 92 92 js.extend(['js/getElementsBySelector.js', 'js/dom-drag.js' , 'js/admin/ordering.js']) 93 93 if opts.admin.js: 94 94 js.extend(opts.admin.js) 95 if has_delete_permission: 96 js.extend(['js/admin/delete.js']) 95 97 seen_collapse = False 96 98 for field_set in field_sets: 97 99 if not seen_collapse and 'collapse' in field_set.classes: … … 209 211 'auto_populated_fields': auto_populated_fields, 210 212 'bound_field_sets': bound_field_sets, 211 213 '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()]), 213 215 'ordered_objects': ordered_objects, 214 216 'inline_related_objects': inline_related_objects, 215 217 'form_url': form_url, … … 731 733 732 734 def change_list(request, app_label, model_name): 733 735 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) 734 739 if model is None: 735 740 raise Http404, "App %r, model %r, not found" % (app_label, model_name) 736 741 if not request.user.has_perm(app_label + '.' + model._meta.get_change_permission()): … … 752 757 'cl': cl, 753 758 }) 754 759 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()])}), 755 762 return render_to_response(['admin/%s/%s/change_list.html' % (app_label, cl.opts.object_name.lower()), 756 763 'admin/%s/change_list.html' % app_label, 757 764 'admin/change_list.html'], context_instance=c) 758 765 change_list = staff_member_required(never_cache(change_list)) 766 767 def 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
1 1 {% 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 %} 3 7 {% block stylesheet %}{% admin_media_prefix %}css/changelists.css{% endblock %} 4 8 {% block bodyclass %}change-list{% endblock %} 5 9 {% block userlinks %}<a href="../../doc/">{% trans 'Documentation' %}</a> / <a href="../../password_change/">{% trans 'Change password' %}</a> / <a href="../../logout/">{% trans 'Log out' %}</a>{% endblock %} … … 7 11 {% block coltype %}flex{% endblock %} 8 12 {% block content %} 9 13 <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> 13 26 <div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist"> 14 27 {% block search %}{% search_form cl %}{% endblock %} 15 28 {% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %} 16 29 {% block filters %}{% filters cl %}{% endblock %} 17 {% block result_list %}{% result_list cl %}{% endblock %}30 {% block result_list %}{% result_list cl user %}{% endblock %} 18 31 {% block pagination %}{% pagination cl %}{% endblock %} 19 32 </div> 20 33 </div> -
django/contrib/admin/templates/admin/change_list_results.html
1 1 {% if results %} 2 <form name="delete_checked_form" method="POST" action="delete/"> 2 3 <table cellspacing="0"> 3 4 <thead> 4 5 <tr> … … 14 15 {% endfor %} 15 16 </tbody> 16 17 </table> 18 </form> 17 19 {% endif %}