def index(): form1 = EnterDBInfo(request.form) form2 = RetrieveDBInfo(request.form) if request.method == 'POST' and form1.validate(): player_details = Player(form1.name.data, form1.amount.data, form1.month.data, form1.year.data) try: db.session.add(player_details) db.session.commit() db.session.close() except: db.session.rollback() return render_template('thanks.html', notes=form1.name.data) if request.method == 'POST' and form2.validate(): try: num_return = int(form2.numRetrieve.data) query_db = Player.query.order_by( Player.id.desc()).limit(num_return) for q in query_db: print(q.name + q.amount + q.month + q.year) db.session.close() except: db.session.rollback() return render_template('results.html', results=query_db, num_return=num_return) return render_template('index.html', form1=form1, form2=form2)
def index(): form1 = EnterDBInfo(request.form) form2 = RetrieveDBInfo(request.form) if request.method == 'POST' and form1.validate(): data_entered = Data(notes=form1.dbNotes.data) try: db.session.add(data_entered) db.session.commit() db.session.close() except: db.session.rollback() return render_template('thanks.html', notes=form1.dbNotes.data) if request.method == 'POST' and form2.validate(): try: num_return = int(form2.numRetrieve.data) query_db = Data.query.order_by(Data.id.desc()).limit(num_return) for q in query_db: print(q.notes) db.session.close() except: db.session.rollback() return render_template('results.html', results=query_db, num_return=num_return) return render_template('index.html', form1=form1, form2=form2)
def flaskTutorial(): print "...in /test.................." form1 = EnterDBInfo(request.form) form2 = RetrieveDBInfo(request.form) if request.method == 'POST' and form1.validate(): data_entered = Data(notes=form1.dbNotes.data) try: db.session.add(data_entered) db.session.commit() db.session.close() except: db.session.rollback() return render_template('thanks.html', notes=form1.dbNotes.data) if request.method == 'POST' and form2.validate(): try: num_return = int(form2.numRetrieve.data) query_db = Data.query.order_by(Data.id.desc()).limit(num_return) for q in query_db: print(q.notes) db.session.close() except: db.session.rollback() return render_template('results.html', results=query_db, num_return=num_return) return render_template('index.html', form1=form1, form2=form2)
def index(): form1 = EnterDBInfo(request.form) form2 = RetrieveDBInfo(request.form) if request.method == 'POST' and form2.validate(): #num_return = str(form2.numRetrieve.data) #num_return=request.form['numRetrieve_field'] #sell_name= request.form['SellerRetrieve_field'] #add_name=request.form['AddressRetrieve_field'] num_return = request.form.get('numRetrieve', "") sell_name = request.form.get('SellerRetrieve', "") add_name = request.form.get('AddressRetrieve', "") #print num_return #query_db = Data.query.order_by(Data.id.desc()).limit(num_return) query_db = pyred.querySHOW(num_return,sell_name,add_name) #print query_db #for q in query_db: # print(q.notes) db.session.close() try: return render_template('results.html', results=query_db, num_return=num_return) except: return render_template('results1.html', results=query_db, num_return=num_return) return render_template('index.html', form1=form1, form2=form2)
def index(): scrape() form1 = RetrieveDBInfo(request.form) if request.method == 'POST' and form1.validate(): try: query_db = Article.query.order_by(Article.id) for q in query_db: print(q.title) db.session.close() except: db.session.rollback() return render_template('results.html', results=query_db) return render_template('index.html', form1=form1)
def index(): fileForm = UploadFile(request.form) form1 = EnterDBInfo(request.form) form2 = RetrieveDBInfo(request.form) if request.method == 'POST' and fileForm.validate_on_submit(): fileContents = fileForm.filePath.data filename = secure_filename(fileContents.filename) try: filePath = os.path.join(application.instance_path, 'photos', filename) fileContents.save(filePath, fileContents) print(filePath) print(fileContents) with open(filePath, newline='') as csvfile: filereader = csv.DictReader(csvfile) for row in filereader: print(row) db.session.add(row) db.session.commit() db.session.close() except: db.session.rollback() return render_template('thanks.html', notes=fileForm.filePath.data) if request.method == 'POST' and form1.validate(): data_entered = Data(notes=form1.dbNotes.data) try: db.session.add(data_entered) db.session.commit() db.session.close() except: db.session.rollback() return render_template('thanks.html', notes=form1.dbNotes.data) if request.method == 'POST' and form2.validate(): try: num_return = int(form2.numRetrieve.data) query_db = Data.query.order_by(Data.id.desc()).limit(num_return) for q in query_db: print(q.notes) db.session.close() except: db.session.rollback() return render_template('results.html', results=query_db, num_return=num_return) return render_template('index.html', fileForm=fileForm, form1=form1, form2=form2)
def index(): form1 = EnterDBInfo(request.form) form2 = RetrieveDBInfo(request.form) if request.method == 'POST' and form1.validate(): data_entered = User(User_id=form1.dbNotes.data, Name=form1.dbNotes2.data, Type='Student', Pw=form1.dbNotes3.data, Email=form1.dbNotes4.data) try: db.session.add(data_entered) db.session.commit() db.session.close() session['userid'] = form1.dbNotes.data except: db.session.rollback() return redirect(url_for('process_upload')) if request.method == 'POST' and form2.validate(): try: userid = str(form2.userid.data) password = str(form2.pw.data) query_db = User.query.filter(User.User_id.in_([userid]), User.Pw.in_([password])) result = query_db.first() if result: print "login successfully" session['userid'] = userid return redirect(url_for('process_upload')) else: print "login failed" return render_template('login_failed.html', studentid=userid) db.session.close() except: db.session.rollback() print "Nothing worked" return render_template('index.html', form1=form1, form2=form2)
def index(): form1 = EnterDBInfo(request.form) form2 = RetrieveDBInfo(request.form) try: query_db2 = Pre_req.query.order_by(Pre_req.Pre_id.desc()).limit(10) db.session.close() except: db.session.rollback() if request.method == 'POST' and form1.validate(): data_entered = User(User_id=form1.dbNotes.data,Name=form1.dbNotes2.data,Type ='Student',Pw =form1.dbNotes3.data,Email = form1.dbNotes4.data) try: db.session.add(data_entered) db.session.commit() db.session.close() except: db.session.rollback() return render_template('login.html', studentid=form1.dbNotes.data,courseinfo = query_db2) if request.method == 'POST' and form2.validate(): try: userid = str(form2.userid.data) password = str(form2.pw.data) query_db = User.query.filter(User.User_id.in_([userid]),User.Pw.in_([password])) result =query_db.first() if result: print "login successfully" return render_template('login.html',studentid =userid,courseinfo = query_db2) else: print "login failed" return render_template('login_failed.html',studentid =userid) db.session.close() except: db.session.rollback() return render_template('index.html', form1=form1, form2=form2)
def index(): # dynamically generate 2 forms with user request form form1 = EnterDBInfo(request.form) form2 = RetrieveDBInfo(request.form) if request.method == 'POST' and form1.validate(): # specifying an id is NOT necessary, default auto_intremental by experiment. data_entered = Data(notes=form1.dbNotes.data) try: db.session.add(data_entered) db.session.commit() db.session.close() except: db.session.rollback() return render_template('thanks.html', notes=form1.dbNotes.data) if request.method == 'POST' and form2.validate(): try: # get the user input from form2 submitted by user # the data is in the numRetrieve field (form contains field) num_return = int(form2.numRetrieve.data) # make the query with Data object is possible because: # Data inhe db.Model generated from Flask with SQLAlchemy # so Data has all the methods in db, which includes query # And here onwards you can use SQLAlchemy Query interface. query_db = Data.query.order_by(Data.id.desc()).limit(num_return) # Each q is a Data object, Data.query returns a bunch of Data # print each out for debugging. for q in query_db: print(q.id) print(q.notes) db.session.close() except: db.session.rollback() # after everything, render the result on html page for user consumption return render_template('results.html', results=query_db, num_return=num_return) # render index page if it is a GET methodd return render_template('index.html', form1=form1, form2=form2)
def index(): form1 = EnterDBInfo(request.form) form2 = RetrieveDBInfo(request.form) if request.method == 'POST' and form1.validate(): number = int(form1.dbNotes.data) parsed = roman_parse(number) data_entered = Data(arabic=number, roman=parsed) try: db.session.add(data_entered) db.session.commit() db.session.close() except: db.session.rollback() data = 'Parsed: {} to {} '.format(number, parsed) return render_template('thanks.html', data=data) if request.method == 'POST' and form2.validate(): num_return = int(form2.numRetrieve.data) query_db = Data.query.order_by(Data.id.desc()).limit(num_return) results = [q for q in query_db] or [] if results is not []: db.session.close() else: db.session.rollback() return render_template('results.html', results=results, num_return=num_return) return render_template('index.html', form1=form1, form2=form2)
def index(): form1 = EnterDBInfo(request.form) form2 = RetrieveDBInfo(request.form) if request.method == 'POST' and form1.validate() and twit.verify( form1.dbNotes.data): user = twit.clean(form1.dbNotes.data) data_entered = Data(notes=user) try: db.session.add(data_entered) db.session.commit() db.session.close() except: db.session.rollback() big5.train_models() tweets = twit.get_tweets(user) result = big5.check_personality(tweets) result['user'] = user data_json = json.dumps(result) loaded_data = json.loads(data_json) return render_template('results.html', notes=loaded_data) return render_template('index.html', form1=form1, form2=form2)