示例#1
0
def session_builder(request):
    #comes from welcome with cardset model loaded in session
    #creates a list of vcard model objects for /practice
    #also creates and saves the session
    user = get_user_from_cookie(request)
    if not user:
        return HttpResponseRedirect('/login')
    cardset = request.session['cardset']
    session = Session(username=user, title=cardset.title)
    session.save()
    cards = Card.objects.filter(cardset__exact=cardset)
    cards = list(cards.order_by('number'))
    vcards = []
    for card in cards:
        vcard = VirtualCard(number=card.number,
                            card=card,
                            session=session,
                            state=1)
        vcard.save()
        vcards.append(vcard)
    session.num_cards = len(vcards)
    session.save()
    del (request.session['cardset'])
    request.session['vcards'] = vcards
    return HttpResponseRedirect('/practice')
示例#2
0
def session_namer(request):
    if request.method == 'GET':
        return render_to_response('session_namer.html',
                                  context_instance=RequestContext(request))

    elif request.method == 'POST':
        user = get_user_from_cookie(request)
        title = request.POST.get('title')
        if new_cardset(title, user) and new_session(
                title, user) and string_check(title):
            session = Session(username=user, title=title)
            session.save()
            new_vcards = request.session['new_vcards']
            vcards, cards_list = [], []
            count = 1
            for new_vcard in new_vcards:
                if new_vcard.card.id in cards_list:
                    continue
                else:
                    cards_list.append(new_vcard.card.id)
                    vcard = VirtualCard(number=count,
                                        card=new_vcard.card,
                                        session=session,
                                        state=1)
                    vcards.append(vcard)
                    vcard.save()
                    count += 1
            request.session['vcards'] = vcards
            session.num_cards = len(vcards)
            session.save()
            return HttpResponseRedirect('/practice')

        elif not string_check(title):
            error = "please enter a title"
            return render_to_response('session_namer.html', {'error': error},
                                      context_instance=RequestContext(request))

        else:
            error = "title is already taken"
            return render_to_response('session_namer.html', {'error': error},
                                      context_instance=RequestContext(request))
示例#3
0
def session_builder(request):
    #comes from welcome with cardset model loaded in session
    #creates a list of vcard model objects for /practice
    #also creates and saves the session
    user = get_user_from_cookie(request)
    if not user:
        return HttpResponseRedirect('/login')
    cardset = request.session['cardset']
    session = Session(username=user, title=cardset.title)
    session.save()
    cards = Card.objects.filter(cardset__exact=cardset)
    cards = list(cards.order_by('number'))
    vcards = []
    for card in cards:
        vcard = VirtualCard(number=card.number, card=card, session=session, state=1)
        vcard.save()
        vcards.append(vcard)
    session.num_cards = len(vcards)
    session.save()
    del(request.session['cardset'])
    request.session['vcards'] = vcards
    return HttpResponseRedirect('/practice')
示例#4
0
def session_namer(request):
    if request.method == 'GET':
        return render_to_response('session_namer.html',
                                  context_instance=RequestContext(request))

    elif request.method == 'POST':
        user = get_user_from_cookie(request)
        title = request.POST.get('title')
        if new_cardset(title, user) and new_session(title, user) and string_check(title):
            session = Session(username=user, title=title)
            session.save()
            new_vcards = request.session['new_vcards']
            vcards, cards_list = [], []
            count = 1
            for new_vcard in new_vcards:
                if new_vcard.card.id in cards_list:
                    continue
                else:
                    cards_list.append(new_vcard.card.id)
                    vcard = VirtualCard(number=count, card=new_vcard.card,
                                        session=session, state=1)
                    vcards.append(vcard)
                    vcard.save()
                    count += 1
            request.session['vcards'] = vcards
            session.num_cards = len(vcards)
            session.save()
            return HttpResponseRedirect('/practice')

        elif not string_check(title):
            error = "please enter a title"
            return render_to_response('session_namer.html', {'error': error},
                                  context_instance=RequestContext(request))

        else:
            error = "title is already taken"
            return render_to_response('session_namer.html', {'error': error},
                                  context_instance=RequestContext(request))