from django.views.generic.edit import FormView


class InlineEditView(FormView):
    """Generic inline edit view: GET returns form fragment, POST returns updated fragment."""

    def get(self, request, *args, **kwargs):
        return self.render_to_response(self.get_context_data())

    def post(self, request, *args, **kwargs):
        form = self.get_form()
        if form.is_valid():
            self.object = form.save()
            return self.render_to_response(self.get_context_data(object=self.object))
        return self.form_invalid(form)
