def saveallcards(request):
    if (request.is_ajax() and request.method == 'POST'):
        # Load data
        json_data = simplejson.loads(request.raw_post_data)
        
        # Collect session information
        try:
            session = int(float(json_data["session"]))
        except KeyError:
            HttpResponseServerError("Malformed JSON data!")

        session_obj = CardSession.objects.get(id=int(float(session)))
        
        # Delete all cards for this session
        ccards = Card.objects.filter(session=session)
        for card in ccards:
            card.delete()
            
        # Print out info for now
        cards = json_data["cards"]
        for k, v in cards.iteritems():
            print "x= %s, y=%s, name= %s" % (v["x"], v["y"], v["name"])
            name = strip(v["name"])
            x = float(v["x"])
            y = float(v["y"])
            global_id = "000-" + str(session) + "-" + name
            
            # Create and save new card
            newCard = Card(name = name,
                    session=session_obj,
                    x_coord=x,
                    y_coord=y,
                    global_id=global_id)
            
            newCard.save();
            
        message = "Cards updated"
    else:
        message = "Invalid access method"
    return HttpResponse(message)
def add_card(request):
    # int(float(request.GET['session_id']))
    if (request.is_ajax() and request.method == 'GET'):
        sname = strip(request.GET['name']);
        session_obj = CardSession.objects.filter(id=int(float(request.GET['session_id'])));

        # test to make sure this global id isn't occupied
        global_id = "000-" + request.GET['session_id'] + "-" + sname
        if( Card.objects.filter(global_id=global_id).count() > 0):
            message = "Card not added.  Duplicate found."
            return HttpResponse(message)
        
        newCard = Card(name = sname,
                    session=session_obj[0],
                    x_coord=request.GET['x_coord'], 
                    y_coord=request.GET['y_coord'],
                    global_id=global_id)
        newCard.save();
        message = "Card added"
    else:
        message = "Invalid access method"
    return HttpResponse(message)