def View_Deck(request): deck_id_signed = request.GET.get('deck_id') deck_id = None card_list = [] signer = Signer(request.user.id) try: deck_id = signer.unsign(deck_id_signed) except signing.BadSignature: print("Tampering detected! View deck") return HttpResponseRedirect('/') form = NewCard(initial={'deck': request.GET.get('deck_id')}) cards = Card.objects.filter(deck_id=deck_id, deleted_flag=0).order_by('-date_created') deck = Deck.objects.filter(deck_id=deck_id, deleted_flag=0) print "here" deck_name = "" try: deck_name = deck[0].deck_name except IndexError: deck_name = "" for card in cards: card_list.append({ "card_id": card.card_id, "front": card.front, "back": card.back, }) upload_form = UploadFile(initial={"deck_id": signer.sign(deck_id)}) context = { "upload_form": upload_form, "form": form, "card_list": card_list, "deck_id": deck_id_signed, "deck_name": deck_name, } return render(request, 'flash_cards/view_deck.html', context)
def Edit_Card(request): if request.method == 'POST': id_card = request.POST.get('card') deck = request.POST.get('deck') front = request.POST.get('front') back = request.POST.get('back') signer = Signer(request.user.id) try: deck = signer.unsign(deck) except signing.BadSignature: return HttpResponseRedirect('/') data = {'deck': deck, 'front': front, 'back': back} form = NewCard(data) if form.is_valid(): card = get_object_or_404(Card, card_id=id_card) card.front = front card.back = back card.save() else: errors = form.errors return HttpResponse(json.dumps(errors)) return HttpResponse(json.dumps({"success": "success"}))
def Edit_Card(request): if request.method == 'POST': id_card = request.POST.get('card') deck = request.POST.get('deck') front = request.POST.get('front') back = request.POST.get('back') signer = Signer(request.user.id) try: deck = signer.unsign(deck) except signing.BadSignature: return HttpResponseRedirect('/') data = {'deck' : deck, 'front' : front, 'back' : back} form = NewCard(data) if form.is_valid(): card = get_object_or_404(Card, card_id=id_card) card.front = front card.back = back card.save() else: errors = form.errors return HttpResponse(json.dumps(errors)) return HttpResponse(json.dumps({"success": "success"}))
def New_Card(request): if request.method == 'POST': deck = request.POST.get('deck') front = request.POST.get('front') back = request.POST.get('back') signer = Signer(request.user.id) try: deck = signer.unsign(deck) except signing.BadSignature: return HttpResponseRedirect('/') data = {'deck': deck, 'front': front, 'back': back} form = NewCard(data) if form.is_valid(): print "valid form" card = form.save(commit=False) card.deck_id = deck card.save() else: print "error" errors = form.errors print errors return HttpResponse(json.dumps(errors)) return HttpResponse(json.dumps({"success": "success"}))
def New_Card(request): if request.method == 'POST': deck = request.POST.get('deck') front = request.POST.get('front') back = request.POST.get('back') signer = Signer(request.user.id) try: deck = signer.unsign(deck) except signing.BadSignature: return HttpResponseRedirect('/') data = {'deck' : deck, 'front' : front, 'back' : back} form = NewCard(data) if form.is_valid(): print "valid form" card = form.save(commit=False) card.deck_id = deck card.save() else: print "error" errors = form.errors print errors return HttpResponse(json.dumps(errors)) return HttpResponse(json.dumps({"success": "success"}))