Beispiel #1
0
def gen( request ):
    user, password = '******', 'pis321'
    UserObject = None
    if not User.objects.filter( username=user ):
        UserObject = User( username=user, password = password )
        UserObject.save()
    else:
        UserObject = User.objects.get( username=user )
    
    # Create two assignemnts for the user
    for title, numofprobs, due in [ ('Physics 1.2', 3, datetime.datetime.now()),
                                    ('Math 1.2', 4, datetime.datetime.now()),
                                    ]:
        AssignObject = Assignment( user=UserObject,
                                   title=title,
                                   numofprobs=numofprobs,
                                   due=due )
        AssignObject.save()
        for problemi in xrange( numofprobs ):
            ProblemObject = Problem( Ass = AssignObject,
                                     index = problemi)
            ProblemObject.save()
            for notei in xrange( 3 ):
                NoteObject = Note( text="this is a hard problem",
                                   prob=ProblemObject )
                NoteObject.save()
    return HttpResponse( 'itz done' )
Beispiel #2
0
def assign( request, id ):
    inGuy = isAuthUser( request )
    if request.method == 'POST':
        kind = request.POST['kind']
        id1 = request.POST['id' ]
        if kind == "minusProb":
            ProblemObj = Problem.objects.get( id=id1 )
            if not ProblemObj.complete:
                AssignmentObj = Assignment.objects.get( id=id )
                AssignmentObj.doneprobs += 1
                AssignmentObj.save()
            ProblemObj.complete = True
            ProblemObj.save()
        elif kind == "plus":
            ProblemObj = Problem.objects.get( id=id1 )
            text = request.POST['text' ]
            NoteObj = Note( prob=ProblemObj,
                            text=text)
            NoteObj.save()
        else:
            assert False, kind
    try:
        assignment = Assignment.objects.get( id=id )
        problems = Problem.objects.filter( Ass=assignment ).order_by( "id" )
    except:
        # Direct to template 404 or something
        assert False
    return render_to_responseC(request, 'assignment.html', locals() )