Ticket #6406: admin_options.diff

File admin_options.diff, 2.1 KB (added by tanzer@…, 16 years ago)

Factor _save_form and _save_formset from save_add and save_change.

  • contrib/admin/options.py

     
    353353        for inline in self.inline_instances:
    354354            yield inline.get_formset(request, obj)
    355355
     356    def _save_form(self, request, model, form, commit=True) :
     357        return form.save(commit=commit)
     358
     359    def _save_formset(self, request, model, formset) :
     360        return formset.save()
     361
    356362    def save_add(self, request, model, form, formsets, post_url_continue):
    357363        """
    358364        Saves the object in the "add" stage and returns an HttpResponseRedirect.
     
    362368        from django.contrib.admin.models import LogEntry, ADDITION
    363369        from django.contrib.contenttypes.models import ContentType
    364370        opts = model._meta
    365         new_object = form.save(commit=True)
     371        new_object = self._save_form(request, model, form, commit=True)
    366372
    367373        if formsets:
    368374            for formset in formsets:
    369375                # HACK: it seems like the parent obejct should be passed into
    370376                # a method of something, not just set as an attribute
    371377                formset.instance = new_object
    372                 formset.save()
     378                self._save_formset(request, model, form)
    373379
    374380        pk_value = new_object._get_pk_val()
    375381        LogEntry.objects.log_action(request.user.id, ContentType.objects.get_for_model(model).id, pk_value, force_unicode(new_object), ADDITION)
     
    412418        from django.contrib.admin.models import LogEntry, CHANGE
    413419        from django.contrib.contenttypes.models import ContentType
    414420        opts = model._meta
    415         new_object = form.save(commit=True)
     421        new_object = self._save_form(request, model, form, commit=True)
    416422        pk_value = new_object._get_pk_val()
    417423
    418424        if formsets:
    419425            for formset in formsets:
    420                 formset.save()
     426                self._save_formset(request, model, form)
    421427
    422428        # Construct the change message.                 
    423429        change_message = []
Back to Top