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 add_card(): if request.method == "POST": card = {"question": request.form['question'], "answer": request.form['answer']} db.append(card) return redirect(url_for("card_view", index=db.index(card))) else: return render_template("add_card.html")
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 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 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 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_card(): if request.method == "POST": card = { 'question': request.form['question'], 'answer': request.form['answer'] } db.append(card) save_json() return redirect(url_for('card_route', index=len(db) - 1)) else: return render_template('add_card.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_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 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": 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 add_account(): if request.method == "POST": account = { "name": request.form["name"], "account": request.form["account"], "budgets": [] } db.append(account) save_db() return redirect(url_for("welcome")) else: return render_template("add_account.html")
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 add_card(): if request.method == "POST": # form has been submitted -> process the data card = { "question": request.form["question"], "answer": request.form["answer"] } db.append(card) return redirect(url_for('card_view', index=len(db) - 1)) else: # else just GET method process return render_template("add_card.html")
def home(): if request.method == "POST": if request.form['nom'] and request.form['prenom'] and request.form[ 'equipe'] != "Choisir l'équipe parmie la liste": nom = request.form['nom'] prenom = request.form['prenom'] equipe = request.form['equipe'] response = request.get_data() personne_select = {"Nom": nom, "Prenom": prenom, "Equipe": equipe} if request.form['type'] == 'update': index = int(request.form['index']) if db[index]['Nom'] == request.form['nom'] and db[index][ 'Prenom'] == request.form['prenom'] and db[index][ 'Equipe'] == request.form['equipe']: print("error") return jsonify( {'error': 'Veuillez modifier au moins un champ'}) else: db[index]['Nom'] = request.form['nom'] db[index]['Prenom'] = request.form['prenom'] db[index]['Equipe'] = request.form['equipe'] save_db() nomPrenom = personne_select['Nom'] + " " + personne_select[ 'Prenom'] return_value = {'nomPrenom': nomPrenom} return return_value elif request.form['type'] == 'suppression': # index = get_index(request.form['nom'], request.form['prenom']) index = int(request.form['index']) db.pop(int(index)) save_db() nomPrenom = personne_select['Nom'] + " " + personne_select[ 'Prenom'] return_value = {'index': index, 'nomPrenom': nomPrenom} return return_value elif request.form['type'] == 'ajout': db.append(personne_select) save_db() nomPrenom = personne_select['Nom'] + " " + personne_select[ 'Prenom'] return_value = {'nomPrenom': nomPrenom} return return_value else: print("error") return jsonify({'error': 'Veuillez remplir tous les champs'}) else: return render_template("member.html", personnes=db)
def add_card(): if request.method == "POST": # User has submitted the form 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: # User has not submitted the form instead requested the form by loading the URL (GET request) return render_template("add_card.html")
def add_card(): try: if request.method == 'POST': card = { "question": request.form['question'], "answer": request.form['answer'] } db.append(card) return redirect(url_for('card_view', index=len(db) - 1)) else: return render_template('add_card.html') except IndexError: abort(404)
def add_card(): if request.method == 'POST': # Process the data and add it to the database. 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 add_card(): if request.method == "POST": #form has been submited, process data card = { "question": request.form['question'], "answer": request.form['answer'] } db.append(card) save_db() return redirect(url_for('welcome')) else: app.logger.info("test") return render_template("add_card.html")
def add_bookmark(): form = BookmarkForm() if form.validate_on_submit(): url = form.url.data description = form.description.data db.append(url) save_db() flash(f"Stored {description}") return redirect(url_for("welcome")) return render_template("add_bookmark.html", form=form)
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 ) # with real db, this line would be different and more involved save_db() return redirect(url_for('card_view', index=len(db) - 1)) else: return render_template("add_card.html")
def addclients(): if request.method == "POST": newClient = { 'Client_Name': request.form['uname'], 'Client_Address': request.form['uaddress'], 'Client_Phone': request.form['uphone'], 'Client_Due': request.form['udue'], 'Client_Paid': request.form['upaid'] } db.append(newClient) save_json() return redirect(url_for('home_page')) else: return "error loading the file"
def add_book(): if request.method == 'POST': books = ["isbn", "title", "author", "publication_year", "publisher", "image_url_s", "image_url_m","image_url_l", "copies", "available"] book = {} 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"): book[attr] = int(request.form[attr]) else: book[attr] = request.form[attr] db.append(book) save_db() return redirect(url_for('admin_lib_view',indx= len(db)-1)) else: return render_template("add_book.html")
def welcome(): if request.method == "POST": try: iD = db[-1]['id'] + 1 except: iD = 1 card = { 'id': iD, 'heading': request.form['heading'], 'task': request.form['task'], 'done': False } db.append(card) save_json() return redirect(url_for('welcome')) elif request.method == "GET": inprogress = list(filter(lambda i: i['done'] == False, db)) completed = list(filter(lambda i: i['done'] == True, db)) return render_template('index.html', inprogress=inprogress, completed=completed)