Ticket #2383: new_multi_delete.diff
File new_multi_delete.diff, 9.7 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
66 66 } 67 67 pagination = register.inclusion_tag('admin/pagination.html')(pagination) 68 68 69 def result_headers(cl ):69 def result_headers(cl, user): 70 70 lookup_opts = cl.lookup_opts 71 71 72 72 for i, field_name in enumerate(lookup_opts.admin.list_display): … … 100 100 "sortable": True, 101 101 "url": cl.get_query_string({ORDER_VAR: i, ORDER_TYPE_VAR: new_order_type}), 102 102 "class_attrib": (th_classes and ' class="%s"' % ' '.join(th_classes) or '')} 103 delete_permission = '%s.%s' % (cl.model._meta.app_label, cl.opts.get_delete_permission()) 104 if user.get_all_permissions().__contains__(delete_permission): 105 yield{"text":"Delete?"} 103 106 104 def items_for_result(cl, result ):107 def items_for_result(cl, result, user): 105 108 first = True 106 109 pk = cl.lookup_opts.pk.attname 107 110 for field_name in cl.lookup_opts.admin.list_display: … … 173 176 (table_tag, row_class, url, (cl.is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %r); return false;"' % result_id or ''), result_repr, table_tag)) 174 177 else: 175 178 yield ('<td%s>%s</td>' % (row_class, result_repr)) 179 delete_permision = '%s.%s' % (cl.model._meta.app_label, cl.opts.get_delete_permission()) 180 if user.get_all_permissions().__contains__(delete_permision) or user.is_superuser: 181 yield('<td><input type="checkbox" name="%s" /></td>' % result_id) 176 182 177 def results(cl ):183 def results(cl, user): 178 184 for res in cl.result_list: 179 yield list(items_for_result(cl,res ))185 yield list(items_for_result(cl,res, user)) 180 186 181 def result_list(cl ):187 def result_list(cl, user): 182 188 return {'cl': cl, 183 'result_headers': list(result_headers(cl )),184 'results': list(results(cl ))}189 'result_headers': list(result_headers(cl, user)), 190 'results': list(results(cl, user))} 185 191 result_list = register.inclusion_tag("admin/change_list_results.html")(result_list) 186 192 187 193 def date_hierarchy(cl): -
django/contrib/admin/urls.py
33 33 # Add/change/delete/history 34 34 ('^([^/]+)/([^/]+)/$', 'django.contrib.admin.views.main.change_list'), 35 35 ('^([^/]+)/([^/]+)/add/$', 'django.contrib.admin.views.main.add_stage'), 36 ('^([^/]+)/([^/]+)/delete/$', 'django.contrib.admin.views.main.delete_checked'), 36 37 ('^([^/]+)/([^/]+)/(.+)/history/$', 'django.contrib.admin.views.main.history'), 37 38 ('^([^/]+)/([^/]+)/(.+)/delete/$', 'django.contrib.admin.views.main.delete_stage'), 38 39 ('^([^/]+)/([^/]+)/(.+)/$', 'django.contrib.admin.views.main.change_stage'), -
django/contrib/admin/views/main.py
78 78 myappend('_' + item) 79 79 return "".join(res) 80 80 81 def get_javascript_imports(opts, auto_populated_fields, field_sets ):81 def get_javascript_imports(opts, auto_populated_fields, field_sets, has_delete_permission): 82 82 # Put in any necessary JavaScript imports. 83 83 js = ['js/core.js', 'js/admin/RelatedObjectLookups.js'] 84 84 if auto_populated_fields: … … 89 89 js.extend(['js/getElementsBySelector.js', 'js/dom-drag.js' , 'js/admin/ordering.js']) 90 90 if opts.admin.js: 91 91 js.extend(opts.admin.js) 92 if has_delete_permission: 93 js.extend(['js/admin/delete.js']) 92 94 seen_collapse = False 93 95 for field_set in field_sets: 94 96 if not seen_collapse and 'collapse' in field_set.classes: … … 206 208 'auto_populated_fields': auto_populated_fields, 207 209 'bound_field_sets': bound_field_sets, 208 210 'first_form_field_id': first_form_field_id, 209 'javascript_imports': get_javascript_imports(opts, auto_populated_fields, field_sets ),211 'javascript_imports': get_javascript_imports(opts, auto_populated_fields, field_sets, context['perms'][app_label][opts.get_delete_permission()]), 210 212 'ordered_objects': ordered_objects, 211 213 'inline_related_objects': inline_related_objects, 212 214 'form_url': form_url, … … 738 740 739 741 def change_list(request, app_label, model_name): 740 742 model = models.get_model(app_label, model_name) 743 opts = model._meta 744 auto_populated_fields = [f for f in opts.fields if f.prepopulate_from] 745 field_sets = opts.admin.get_field_sets(opts) 741 746 if model is None: 742 747 raise Http404, "App %r, model %r, not found" % (app_label, model_name) 743 748 if not request.user.has_perm(app_label + '.' + model._meta.get_change_permission()): … … 759 764 'cl': cl, 760 765 }) 761 766 c.update({'has_add_permission': c['perms'][app_label][cl.opts.get_add_permission()]}), 767 c.update({'has_delete_permission': c['perms'][app_label][cl.opts.get_delete_permission()]}), 768 c.update({'javascript_imports': get_javascript_imports(opts, auto_populated_fields, field_sets, c['perms'][app_label][opts.get_delete_permission()])}), 762 769 return render_to_response(['admin/%s/%s/change_list.html' % (app_label, cl.opts.object_name.lower()), 763 770 'admin/%s/change_list.html' % app_label, 764 771 'admin/change_list.html'], context_instance=c) 765 772 change_list = staff_member_required(never_cache(change_list)) 773 774 def delete_checked(request, app_name, model_name): 775 if request.POST: 776 model = models.get_model(app_name, model_name) 777 for item in request.POST: 778 ob = model.objects.get(id=item) 779 ob.delete() 780 return HttpResponseRedirect('/admin/%s/%s/' % (app_name, model_name)) 781 else: 782 return HttpResponseRedirect('/admin/%s/%s/' % (app_name, model_name)) 783 -
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 %}