Beispiel #1
0
def valid(request, requirement_id=0):
    if requirement_id:
        requirement = Requirement.objects.get(pk=requirement_id)
        requirement_form = RequirementForm(request.POST, instance=requirement)
    else:
        requirement_form = RequirementForm(request.POST)

    if requirement_form.is_valid():
        requirement = requirement_form.save()
        return success(message='Requirement saved',
                       data={ "parent_id" : getattr(requirement.parent,"id", 0),
                              "current_id" : requirement.id })

    return failed(message="Validation errors %s" % requirement_form.error_message(),
                  data=requirement_form.errors_list())
Beispiel #2
0
def valid(request, requirement_id=0):
    if requirement_id:
        requirement = Requirement.objects.get(pk=requirement_id)
        requirement_form = RequirementForm(request.POST, instance=requirement)
    else:
        requirement_form = RequirementForm(request.POST)

    if requirement_form.is_valid():
        requirement = requirement_form.save()
        return success(message='Requirment saved', 
                       data={ "parent_id" : getattr(requirement.parent,"id", 0), 
                              "current_id" : requirement.id })
    
    # TODO: move this functionality to helpers
    return failed(message="Validation errors %s" % " ".join([e for e in requirement_form.non_field_errors()]),
                  data=[(k, v[0]) for k, v in requirement_form.errors.items()])