Skip to content

Commit

Permalink
Merge pull request #79 from software-students-spring2024/fix-edit-route
Browse files Browse the repository at this point in the history
Fix edit template + route
  • Loading branch information
shriyakalakata authored Mar 3, 2024
2 parents 9812dbf + df2b37e commit d436e1d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def home():
return redirect(url_for('signup'))
elif 'play-as-guest' in request.form:
return redirect(url_for('allDecks', username='guest'))
if request.method == 'GET':
if (current_user.is_authenticated):
return redirect(url_for('allDecks', username=current_user.id))
return render_template('start.html')

# Handle authentication related stuff in authentication.py file
Expand Down Expand Up @@ -105,13 +108,14 @@ def addCard(username, deckTitle, cardIndex):
@app.route("/<username>/<deckTitle>/<cardIndex>/edit", methods=["POST"])
def editCard(username, deckTitle, cardIndex):
# authenticate user
if (not current_user.is_authenticated or current_user.id != username):
return redirect(url_for('login'))
# if (not current_user.is_authenticated or current_user.id != username):
# return redirect(url_for('login'))
newCard = request.form["question"]
oldCard = request.form["oldQuestion"]
db.users.update_one(
{"user_id": username, "personalDecks.title": deckTitle},
{"$set": {"personalDecks.$[deck].cards.$[card]": newCard}},
array_filters=[{"deck.title": deckTitle}, {"card": newCard}]
array_filters=[{"deck.title": deckTitle}, {"card": oldCard}]
)
# would redirect to template for Cards
# TODO: is there a way to not have to refresh the page and show the edited card
Expand Down
2 changes: 2 additions & 0 deletions templates/card.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ <h3 id="next-question"> START </h3>
<path fill="#D9D9D9" d="M15,3C8.373,3,3,8.373,3,15c0,6.627,5.373,12,12,12s12-5.373,12-12C27,8.373,21.627,3,15,3z M16.414,15 c0,0,3.139,3.139,3.293,3.293c0.391,0.391,0.391,1.024,0,1.414c-0.391,0.391-1.024,0.391-1.414,0C18.139,19.554,15,16.414,15,16.414 s-3.139,3.139-3.293,3.293c-0.391,0.391-1.024,0.391-1.414,0c-0.391-0.391-0.391-1.024,0-1.414C10.446,18.139,13.586,15,13.586,15 s-3.139-3.139-3.293-3.293c-0.391-0.391-0.391-1.024,0-1.414c0.391-0.391,1.024-0.391,1.414,0C11.861,10.446,15,13.586,15,13.586 s3.139-3.139,3.293-3.293c0.391-0.391,1.024-0.391,1.414,0c0.391,0.391,0.391,1.024,0,1.414C19.554,11.861,16.414,15,16.414,15z"/>
</svg>
<textarea name="question" required></textarea>
<input type="hidden" name="oldQuestion">
<button class="button2">Done</button>
</form>

Expand Down Expand Up @@ -136,6 +137,7 @@ <h3 id="next-question"> START </h3>
document.querySelector("#delete-card-button").style.display="none"
document.querySelector("#card-form").style.display="initial"
document.querySelector("#card-form textarea").textContent = cardList[cardIndex]
document.querySelector("#card-form input").value = cardList[cardIndex]

document.querySelector("#card-form").action="/" + username + "/" + deckTitle + "/" + cardIndex + "/edit"
})
Expand Down

0 comments on commit d436e1d

Please sign in to comment.