def form_valid(self, form):
        # This overrides the original Django form_valid method

        self.object = form.save(commit=False)

        if hasattr(self, 'get_instance_extra_data'):
            for key, value in self.get_instance_extra_data().items():
                setattr(self.object, key, value)

        if hasattr(self, 'get_save_extra_data'):
            save_extra_data = self.get_save_extra_data()
        else:
            save_extra_data = {}

        self.object.save(**save_extra_data)

        try:
            messages.success(
                self.request,
                _(
                    '%s created successfully.'
                ) % self.extra_context['object_name']
            )
        except __HOLE__:
            messages.success(
                self.request, _('New object created successfully.')
            )

        return HttpResponseRedirect(self.get_success_url())
dataset/ETHPy150Open mayan-edms/mayan-edms/mayan/apps/common/generics.py/SingleObjectCreateView.form_valid