From d8921694c8949174dd33958d919330fa189e128c Mon Sep 17 00:00:00 2001 From: shriyakalakata Date: Mon, 26 Feb 2024 18:12:28 -0500 Subject: [PATCH 1/2] Fixed display all decks file, added displaying singular cards, connected more buttons --- app.py | 27 +++++++++++++++++++++++++-- static/css/style.css | 11 ----------- templates/card.html | 14 ++++++++++++++ templates/decks.html | 19 ++++++++++++------- 4 files changed, 51 insertions(+), 20 deletions(-) create mode 100644 templates/card.html diff --git a/app.py b/app.py index fb7f021..f071f63 100644 --- a/app.py +++ b/app.py @@ -1,6 +1,7 @@ from flask import Flask, render_template, request, redirect, abort, url_for, make_response from authentication import * from db import * +import random app = Flask(__name__) @@ -27,8 +28,30 @@ def signup(): @app.route("//decks") def allDecks(username): # would need to first find user in db, but not set up yet - mainDecks = db.decks.find({}) - return render_template('decks.html', mainDecks=mainDecks) + if username == "guest": + mainDecks = db.decks.find({}) + return render_template('decks.html', mainDecks=mainDecks) + else: + return "to do: for users" + +@app.route("//") +def displayDeck(username, deckTitle): + if username == "guest": + # get the list of cards for the deck + cardList = db.decks.find_one({"title": deckTitle}).cards + # generate a random index to generate a random card + index = random.randint(0, len(cardList)) + question = cardList[index] + # remove card to avoid repetition + cardList.pop(index) + + render_template('card.html', deckTitle=deckTitle, question=question, username=username) + + if 'add-card' in request.form: + return redirect('/username/deckTitle/add') + elif 'edit' in request.form: + return redirect('/username/deckTitle/index/add') + return "temp" @app.route("//create", methods=["POST"]) def createDeck(username): diff --git a/static/css/style.css b/static/css/style.css index 66b2a36..dd60fe1 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -67,17 +67,6 @@ h3 { } -.vertical-alig { - display: flex; - justify-content: space-between; - flex-direction: column; - align-items: center; - margin: auto; - width: 90%; - aspect-ratio: 9 / 5; - -} - .button { width: 100%; height: 25%; diff --git a/templates/card.html b/templates/card.html new file mode 100644 index 0000000..704eb2a --- /dev/null +++ b/templates/card.html @@ -0,0 +1,14 @@ +{% extends 'base.html' %} + +{% block container %} +

{{ deckTitle }}

+
+

{{ question }}

+
+ +
+ + +
+ +{% endblock %} \ No newline at end of file diff --git a/templates/decks.html b/templates/decks.html index 4eee469..94d7808 100644 --- a/templates/decks.html +++ b/templates/decks.html @@ -2,13 +2,18 @@ {% block container %} - -
-
- {% for deck in mainDecks %} - - {% endfor %} -
+{% for deck in mainDecks %} + +{% endfor %} + +{% for deck in personalDecks %} + +{% endfor %} {% endblock %} \ No newline at end of file From 5f0dcc4500d698cc2b5bd44cc3950809fd4e5bf0 Mon Sep 17 00:00:00 2001 From: shriyakalakata Date: Mon, 26 Feb 2024 19:02:00 -0500 Subject: [PATCH 2/2] Fix connection to displaying card --- app.py | 7 ++++--- templates/card.html | 2 +- templates/decks.html | 4 +--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index f071f63..5a25882 100644 --- a/app.py +++ b/app.py @@ -38,14 +38,15 @@ def allDecks(username): def displayDeck(username, deckTitle): if username == "guest": # get the list of cards for the deck - cardList = db.decks.find_one({"title": deckTitle}).cards + currentDeck = db.decks.find_one({"title": deckTitle}) + cardList = currentDeck['cards'] # generate a random index to generate a random card - index = random.randint(0, len(cardList)) + index = random.randint(0, len(cardList)-1) question = cardList[index] # remove card to avoid repetition cardList.pop(index) - render_template('card.html', deckTitle=deckTitle, question=question, username=username) + return render_template('card.html', deckTitle=deckTitle, question=question, username=username) if 'add-card' in request.form: return redirect('/username/deckTitle/add') diff --git a/templates/card.html b/templates/card.html index 704eb2a..ea2aa3b 100644 --- a/templates/card.html +++ b/templates/card.html @@ -1,7 +1,7 @@ {% extends 'base.html' %} {% block container %} -

{{ deckTitle }}

+

{{ deckTitle }}

{{ question }}

diff --git a/templates/decks.html b/templates/decks.html index 94d7808..a7732a3 100644 --- a/templates/decks.html +++ b/templates/decks.html @@ -4,9 +4,7 @@ {% for deck in mainDecks %} {% endfor %}