from django.shortcuts import render_to_response

def addnumber(request,what):

    if not what or not 'numbers' in request.session:
        request.session['numbers']=[]
    else:
        try:
            what_int=int(what)
            request.session['numbers']+=[what_int]
        except:
            pass
    numbers=request.session['numbers']
    candidates=range(1,10)
    return render_to_response('add.html',
        {'numbers':numbers,'candidates':candidates} )

def addnull(request):
    
    return addnumber(request,None)

def sum(request):

    if not 'numbers' in request.session:
        request.session['numbers']=[]
    sum=0
    for num in request.session['numbers']:
        sum+=num
    request.session['numbers']=[]
    return render_to_response('sum.html',{'sum':sum} )
    
    

    

