Code

Ticket #5520: 01-admin-saveas.2.diff

File 01-admin-saveas.2.diff, 5.8 KB (added by Petr Marhoun <petr.marhoun@…>, 6 years ago)

new version - after autoescape merge

Line 
1=== modified file 'django/contrib/admin/options.py'
2--- django/contrib/admin/options.py     2007-11-30 13:28:56 +0000
3+++ django/contrib/admin/options.py     2007-11-30 14:03:58 +0000
4@@ -459,7 +459,8 @@
5         request.user.message_set.create(message=msg)
6         return HttpResponseRedirect(redirect_url)
7 
8-    def render_change_form(self, model, context, add=False, change=False, form_url=''):
9+    def render_change_form(self, request, context, add=False, change=False):
10+        model = self.model
11         opts = model._meta
12         app_label = opts.app_label
13         ordered_objects = opts.get_ordered_objects()
14@@ -471,10 +472,11 @@
15             'has_file_field': True, # FIXME - this should check if form or formsets have a FileField,
16             'has_absolute_url': hasattr(model, 'get_absolute_url'),
17             'ordered_objects': ordered_objects,
18-            'form_url': mark_safe(form_url),
19             'opts': opts,
20             'content_type_id': ContentType.objects.get_for_model(model).id,
21             'save_on_top': self.save_on_top,
22+            'save_as': self.save_as,
23+            'is_save_as': request.POST.has_key('_saveasnew'),
24         }
25         context.update(extra_context)
26         return render_to_response([
27@@ -482,7 +484,7 @@
28             "admin/%s/change_form.html" % app_label,
29             "admin/change_form.html"], context_instance=context)
30 
31-    def add_view(self, request, form_url=''):
32+    def add_view(self, request):
33         "The 'add' admin view for this model."
34         model = self.model
35         opts = model._meta
36@@ -527,7 +529,7 @@
37             'media': media,
38             'inline_admin_formsets': inline_admin_formsets,
39         })
40-        return self.render_change_form(model, c, add=True)
41+        return self.render_change_form(request, c, add=True)
42     
43     def change_view(self, request, object_id):
44         "The 'change' admin view for this model."
45@@ -549,8 +551,8 @@
46         if obj is None:
47             raise Http404('%s object with primary key %r does not exist.' % (opts.verbose_name, escape(object_id)))
48 
49-        if request.POST and request.POST.has_key("_saveasnew"):
50-            return self.add_view(request, form_url='../../add/')
51+        if request.POST and request.POST.has_key('_saveasnew'):
52+            return self.add_view(request)
53 
54         ModelForm = self.form_change(request, obj)
55         inline_formsets = []
56@@ -604,7 +606,7 @@
57             'media': media,
58             'inline_admin_formsets': inline_admin_formsets,
59         })
60-        return self.render_change_form(model, c, change=True)
61+        return self.render_change_form(request, c, change=True)
62 
63     def changelist_view(self, request):
64         "The 'change list' admin view for this model."
65
66=== modified file 'django/contrib/admin/templates/admin/change_form.html'
67--- django/contrib/admin/templates/admin/change_form.html       2007-11-30 09:51:14 +0000
68+++ django/contrib/admin/templates/admin/change_form.html       2007-11-30 10:59:35 +0000
69@@ -30,7 +30,7 @@
70   </ul>
71 {% endif %}{% endif %}
72 {% endblock %}
73-<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="{{ opts.module_name }}_form">{% block form_top %}{% endblock %}
74+<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="." method="post" id="{{ opts.module_name }}_form">{% block form_top %}{% endblock %}
75 <div>
76 {% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
77 {% if save_on_top %}{% submit_row %}{% endif %}
78
79=== modified file 'django/contrib/admin/templatetags/admin_modify.py'
80--- django/contrib/admin/templatetags/admin_modify.py   2007-11-30 09:51:14 +0000
81+++ django/contrib/admin/templatetags/admin_modify.py   2007-11-30 10:59:35 +0000
82@@ -18,20 +18,20 @@
83 
84 def submit_row(context):
85     opts = context['opts']
86+    add = context['add']
87     change = context['change']
88     is_popup = context['is_popup']
89-    # TODO: Fix this hack.
90-    # save_as = opts.admin.save_as
91-    save_as = False
92+    save_as = context['save_as']
93+    is_save_as = context['is_save_as']
94     return {
95         'onclick_attrib': (opts.get_ordered_objects() and change
96                             and 'onclick="submitOrderForm();"' or ''),
97         'show_delete_link': (not is_popup and context['has_delete_permission']
98                               and (change or context['show_delete'])),
99-        'show_save_as_new': not is_popup and change and save_as,
100-        'show_save_and_add_another': not is_popup and (not save_as or context['add']),
101-        'show_save_and_continue': not is_popup and context['has_change_permission'],
102-        'show_save': True
103+        'show_save_as_new': not is_popup and save_as and (is_save_as or change),
104+        'show_save_and_add_another': not is_popup and not is_save_as and (add or not save_as),
105+        'show_save_and_continue': not is_popup and not is_save_as and context['has_change_permission'],
106+        'show_save':  not is_save_as,
107     }
108 submit_row = register.inclusion_tag('admin/submit_line.html', takes_context=True)(submit_row)
109 
110
111=== modified file 'django/contrib/admin/views/auth.py'
112--- django/contrib/admin/views/auth.py  2007-11-13 02:22:00 +0000
113+++ django/contrib/admin/views/auth.py  2007-11-13 02:19:13 +0000
114@@ -40,6 +40,8 @@
115         'auto_populated_fields': (),
116         'opts': User._meta,
117         'username_help_text': User._meta.get_field('username').help_text,
118+        'save_as': False,
119+        'is_save_as': False,
120     }, context_instance=template.RequestContext(request))
121 user_add_stage = staff_member_required(user_add_stage)
122 
123@@ -71,5 +73,7 @@
124         'opts': User._meta,
125         'original': user,
126         'show_save': True,
127+        'save_as': False,
128+        'is_save_as': False,
129     }, context_instance=template.RequestContext(request))
130 user_change_password = staff_member_required(user_change_password)
131