Ticket #3380: patch_django.diff
File patch_django.diff, 5.6 KB (added by , 18 years ago) |
---|
-
django/contrib/admin/urls.py
35 35 # Add/change/delete/history 36 36 ('^([^/]+)/([^/]+)/$', 'django.contrib.admin.views.main.change_list'), 37 37 ('^([^/]+)/([^/]+)/add/$', 'django.contrib.admin.views.main.add_stage'), 38 ('^([^/]+)/([^/]+)/backup/$', 'django.contrib.admin.views.main.backup'), 39 ('^([^/]+)/([^/]+)/restore/$', 'django.contrib.admin.views.main.restore'), 38 40 ('^([^/]+)/([^/]+)/(.+)/history/$', 'django.contrib.admin.views.main.history'), 39 41 ('^([^/]+)/([^/]+)/(.+)/delete/$', 'django.contrib.admin.views.main.delete_stage'), 40 42 ('^([^/]+)/([^/]+)/(.+)/$', 'django.contrib.admin.views.main.change_stage'), -
django/contrib/admin/views/main.py
13 13 from django.utils.html import escape 14 14 from django.utils.text import capfirst, get_text_list 15 15 import operator 16 import cPickle 17 from time import strftime, gmtime 16 18 17 19 from django.contrib.admin.models import LogEntry, ADDITION, CHANGE, DELETION 18 20 if not LogEntry._meta.installed: … … 767 769 'admin/%s/change_list.html' % app_label, 768 770 'admin/change_list.html'], context_instance=c) 769 771 change_list = staff_member_required(never_cache(change_list)) 772 773 def backup(request, app_label, model_name): 774 model = models.get_model(app_label, model_name) 775 if model is None: 776 raise Http404("App %r, model %r, not found" % (app_label, model_name)) 777 opts = model._meta 778 779 if not request.user.has_perm(app_label + '.' + opts.get_add_permission()): 780 raise PermissionDenied 781 782 objects = model.objects.all() 783 l=[] 784 for o in objects: 785 l.append(o) 786 response = HttpResponse(mimetype="text/plain") 787 response['Content-Disposition'] = 'attachment; filename=backup_%s__%s.txt' % (model_name, strftime('%c').replace(" ", "_")) 788 cPickle.dump(l, response) 789 return response 790 791 def restore(request, app_label, model_name): 792 model = models.get_model(app_label, model_name) 793 if model is None: 794 raise Http404("App %r, model %r, not found" % (app_label, model_name)) 795 opts = model._meta 796 797 if not request.user.has_perm(app_label + '.' + opts.get_add_permission()): 798 raise PermissionDenied 799 800 c={"unloaded":True} 801 if request.FILES.has_key("restore_file"): 802 try: 803 objects=cPickle.loads(request.FILES["restore_file"]["content"]) 804 except: 805 c={'unloaded':True, 'file_invalid':True} 806 else: 807 c={"objects_updated":[], "loaded":True} 808 for o in objects: 809 o.save() 810 c["objects_updated"].append(str(o)) 811 return render_to_response(["admin/%s/%s/restore.html" % (app_label, model._meta.object_name.lower()), 812 "admin/%s/restore.html" % app_label , 813 "admin/restore.html"], c) 814 No newline at end of file -
django/contrib/admin/templates/admin/change_list.html
7 7 {% block coltype %}flex{% endblock %} 8 8 {% block content %} 9 9 <div id="content-main"> 10 <p><a href="backup/">{% trans 'Backup' %}</a> | <a href="restore/">{% trans 'Restore' %}</a></p> 10 11 {% block object-tools %} 11 12 {% if has_add_permission %} 12 13 <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> -
django/contrib/admin/templates/admin/restore.html
1 {% extends "admin/base_site.html" %} 2 {% load i18n %} 3 {% block userlinks %}<a href="../../../../doc/">{% trans 'Documentation' %}</a> / <a href="../../../../password_change/">{% trans 'Change password' %}</a> / <a href="../../../../logout/">{% trans 'Log out' %}</a>{% endblock %} 4 5 {% block content %} 6 {% if perms_lacking %} 7 <p>{% blocktrans with object|escape as escaped_object %}Restoring the {{ object_name }} '{{ escaped_object }}' would result in updating related objects, but your account doesn't have permission to update the following types of objects:{% endblocktrans %}</p> 8 <ul> 9 {% for obj in perms_lacking %} 10 <li>{{ obj|escape }}</li> 11 {% endfor %} 12 </ul> 13 {% endif %} 14 {% if unloaded %} 15 {% if file_invalid %} 16 <p>{% blocktrans %}Invalid file !{% endblocktrans %}</p> 17 18 {% else %} 19 <p>{% blocktrans %}Caution ! You will override all the existing objects in the database !{% endblocktrans %}</p> 20 <form action="" method="post" enctype="multipart/form-data"> 21 <div> 22 <input type="file" name="restore_file"> 23 </div> 24 <div> 25 <input type="submit" value="{% trans "Submit" %}" /> 26 </div> 27 </form> 28 {% endif %} 29 30 {% else %} 31 <p><p>{% blocktrans with object|escape as escaped_object %}Congratulation ! The following objects were updated :{% endblocktrans %}</p> 32 <ul> 33 {% for obj in objects_updated %} 34 <li>{{ obj|escape }}</li> 35 {% endfor %} 36 </ul> 37 {% endif %} 38 {% endblock %}