Skip to content

Commit

Permalink
Fixed display all decks file, added displaying singular cards, connec…
Browse files Browse the repository at this point in the history
…ted more buttons
  • Loading branch information
shriyakalakata committed Feb 26, 2024
1 parent 50d7fb9 commit d892169
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 20 deletions.
27 changes: 25 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
@@ -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__)

Expand All @@ -27,8 +28,30 @@ def signup():
@app.route("/<username>/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("/<username>/<deckTitle>")
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("/<username>/create", methods=["POST"])
def createDeck(username):
Expand Down
11 changes: 0 additions & 11 deletions static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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%;
Expand Down
14 changes: 14 additions & 0 deletions templates/card.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends 'base.html' %}

{% block container %}
<h3>{{ deckTitle }}</h3>
<div class="card">
<h3>{{ question }}</h3>
</div>

<form class="vertical-align" method="post">
<button class="button2" type="submit" name="add-card">Add Card</button>
<button class="button2" type="submit" name="edit">Edit</button>
</form>

{% endblock %}
19 changes: 12 additions & 7 deletions templates/decks.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

{% block container %}

<!--IN WORKS: need to change the temps-->
<div class="temp">
<form class="vertical-alig" method="post">
{% for deck in mainDecks %}
<button class="main-deck" type="submit" name="temp"><h3>{{deck.title}}</h3></button>
{% endfor %}
</form>
{% for deck in mainDecks %}
<div class="main-deck">
<!--a href="/{{ username }}/{{ deck.title}}"><h3>{{ deck.title }}</h3></a-->
<!--a href="{{ url_for('edit', post_id=doc._id)}}"></a-->
<a href="{{ url_for('displayDeck', username='lalalala', deckTitle=deck.title)}}"><h3>{{ deck.title }}</h3></a>
</div>
{% endfor %}

{% for deck in personalDecks %}
<div class="personal-deck">
<a href="{{ url_for('home') }}"><h3>{{ deck.title }}</h3></a>
</div>
{% endfor %}

{% endblock %}

0 comments on commit d892169

Please sign in to comment.