def remove_card(index): if request.method == "POST": del wordsDB[index] save_db() return redirect(url_for('welcome')) else: return render_template("remove_card.html", word=wordsDB[index])
def remove_book(indx): if request.method == 'POST': del db[indx] save_db() return redirect(url_for('admin')) else: return render_template("remove_book.html", book=db[indx])
def add_card(): # request is defined by Flask but it must be imported before use # we can test request.method to see if it was POST if request.method == "POST": # form has been submitted, process data # request contains a form dictionary of the # posted data by name we assigned # using this info we can create a dictionary of our own # containing the user submitted data card = { "question": request.form['question'], "answer": request.form['answer'] } # since our database is just a list we can add the new card db.append(card) # make sure new data gets written to disk save_db() # after new data is added, send the user to a new page that # shows the result for verification of success. # this will require us to import more Flask functions, redirect & url_for # make sure to use return with redirect # redirect sends a code back to the browser telling it GET the new url # which would show the user the page redirected to # url_for(<function name>, <variable>=<value>) return redirect(url_for("card_view", index=len(db) - 1)) else: # this signifies that the request was GET # so the user just needs the form to fill in return render_template("add_card.html")
def edit_book(indx): try: book = db[indx] if request.method == 'POST': books = ["isbn", "title", "author", "publication_year", "publisher", "image_url_s", "image_url_m","image_url_l", "copies", "available"] for attr in books: if request.form[attr] == '': book[attr] = "" if attr == "image_url_s": book[attr] = "../static/thumbz-s.jpg" if attr == "image_url_m": book[attr] = "../static/thumbz-m.jpg" if attr == "image_url_l": book[attr] = "../static/thumbz-l.jpg" else: if(attr == "copies" or attr == "available"): if int(request.form[attr]) <= 0: book[attr] = 0 if int(request.form["copies"]) == 0: book["available"] = 0 if int(request.form["copies"]) < int(request.form["available"]): return render_template("edit_book.html", book=book, indx=indx) else: book[attr] = int(request.form[attr]) else: book[attr] = request.form[attr] save_db() return redirect(url_for('admin')) else: return render_template("edit_book.html", book=book, indx=indx) except IndexError: abort(404)
def remove_card(index): if request.method == 'POST': del db[index] save_db() return redirect(url_for('welcome')) else: return render_template("remove_card.html", card=db[index])
def delete_cards(): if request.method == 'POST': db.pop(int(request.form['delete_index'])) save_db() return redirect(url_for('delete_cards')) if request.method == 'GET': return render_template('delete_cards.html', cards=db)
def decrypter(): value_count = db['values_decrypted'] if request.method == "POST": # form has been submitted, process data try: value_to_decrypt = int(request.form['value_to_decrypt'].replace( ',', '')) # ENFORCE INTEGER CONSTRAINT except ValueError: alert_message = 'You must enter an integer.' return render_template('decrypter.html', value_count=value_count, decrypted_value='', alert_code=True, alert_message=alert_message) decryption_key = int( request.form['decryption_key']) # ENFORCE INTEGER CONSTRAINT decrypted_value = decrypt(value_to_decrypt, decryption_key) print(decrypted_value) value_count += 1 db['values_decrypted'] = value_count save_db() return render_template('decrypter.html', value_count=value_count, decrypted_value=str(decrypted_value)) else: return render_template('decrypter.html', value_count=value_count)
def add_card(): if request.method == "POST": # process data db.append(dict(request.form.to_dict(), **{"index": len(db) - 1})) save_db() return redirect(url_for("card_view", index=len(db) - 1)) else: return render_template("create_card.html")
def add_card(): if request.method == "POST": card = {"question" : request.form['question'], "answer" : request.form['answer']} db.append(card) save_db() return redirect(url_for('card_view', index=len(db)-1)) else: return render_template("create_card.html")
def add_card(): if request.method == 'POST': card = { 'question': request.form['question'], 'answer': request.form['answer'] } db.append(card) save_db() return redirect(url_for('card_view', index=len(db) - 1)) return render_template('add_card.html')
def remove_card(index): try: if request.method == "POST": del db[index] save_db() return redirect(url_for('welcome')) else: return render_template("remove_card.html", card=db[index]) except IndexError: abort(404)
def remove_account(index): try: if request.method == "POST": del db[index] save_db() return redirect(url_for("welcome")) else: return render_template("remove_account.html", account=db[index]) except IndexError: abort(404)
def add_card(): if request.method == "POST": # form has been submitted, process data card = {"question": request.form['question'], "answer": request.form['answer']} db.append(card) save_db() return redirect(url_for('card_view', index=len(db)-1)) else: return render_template("add_card.html")
def delete_card(index): try: if request.method == 'POST': db.pop(index) save_db() return redirect(url_for('welcome')) if request.method == 'GET': return render_template('delete_card.html', card=db[index]) except IndexError: abort(404)
def remove_blog(index): try: if request.method == "POST": db.pop(index) save_db() return redirect(url_for('welcome')) else: return render_template("remove_blog.html", blog=db[index]) except IndexError: abort(404)
def add_blog(): if request.method == 'POST': blog = { "Title": request.form['title'], "Content": request.form['content'] } db.append(blog) save_db() return redirect(url_for('welcome')) else: return render_template("add_blog.html")
def add_salary(): if request.method == "POST": salary_record = { "name": request.form['name'], "salary": request.form['salary'] } model.db.append(salary_record) model.save_db() return redirect(url_for('salary_view', index=len(model.db) - 1)) else: return render_template("add_salary.html")
def delete_salary(index): try: if request.method == "POST": del model.db[index] model.save_db() return redirect(url_for('welcome_view')) else: return render_template("delete_salary.html", salary_record=model.db[index]) except IndexError: abort(404)
def addcard(): if request.method == "POST": card = { "name": request.form["name"], "class": int(request.form["class"]) } db.append(card) save_db() return redirect(url_for('card', index=len(db) - 1)) else: return render_template("addcard.html")
def add_card(): if request.method == "POST": dish = { "name_en": request.form['name_en'], "name_nl": request.form['name_nl'] } db.append(dish) save_db() return redirect(url_for('dishes', index=len(db) - 1)) else: return render_template('add_dish.html')
def add_card_view(): if request.method == 'POST': # form has been submitted, process data card = { "question": request.form['question'], "answer": request.form['answer'] } db.append(card) save_db() return redirect(url_for('card_view', index=len(db) - 1)) return render_template('add_card.html', pagetitle="Add Card")
def add_repository(): if request.method == "POST": repo = { "title": request.form['title'], "author": request.form['author'] } db.append(repo) save_db() return redirect(url_for("repository", index=len(db) - 1)) else: return render_template('add_repository.html')
def remove_card(index): try: if request.method == "POST": db.pop(index) save_db() return redirect(url_for('index')) else: return render_template('removecard.html', card=db[index]) except IndexError: abort(404)
def remove_card(index): if request.method == "POST": try: card = db[index] db.remove(card) save_db() return redirect(url_for("welcome", cards=db)) except IndexError: abort(404) else: return render_template("remove_card.html", card=db[index])
def remove_card(index): try: if request.method == "POST": # db.pop(index) del db[index] save_db() return redirect(url_for('welcome')) else: card = api_card_detail(index) return render_template("remove_card.html", card=card) except IndexError: abort(404)
def add_query(): if request.method == 'POST': #submission query = { "value1": request.form['value1'], "value2": request.form['value2'] } db.append(query) save_db() return redirect(url_for('query_view', index=len(db) - 1)) else: return render_template("add_query.html")
def remove_card(index): try: card = db[index] if request.method == "POST": print("Card removed successfully") db.remove(card) # or del db[index] save_db() return redirect(url_for('welcome')) else: return render_template("remove_card.html", card=card) except IndexError: abort(404)
def remove_card(index): try: if request.method == 'POST': # form submitted, delete the card del db[index] save_db() return redirect(url_for('welcome')) else: card = db[index] return render_template('remove_card.html', card=card) except: abort(404)
def add_card(): if request.method == "POST": card = { "question": request.form["question"], "answer": request.form["answer"] } db.append(card) save_db() flash(f"Stored card {card}") return redirect(url_for("card_view", index=len(db) - 1)) else: return render_template("add_card.html")
def remove_card(index): try: if request.method == 'POST': # Delete the entry from the db db.pop(index) save_db() return redirect(url_for('welcome')) except IndexError: abort(404) else: return render_template('remove_card.html', card=db[index])