Esempio n. 1
0
def manage_p(request, url):
    article = Person.objects.get(pk=url)
    if request.method == 'GET':
        form = AddPersonForm(instance=article)
        return render_to_response('m_person.html', {'form': form}, context_instance=RequestContext(request))
    form = AddPersonForm(request.POST or None, request.FILES or None, instance=article)
    response = lambda data: HttpResponse(simplejson.dumps(data), mimetype="application/json")
    if form.is_valid():
        form.save()
        return response('Data saved')
    else:
        errors = str()
        for data in form.errors.values():
            errors += str(data)
        return response(errors)
def team_add_person(request):
    if request.method == "POST":
        form = AddPersonForm(request, data=request.POST)
        if form.is_valid():

            # contract_type_id = int(form.cleaned_data['contract_type'])
            team_id = form.cleaned_data.pop("team_id")
            newperson = Person(**form.cleaned_data)
            newperson.save()
            TeamPerson(arrival_date=newperson.arrival_date, team_id=team_id, person_id=newperson.id).save()

            return {"status": "OK"}
        else:
            return {"status": "KO", "error": str(form.errors)}
    else:
        form = AddPersonForm(request)

    return {"form": form, "status": "NEW"}
Esempio n. 3
0
def manage_p(request, url):
    article = Person.objects.get(pk=url)
    if request.method == 'GET':
        form = AddPersonForm(instance=article)
        return render_to_response('m_person.html', {'form': form},
                                  context_instance=RequestContext(request))
    form = AddPersonForm(request.POST or None,
                         request.FILES or None,
                         instance=article)
    response = lambda data: HttpResponse(simplejson.dumps(data),
                                         mimetype="application/json")
    if form.is_valid():
        form.save()
        return response('Data saved')
    else:
        errors = str()
        for data in form.errors.values():
            errors += str(data)
        return response(errors)