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")
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)