def deletephone(): db = Database(DB_PATH) if request.method == "POST" and request.form["delete"]: if db.delete(session["delete"]): flash("A phone number has been deleted") else: flash("A phone number can not be deleted") session.pop("delete", None) return redirect(url_for("index")) else: return redirect(url_for("index"))
def select_data(): #if request.method == 'GET': # user_id = str(request.args.get('id')) #else: # user_id = str(request.form["id"]) db = Database() #sql_query = "SELECT * FROM inventory WHERE id = %s;" % (user_id) #打ID只顯示撈回一筆上方if#要拿掉 sql_query = "SELECT * FROM inventory;" #撈回inventory全部資料要用,上面if else要#掉 data_string = db.execute_select(sql_query) return render_template('main.html', result=data_string)
def delete(id): db = Database(DB_PATH) row = db.read_by_id(id) print(row["Name"], row["Phone"], row["Address"]) if not row: return redirect(url_for("index")) else: session["delete"] = id return render_template("delete.html", Name=row["Name"], Phone=row["Phone"], Address=row["Address"])
def update(id): db = Database(DB_PATH) row = db.read_by_id(id) if not row: return redirect(url_for("index")) else: session["update"] = id data = { "Name": row["Name"], "Phone": row["Phone"], "Address": row["Address"] } return render_template("update.html", data=data)
def select_data(): #if request.method == 'GET': # user_id = str(request.args.get('id')) #else: # user_id = str(request.form["id"]) db = Database() #sql_query = "SELECT * FROM inventory WHERE id = %s;" % (user_id) #打ID只顯示撈回一筆上方if#要拿掉 sql_query = "SELECT * FROM inventory;" #撈回inventory全部資料要用,上面if else要#掉 data_string = db.execute_select(sql_query) return data_string + \ "<form method='get' action='/mysql'>" \ "</br>" \ "<button type='submit'>回mysql頁面</button></form>"
def delete_data(): if request.method == 'GET': user_id = str(request.args.get('id')) else: user_id = str(request.form["id"]) db = Database() sql_query = "DELETE FROM inventory WHERE id = %s;" db.execute(sql_query, (user_id, )) print("ID:%s delete ok" % user_id) #PI顯示 return "id: " + user_id +'</br>' + "delete_data OK" + \ "<form method='get' action='/mysql'>" \ "</br>" \ "<button type='submit'>回mysql頁面</button></form>"
def add_data(): if request.method == 'GET': name = str(request.args.get('name')) quantity = str(request.args.get('quantity')) else: name = str(request.form["name"]) quantity = str(request.form["quantity"]) db = Database() sql_query = ("INSERT INTO inventory (name, quantity) VALUES (%s, %s)") db.execute(sql_query, (name, quantity)) return "name: " + name + '</br>' + "quantity: " + quantity + '</br>' + "add OK" + \ "<form method='get' action='/mysql'>" \ "</br>" \ "<button type='submit'>回mysql頁面</button></form>"
def addphone(): if request.method == "POST" and request.form["save"]: data = { "Name": request.form["name"], "Phone": request.form["phone"], "Address": request.form["address"] } db = Database(DB_PATH) if db.insert(data): flash("A new phone number has been added") else: flash("A new phone number can not be added") return redirect(url_for("index")) else: return redirect(url_for("index"))
def load_database(self, db_path): if not os.path.isfile(db_path): return Database() else: with open(db_path, 'rb') as f: db = pickle.load(f) return db
def updatephone(): if request.method == "POST" and request.form["update"]: db = Database(DB_PATH) data = { "Name": request.form["name"], "Phone": request.form["phone"], "Address": request.form["address"], "ContactId": int(session["update"]) } if db.update(data): flash("A phone number has been updated") else: flash("A phone number can not be updated") session.pop("update", None) return redirect(url_for("index")) else: return redirect(url_for("index"))
def update_data(): if request.method == 'GET': user_id = str(request.args.get('id')) name = str(request.args.get('name')) quantity = str(request.args.get('quantity')) else: user_id = str(request.form["id"]) name = str(request.form["name"]) quantity = str(request.form["quantity"]) db = Database() sql_query = "UPDATE inventory SET quantity = %s, name = %s WHERE id = %s;" db.execute(sql_query, (quantity, name, user_id)) return "id: " + user_id +'</br>' +"name: " + name + '</br>' + "quantity: " + quantity + '</br>' + \ "update_data OK" + \ "<form method='get' action='/mysql'>" \ "</br>" \ "<button type='submit'>回mysql頁面</button></form>"
def rfid_read_data(): #首頁function #try: #if request.method == 'POST': i = datetime.datetime.now() #定義i=時間套件 nowdate = ("%s/%s/%s" % (i.year, i.month, i.day)) #日期 nowtime = ("%s:%s:%s" % (i.hour, i.minute, i.second)) #時間 id, text = reader.read() #讀取RFID內部資料 #print(id) #PI顯示id內容 print(text) #PI顯示text內容 db = Database() #定義db=檔案Database() sql_query = ("INSERT INTO rfid (name,date,time) VALUES (%s, %s, %s)" ) #SQL語法上傳資料到rfid資料表 db.execute(sql_query, (text, nowdate, nowtime)) #上傳到DB的值 #finally: #try:最後要用finally: #GPIO.cleanup() #清掉結束GPIO return "RFID Read OK!!</br>" \ " Hello!! " + text + "</br>" \ "刷卡資料已上傳到Mysql" \ "<form method='get' action='/rfid'>" \ "</br>" \ "<button type='submit'>回RFID頁</button></form>"
def index(): db = Database(DB_PATH) data = db.read_all() return render_template("index.html", data=data)
def database(): global __database if __database is None: __database = Database(**config['database']) return __database
#-*- coding: utf-8 -*- from flask import Flask, flash, render_template, redirect, url_for, request, session from module.database import Database from module import engine_doc2vec as Engine app = Flask(__name__) if __name__ == '__main__': db = Database() con = db.connect() cur = con.cursor() app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT' model = Engine.load_model() @app.route('/') def index(): return render_template('index.html') @app.route('/signUp') def signUp(): if 'user_id' in session and session['user_id'] != None: return redirect(url_for('index')) else: return render_template('signUp.html') @app.route('/signUpUser', methods=['POST']) def signUpUser(): if 'user_id' in session and session['user_id'] != None:
import datetime import json import http.client import sys sys.path.append("..") from .auth import login_required from flask import (Blueprint, flash, g, redirect, render_template, request, session, url_for, jsonify) from werkzeug.security import check_password_hash, generate_password_hash from module.database import Database from werkzeug.exceptions import abort bp = Blueprint('customer_point', __name__, url_prefix='/back/customer_point') db = Database() @bp.context_processor def inject_today_date(): return {'today_date': datetime.date.today()} @bp.context_processor def get_script_root(): url = request.url menu = url.split("/")[4:5][0] return {'menu': menu} @bp.route('/', methods=('GET', 'POST'))
''' Created on Jan 10, 2017 @author: hanif ''' import os from flask import Flask, flash, render_template, redirect, url_for, request, session from module.database import Database app = Flask(__name__) app.secret_key = "mys3cr3tk3y" db = Database() db.initialize() @app.route('/') def index(): data = db.read(None) return render_template('index.html', data=data) @app.route('/add/') def add(): return render_template('add.html') @app.route('/addphone', methods=['POST', 'GET']) def addphone(): if request.method == 'POST' and request.form['save']: