def add_recipe(): form = AddForm() if request.method == 'POST': if form.validate_on_submit(): # Get the image from the submitted form image = request.files.get('file') # Get the submitted form and perform the required # manipulation form_data = request.form.to_dict() form_data = populate_form(form_data, image_name=image.filename ) if image else populate_form(form_data) # Saves the image to the file system if image: image.save( os.path.join(app.config.get('IMAGES_FOLDER'), image.filename)) recipes = mongo.db.recipes recipes.insert_one(form_data) return redirect(url_for('get_recipes')) # Implicit GET request return render_template("addrecipe.html", form=form, cuisines=mongo.db.cuisines.find(), countries=mongo.db.countries.find())
def add_pup(): form = AddForm() if form.validate_on_submit(): name = form.name.data pup = Puppy(name) db.session.add(pup) db.session.commit() return redirect(url_for('list_pup')) return render_template('addpup.html', form=form)
def Edit(id_number): form = AddForm() var = Students.query.filter_by(idNumber=id_number).first() if form.validate_on_submit(): var.idNumber = form.idNumber.data var.fullName = form.fullName.data var.Course = form.Course.data db.session.commit() return redirect(url_for('View')) return render_template('edit.html',title='Edit', var = var, form = form)
def Register(): form = AddForm() if form.validate_on_submit(): try: students_1 = Students(fullName=form.fullName.data, Course=form.Course.data, idNumber=form.idNumber.data) db.session.add(students_1) db.session.commit() flash('Registered Successfully!') except: flash('Information Already Exist!') return redirect(url_for('home')) return render_template('register.html',title='Register', form=form)
def add(): form = AddForm() if form.validate_on_submit(): name = form.name.data ## Getting name from the form. new_name = Student(name) ## new_name is the object of the class. db.session.add(new_name) ## We are adding new_name db.session.commit() return redirect(url_for("list")) return render_template("add.html", form=form)
def add(): form = AddForm() if form.validate_on_submit(): key = form.key.data main_data_source_key = form.main_data_source_key.data entity = form.entity.data field = form.field.data normalize_type = form.normalize_type.data new_data = DataCatalog(key, main_data_source_key, entity, field, normalize_type) db.session.add(new_data) db.session.commit() return redirect(url_for("index")) return render_template("add.html", form=form)
def edit_cuisine(cuisine_id): form = AddForm() if request.method == 'POST' and form.validate_on_submit(): # Get the image from the submitted form image = request.files.get('file') # Get the submitted form and perform the required # manipulation form_data = request.form.to_dict() form_data = populate_form( form_data, image_name=image.filename) if image else populate_form(form_data) # Saves the image to the file system if image: image.save( os.path.join(app.config.get('IMAGES_FOLDER'), image.filename)) cuisines = mongo.db.cuisines cuisines.update({'_id': ObjectId(cuisine_id)}, form_data) return redirect(url_for('get_cuisines')) # Implicit GET request the_cuisine = mongo.db.cuisines.find_one({"_id": ObjectId(cuisine_id)}) form.cuisine.data = the_cuisine.get('recipe') form.allergens.data = the_cuisine.get('allergens') form.ingredients.data = '; '.join(the_cuisine.get('ingredients')) form.methods.data = '; '.join(the_cuisine.get('methods')) form.cuisine.data = next(k for k, v in cuisine_mapping.items() if v == the_cuisine.get('cuisine')) form.country.data = next(k for k, v in country_mapping.items() if v == the_cuisine.get('country')) all_cuisines = mongo.db.cuisines.find() all_countries = mongo.db.countries.find() return render_template('editcuisine.html', cuisine=the_cuisine, form=form, cuisines=all_cuisines, countries=all_countries)