Exemplo n.º 1
0
def printquota(request, kennitala, user_id):
    student = get_object_or_404(Student, pk=kennitala)
    userp   = get_object_or_404(UserProfile, pk=user_id, kennitala=kennitala)
    noquota = False

    if request.method == "POST":
        form = PrintQuotaForm(request.POST)
        if form.is_valid():
            balance = form.cleaned_data['balance']
            log.info("Updating quota, kennitala=%s, balance=%d",
                kennitala, balance)
            set_printquota(userp.user, balance)
            return HttpResponseRedirect("/students/list/")
    else:
        balance = get_printquota(userp.user)
        noquota = balance is None
        form = PrintQuotaForm(initial={'balance': balance})

    return render_to_response('student/printquota.html',
        {
            'form':    form.as_ul(),
            'userp':   userp,
            'noquota': noquota,
        },
        context_instance=RequestContext(request))