Esempio n. 1
0
def addCard(request):
    try:
        q = request.POST['question']
        a = request.POST['answer']
    except KeyError:
        return review(request)
    else:
        c = Card(question=q, answer=a, username = request.user.username)
        c.save()
    return HttpResponseRedirect(reverse('spacedRepetition.flashcards.views.add') + "?added=true")
Esempio n. 2
0
def handle_uploaded_file(f, username):
    j =  f.read()
    
    try:
        cards = json.loads(j)
    except ValueError:
        return 0    

    for c in cards:
        q = c["1_question"]
        a = c["2_answer"]

        c = Card(question=q, answer=a, username = username) 
        c.save()

    return len(cards)