示例#1
0
def changeStudent(request, id):
    ''' Change an existing student (intro phase only) '''
    profile = profileOrRedirect(request.user)

    try:
        student = Student.objects.get(user=profile, id=id)

    except:
        return HttpResponseRedirect('/records/')

    if request.method == 'POST':
        form = StudentAddForm(request.POST, instance=student)

        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/records/')

    else:
        form = StudentAddForm(instance=student)

    context = {
        'form': form,
        'profile': profile,
    }
    addToContext(profile, context)
    return render_to_response('records/changeStudent.html',
                              context,
                              context_instance=RequestContext(request))
示例#2
0
def addStudent(request):
    ''' Add new Student (intro-phase only) '''
    try:
        profile = request.user.get_profile()
    except:
        return HttpResponseRedirect('/records/profile/')

    if request.method == 'POST':
        form = StudentAddForm(request.POST)

        if form.is_valid():
            instance = form.save(commit=False)
            instance.user = profile
            instance.save()
            return HttpResponseRedirect('/records/')

    else:
        form = StudentAddForm()

    context = {'profile': profile, 'form': form}
    addToContext(profile, context)
    return render_to_response('records/addStudent.html',
                              context,
                              context_instance=RequestContext(request))