예제 #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' )
예제 #2
0
def create( request ):
    inGuy = isAuthUser( request )
    if request.method == 'POST' and inGuy:
        problems = literal_eval(request.POST['problems'])
        title = request.POST['title']
        if not title:
            title = "Untitled"
        AssignmentObj = Assignment( user=inGuy,
                                    title=title,
                                    due=datetime.datetime.now(),
                                    numofprobs=len(problems))
        AssignmentObj.save()
        if not problems: problems = [{'question':''}]
        for i, problem in enumerate(problems):
            title = problem[ 'question' ] if problem[ 'question' ] else ( "Problem :" + str( i + 1 ) )
            ProblemObj = Problem( Ass=AssignmentObj,
                                  title=problem[ 'question' ],
                                  index=i+1,
                                  )
            ProblemObj.save()
        return HttpResponse(simplejson.dumps({"success":"Your crap has been successfully saved" }), 'application/json' )
    return render_to_responseC( request, 'create.html', locals() )