def index(): form = HelloForm() if form.validate_on_submit(): name = form.name.data s_date = form.s_date.data e_date = form.e_date.data t1 = s_date.strftime("%Y-%m-%d %H:%M:%S") t1 = datetime.strptime(t1, r"%Y-%m-%d %H:%M:%S") t2 = e_date.strftime("%Y-%m-%d %H:%M:%S") t2 = datetime.strptime(t2, r"%Y-%m-%d %H:%M:%S") all_date = t2 - t1 message = Message(s_date=s_date, e_date=e_date, name=name, all_date=all_date) db.session.add(message) db.session.commit() flash('%s,你已经签到成功!!' % name) return redirect(url_for('index')) page = request.args.get('page', 1, type=int) per_page = 10 # 10 pagination = Message.query.order_by(Message.s_date.desc()).paginate( page, per_page=per_page) messages = pagination.items # messages = Message.query.order_by(Message.timestamp.desc()).all() return render_template('index.html', form=form, messages=messages, pagination=pagination)
def index(): form = HelloForm() if form.validate_on_submit(): #单击获取内容按钮 if form.submit.data: url = form.url.data p = EasySina() form.text.data = p.getUrlContent(url) #单击文本分类按钮: if form.submit2.data: #获取文本内容 content = form.text.data #分类 cnn = CnnModel() form.classification.data = cnn.predict(content) print(cnn.predict(content)) print("以上是分类结果") #预测 #重定向,是index的url / return render_template('index.html', form=form) return redirect(url_for('index')) #render_template的功能是对先引入index.html,同时根据后面传入的参数,对html进行修改渲染。 return render_template('index.html', form=form)
def index(): form = HelloForm() if form.validate_on_submit(): Age = form.Age.data Income = form.Income.data Weight = form.Weight.data Height = form.Height.data Marriage = form.Marriage.data Sex = form.Sex.data Card_ID = form.Card_Id.data information = Information(Age=Age, Income=Income, Height=Height, Weight=Weight, Marriage=Marriage, Sex=Sex, Card_ID=Card_ID) print("No." + Card_ID + " customet" + " is waiting for your advice") db.session.add(information) db.session.commit() flash('Your message has been updated') return redirect(url_for("index")) if not form.validate_on_submit(): print(form.errors) information = Information.query.all() return render_template("index.html", form=form, information=information)
def index(): messages = Message.query.order_by(Message.timestamp.desc()).all() form = HelloForm() if form.validate_on_submit(): name = form.name.data body = form.body.data message = Message(body=body, name=name) db.session.add(message) db.session.commit() flash('Your message have been sent to the world!') return redirect(url_for('index')) return render_template('index.html', form=form, messages=messages)
def index(): form = HelloForm() if form.validate_on_submit(): name = form.name.data body = form.body.data message = Message(name=name, body=body) db.session.add(message) db.session.commit() flash('消息发布成功!') return redirect(url_for('index')) messages = Message.query.order_by(Message.timestamp.desc()).all() return render_template('index.html', form=form, messages=messages)
def index(): #加载所有记录 messages = Message.query.order_by(Message.timestamp.desc()).all() form = HelloForm() if form.validate_on_submit(): sender = form.sender.data content = form.content.data message = Message(sender=sender, content=content) db.session.add(message) db.session.commit() flash('留言发表成功') return redirect(url_for('index')) return render_template('index.html', form=form, messages=messages)
def index(): # 加载所有的记录 messages = Message.query.order_by(Message.timestamp.desc()).all() form = HelloForm() if form.validate_on_submit(): name = form.name.data body = form.body.data messages = Message(body=body, name=name) # 实例化模型类,创建记录 db.session.add(messages) # 添加记录到数据库会话 db.session.commit() # 提交会话 flash('Your message have been sent to world!') return redirect(url_for('index')) # 重定向到index视图 return render_template('index.html', form=form, messages=messages)
def index(): form = HelloForm() if form.validate_on_submit(): name = form.name body = form.body message = Message(body=body,name=name) #实例化模型类,创建记录 db.message.add(message)#添加记录到数据库会话 db.message.commit()#提交数据库会话 flash("Your Message have been sent to the world!") return redirect(url_for("index")) #重定向index视图 #加载所有记录 messages = Message.query.order_by(Message.timestamp.desc()).all() return render_template('index.html',form=form,messages=messages)
def index(page): # page = request.args.get('page', 1, type=int) form = HelloForm() # http://flask-sqlalchemy.pocoo.org/2.3/api/#flask_sqlalchemy.BaseQuery.paginate pagination = Message.query.order_by(Message.timestamp.desc()).paginate(page=page, per_page=50) if form.validate_on_submit(): name = form.name.data body = form.body.data message = Message(body=body, name=name) db.session.add(message) db.session.commit() flash('发送成功!') return redirect(url_for('index')) return render_template('index.html', form=form, messages=pagination.items, pagination=pagination)
def index(): form = HelloForm() message = Message() if form.validate_on_submit(): inppp = form.body.data if inppp is not None or len(inppp) > 0: inppp = inppp.strip() if len(inppp) > 0: if inppp[0] in qingwa.trans_m: body = decrypt_string(inppp) else: body = encrypt_string(inppp) message = Message(body=body) return render_template('index.html', form=form, message=message)
def index(): messages = Message.query.order_by(Message.timestamp.desc()).all() form = HelloForm() if form.validate_on_submit(): name = form.name.data body = form.body.data m = Message(name=name, body=body) db.session.add(m) db.session.commit() flash("Your Message have been saved!") redirect(url_for('index')) # return render_template('index.html', form=form, messages=messages) return render_template('index_bootstrap.html', form=form, messages=messages)
def index(): page = request.args.get('page', 1, int) per_page = current_app.config['SAYHELLO_PER_PAGE'] pagination = Message.query.order_by(Message.timestamp.desc()).paginate(page, per_page) messages = pagination.items form = HelloForm() if form.validate_on_submit(): message = Message() message.username = form.username.data message.body = form.body.data db.session.add(message) db.session.commit() flash('发布成功') return redirect(url_for('index', page=1)) return render_template('index.html', messages=messages, form=form, pagination=pagination)
def index(): form = HelloForm() if form.validate_on_submit(): # 处理 POST 请求 name = form.name.data body = form.body.data # 新增一条消息到数据库 message = Message(name=name, body=body) db.session.add(message) db.session.commit() flash('Your message have been sent to the world!') return redirect(url_for('index')) # 处理 GET 请求 # 加载所有记录, 按照最新时间排序 messages = Message.query.order_by(Message.timestamp.desc()).all() return render_template('index.html', form=form, messages=messages)
def index(): form = HelloForm() if form.validate_on_submit(): name = form.name.data message = form.message.data body = form.body.data form.validate_body(body) message = Message(name=name, body=message) db.session.add(message) db.session.commit() flash('Your message hava been sent to the world!') return redirect(url_for('index')) page = request.args.get('page', 1, type=int) per_page = app.config['PER_PAGE'] pagination = Message.query.order_by(Message.timestamp.desc()).paginate( page, per_page) messages = pagination.items return render_template('index.html', form=form, messages=messages, pagination=pagination)
def index(): global answer_feedback fact_form = HelloForm() change = False if fact_form.validate_on_submit(): change = True body = fact_form.body_textarea.data c_type = fact_form.c_type.data nl_body = body # Handle if user input facts if c_type == "Facts": query_result = utils.query(body) print("*************************") print(query_result) print("*************************") if query_result: body = str(query_result) else: # seems like emotional flash('您的评论可能不是事实,因此将不被接受。') return redirect(url_for('index')) if c_type == "Predicates": query_result = utils.break_logic(body) print("*************************") print(query_result) print("*************************") if query_result[0]: nl_body = query_result[0] else: # seems like with errors! c_type = "Emotional" body = query_result[1] if c_type == "Emotional": pass if c_type == "SubmitFunction": query_result = utils.query(body, True) print("*************************") print('Submitted Function!', query_result) print("*************************") if query_result: flash('成功提交一条行为至行为库。') else: # seems like emotional flash('您提交的行为似乎不能被识别,将不被接受。') return redirect(url_for('index')) if c_type == "Query": print("DO QUERY Inference... ") refresh_inf(body) return redirect(url_for('index')) message = Message(body=body, c_type=c_type, nl_body=nl_body) db.session.add(message) db.session.commit() flash('成功发表一条评论。') return redirect(url_for('index')) messages = Message.query.order_by(Message.timestamp.desc()).all() facts = [] predicates = [] emotionals = [] for i in messages: if i.c_type == "Facts": facts.append(i) elif i.c_type == "Predicates": predicates.append(i) elif i.c_type == "Emotional": emotionals.append(i) entity_dict = utils.commonDB.fetch() nen_per = ','.join(entity_dict['PER']) nen_loc = ','.join(entity_dict['LOC']) nen_org = ','.join(entity_dict['ORG']) funcs = utils.funcDB.fetch() complex_functions = [] for i in funcs: this = SingleFunction(i) complex_functions.append(this) # Read MLN result # Extract functions in mln format functions_mln = [] functions_query = [] for i in funcs: try: if len(i['args']) == 1: functions_query.append(i['verb']) functions_mln.append(i['function_mln']) except: print("bug handled!") functions_query = ",".join(functions_query) print("===============") print(functions_query) print("===============") # Write MLN KB files try: write_mln_files(facts, predicates, functions_mln, nen_per, nen_org, nen_loc, db_path, mln_path) print("Finished WRITING!") except: print("Write MLN db and mln failed...") return render_template('index.html', fact_form=fact_form, predicates=predicates, facts=facts, emotionals=emotionals, nen_per=nen_per, nen_loc=nen_loc, nen_org=nen_org, functions=complex_functions, infresult=answer_feedback)