#主業務邏輯中的視圖和路由的定義 import os import datetime from flask import render_template, request, session #導入藍圖程序,用於構建路由 from werkzeug.utils import redirect from . import main from manage import mqtt #導入db,用於操作數據庫 from manage import db #導入實體類,用於操作數據庫 from ..models import * import json from datetime import datetime as dt from sqlalchemy import text #主頁的訪問路徑 @main.route('/') def main_index(): #獲取登入信息 if 'id' in session and 'uname' in session: username = session['uname'] try: liquid = LiquidTank.query.order_by(text('datetime desc')).first() except Exception: pass try: tank1_duration1 = liquid.tk1_duration1 except Exception: pass try: tank1_duration2 = liquid.tk1_duration2 except Exception: pass try: tank1_duration3 = liquid.tk1_duration3 except Exception: pass try: tank2_duration1 = liquid.tk2_duration1 except Exception: pass try: tank2_duration2 = liquid.tk2_duration2 except Exception: pass try: tank2_duration3 = liquid.tk2_duration3 except Exception: pass try: tank1_from_hr1, tank1_from_min1 = liquid.tk1_start1.split(':')[0], liquid.tk1_start1.split(':')[1] tank1_to_hr1, tank1_to_min1 = liquid.tk1_end1.split(':')[0], liquid.tk1_end1.split(':')[1] except Exception: pass try: tank1_from_hr2, tank1_from_min2 = liquid.tk1_start2.split(':')[0], liquid.tk1_start2.split(':')[1] tank1_to_hr2, tank1_to_min2 = liquid.tk1_end2.split(':')[0], liquid.tk1_end2.split(':')[1] except Exception: pass try: tank1_from_hr3, tank1_from_min3 = liquid.tk1_start3.split(':')[0], liquid.tk1_start3.split(':')[1] tank1_to_hr3, tank1_to_min3 = liquid.tk1_end3.split(':')[0], liquid.tk1_end3.split(':')[1] except Exception: pass try: tank2_from_hr1, tank2_from_min1 = liquid.tk2_start1.split(':')[0], liquid.tk2_start1.split(':')[1] tank2_to_hr1, tank2_to_min1 = liquid.tk2_end1.split(':')[0], liquid.tk2_end1.split(':')[1] except Exception: pass try: tank2_from_hr2, tank2_from_min2 = liquid.tk2_start2.split(':')[0], liquid.tk2_start2.split(':')[1] tank2_to_hr2, tank2_to_min2 = liquid.tk2_end2.split(':')[0], liquid.tk2_end2.split(':')[1] except Exception: pass try: tank2_from_hr3, tank2_from_min3 = liquid.tk2_start3.split(':')[0], liquid.tk2_start3.split(':')[1] tank2_to_hr3, tank2_to_min3 = liquid.tk2_end3.split(':')[0], liquid.tk2_end3.split(':')[1] except Exception: pass return render_template('set_liquid.html',params=locals()) else: return render_template('sign_in.html') #登入頁面的訪問路徑 @main.route('/login', methods=['GET','POST']) def login_views(): if request.method == 'GET': if 'id' in session and 'uname' in session: return redirect('/') else: return render_template('sign_in.html') else: #接收前端傳過來的資料 username = request.form['username'] password = request.form['password'] #使用接收的用戶和密碼到資料庫中查詢 user = User.query.filter_by(username=username, password=password).first() #如果用戶存在,將信息保存置session並重定向回首頁,否則重定向回登入頁 if user: resp = redirect('/') #判斷是否有記住密碼 if 'rem' in request.form: userID = str(user.userID) max_age = 60*60*24*365 resp.set_cookie("username", username, max_age=max_age) resp.set_cookie("userID", userID, max_age=max_age) session['uname'] = user.username session['id'] = user.userID return resp else: errMsg = "Wrong login or password" return render_template('sign_in.html',errMsg=errMsg) #登入重設密碼的頁面 @main.route('/reset_password', methods=['POST', 'GET']) def reset_password_views(): if request.method == 'GET': if 'mail' in session: del session['mail'] return render_template('reset_pwd1.html') else: #如果有id在session裡,代表從reset_pwd2過來的 if "mail" in session: new_pwd = request.form['new_pwd'] confirm_pwd = request.form['confirm_pwd'] #判斷密碼是否一致 if new_pwd == confirm_pwd: mail = session['mail'] user = User.query.filter_by(mail=mail).first() user.password = new_pwd db.session.add(user) del session['mail'] #修改完後回登入頁 return redirect('/login') else: errMsg = "Passwords does not match" return render_template('reset_pwd2.html', errMsg=errMsg) email = request.form['email'] user = User.query.filter_by(mail=email).first() if user: session['mail'] = user.mail return render_template('reset_pwd2.html') else: errMsg = "Wrong email.Please try again" return render_template('reset_pwd1.html', errMsg=errMsg) #註冊頁面的訪問路徑 @main.route('/register',methods=['POST',"GET"]) def register_views(): if request.method == 'GET': return render_template('registration.html') else: #獲取文本框的值並賦值給user實體對象 user = User() user.firstname = request.form['firstname'] user.lastname = request.form['lastname'] user.mail = request.form['email'] user.phone = request.form['phone'] user.username = request.form['username'] user.password = request.form['password'] user.status = 1 #將數據保存進資料庫 - 註冊 db.session.add(user) #手動提交,目的是為了獲取提交後的user的id db.session.commit() #當user成功插入進資料庫之後,程序會自動將所有信息取出來在賦值給user #完成登入的操作 user = User.query.filter_by(username=user.username).first() session['id'] = user.userID session['uname'] = user.username return redirect('/') #驗證email訪問路徑 @main.route('/check_email') def check_email_views(): email = request.args['email'] user = User.query.filter_by(mail=email).first() if user: result = {"errMsg":" "} else: result = {"pass":" "} return json.dumps(result) #驗證username訪問路徑 @main.route('/check_username') def check_username_views(): username = request.args['username'] user = User.query.filter_by(username=username).first() if user: result = {"errMsg":" "} else: result = {"pass":" "} return json.dumps(result) #liquid的訪問路徑 @main.route('/setting_liquid', methods=['POST','GET']) def setting_liquid_views(): username = session['uname'] if request.method == 'GET': liquid = LiquidTank.query.order_by('datetime desc').limit(1) return render_template('set_liquid.html', params=locals()) else: liquid = LiquidTank() liquid.datetime = dt.now() tank1_num = 1 tank1_from_num = 1 tank1_to_num = 1 tank2_num = 1 tank2_from_num = 1 tank2_to_num = 1 for i in request.form: if i[:14] == 'tank1_duration': if tank1_num == 1: liquid.tk1_duration1 = request.form[i] tank1_num += 1 elif tank1_num == 2: liquid.tk1_duration2 = request.form[i] tank1_num += 1 elif tank1_num == 3: liquid.tk1_duration3 = request.form[i] else: if i[:13] == 'tank1_from_hr': tk1_from_hr = request.form[i] elif i[:14] == 'tank1_from_min': tk1_from_min = request.form[i] if tank1_from_num == 1: liquid.tk1_start1 = tk1_from_hr + ":" + tk1_from_min tank1_from_num += 1 elif tank1_from_num == 2: liquid.tk1_start2 = tk1_from_hr + ":" + tk1_from_min tank1_from_num += 1 elif tank1_from_num == 3: liquid.tk1_start3 = tk1_from_hr + ":" + tk1_from_min elif i[:11] == 'tank1_to_hr': tk1_to_hr = request.form[i] elif i[:12] == 'tank1_to_min': tk1_to_min = request.form[i] if tank1_to_num ==1 : liquid.tk1_end1 = tk1_to_hr + ":" + tk1_to_min tank1_to_num += 1 elif tank1_to_num == 2: liquid.tk1_end2 = tk1_to_hr + ":" + tk1_to_min tank1_to_num += 1 elif tank1_to_num == 3: liquid.tk1_end3 = tk1_to_hr + ":" + tk1_to_min if i[:14] == 'tank2_duration': if tank2_num == 1: liquid.tk2_duration1 = request.form[i] tank2_num += 1 elif tank2_num == 2: liquid.tk2_duration2 = request.form[i] tank2_num += 1 elif tank2_num == 3: liquid.tk2_duration3 = request.form[i] else: if i[:13] == 'tank2_from_hr': tk2_from_hr = request.form[i] elif i[:14] == 'tank2_from_min': tk2_from_min = request.form[i] if tank2_from_num == 1: liquid.tk2_start1 = tk2_from_hr + ":" + tk2_from_min tank2_from_num += 1 elif tank2_from_num == 2: liquid.tk2_start2 = tk2_from_hr + ":" + tk2_from_min tank2_from_num += 1 elif tank2_from_num == 3: liquid.tk2_start3 = tk2_from_hr + ":" + tk2_from_min elif i[:11] == 'tank2_to_hr': tk2_to_hr = request.form[i] elif i[:12] == 'tank2_to_min': tk2_to_min = request.form[i] if tank2_to_num == 1: liquid.tk2_end1 = tk2_to_hr + ":" + tk2_to_min tank2_to_num += 1 elif tank2_to_num == 2: liquid.tk2_end2 = tk2_to_hr + ":" + tk2_to_min tank2_to_num += 1 elif tank2_to_num == 3: liquid.tk2_end3 = tk2_to_hr + ":" + tk2_to_min db.session.add(liquid) db.session.commit() # return render_template('set_root.html', params=locals()) return redirect('/setting_root') #root systems的訪問路徑 @main.route('/setting_root', methods=['POST','GET']) def setting_root_views(): username = session['uname'] if request.method == 'GET': root = RootSystem.query.order_by(text('datetime desc')).first() try: tem1 = root.tem_tem1 except Exception: pass try: tem2 = root.tem_tem2 except Exception: pass try: tem3 = root.tem_tem3 except Exception: pass try: tem_from_hr1, tem_from_min1 = root.tem_start1.split(':')[0], root.tem_start1.split(':')[1] except Exception: pass try: tem_to_hr1, tem_to_min1 = root.tem_end1.split(':')[0], root.tem_end1.split(':')[1] except Exception: pass try: tem_from_hr2, tem_from_min2 = root.tem_start2.split(':')[0], root.tem_start2.split(':')[1] except Exception: pass try: tem_to_hr2, tem_to_min2 = root.tem_end2.split(':')[0], root.tem_end2.split(':')[1] except Exception: pass try: tem_from_hr3, tem_from_min3 = root.tem_start3.split(':')[0], root.tem_start3.split(':')[1] except Exception: pass try: tem_to_hr3, tem_to_min3 = root.tem_end3.split(':')[0], root.tem_end3.split(':')[1] except Exception: pass try: lamp_from_hr1, lamp_from_min1 = root.l_start1.split(':')[0], root.l_start1.split(':')[1] except Exception: pass try: lamp_to_hr1, lamp_to_min1 = root.l_end1.split(':')[0], root.l_end1.split(':')[1] except Exception: pass try: lamp_from_hr2, lamp_from_min2 = root.l_start2.split(':')[0], root.l_start2.split(':')[1] except Exception: pass try: lamp_to_hr2, lamp_to_min2 = root.l_end2.split(':')[0], root.l_end2.split(':')[1] except Exception: pass try: lamp_from_hr3, lamp_from_min3 = root.l_start3.split(':')[0], root.l_start3.split(':')[1] except Exception: pass try: lamp_to_hr3, lamp_to_min3 = root.l_end3.split(':')[0], root.l_end3.split(':')[1] except Exception: pass try: r = str(root.l_r) g = str(root.l_g) b = str(root.l_b) color = '(' + r + ',' + g + ',' + b + ')' except Exception: pass try: if root.l_bright_auto == 0: #+1是為了讓前端不要判定為假 bright_on = root.l_bright_auto + 1 bright_vol = root.l_bright_vol if root.fan_status == 0: fan_on = root.fan_status + 1 periodicity = root.fan_periodicity duration = root.fan_duration speed = root.fan_speed humidity = root.humidity except Exception: pass return render_template('set_root.html', params=locals()) else: root = RootSystem() root.datetime = dt.now() tem_num = 1 tem_from_num = 1 tem_to_num = 1 lamp_from_num = 1 lamp_to_num = 1 for i in request.form: if i[:3] == 'tem' and len(i) <= 7: if tem_num == 1: root.tem_tem1 = request.form[i] tem_num += 1 elif tem_num == 2: root.tem_tem2 = request.form[i] tem_num += 1 elif tem_num == 3: root.tem_tem3 = request.form[i] else: if i[:11] == 'tem_from_hr': tem_from_hr = request.form[i] elif i[:12] == 'tem_from_min': tem_from_min = request.form[i] if tem_from_num == 1: root.tem_start1 = tem_from_hr + ":" + tem_from_min tem_from_num += 1 elif tem_from_num == 2: root.tem_start2 = tem_from_hr + ":" + tem_from_min tem_from_num += 1 elif tem_from_num == 3: root.tem_start3 = tem_from_hr + ":" + tem_from_min elif i[:9] == 'tem_to_hr': tem_to_hr = request.form[i] elif i[:10] == 'tem_to_min': tem_to_min = request.form[i] if tem_to_num ==1 : root.tem_end1 = tem_to_hr + ":" + tem_to_min tem_to_num += 1 elif tem_to_num == 2: root.tem_end2 = tem_to_hr + ":" + tem_to_min tem_to_num += 1 elif tem_to_num == 3: root.tem_end3 = tem_to_hr + ":" + tem_to_min if i[:12] == 'lamp_from_hr': lamp_from_hr = request.form[i] elif i[:13] == 'lamp_from_min': lamp_from_min = request.form[i] if lamp_from_num == 1: root.l_start1 = lamp_from_hr + ":" + lamp_from_min lamp_from_num += 1 elif lamp_from_num == 2: root.l_start2 = lamp_from_hr + ":" + lamp_from_min lamp_from_num += 1 elif lamp_from_num == 3: root.l_start3 = lamp_from_hr + ":" + lamp_from_min if i[:10] == 'lamp_to_hr': lamp_to_hr = request.form[i] elif i[:11] == 'lamp_to_min': lamp_to_min = request.form[i] if lamp_to_num ==1 : root.l_end1 = lamp_to_hr + ":" + lamp_to_min lamp_to_num += 1 elif lamp_to_num == 2: root.l_end2 = lamp_to_hr + ":" + lamp_to_min lamp_to_num += 1 elif lamp_to_num == 3: root.l_end3 = lamp_to_hr + ":" + lamp_to_min if i == 'color': try: color = request.form['color'] root.l_r, root.l_g, root.l_b = color.split(',')[0], color.split(',')[1][1:], color.split(',')[2][1:] except Exception: pass if 'bright-on' in request.form: root.l_bright_auto = 1 else: root.l_bright_auto = 0 root.l_bright_vol = request.form['bright-vol'] if 'fan-on' in request.form: root.fan_status = 1 else: root.fan_status = 0 root.fan_periodicity = request.form['periodicity'] root.fan_duration = request.form['duration'] root.fan_speed = request.form['speed'] root.humidity = request.form['humidity'] db.session.add(root) db.session.commit() # return render_template('set_stem.html', params=locals()) return redirect('/setting_stem') #stem systems的訪問路徑 @main.route('/setting_stem', methods=['POST','GET']) def setting_stem_views(): username = session['uname'] if request.method == 'GET': stem = StemSystem.query.order_by(text('datetime desc')).first() try: tem1 = stem.tem_tem1 except Exception: pass try: tem2 = stem.tem_tem2 except Exception: pass try: tem3 = stem.tem_tem3 except Exception: pass try: tem_from_hr1, tem_from_min1 = stem.tem_start1.split(':')[0], stem.tem_start1.split(':')[1] except Exception: pass try: tem_to_hr1, tem_to_min1 = stem.tem_end1.split(':')[0], stem.tem_end1.split(':')[1] except Exception: pass try: tem_from_hr2, tem_from_min2 = stem.tem_start2.split(':')[0], stem.tem_start2.split(':')[1] except Exception: pass try: tem_to_hr2, tem_to_min2 = stem.tem_end2.split(':')[0], stem.tem_end2.split(':')[1] except Exception: pass try: tem_from_hr3, tem_from_min3 = stem.tem_start3.split(':')[0], stem.tem_start3.split(':')[1] except Exception: pass try: tem_to_hr3, tem_to_min3 = stem.tem_end3.split(':')[0], stem.tem_end3.split(':')[1] except Exception: pass try: led_from_hr1, led_from_min1 = stem.l_start1.split(':')[0], stem.l_start1.split(':')[1] except Exception: pass try: led_to_hr1, led_to_min1 = stem.l_end1.split(':')[0], stem.l_end1.split(':')[1] except Exception: pass try: led_from_hr2, led_from_min2 = stem.l_start2.split(':')[0], stem.l_start2.split(':')[1] except Exception: pass try: led_to_hr2, led_to_min2 = stem.l_end2.split(':')[0], stem.l_end2.split(':')[1] except Exception: pass try: led_from_hr3, led_from_min3 = stem.l_start3.split(':')[0], stem.l_start3.split(':')[1] except Exception: pass try: led_to_hr3, led_to_min3 = stem.l_end3.split(':')[0], stem.l_end3.split(':')[1] except Exception: pass try: r = str(stem.l_r) g = str(stem.l_g) b = str(stem.l_b) color = '(' + r + ',' + g + ',' + b + ')' except Exception: pass try: if stem.l_bright_auto == 0: #+1是為了讓前端不要判定為假 bright_on = stem.l_bright_auto + 1 bright_vol = stem.l_bright_vol except Exception: pass try: if stem.c_status == 0: # +1是為了讓前端不要判定為假 camera_on = stem.c_status + 1 except Exception: pass try: duration = stem.c_duration except Exception: pass try: tem_near_stem1 = stem.t_n_s_tem1 except Exception: pass try: tem_near_stem2 = stem.t_n_s_tem2 except Exception: pass try: tem_near_stem3 = stem.t_n_s_tem3 except Exception: pass try: t_n_s_from_hr1, t_n_s_from_min1 = stem.t_n_s_start1.split(':')[0], stem.t_n_s_start1.split(':')[1] except Exception: pass try: t_n_s_to_hr1, t_n_s_to_min1 = stem.t_n_s_end1.split(':')[0], stem.t_n_s_end1.split(':')[1] except Exception: pass try: t_n_s_from_hr2, t_n_s_from_min2 = stem.t_n_s_start2.split(':')[0], stem.t_n_s_start2.split(':')[1] except Exception: pass try: t_n_s_to_hr2, t_n_s_to_min2 = stem.t_n_s_end2.split(':')[0], stem.t_n_s_end2.split(':')[1] except Exception: pass try: t_n_s_from_hr3, t_n_s_from_min3 = stem.t_n_s_start3.split(':')[0], stem.t_n_s_start3.split(':')[1] except Exception: pass try: t_n_s_to_hr3, t_n_s_to_min3 = stem.t_n_s_end3.split(':')[0], stem.t_n_s_end3.split(':')[1] except Exception: pass try: music1 = stem.m_playlist1 except Exception: pass try: music2 = stem.m_playlist2 except Exception: pass try: music3 = stem.m_playlist3 except Exception: pass try: music_from_hr1, music_from_min1 = stem.m_start1.split(':')[0], stem.m_start1.split(':')[1] except Exception: pass try: music_to_hr1, music_to_min1 = stem.m_end1.split(':')[0], stem.m_end1.split(':')[1] except Exception: pass try: music_from_hr2, music_from_min2 = stem.m_start2.split(':')[0], stem.m_start2.split(':')[1] except Exception: pass try: music_to_hr2, music_to_min2 = stem.m_end2.split(':')[0], stem.m_end2.split(':')[1] except Exception: pass try: music_from_hr3, music_from_min3 = stem.m_start3.split(':')[0], stem.m_start3.split(':')[1] except Exception: pass try: music_to_hr3, music_to_min3 = stem.m_end3.split(':')[0], stem.m_end3.split(':')[1] except Exception: pass try: u_s_from_hr1, u_s_from_min1 = stem.u_s_start1.split(':')[0], stem.u_s_start1.split(':')[1] except Exception: pass try: u_s_to_hr1, u_s_to_min1 = stem.u_s_end1.split(':')[0], stem.u_s_end1.split(':')[1] except Exception: pass try: u_s_from_hr2, u_s_from_min2 = stem.u_s_start2.split(':')[0], stem.u_s_start2.split(':')[1] except Exception: pass try: u_s_to_hr2, u_s_to_min2 = stem.u_s_end2.split(':')[0], stem.u_s_end2.split(':')[1] except Exception: pass try: u_s_from_hr3, u_s_from_min3 = stem.u_s_start3.split(':')[0], stem.u_s_start3.split(':')[1] except Exception: pass try: u_s_to_hr3, u_s_to_min3 = stem.u_s_end3.split(':')[0], stem.u_s_end3.split(':')[1] except Exception: pass try: if stem.u_s_status == 0: # +1是為了讓前端不要判定為假 ultra_sonic_on = stem.u_s_status + 1 except Exception: pass try: volume = stem.u_s_vol except Exception: pass try: vibration1 = stem.v_vol1 except Exception: pass try: vibration2 = stem.v_vol2 except Exception: pass try: vibration3 = stem.v_vol3 except Exception: pass try: v_from_hr1, v_from_min1 = stem.v_start1.split(':')[0], stem.v_start1.split(':')[1] except Exception: pass try: v_to_hr1, v_to_min1 = stem.v_end1.split(':')[0], stem.v_end1.split(':')[1] except Exception: pass try: v_from_hr2, v_from_min2 = stem.v_start2.split(':')[0], stem.v_start2.split(':')[1] except Exception: pass try: v_to_hr2, v_to_min2 = stem.v_end2.split(':')[0], stem.v_end2.split(':')[1] except Exception: pass try: v_from_hr3, v_from_min3 = stem.v_start3.split(':')[0], stem.v_start3.split(':')[1] except Exception: pass try: v_to_hr3, v_to_min3 = stem.v_end3.split(':')[0], stem.v_end3.split(':')[1] except Exception: pass try: wind_flow1 = stem.w_vol1 except Exception: pass try: wind_flow2 = stem.w_vol2 except Exception: pass try: wind_flow3 = stem.w_vol3 except Exception: pass try: w_from_hr1, w_from_min1 = stem.w_start1.split(':')[0], stem.w_start1.split(':')[1] except Exception: pass try: w_to_hr1, w_to_min1 = stem.w_end1.split(':')[0], stem.w_end1.split(':')[1] except Exception: pass try: w_from_hr2, w_from_min2 = stem.w_start2.split(':')[0], stem.w_start2.split(':')[1] except Exception: pass try: w_to_hr2, w_to_min2 = stem.w_end2.split(':')[0], stem.w_end2.split(':')[1] except Exception: pass try: w_from_hr3, w_from_min3 = stem.w_start3.split(':')[0], stem.w_start3.split(':')[1] except Exception: pass try: w_to_hr3, w_to_min3 = stem.w_end3.split(':')[0], stem.w_end3.split(':')[1] except Exception: pass try: c_duration = stem.c_duration except Exception: pass try: rh = stem.rh except Exception: pass return render_template('set_stem.html', params=locals()) else: stem = StemSystem() stem.datetime = dt.now() tem_num = 1 tem_from_num = 1 tem_to_num = 1 led_from_num = 1 led_to_num = 1 t_n_s_num = 1 t_n_s_from_num = 1 t_n_s_to_num = 1 music_num = 1 music_from_num = 1 music_to_num = 1 u_s_from_num = 1 u_s_to_num = 1 v_num = 1 v_from_num = 1 v_to_num = 1 w_num = 1 w_from_num = 1 w_to_num = 1 for i in request.form: if i[:3] == 'tem' and len(i) <= 7: if tem_num == 1: stem.tem_tem1 = request.form[i] tem_num += 1 elif tem_num == 2: stem.tem_tem2 = request.form[i] tem_num += 1 elif tem_num == 3: stem.tem_tem3 = request.form[i] else: if i[:11] == 'tem_from_hr': tem_from_hr = request.form[i] elif i[:12] == 'tem_from_min': tem_from_min = request.form[i] if tem_from_num == 1: stem.tem_start1 = tem_from_hr + ":" + tem_from_min tem_from_num += 1 elif tem_from_num == 2: stem.tem_start2 = tem_from_hr + ":" + tem_from_min tem_from_num += 1 elif tem_from_num == 3: stem.tem_start3 = tem_from_hr + ":" + tem_from_min elif i[:9] == 'tem_to_hr': tem_to_hr = request.form[i] elif i[:10] == 'tem_to_min': tem_to_min = request.form[i] if tem_to_num ==1 : stem.tem_end1 = tem_to_hr + ":" + tem_to_min tem_to_num += 1 elif tem_to_num == 2: stem.tem_end2 = tem_to_hr + ":" + tem_to_min tem_to_num += 1 elif tem_to_num == 3: stem.tem_end3 = tem_to_hr + ":" + tem_to_min if i[:11] == 'led_from_hr': led_from_hr = request.form[i] elif i[:12] == 'led_from_min': led_from_min = request.form[i] if led_from_num == 1: stem.l_start1 = led_from_hr + ":" + led_from_min led_from_num += 1 elif led_from_num == 2: stem.l_start2 = led_from_hr + ":" + led_from_min led_from_num += 1 elif led_from_num == 3: stem.l_start3 = led_from_hr + ":" + led_from_min if i[:9] == 'led_to_hr': led_to_hr = request.form[i] elif i[:10] == 'led_to_min': led_to_min = request.form[i] if led_to_num ==1 : stem.l_end1 = led_to_hr + ":" + led_to_min led_to_num += 1 elif led_to_num == 2: stem.l_end2 = led_to_hr + ":" + led_to_min led_to_num += 1 elif led_to_num == 3: stem.l_end3 = led_to_hr + ":" + led_to_min if i == 'color': try: color = request.form['color'] stem.l_r, stem.l_g, stem.l_b = color.split(',')[0], color.split(',')[1][1:], color.split(',')[2][1:] except Exception: pass if i[:13] == 'tem-near-stem': if t_n_s_num == 1: stem.t_n_s_tem1 = request.form[i] print(request.form[i]) t_n_s_num += 1 elif t_n_s_num == 2: stem.t_n_s_tem2 = request.form[i] t_n_s_num += 1 elif t_n_s_num == 3: stem.t_n_s_tem3 = request.form[i] else: if i[:11] == 'tns_from_hr': t_n_s_from_hr = request.form[i] elif i[:12] == 'tns_from_min': t_n_s_from_min = request.form[i] if t_n_s_from_num == 1: stem.t_n_s_start1 = t_n_s_from_hr + ":" + t_n_s_from_min t_n_s_from_num += 1 elif t_n_s_from_num == 2: stem.t_n_s_start2 = t_n_s_from_hr + ":" + t_n_s_from_min t_n_s_from_num += 1 elif t_n_s_from_num == 3: stem.t_n_s_start3 = t_n_s_from_hr + ":" + t_n_s_from_min elif i[:9] == 'tns_to_hr': t_n_s_to_hr = request.form[i] elif i[:10] == 'tns_to_min': t_n_s_to_min = request.form[i] if t_n_s_to_num == 1: stem.t_n_s_end1 = t_n_s_to_hr + ":" + t_n_s_to_min t_n_s_to_num += 1 elif t_n_s_to_num == 2: stem.t_n_s_end2 = t_n_s_to_hr + ":" + t_n_s_to_min t_n_s_to_num += 1 elif t_n_s_to_num == 3: stem.t_n_s_end3 = t_n_s_to_hr + ":" + t_n_s_to_min if i[:5] == 'music' and len(i) <=11: if music_num == 1: stem.m_playlist1 = request.form[i] music_num += 1 elif music_num == 2: stem.m_playlist2 = request.form[i] music_num += 1 elif music_num == 3: stem.m_playlist3 = request.form[i] else: if i[:13] == 'music_from_hr': music_from_hr = request.form[i] elif i[:14] == 'music_from_min': music_from_min = request.form[i] if music_from_num == 1: stem.m_start1 = music_from_hr + ":" + music_from_min music_from_num += 1 elif music_from_num == 2: stem.m_start2 = music_from_hr + ":" + music_from_min music_from_num += 1 elif music_from_num == 3: stem.m_start3 = music_from_hr + ":" + music_from_min elif i[:11] == 'music_to_hr': music_to_hr = request.form[i] elif i[:12] == 'music_to_min': music_to_min = request.form[i] if music_to_num == 1: stem.m_end1 = music_to_hr + ":" + music_to_min music_to_num += 1 elif music_to_num == 2: stem.m_end2 = music_to_hr + ":" + music_to_min music_to_num += 1 elif music_to_num == 3: stem.m_end3 = music_to_hr + ":" + music_to_min if i[:9] == 'vibration': if v_num == 1: stem.v_vol1 = request.form[i] v_num += 1 elif v_num == 2: stem.v_vol2 = request.form[i] v_num += 1 elif v_num == 3: stem.v_vol3 = request.form[i] else: if i[:9] == 'v_from_hr': v_from_hr = request.form[i] elif i[:10] == 'v_from_min': v_from_min = request.form[i] if v_from_num == 1: stem.v_start1 = v_from_hr + ":" + v_from_min v_from_num += 1 elif v_from_num == 2: stem.v_start2 = v_from_hr + ":" + v_from_min v_from_num += 1 elif v_from_num == 3: stem.v_start3 = v_from_hr + ":" + v_from_min elif i[:7] == 'v_to_hr': v_to_hr = request.form[i] elif i[:8] == 'v_to_min': v_to_min = request.form[i] if v_to_num == 1: stem.v_end1 = v_to_hr + ":" + v_to_min v_to_num += 1 elif v_to_num == 2: stem.v_end2 = v_to_hr + ":" + v_to_min v_to_num += 1 elif v_to_num == 3: stem.v_end3 = v_to_hr + ":" + v_to_min if i[:9] == 'wind-flow': if w_num == 1: stem.w_vol1 = request.form[i] w_num += 1 elif w_num == 2: stem.w_vol2 = request.form[i] w_num += 1 elif w_num == 3: stem.w_vol3 = request.form[i] else: if i[:9] == 'w_from_hr': w_from_hr = request.form[i] elif i[:10] == 'w_from_min': w_from_min = request.form[i] if w_from_num == 1: stem.w_start1 = w_from_hr + ":" + w_from_min w_from_num += 1 elif w_from_num == 2: stem.w_start2 = w_from_hr + ":" + w_from_min w_from_num += 1 elif w_from_num == 3: stem.w_start3 = w_from_hr + ":" + w_from_min elif i[:7] == 'w_to_hr': w_to_hr = request.form[i] elif i[:8] == 'w_to_min': w_to_min = request.form[i] if w_to_num == 1: stem.w_end1 = w_to_hr + ":" + w_to_min w_to_num += 1 elif w_to_num == 2: stem.w_end2 = w_to_hr + ":" + w_to_min w_to_num += 1 elif w_to_num == 3: stem.w_end3 = w_to_hr + ":" + w_to_min if i[:10] == 'us_from_hr': u_s_from_hr = request.form[i] elif i[:11] == 'us_from_min': u_s_from_min = request.form[i] if u_s_from_num == 1: stem.u_s_start1 = u_s_from_hr + ":" + u_s_from_min u_s_from_num += 1 elif u_s_from_num == 2: stem.u_s_start2 = u_s_from_hr + ":" + u_s_from_min u_s_from_num += 1 elif u_s_from_num == 3: stem.u_s_start3 = u_s_from_hr + ":" + u_s_from_min elif i[:8] == 'us_to_hr': u_s_to_hr = request.form[i] elif i[:9] == 'us_to_min': u_s_to_min = request.form[i] if u_s_to_num == 1: stem.u_s_end1 = u_s_to_hr + ":" + u_s_to_min u_s_to_num += 1 elif u_s_to_num == 2: stem.u_s_end2 = u_s_to_hr + ":" + u_s_to_min u_s_to_num += 1 elif u_s_to_num == 3: stem.u_s_end3 = u_s_to_hr + ":" + u_s_to_min if 'ultra-sonic-on' in request.form: stem.u_s_status = 1 else: stem.u_s_status = 0 if 'volume' in request.form: stem.u_s_vol = request.form['volume'] if 'bright-on' in request.form: stem.l_bright_auto = 1 else: stem.l_bright_auto = 0 stem.l_bright_vol = request.form['bright-vol'] if 'camera-on' in request.form: stem.c_status = 1 else: stem.c_status = 0 stem.c_duration = request.form['duration'] stem.rh = request.form['rh'] db.session.add(stem) db.session.commit() print(request.form) # return render_template('online_fitolab.html', params=locals()) return redirect('online_fitolab') #online_fitolab的訪問路徑 @main.route('/online_fitolab', methods=['POST',"GET"]) def online_fitolib_views(): username = session['uname'] if request.method == 'GET': stem = StemSystem.query.order_by(text('datetime desc')).first() root = RootSystem.query.order_by(text('datetime desc')).first() liquid = LiquidTank.query.order_by(text('datetime desc')).first() fitolab1 = Fitolab1Sensor.query.order_by(text('datetime desc')).first() try: stem_r = str(stem.l_r) stem_g = str(stem.l_g) stem_b = str(stem.l_b) stem_color = '(' + stem_r + ',' + stem_g + ',' + stem_b + ')' except Exception: pass try: if stem.l_bright_auto == 0: #+1是為了讓前端不要判定為假 stem_bright_on = stem.l_bright_auto + 1 stem_bright_vol = stem.l_bright_vol except Exception: pass try: music1 = stem.m_playlist1 except Exception: pass try: music2 = stem.m_playlist2 except Exception: pass try: music3 = stem.m_playlist3 except Exception: pass try: music_from_hr1, music_from_min1 = stem.m_start1.split(':')[0], stem.m_start1.split(':')[1] except Exception: pass try: music_to_hr1, music_to_min1 = stem.m_end1.split(':')[0], stem.m_end1.split(':')[1] except Exception: pass try: music_from_hr2, music_from_min2 = stem.m_start2.split(':')[0], stem.m_start2.split(':')[1] except Exception: pass try: music_to_hr2, music_to_min2 = stem.m_end2.split(':')[0], stem.m_end2.split(':')[1] except Exception: pass try: music_from_hr3, music_from_min3 = stem.m_start3.split(':')[0], stem.m_start3.split(':')[1] except Exception: pass try: music_to_hr3, music_to_min3 = stem.m_end3.split(':')[0], stem.m_end3.split(':')[1] except Exception: pass try: m_vol = stem.m_vol except Exception: pass try: root_r = str(root.l_r) root_g = str(root.l_g) root_b = str(root.l_b) root_color = '(' + root_r + ',' + root_g + ',' + root_b + ')' except Exception: pass try: if root.l_bright_auto == 0: #+1是為了讓前端不要判定為假 root_bright_on = root.l_bright_auto + 1 root_bright_vol = root.l_bright_vol except Exception: pass try: vibration1 = stem.v_vol1 except Exception: pass try: vibration2 = stem.v_vol2 except Exception: pass try: vibration3 = stem.v_vol3 except Exception: pass try: v_from_hr1, v_from_min1 = stem.v_start1.split(':')[0], stem.v_start1.split(':')[1] except Exception: pass try: v_to_hr1, v_to_min1 = stem.v_end1.split(':')[0], stem.v_end1.split(':')[1] except Exception: pass try: v_from_hr2, v_from_min2 = stem.v_start2.split(':')[0], stem.v_start2.split(':')[1] except Exception: pass try: v_to_hr2, v_to_min2 = stem.v_end2.split(':')[0], stem.v_end2.split(':')[1] except Exception: pass try: v_from_hr3, v_from_min3 = stem.v_start3.split(':')[0], stem.v_start3.split(':')[1] except Exception: pass try: v_to_hr3, v_to_min3 = stem.v_end3.split(':')[0], stem.v_end3.split(':')[1] except Exception: pass try: v_pow = stem.v_power except Exception: pass try: tank1_duration1 = liquid.tk1_duration1 tank2_duration1 = liquid.tk2_duration1 tank1_from_hr1, tank1_from_min1 = liquid.tk1_start1.split(':')[0], liquid.tk1_start1.split(':')[1] tank1_to_hr1, tank1_to_min1 = liquid.tk1_end1.split(':')[0], liquid.tk1_end1.split(':')[1] except Exception: pass try: tank1_from_hr2, tank1_from_min2 = liquid.tk1_start2.split(':')[0], liquid.tk1_start2.split(':')[1] tank1_to_hr2, tank1_to_min2 = liquid.tk1_end2.split(':')[0], liquid.tk1_end2.split(':')[1] except Exception: pass try: tank1_from_hr3, tank1_from_min3 = liquid.tk1_start3.split(':')[0], liquid.tk1_start3.split(':')[1] tank1_to_hr3, tank1_to_min3 = liquid.tk1_end3.split(':')[0], liquid.tk1_end3.split(':')[1] except Exception: pass try: tank2_from_hr1, tank2_from_min1 = liquid.tk2_start1.split(':')[0], liquid.tk2_start1.split(':')[1] tank2_to_hr1, tank2_to_min1 = liquid.tk2_end1.split(':')[0], liquid.tk2_end1.split(':')[1] except Exception: pass try: tank2_from_hr2, tank2_from_min2 = liquid.tk2_start2.split(':')[0], liquid.tk2_start2.split(':')[1] tank2_to_hr2, tank2_to_min2 = liquid.tk2_end2.split(':')[0], liquid.tk2_end2.split(':')[1] except Exception: pass try: tank2_from_hr3, tank2_from_min3 = liquid.tk2_start3.split(':')[0], liquid.tk2_start3.split(':')[1] tank2_to_hr3, tank2_to_min3 = liquid.tk2_end3.split(':')[0], liquid.tk2_end3.split(':')[1] except Exception: pass try: if stem.c_status == 0: # +1是為了讓前端不要判定為假 camera_on = stem.c_status + 1 except Exception: pass try: c_duration = stem.c_duration except Exception: pass try: music1 = stem.m_playlist1 except Exception: pass try: music2 = stem.m_playlist2 except Exception: pass try: music3 = stem.m_playlist3 except Exception: pass try: music_from_hr1, music_from_min1 = stem.m_start1.split(':')[0], stem.m_start1.split(':')[1] except Exception: pass try: music_to_hr1, music_to_min1 = stem.m_end1.split(':')[0], stem.m_end1.split(':')[1] except Exception: pass try: music_from_hr2, music_from_min2 = stem.m_start2.split(':')[0], stem.m_start2.split(':')[1] except Exception: pass try: music_to_hr2, music_to_min2 = stem.m_end2.split(':')[0], stem.m_end2.split(':')[1] except Exception: pass try: music_from_hr3, music_from_min3 = stem.m_start3.split(':')[0], stem.m_start3.split(':')[1] except Exception: pass try: music_to_hr3, music_to_min3 = stem.m_end3.split(':')[0], stem.m_end3.split(':')[1] except Exception: pass try: m_vol = stem.m_vol except Exception: pass try: if stem.c_status == 0: #+1是為了讓前端不要判定為假 camara_on = stem.c_status + 1 except Exception: pass try: vibration1 = stem.v_vol1 except Exception: pass try: vibration2 = stem.v_vol2 except Exception: pass try: vibration3 = stem.v_vol3 except Exception: pass try: v_from_hr1, v_from_min1 = stem.v_start1.split(':')[0], stem.v_start1.split(':')[1] except Exception: pass try: v_to_hr1, v_to_min1 = stem.v_end1.split(':')[0], stem.v_end1.split(':')[1] except Exception: pass try: v_from_hr2, v_from_min2 = stem.v_start2.split(':')[0], stem.v_start2.split(':')[1] except Exception: pass try: v_to_hr2, v_to_min2 = stem.v_end2.split(':')[0], stem.v_end2.split(':')[1] except Exception: pass try: v_from_hr3, v_from_min3 = stem.v_start3.split(':')[0], stem.v_start3.split(':')[1] except Exception: pass try: v_to_hr3, v_to_min3 = stem.v_end3.split(':')[0], stem.v_end3.split(':')[1] except Exception: pass try: v_pow = stem.v_power except Exception: pass try: tank1_duration1 = liquid.tk1_duration1 except Exception: pass try: tank1_duration2 = liquid.tk1_duration2 except Exception: pass try: tank1_duration3 = liquid.tk1_duration3 except Exception: pass try: tank2_duration1 = liquid.tk2_duration1 except Exception: pass try: tank2_duration2 = liquid.tk2_duration2 except Exception: pass try: tank2_duration3 = liquid.tk2_duration3 except Exception: pass try: tank1_from_hr1, tank1_from_min1 = liquid.tk1_start1.split(':')[0], liquid.tk1_start1.split(':')[1] tank1_to_hr1, tank1_to_min1 = liquid.tk1_end1.split(':')[0], liquid.tk1_end1.split(':')[1] except Exception: pass try: tank1_from_hr2, tank1_from_min2 = liquid.tk1_start2.split(':')[0], liquid.tk1_start2.split(':')[1] tank1_to_hr2, tank1_to_min2 = liquid.tk1_end2.split(':')[0], liquid.tk1_end2.split(':')[1] except Exception: pass try: tank1_from_hr3, tank1_from_min3 = liquid.tk1_start3.split(':')[0], liquid.tk1_start3.split(':')[1] tank1_to_hr3, tank1_to_min3 = liquid.tk1_end3.split(':')[0], liquid.tk1_end3.split(':')[1] except Exception: pass try: tank2_from_hr1, tank2_from_min1 = liquid.tk2_start1.split(':')[0], liquid.tk2_start1.split(':')[1] tank2_to_hr1, tank2_to_min1 = liquid.tk2_end1.split(':')[0], liquid.tk2_end1.split(':')[1] except Exception: pass try: tank2_from_hr2, tank2_from_min2 = liquid.tk2_start2.split(':')[0], liquid.tk2_start2.split(':')[1] tank2_to_hr2, tank2_to_min2 = liquid.tk2_end2.split(':')[0], liquid.tk2_end2.split(':')[1] except Exception: pass try: tank2_from_hr3, tank2_from_min3 = liquid.tk2_start3.split(':')[0], liquid.tk2_start3.split(':')[1] tank2_to_hr3, tank2_to_min3 = liquid.tk2_end3.split(':')[0], liquid.tk2_end3.split(':')[1] except Exception: pass try: air_temp1 = fitolab1.s_air_tem1 except Exception: pass try: air_humidity1 = fitolab1.s_humidity except Exception: pass try: ph = fitolab1.r_ph except Exception: pass try: do = fitolab1.r_do except Exception: pass try: ec = fitolab1.r_ec except Exception: pass try: water_level = fitolab1.r_water_level except Exception: pass try: tds1 = fitolab1.r_turbidity except Exception: pass try: o3 = fitolab1.s_o3 except Exception: pass try: co2 = fitolab1.s_co2 except Exception: pass try: h2 = fitolab1.s_h2 except Exception: pass try: weight1 = fitolab1.s_wgt_sensor1 except Exception: pass try: weight2 = fitolab1.s_wgt_sensor2 except Exception: pass return render_template('online_fitolab.html', params=locals()) else: stem = StemSystem.query.order_by(text('datetime desc')).first() root = RootSystem.query.order_by(text('datetime desc')).first() liquid = LiquidTank.query.order_by(text('datetime desc')).first() fitolab1 = Fitolab1Sensor.query.order_by(text('datetime desc')).first() music_num = 1 music_from_num = 1 music_to_num = 1 v_num = 1 v_from_num = 1 v_to_num = 1 tank1_num = 1 tank1_from_num = 1 tank1_to_num = 1 tank2_num = 1 tank2_from_num = 1 tank2_to_num = 1 for i in request.form: if i == 'stem-color': try: color = request.form['stem-color'] stem.l_r, stem.l_g, stem.l_b = color.split(',')[0], color.split(',')[1][1:], color.split(',')[2][1:] except Exception: pass elif i == 'root-color': try: color = request.form['root-color'] root.l_r, root.l_g, root.l_b = color.split(',')[0], color.split(',')[1][1:], color.split(',')[2][1:] except Exception: pass if 'stem-bright-on' in request.form: stem.l_bright_auto = 1 else: stem.l_bright_auto = 0 if 'root-bright-on' in request.form: root.l_bright_auto = 1 else: root.l_bright_auto = 0 if i[:5] == 'music' and len(i) <=11: if music_num == 1: stem.m_playlist1 = request.form[i] stem.m_playlist2 = None stem.m_playlist3 = None music_num += 1 elif music_num == 2: stem.m_playlist2 = request.form[i] stem.m_playlist3 = None music_num += 1 elif music_num == 3: stem.m_playlist3 = request.form[i] else: if i[:13] == 'music_from_hr': music_from_hr = request.form[i] elif i[:14] == 'music_from_min': music_from_min = request.form[i] if music_from_num == 1: stem.m_start1 = music_from_hr + ":" + music_from_min stem.m_start2 = None stem.m_start3 = None music_from_num += 1 elif music_from_num == 2: stem.m_start2 = music_from_hr + ":" + music_from_min stem.m_start3 = None music_from_num += 1 elif music_from_num == 3: stem.m_start3 = music_from_hr + ":" + music_from_min elif i[:11] == 'music_to_hr': music_to_hr = request.form[i] elif i[:12] == 'music_to_min': music_to_min = request.form[i] if music_to_num == 1: stem.m_end1 = music_to_hr + ":" + music_to_min stem.m_end2 = None stem.m_end3 = None music_to_num += 1 elif music_to_num == 2: stem.m_end2 = music_to_hr + ":" + music_to_min stem.m_end3 = None music_to_num += 1 elif music_to_num == 3: stem.m_end3 = music_to_hr + ":" + music_to_min if 'camera-on' in request.form: stem.c_status = 1 else: stem.c_status = 0 if i[:9] == 'vibration': if v_num == 1: stem.v_vol1 = request.form[i] stem.v_vol2 = None stem.v_vol3 = None v_num += 1 elif v_num == 2: stem.v_vol2 = request.form[i] stem.v_vol3 = None v_num += 1 elif v_num == 3: stem.v_vol3 = request.form[i] else: if i[:9] == 'v_from_hr': v_from_hr = request.form[i] elif i[:10] == 'v_from_min': v_from_min = request.form[i] if v_from_num == 1: stem.v_start1 = v_from_hr + ":" + v_from_min stem.v_start2 = None stem.v_start3 = None v_from_num += 1 elif v_from_num == 2: stem.v_start2 = v_from_hr + ":" + v_from_min stem.v_start3 = None v_from_num += 1 elif v_from_num == 3: stem.v_start3 = v_from_hr + ":" + v_from_min elif i[:7] == 'v_to_hr': v_to_hr = request.form[i] elif i[:8] == 'v_to_min': v_to_min = request.form[i] if v_to_num == 1: stem.v_end1 = v_to_hr + ":" + v_to_min stem.v_end2 = None stem.v_end3 = None v_to_num += 1 elif v_to_num == 2: stem.v_end2 = v_to_hr + ":" + v_to_min stem.v_end3 = None v_to_num += 1 elif v_to_num == 3: stem.v_end3 = v_to_hr + ":" + v_to_min if i[:14] == 'tank1_duration': if tank1_num == 1: liquid.tk1_duration1 = request.form[i] liquid.tk1_duration2 = None liquid.tk1_duration3 = None tank1_num += 1 elif tank1_num == 2: liquid.tk1_duration2 = request.form[i] liquid.tk1_duration3 = None tank1_num += 1 elif tank1_num == 3: liquid.tk1_duration3 = request.form[i] else: if i[:13] == 'tank1_from_hr': tk1_from_hr = request.form[i] elif i[:14] == 'tank1_from_min': tk1_from_min = request.form[i] if tank1_from_num == 1: liquid.tk1_start1 = tk1_from_hr + ":" + tk1_from_min liquid.tk1_start2 = None liquid.tk1_start3 = None tank1_from_num += 1 elif tank1_from_num == 2: liquid.tk1_start2 = tk1_from_hr + ":" + tk1_from_min liquid.tk1_start3 = None tank1_from_num += 1 elif tank1_from_num == 3: liquid.tk1_start3 = tk1_from_hr + ":" + tk1_from_min elif i[:11] == 'tank1_to_hr': tk1_to_hr = request.form[i] elif i[:12] == 'tank1_to_min': tk1_to_min = request.form[i] if tank1_to_num == 1: liquid.tk1_end1 = tk1_to_hr + ":" + tk1_to_min liquid.tk1_end2 = None liquid.tk1_end3 = None tank1_to_num += 1 elif tank1_to_num == 2: liquid.tk1_end2 = tk1_to_hr + ":" + tk1_to_min liquid.tk1_end3 = None tank1_to_num += 1 elif tank1_to_num == 3: liquid.tk1_end3 = tk1_to_hr + ":" + tk1_to_min if i[:14] == 'tank2_duration': if tank2_num == 1: liquid.tk2_duration1 = request.form[i] liquid.tk2_duration2 = None liquid.tk2_duration3 = None tank2_num += 1 elif tank2_num == 2: liquid.tk2_duration2 = request.form[i] liquid.tk2_duration3 = None tank2_num += 1 elif tank2_num == 3: liquid.tk2_duration3 = request.form[i] else: if i[:13] == 'tank2_from_hr': tk2_from_hr = request.form[i] elif i[:14] == 'tank2_from_min': tk2_from_min = request.form[i] if tank2_from_num == 1: liquid.tk2_start1 = tk2_from_hr + ":" + tk2_from_min liquid.tk2_start2 = None liquid.tk2_start3 = None tank2_from_num += 1 elif tank2_from_num == 2: liquid.tk2_start2 = tk2_from_hr + ":" + tk2_from_min liquid.tk2_start3 = None tank2_from_num += 1 elif tank2_from_num == 3: liquid.tk2_start3 = tk2_from_hr + ":" + tk2_from_min elif i[:11] == 'tank2_to_hr': tk2_to_hr = request.form[i] elif i[:12] == 'tank2_to_min': tk2_to_min = request.form[i] if tank2_to_num == 1: liquid.tk2_end1 = tk2_to_hr + ":" + tk2_to_min liquid.tk2_end2 = None liquid.tk2_end3 = None tank2_to_num += 1 elif tank2_to_num == 2: liquid.tk2_end2 = tk2_to_hr + ":" + tk2_to_min liquid.tk2_end3 = None tank2_to_num += 1 elif tank2_to_num == 3: liquid.tk2_end3 = tk2_to_hr + ":" + tk2_to_min if i == 'root-color': try: color = request.form['root-color'] root.l_r, root.l_g, root.l_b = color.split(',')[0], color.split(',')[1][1:], color.split(',')[2][1:] except Exception: pass if i == 'stem-color': try: color = request.form['stem-color'] stem.l_r, stem.l_g, stem.l_b = color.split(',')[0], color.split(',')[1][1:], color.split(',')[2][1:] except Exception: pass stem.l_bright_vol = request.form['stem-bright-vol'] root.l_bright_vol = request.form['root-bright-vol'] stem.m_vol = request.form['m-vol'] stem.c_duration = request.form['c-duration'] stem.v_power = request.form['v-pow'] db.session.add(stem) db.session.add(root) db.session.commit() return redirect('/online_fitolab') #退出的訪問路徑 @main.route('/logout') def logout_views(): if 'id' in session and 'uname' in session: del session['id'] del session['uname'] return redirect('/')