Ticket #22: file_del.patch
File file_del.patch, 4.8 KB (added by , 19 years ago) |
---|
-
contrib/admin/urls/admin.py
53 53 ('^(?P<app_label>[^/]+)/(?P<module_name>[^/]+)/add/$', 'django.contrib.admin.views.main.add_stage'), 54 54 ('^(?P<app_label>[^/]+)/(?P<module_name>[^/]+)/(?P<object_id>.+)/history/$', 'django.contrib.admin.views.main.history'), 55 55 ('^(?P<app_label>[^/]+)/(?P<module_name>[^/]+)/(?P<object_id>.+)/delete/$', 'django.contrib.admin.views.main.delete_stage'), 56 ('^(?P<app_label>[^/]+)/(?P<module_name>[^/]+)/(?P<object_id>.+)/delete_file/(?P<attname>.+)/$', 'django.contrib.admin.views.main.delete_file'), 56 57 ('^(?P<app_label>[^/]+)/(?P<module_name>[^/]+)/(?P<object_id>.+)/$', 'django.contrib.admin.views.main.change_stage'), 57 58 ) 58 59 urlpatterns = patterns('', *urlpatterns) -
contrib/admin/templatetags/admin_modify.py
243 243 def object_pk(bound_manip, ordered_obj): 244 244 return bound_manip.get_ordered_object_pk(ordered_obj) 245 245 object_pk = register.simple_tag(object_pk) 246 247 def admin_file_delete_link(bound_field): 248 s = '' 249 container_obj = bound_field.original 250 if container_obj: 251 inf = container_obj._meta 252 pk = getattr(container_obj,inf.pk.name) 253 s = "../../../%s/%s/%s/delete_file/%s/" % \ 254 (inf.app_label,inf.module_name,pk,bound_field.field.attname) 255 return s 256 admin_file_delete_link = register.simple_tag(admin_file_delete_link) -
contrib/admin/views/main.py
670 670 'object': obj, 671 671 }, context_instance=Context(request)) 672 672 history = staff_member_required(history) 673 674 def delete_file(request, app_label, module_name, object_id,attname): 675 try: 676 mod = meta.get_module(app_label, module_name) 677 except ImportError: 678 raise Http404 679 opts = mod.Klass._meta 680 if not request.user.has_perm(app_label + '.' + opts.get_delete_permission()): 681 raise PermissionDenied 682 obj = get_object_or_404(mod, pk=object_id) 683 try: 684 delete_f = getattr(obj, 'delete_%s_file' % attname) 685 delete_f() 686 except AttributeError: pass 687 return HttpResponseRedirect(request.META['HTTP_REFERER']) 688 delete_file = staff_member_required(delete_file) -
contrib/admin/templates/widget/file.html
1 1 {% load admin_modify i18n %}{% if bound_field.original_value %} 2 {% trans "Currently:" %} <a href="{{ bound_field.original_url }}" > {{ bound_field.original_value }} </a><br /> 2 {% trans "Currently:" %} <a href="{{ bound_field.original_url }}" > {{ bound_field.original_value }} </a> 3 <br /> 4 <a href="{% admin_file_delete_link bound_field %}">{% trans "Delete this file." %}</a> 5 <br /> 3 6 {% trans "Change:" %}{% output_all bound_field.form_fields %} 4 7 {% else %} {% output_all bound_field.form_fields %} {% endif %} -
core/meta/__init__.py
828 828 func = curry(method_save_file, f) 829 829 func.alters_data = True 830 830 setattr(new_class, 'save_%s_file' % f.name, func) 831 func = curry(method_delete_file, f) 832 func.alters_data = True 833 setattr(new_class, 'delete_%s_file' % f.name, func) 831 834 if isinstance(f, ImageField): 832 835 # Add get_BLAH_width and get_BLAH_height methods, but only 833 836 # if the image field doesn't have width and height cache … … 1310 1313 # Save the object, because it has changed. 1311 1314 self.save() 1312 1315 1316 def method_delete_file(field, self): 1317 filename = getattr(self, 'get_%s_filename' % field.name)() 1318 #start of physical file removal logic 1319 #you might want to comment out this block if you are accustomed 1320 #the share one physical file/image among many objects 1321 old_att_value = getattr(self, field.attname) 1322 if old_att_value: 1323 if os.path.exists(filename): 1324 try: os.unlink(filename) 1325 except: pass 1326 #end of physical file removal logic 1327 setattr(self, field.attname, '') 1328 # Save the object, because it has changed. 1329 self.save() 1330 1313 1331 # IMAGE FIELD METHODS ###################### 1314 1332 1315 1333 def method_get_image_width(field, self):