コード例 #1
0
def flash_card_next(request, section_id=0, template_name="flashcard/flash_card_detail.html"):
    
    sect = get_object_or_404(Section, pk=section_id)
    
    card = get_object_or_404(FlashCard, pk=int(request.GET['flash_card']))
    
    cresponse = CardUserResponse(object_owner=request.user, flash_card=card)
    response_type = None
    try: 
        rt = request.GET['correct']
        if rt: response_type = "A"
    except:
        try:
            rt = request.GET['incorrect']
            if rt: response_type = "B"
        except: pass
    if response_type != None:
        cresponse.response_type = response_type
        #TODO:  we are not saving until the rest of the functionality that uses this is implemented.
        #cresponse.save()
    
    def get_next_card():
        cards = FlashCard.objects.filter(section=card.section).order_by('?')
        if cards: return cards[0]
    
    next_card = get_next_card()
    cnt = 0
    while ((next_card.id == card.id) and (cnt <= 4)):
        next_card = get_next_card()
        cnt += 1
       
    return flash_card_detail(request, next_card.id)
コード例 #2
0
def flash_card_next_chapter(request, chapter_id=0, template_name="flashcard/flash_card_detail.html"):
    from book.models import Chapter
    chapt = get_object_or_404(Chapter, pk=chapter_id)
    
    try: card = FlashCard.objects.get(id=int(request.GET['flash_card']))
    except: card = None
    
    
    try: cresponse = CardUserResponse(object_owner=request.user, flash_card=card)
    except: cresponse = None
    response_type = None
    
    try: 
        rt = request.GET['correct']
        if rt: response_type = "A"
    except:
        try:
            rt = request.GET['incorrect']
            if rt: response_type = "B"
        except: pass
    if response_type != None and cresponse != None:
        cresponse.response_type = response_type
        #TODO:  we are not saving until the rest of the functionality that uses this is implemented.
        #cresponse.save()
    
    def get_next_card():
        cards = FlashCard.objects.filter(section__chapter=chapt).order_by('?')
        if cards: return cards[0]
    
    next_card = get_next_card()
    
    if card:
        cnt = 0
        while ((next_card.id == card.id) and (cnt <= 4)):
            next_card = get_next_card()
            cnt += 1
       
    return flash_card_detail(request, next_card.id, by_chapter=True)