def retrieve(): code = request.args.get('code', None) if code is None: return render_template("retrieve.jinja2") try: saved_total = SavedTotal.get(SavedTotal.code == code) except SavedTotal.DoesNotExist: return render_template("retrieve.jinja2") session['total'] = saved_total.value return redirect(url_for('add'))
def retrieve(): code = request.args.get('code', None) # If user is visiting the page (did not submit yet) # Then just render reterieve.jinja2 templste # But if they did submit: # Attempt retrieve saved total based on code # Then Save the total from that SavedTotal session # Then Redirect the user back to the 'add' page if code is None: return render_template('retrieve.jinja2') else: try: saved_total = SavedTotal.get(SavedTotal.code == code) except SavedTotal.DoesNotExist: return render_template('retreive.jinja2', error="Code not found.") session['total'] = saved_total.value return redirect(url_for('add'))
def retrieve(): code = request.args.get("code", None) # If the user is visiting the retrieve page (did not submit form yet): # Then just render the retrieve.jinja2 template # But if they did submit the form: # Then attempt to retrieve the SavedTotal that has the provided code # Then save the total from that SavedTotal into session["total"] # Then redirect the user back to the main "add" page if code is None: return render_template("retrieve.jinja2") else: try: saved_total = SavedTotal.get(SavedTotal.code == code) except SavedTotal.DoesNotExist: return render_template("retrieve.jinja2", error="Code not found.") session["total"] = saved_total.value return redirect(url_for("add"))
def retrieve(): code = request.args.get('code', None) ''' If the user is visiting this page, but has no submit it will just render the retrieve.jinja2 template. If they DID submit the form, it will attempt to retrieve the SavedTotal that has the provided code, then save the total from that SavedTotal into session['total']. After this, it will redirect back to add ''' if code is None: return render_template('retrieve.jinja2') # else: try: saved_total = SavedTotal.get(SavedTotal.code == code) except SavedTotal.DoesNotExist: return render_template('retrieve.jinja2', error="Code not found.") session['total'] = saved_total.value return redirect(url_for('add'))
def retrieve(): # Retrieve code argument from the user's code sumbission # Compare to request.form method because retrieve form uses GET method code = request.args.get('code', None) # If the user is visiting the retrieve page (did not submit form yet): # Then just render the retrieve.jinja2 template # But if they did submit the form: # Then attempt to retrieve the SavedTotal that has the provided code # Then save the total from that SavedTotal into session["total"] # Then redirect the user back to the main 'add' page if code is None: return render_template("retrieve.jinja2") try: saved_total = SavedTotal.get(SavedTotal.code == code) except SavedTotal.DoesNotExist: return render_template("retrieve.jinja2", error="Code not found") session['total'] = saved_total.value return redirect(url_for('add'))