'Handler for HTTP POST requests.'

def post(self, request, *args, **kwargs):

    context = self.get_context_data(**kwargs)
    workflow = context[self.context_object_name]
    try:
        validate_step_start = int(self.request.META.get('HTTP_X_HORIZON_VALIDATE_STEP_START', ''))
        validate_step_end = int(self.request.META.get('HTTP_X_HORIZON_VALIDATE_STEP_END', ''))
    except ValueError:
        pass
    else:
        data = self.validate_steps(request, workflow, validate_step_start, validate_step_end)
        return http.HttpResponse(json.dumps(data), content_type='application/json')
    if (not workflow.is_valid()):
        return self.render_to_response(context)
    try:
        success = workflow.finalize()
    except forms.ValidationError:
        return self.render_to_response(context)
    except Exception:
        success = False
        exceptions.handle(request)
    if success:
        msg = workflow.format_status_message(workflow.success_message)
        messages.success(request, msg)
    else:
        msg = workflow.format_status_message(workflow.failure_message)
        messages.error(request, msg)
    if ('HTTP_X_HORIZON_ADD_TO_FIELD' in self.request.META):
        field_id = self.request.META['HTTP_X_HORIZON_ADD_TO_FIELD']
        response = http.HttpResponse()
        if workflow.object:
            data = [self.get_object_id(workflow.object), self.get_object_display(workflow.object)]
            response.content = json.dumps(data)
            response['X-Horizon-Add-To-Field'] = field_id
        return response
    next_url = self.request.POST.get(workflow.redirect_param_name)
    return shortcuts.redirect((next_url or workflow.get_success_url()))
