Ticket #23387: formset_save_as_validation.3.patch

File formset_save_as_validation.3.patch, 2.2 KB (added by John R. Tipton, 10 years ago)
  • django/contrib/admin/options.py

    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    index 8a7483c..67b09d3 100644
    a b class ModelAdmin(BaseModelAdmin):  
    11811181            'preserved_filters': self.get_preserved_filters(request),
    11821182        }
    11831183        context.update(extra_context or {})
     1184        # Send back to Change form if we get a validation error preventing Save as New
     1185        if request.method == 'POST' and not form_validated and "_saveasnew" in request.POST:
     1186            # Hide Save and Save Continue buttons since Save as New was previously chosen and the others are broken.
     1187            context['show_save'] = False
     1188            context['show_save_and_continue']  = False
     1189            return self.render_change_form(request, context, form_url=form_url, change=True)
    11841190        return self.render_change_form(request, context, form_url=form_url, add=True)
    11851191
    11861192    @csrf_protect_m
  • django/contrib/admin/templatetags/admin_modify.py

    diff --git a/django/contrib/admin/templatetags/admin_modify.py b/django/contrib/admin/templatetags/admin_modify.py
    index 98ac1a6..8f7d6fb 100644
    a b def submit_row(context):  
    2828    change = context['change']
    2929    is_popup = context['is_popup']
    3030    save_as = context['save_as']
     31    show_save = context.get('show_save', True)
     32    show_save_and_continue = context.get('show_save_and_continue', True)
    3133    ctx = {
    3234        'opts': opts,
    3335        'show_delete_link': (not is_popup and context['has_delete_permission']
    def submit_row(context):  
    3537        'show_save_as_new': not is_popup and change and save_as,
    3638        'show_save_and_add_another': context['has_add_permission'] and
    3739                            not is_popup and (not save_as or context['add']),
    38         'show_save_and_continue': not is_popup and context['has_change_permission'],
     40        'show_save_and_continue': not is_popup and context['has_change_permission'] and show_save_and_continue,
    3941        'is_popup': is_popup,
    40         'show_save': True,
     42        'show_save': show_save,
    4143        'preserved_filters': context.get('preserved_filters'),
    4244    }
    4345    if context.get('original') is not None:
Back to Top