def edit(question_id): question = get_or_404(question_id) form = AddForm() if form.validate_on_submit(): new_answers = form.answers.data question.question = form.question.data question.correct = new_answers[int(form.correct.data)] question.save() for i, ans in enumerate(question.answers): ans.answer = new_answers[i] ans.save() flash('Question updated: {}'.format(form.question.data)) return redirect(url_for('question_list')) elif request.method == 'POST': flash_errors(form) for i in range(3): if question.correct == question.answers[i].answer: question.correct = i break form = AddForm(obj=question) return render_template('edit.html', form=form, radio=list(form.correct))
def add(request): if request.method == 'POST': form = AddForm(request.POST) if form.is_valid(): hostname = form.cleaned_data['hostname'] asset = form.cleaned_data['ip'] group_id = form.cleaned_data['group_id'] template_id = form.cleaned_data['template_id'] if asset.ip: ip = asset.ip elif asset.other_ip: ip = asset.other_ip else: ip = '127.0.0.1' if asset.asset_type in [2, 3]: returns = zabbixAPI.addSnmpDevice(hostname, ip, group_id, template_id) else: returns = zabbixAPI.addHost(hostname, ip, group_id, template_id) messages.add_message(request, messages.SUCCESS, u'创建成功:{0}'.format(returns)) return HttpResponseRedirect(reverse('ADD')) else: form = AddForm() return render(request, 'zabbix/add.html', locals())
def index(request): if request.method=='POST': #当提交表单 form=AddForm(request.POST) #form包含提交的数据 if form.is_valid():# 如果提交的数据合法 a=form.cleaned_data['a'] b=form.cleaned_data['b'] return HttpResponse(str(int(a)+int(b))) else: form=AddForm() return render(request,'index.html',{'form':form})
def add(): """ :return: """ form = AddForm(request.form) if request.method == 'POST' and form.validate(): data = request.form filename = 'item-10.jpg' if 'image' in request.files: photo = request.files['image'] try: check_fold = os.path.isfile( os.path.abspath(os.getcwd()) + '/' + app.config['UPLOADED_PHOTOS_DEST'] + '/' + photo.filename) if check_fold is not False: filename = str(photo.filename) else: filename = photos.save(photo) except UploadNotAllowed: return redirect(url_for('error', message='INVALID FILE UPLOAD')) good = Goods(name=data['name'].title(), price=data['price'], quantity=data['quantity'], image=filename) db.session.add(good) db.session.commit() return redirect(url_for('index')) else: print(form.errors) return render_template('add.html', form=form)
def add_sale(): form = AddForm() if form.validate_on_submit(): new_sale = TractortekSales(sales_team_lead=form.sales_team_lead.data, item_code=form.item_code.data, emp_id=form.emp_id.data, year=form.year.data, week=form.week.data, quantity=form.quantity.data) sql = ( f"Insert into tractortek_sales (sales_team_lead, item_code, emp_id, year, week, quantity) " f"values ('{form.sales_team_lead.data}', " f"'{form.item_code.data}'," f"'{form.emp_id.data}', " f"'{form.year.data}', " f"'{form.week.data}', " f"'{form.quantity.data}');") #repr(eval(sql)) db.engine.execute(sql) return redirect(url_for("index")) else: return render_template('add.html', form=form)
def add_student(): form = AddForm() student = Student.query.all() next_index = 0 if len(student) == 0: next_index = 1 else: next_index = len(student) + 1 if form.validate_on_submit(): student = Student(student_id=u"MKT%s" % str(next_index), first_name_en=form.first_name_en.data, last_name_en=form.last_name_en.data, first_name_kh=form.first_name_kh.data, last_name_kh=form.last_name_kh.data, gender=form.gender.data, date_of_birth=form.date_of_birth.data, phone=form.phone.data, email=form.email.data, address=form.address.data) db.session.add(student) db.session.commit() flash('Student has been registered successfuly!', category='success') return redirect(url_for('index', option='active')) return render_template('add_student.html', form=form)
def add_data(): form = AddForm() if form.validate_on_submit(): name = form.name.data age = form.age.data tsh = form.tsh.data t3 = form.t3.data tt4 = form.tt4.data t4u = form.t4u.data fti = form.fti.data if name == "" or age == "" or tsh == "" or t3 == "" or tt4 == "" or t4u == "" or fti == "": return render_template('add.html', form=form) else: new_data = Hypothyroid(name, age, tsh, t3, tt4, t4u, fti) db.session.add(new_data) db.session.commit() input_values = new_data.input_data() data_arr = new_data.data_array() predictions = hypothyroid_pred(data_arr) return render_template('result.html',input_values=input_values, \ data_arr=data_arr, predictions=predictions) else: return render_template('add.html', form=form)
def index(): update_form = UpdateForm() liquidate_form = LiquidateForm() add_form = AddForm() find_port_form = FindPortForm() if find_port_form.SubmitFind_Port.data: try: dataframe = getPortfolioValue(find_port_form.Find_Portfolio.data, "database.xlsx") producePNG(dataframe, "uploads/image.png") portfolioComponents = getPortfolioComponents(find_port_form.Find_Portfolio.data, "database.xlsx") portfolioComponents = portfolioComponents.to_string() portfolioStats = getStats(dataframe) return redirect(url_for('display', portfolioStats=portfolioStats, portfolioComponents=portfolioComponents)) except: print("ERROR EMAIL NOT IN DATABASE") if add_form.SubmitAdd.data: addtoDB(add_form.Add_Portfolio.data, add_form.Add_Ticker.data, float(add_form.Price.data), int(add_form.Quantity.data), "database.xlsx") if liquidate_form.SubmitLiquidate.data: removeDB(liquidate_form.Liquidate_Portfolio.data, liquidate_form.Liquidate_Ticker.data, "database.xlsx", "database.xlsx") if update_form.SubmitUpdate.data: changeQuantity(update_form.Update_Portfolio.data, update_form.Update_Ticker.data, int(update_form.New_Quantity.data), "database.xlsx", "database.xlsx") return render_template('index.html', add_form=add_form, liquidate_form=liquidate_form, update_form=update_form, find_port_form=find_port_form)
def search(): """Search Search for the successor node responsible for a given key. :param key: the key of the node which should be found. :returns: html page with node information, possible also with errors if the input is invalid. """ search_form = SearchForm() if search_form.validate_on_submit(): result_node, msg, count = node.find_successor( int(request.form.get('key')), node.key) if result_node is not None: output = "{0}:{1}, key={2}, msg={3}, hop count = {4}".format( result_node.ip, result_node.port, result_node.key, msg, count) else: output = msg flash(output, 'success') return redirect(url_for('home')) join_form = JoinForm() add_form = AddForm() return render_template('home.html', node=node, join_form=join_form, add_form=add_form, search_form=search_form)
def request_add_photon(): """Request add photon This endpoint will make the node search for the appropriate node of which the photon should be added to. If such a node is found without any error, the photon will be added to it. :param photon_id: the particle-io id of the photon that should be added to the network. :returns: html page with node information, and information about the operation. """ add_form = AddForm() if add_form.validate_on_submit(): photon_id = request.form.get('photon_id') if node.request_photon_add(photon_id): key = encode_key(photon_id) flash( 'Successfully added photon to the network, with key: ' + str(key), 'success') else: flash('Failed to add photon to the network', 'danger') return redirect(url_for('home')) join_form = JoinForm() search_form = SearchForm() return render_template('home.html', node=node, join_form=join_form, add_form=add_form, search_form=search_form)
def add_data(): form = AddForm() if form.validate_on_submit(): name = form.name.data age = form.age.data tsh = form.tsh.data t3 = form.t3.data tt4 = form.tt4.data t4u = form.t4u.data fti = form.fti.data # Add new Puppy to database new_data = Hypothyroid(name, age, tsh, t3, tt4, t4u, fti) db.session.add(new_data) db.session.commit() input_values = new_data.input_data() data_arr = new_data.data_array() predictions = hypothyroid_pred(data_arr) # return redirect(url_for('list_data')), # return redirect('json.html', json_data=json_data) return render_template('result.html', input_values=input_values, data_arr=data_arr, predictions=predictions) else: return render_template('add.html', form=form)
def add_bt7j0srn69(): form = AddForm() if form.validate_on_submit(): playlist_id = form.playlist.data db.seed_playlist.insert({"playlist_id": playlist_id}) flash('Playlist added') return redirect('/add_bt7j0srn69') return render_template('add.html', form=form)
def blog_add(): if request.method == "GET": return render_template("blog_add.html", form=AddForm()) if request.method == "POST": form = AddForm(request.form) if form.validate_on_submit(): create_time = str(datetime.fromtimestamp(int(time.time()))) new_blog = Blog(title=form.title.data, author=form.author.data, content=form.content.data, create_time=create_time) db.session.add(new_blog) db.session.commit() b = Blog.query.filter_by(create_time=create_time).first() return redirect(url_for('blog_id', bid=b.id)) else: return render_template("blog_add.html", form=form)
def add_unicorn(): form=AddForm() if form.validate_on_submit(): name=form.name.data new_unicorn=Unicorn(name) db.session.add(new_unicorn) db.session.commit() return redirect(url_for('list_unicorn')) return render_template('add.html',form=form)
def add_puppy(): form=AddForm() if form.validate_on_submit(): name=form.name.data new_puppy=Puppy(name) db.session.add(new_puppy) db.session.commit() return redirect(url_for('list_puppy')) return render_template('add.html',form=form)
def add_cat(): form = AddForm() if form.validate_on_submit(): name = form.cat_name.data new_cat = Cat(name) db.session.add(new_cat) db.session.commit() return redirect(url_for('list')) return (render_template('add.html', form=form))
def add_pup(): form = AddForm() if form.validate_on_submit(): name = form.name.data # Add new Puppy to DB new_pup = Puppy(name) db.session.add(new_pup) db.session.commit() return redirect(url_for("list_pup")) return render_template("add.html", form=form)
def add_pup(): form = AddForm() if form.validate_on_submit(): name = form.name.data pup_name = Puppy(name) db.session.add_all([pup_name]) db.session.commit() return (redirect(url_for('list_pup'))) return (render_template('add.html', form=form))
def adddevice(): form = AddForm() # Eingabe if request.method == 'GET': # get args from home if request.args.get('servername'): sn = request.args.get('servername') print(sn) dn = "(servername=%s)" % sn print(dn) vms = ldap_search(dn) print(vms) form.servername.data = (vms[0][0][1]["servername"][0]) form.internalname.data = (vms[0][0][1]["internalname"][0]) form.mainresponsible.data = (vms[0][0][1]["mainresponsible"][0]) form.substitute.data = (vms[0][0][1]["substitute"][0]) form.costcenter.data = (int(vms[0][0][1]["costcenter"][0])) form.location.data = (vms[0][0][1]["location"][0]) form.department.data = (vms[0][0][1]["department"][0]) form.servertype.data = bool(vms[0][0][1]["servertype"][0]) form.serverdescription.data = ( vms[0][0][1]["serverdescription"][0]) form.serverservice.data = (vms[0][0][1]["serverservice"][0]) form.workloadservice.data = int(vms[0][0][1]["workloadservice"][0]) form.workloadintime.data = (vms[0][0][1]["workloadintime"][0]) form.privacyrelatedfiles.data = bool( vms[0][0][1]["privacyrelatedfiles"][0]) form.dependencies.data = (vms[0][0][1]["dependencies"][0]) form.redundancy.data = (vms[0][0][1]["redundancy"][0]) form.bootorder.data = (vms[0][0][1]["bootorder"][0]) form.impactforotherserver.data = ( vms[0][0][1]["impactforotherserver"][0]) form.departmentaffected.data = ( vms[0][0][1]["departmentaffected"][0]) form.furtherwork.data = bool(vms[0][0][1]["furtherwork"][0]) form.cost.data = float(vms[0][0][1]["cost"][0]) form.serviceaccount.data = (vms[0][0][1]["serviceaccount"][0]) form.purposeaccount.data = (vms[0][0][1]["purposeaccount"][0]) form.manuallyrestart.data = (vms[0][0][1]["manuallyrestart"][0]) form.otherinformation.data = (vms[0][0][1]["otherinformation"][0]) return render_template('add.html', form=form) else: return render_template('add.html', form=form) elif request.method == 'POST': # Fehler if not form.validate(): flash('Error, validation faild.') return render_template('add.html', form=form) else: print(form.servername.data) return render_template('add.html', form=form)
def add(): # Adding Addform so we can get the data from the home page add_form = AddForm() #If it does not validate, return home if not add_form.validate_on_submit(): flash("Name or Description too long") return redirect(url_for('home')) # Setting variable to data for easy reading item_name = add_form.name.data description = add_form.description.data add_backpack(item_name, description) return redirect(url_for('home'))
def add_character(): form = AddForm() if form.validate_on_submit(): name = form.p_name.data date = form.p_date.data new_date = Characters(date) new_char = Characters(name) db.session.add(new_char, new_date) db.commit() return redirect(url_for('characters')) return render_template('add-character.html', form=form)
def add_item(): form = AddForm() if form.validate_on_submit(): name1 = form.name.data item1 = form.item.data review1 = form.review.data new_item = Market(name=name1,item=item1,review=review1) db.session.add(new_item) db.session.commit() return redirect(url_for('thankyou')) return render_template('add.html',form=form)
def home_todo(): form = AddForm() if form.validate_on_submit(): date = form.date.data new_date = Date(date) db.session.add(new_date) db.session.commit() return redirect(url_for('add_todo')) else: return render_template('home.html', form=form)
def add_kit(): form = AddForm() if form.validate_on_submit(): name = form.name.data new_kit = Kitten(name) # grabs the name of the user form User model db.session.add(new_kit) db.session.commit() return redirect(url_for('list_kit')) return render_template('add.html', form = form)
def add_student(): form = AddForm() if form.validate_on_submit(): name = form.name.data new_student = Student(name) db.session.add(new_student) db.session.commit() return redirect(url_for('list_student')) return render_template('add.html', form=form)
def menusetup(user): form = AddForm() available = [] localrepopath = settings.WORKING_DIR + user.nickname for sub in os.listdir(localrepopath): subpath = localrepopath + "/" + sub if os.path.isdir(subpath): available.extend([(sub,sub)]) available.extend(allsubdirectories(user, sub, "|-", localrepopath)) form.location.choices = available types = [("None","Other"), ("mkdir","Directory")] languages = Language.query.all() for lang in languages: types.extend([(lang.filetype,"." + lang.filetype)]) form.type.choices = types if request.form.get('bar', None) == 'Add': if form.validate_on_submit(): userlocation = form.location.data locationpath = settings.WORKING_DIR + user.nickname + "/" + userlocation if os.path.isdir(locationpath): filepath = locationpath + "/" + form.filename.data if form.type.data == "mkdir": if not os.path.isdir(filepath): p1 = subprocess.Popen(["sudo", "mkdir", filepath]) p1.wait() flash('New Directory Created', 'success') else: flash('Directory already exists', 'error') else: if not form.type.data == "None": filepath = filepath + "." + form.type.data if not os.path.exists(filepath): open(filepath, 'a').close() repository = userlocation.split("/")[0] myrepo = user.repos.filter_by(repourl= "/" + repository + "/" ).first() filename = form.filename.data if not form.type.data == "None": filename = form.filename.data + "." + form.type.data f = File(filename=filename, path=userlocation, type="txt", repo=myrepo) flash("Created file " + filename + " in " + userlocation, 'success') db.session.add(f) db.session.commit() else: flash('File or directory already exists', 'error') else: flash('Name of new file or directory must not have spaces or slashes', 'error') cleanprocess() return form
def home(): # Adding all the forms to home page to be able to input data add_form = AddForm() delete_form = DeleteForm() clear_form = ClearForm() edit_form = EditForm() contents = view_backpack() return render_template("home.html", contents=contents, add_form=add_form, delete_form=delete_form, clear_form=clear_form, edit_form=edit_form, id=id)
def add_pup(): form = AddForm() if form.validate_on_submit(): name = form.name.data flash(f"{name.capitalize()} has been added to the database!", category="success") new_pup = Puppy(name) db.session.add(new_pup) db.session.commit() return redirect(url_for('list_pup')) return render_template('add.html', form=form)
def add_tractor(): form = AddForm() if form.validate_on_submit(): name = form.name.data # Add new Tractor to database new_tractor = Tractor(name) db.session.add(new_tractor) db.session.commit() return redirect(url_for('list_tractor')) return render_template('add.html',form=form)
def add_pup(): form = AddForm() if form.validate_on_submit(): name = form.name.data # Add new Puppy to database new_pup = Puppy(name) db.session.add(new_pup) db.session.commit() return redirect(url_for('list_pup')) return render_template('add_pup.html', form=form)