67 | | def get_deleted_objects(objs, opts, user, admin_site, using): |
68 | | """ |
69 | | Find all objects related to ``objs`` that should also be deleted. ``objs`` |
70 | | must be a homogenous iterable of objects (e.g. a QuerySet). |
71 | | |
72 | | Returns a nested list of strings suitable for display in the |
73 | | template with the ``unordered_list`` filter. |
74 | | |
75 | | """ |
76 | | collector = NestedObjects(using=using) |
77 | | collector.collect(objs) |
78 | | perms_needed = set() |
79 | | |
80 | | def format_callback(obj): |
81 | | has_admin = obj.__class__ in admin_site._registry |
82 | | opts = obj._meta |
83 | | |
84 | | if has_admin: |
85 | | admin_url = reverse('%s:%s_%s_change' |
86 | | % (admin_site.name, |
87 | | opts.app_label, |
88 | | opts.object_name.lower()), |
89 | | None, (quote(obj._get_pk_val()),)) |
90 | | p = '%s.%s' % (opts.app_label, |
91 | | opts.get_delete_permission()) |
92 | | if not user.has_perm(p): |
93 | | perms_needed.add(opts.verbose_name) |
94 | | # Display a link to the admin page. |
95 | | return mark_safe(u'%s: <a href="%s">%s</a>' % |
96 | | (escape(capfirst(opts.verbose_name)), |
97 | | admin_url, |
98 | | escape(obj))) |
99 | | else: |
100 | | # Don't display link to edit, because it either has no |
101 | | # admin or is edited inline. |
102 | | return u'%s: %s' % (capfirst(opts.verbose_name), |
103 | | force_unicode(obj)) |
104 | | |
105 | | to_delete = collector.nested(format_callback) |
106 | | |
107 | | protected = [format_callback(obj) for obj in collector.protected] |
108 | | |
109 | | return to_delete, perms_needed, protected |
110 | | |
111 | | |
| 118 | def get_deleted_objects(objs, opts, user, admin_site, using, collector_class=NestedObjects): |
| 119 | """ |
| 120 | Find all objects related to ``objs`` that should also be deleted. ``objs`` |
| 121 | must be a homogenous iterable of objects (e.g. a QuerySet). |
| 122 | |
| 123 | Returns a nested list of strings suitable for display in the |
| 124 | template with the ``unordered_list`` filter. |
| 125 | |
| 126 | """ |
| 127 | collector = collector_class(using=using) |
| 128 | collector.collect(objs) |
| 129 | perms_needed = set() |
| 130 | |
| 131 | def format_callback(obj): |
| 132 | has_admin = obj.__class__ in admin_site._registry |
| 133 | opts = obj._meta |
| 134 | |
| 135 | if has_admin: |
| 136 | admin_url = reverse('%s:%s_%s_change' |
| 137 | % (admin_site.name, |
| 138 | opts.app_label, |
| 139 | opts.object_name.lower()), |
| 140 | None, (quote(obj._get_pk_val()),)) |
| 141 | p = '%s.%s' % (opts.app_label, |
| 142 | opts.get_delete_permission()) |
| 143 | if not user.has_perm(p): |
| 144 | perms_needed.add(opts.verbose_name) |
| 145 | # Display a link to the admin page. |
| 146 | return mark_safe(u'%s: <a href="%s">%s</a>' % |
| 147 | (escape(capfirst(opts.verbose_name)), |
| 148 | admin_url, |
| 149 | escape(obj))) |
| 150 | else: |
| 151 | # Don't display link to edit, because it either has no |
| 152 | # admin or is edited inline. |
| 153 | return u'%s: %s' % (capfirst(opts.verbose_name), |
| 154 | force_unicode(obj)) |
| 155 | |
| 156 | to_delete = collector.nested(format_callback) |
| 157 | |
| 158 | protected = [format_callback(obj) for obj in collector.protected] |
| 159 | |
| 160 | return to_delete, perms_needed, protected |
| 161 | |
| 162 | |