Ejemplo n.º 1
0
    def form_valid(self, form):
        attachment_formset = FeedbackAttachmentFormSet(self.request.POST,
                                            self.request.FILES,
                                            instance=self.object)
        is_valid = all([attachment_formset.is_valid()])

        if is_valid:
            form.save()
            attachment_formset.save()
            return HttpResponseRedirect(self.get_success_url())

        ctx = self.get_context_data(form=form,
                                    attachment_formset=attachment_formset)
        return self.render_to_response(ctx)
Ejemplo n.º 2
0
    def form_valid(self, form):
        feedback = form.save()
        attachment_formset = FeedbackAttachmentFormSet(self.request.POST,
                                            self.request.FILES,
                                            instance=feedback)

        is_valid = all([attachment_formset.is_valid()])
        if is_valid:
            attachment_formset.save()
            return HttpResponseRedirect(self.get_success_url(feedback))

        messages.error(self.request,
                       _("Your submitted data was not valid - please "
                         "correct the below errors"))

        # Delete feedback as its relations were not valid
        feedback.delete()
        ctx = self.get_context_data(form=form,
                                    attachment_formset=attachment_formset)
        return self.render_to_response(ctx)