import json
if 82 - 82: Iii1i
from flask import Blueprint , render_template , request , g , redirect , url_for , flash
from sqlalchemy import or_ , and_ , text
if 87 - 87: Ii % i1i1i1111I . Oo / OooOoo * I1Ii1I1 - I1I
from forms . wgcommform import *
from exts import db
from decorators import login_required
from forms . wgcommform import Addextern_tasklistForm
from models . iccard import *
import vwAppConfig
if 81 - 81: i1 + ooOOO / oOo0O00 * i1iiIII111 * IiIIii11Ii
__all__ = [
 "bp" ,
 "web_extern_tasklist_list" ,
 "web_extern_tasklist_add" ,
 "web_extern_tasklist_del" ,
 "web_extern_tasklist_edit" ,
 "web_extern_tasklist_edit4floor" ,
 "web_extern_tasklist_add4floor"

]
bp = Blueprint ( 'wgcomm_extern_tasklist' , __name__ , url_prefix = '/' )
if 84 - 84: ooo000 - Ooo0Ooo + iI1iII1I1I1i . IIiIIiIi11I1
iI111iiIi11i = 99991001
OoOoo0o = 99991002
@ bp . route ( '/web_extern_tasklist_list' , methods = [ 'GET' , 'POST' ] )
@ login_required
def web_extern_tasklist_list ( ) :
 if 11 - 11: i1I1 - O000o / O0OO0OooooOo * ii % Ii * i1
 ii1iI1I = [ "0. Door Controlled" ,
 "1. Door Open" ,
 "2. Door Closed" ,
 "3. Disable Time Profile" ,
 "4. Enable Time Profile" ,
 "5. Card - NoPassword" ,
 "6. (In) Card + Password" ,
 "7. (In-Out) Card + Password" ,
 "8. MoreCard Disable" ,
 "9. MoreCard Enable" ,
 "10. Trigger Once" ,
 "11. PushButtons Disable" ,
 "12. PushButtons Enable" , ]
 ii1iI1I = [ "OnLine" ,
 "NormalOpen" ,
 "NormalClosed" ,
 "Disable Time Profile" ,
 "Enable Time Profile" ,
 "Card - NoPassword" ,
 "(In) Card + Password" ,
 "(In-Out) Card + Password" ,
 "MoreCard Disable" ,
 "MoreCard Enable" ,
 "Trigger Once" ,
 "PushButtons Disable" ,
 "PushButtons Enable" , ]
 i11IiIIiii1II = TBControllertasklist4floor . query . order_by ( TBControllertasklist4floor . f_Id )
 O0o000ooO = i11IiIIiii1II . all ( )
 if 94 - 94: i1 . I1I / O000o
 if 58 - 58: I1Ii1I1 - ooOOO
 oO0 = { }
 i1iiiiIIIiIi = { }
 if 22 - 22: ooo000 . iI1iII1I1I1i + Ooo0Ooo + O000o
 if 85 - 85: OooOoo - oOo0O00 / Ii / O000o % i1iiIII111 . Ii
 for I1ii1iii1i in O0o000ooO :
  if I1ii1iii1i . f_DoorID == iI111iiIi11i :
   i1iiiiIIIiIi [ I1ii1iii1i . f_Id ] = ii1iI1I [ I1ii1iii1i . f_DoorControl ]
   oO0 [ I1ii1iii1i . f_Id ] = "All Doors"
   I1i = TBDoor . query . filter ( TBDoor . f_DoorID . in_ ( I1ii1iii1i . f_FloorNames . split ( ',' ) ) ) . order_by ( TBDoor . f_DoorName ) . all ( )
   if I1i :
    oO0 [ I1ii1iii1i . f_Id ] = ", " . join ( [ door . f_DoorName for door in I1i ] )
  elif I1ii1iii1i . f_DoorID == OoOoo0o :
   i1iiiiIIIiIi [ I1ii1iii1i . f_Id ] = ii1iI1I [ I1ii1iii1i . f_DoorControl ]
   oO0 [ I1ii1iii1i . f_Id ] = "All Floors"
   I1i = TBFloor . query . filter ( TBFloor . f_FloorId . in_ ( I1ii1iii1i . f_FloorNames . split ( ',' ) ) ) . order_by ( TBFloor . f_FloorName ) . all ( )
   i11IiIIiii1II = db . session . query ( TBDoor . f_DoorID , TBDoor . f_DoorName , TBFloor . f_FloorNO , TBFloor . f_FloorName ,
 TBFloor . f_FloorId
 ) . join ( TBFloor ,
 TBFloor . f_DoorID == TBDoor . f_DoorID ,
 isouter = False ) . filter ( TBFloor . f_FloorId . in_ ( I1ii1iii1i . f_FloorNames . split ( ',' ) ) ) . order_by ( TBDoor . f_DoorName ) . order_by ( TBFloor . f_FloorNO )
   I1i = i11IiIIiii1II . all ( )
   if I1i :
    oO0 [ I1ii1iii1i . f_Id ] = ", " . join ( [ "{0}.{1}" . format ( door . f_DoorName , door . f_FloorName ) for door in I1i ] )
    if 75 - 75: ii . Ooo0Ooo . O0OO0OooooOo * i1I1 % i1iiIII111
    if 34 - 34: i1iiIII111 * i1
 O00O = {
 "objlist" : O0o000ooO ,
 "dict_col_controlmoddesc" : i1iiiiIIIiIi ,
 "dict_col_floornames" : oO0 ,
 "deleteUrl" : "/extern_tasklist_del" ,
 "editSeg" : "/extern_tasklist_edit"
 }
 return render_template ( "wgcomm/extern-tasklist-list.html" , ** O00O )
 if 59 - 59: Iii1i . ii - O0OO0OooooOo
 if 13 - 13: O000o
@ bp . route ( '/extern_tasklist_add' , methods = [ 'GET' , 'POST' ] )
@ login_required
def web_extern_tasklist_add ( ) :
 IIii = "wgcomm/extern-tasklist-add.html"
 OO00 = "wgcomm_extern_tasklist.web_extern_tasklist_list"
 ii1iI1I = [ "0. Door Controlled" ,
 "1. Door Open" ,
 "2. Door Closed" ,
 "3. Disable Time Profile" ,
 "4. Enable Time Profile" ,
 "5. Card - NoPassword" ,
 "6. (In) Card + Password" ,
 "7. (In-Out) Card + Password" ,
 "8. MoreCard Disable" ,
 "9. MoreCard Enable" ,
 "10. Trigger Once" ,
 "11. PushButtons Disable" ,
 "12. PushButtons Enable" , ]
 if 39 - 39: i1I1 * O000o . Oo + ooOOO / Oo
 iI1i1I = TBController . query . all ( )
 iI1i1I = [ x . f_ControllerID for x in iI1i1I if not ( x . f_ControllerSN > 170000000 and x . f_ControllerSN < 180000000 ) ]
 if 27 - 27: ooOOO * IIiIIiIi11I1 % Ii + Ooo0Ooo . Ii + Iii1i
 I1i = TBDoor . query . filter_by ( f_DoorEnabled = True ) . filter ( TBDoor . f_ControllerID . in_ ( iI1i1I ) ) . order_by ( TBDoor . f_DoorName ) . all ( )
 if request . method == 'GET' :
  oOo0O00O0ooo = Addextern_tasklistForm ( )
  oOo0O00O0ooo . f_Id . data = 1
  i11iIii = TBControllertasklist4floor . query . order_by ( TBControllertasklist4floor . f_Id ) . all ( )
  if 40 - 40: IiIIii11Ii . i1 / Oo
  O0ooooOoo0O = 1
  if i11iIii :
   if 53 - 53: i1 * I1Ii1I1 + Oo * Ii - i1 - I1I
   for Oooo0o in i11iIii :
    if Oooo0o . f_Id >= O0ooooOoo0O :
     O0ooooOoo0O = Oooo0o . f_Id + 1
  oOo0O00O0ooo . f_Id . data = O0ooooOoo0O
  if 52 - 52: i1i1i1111I + IiIIii11Ii + i1I1
  return render_template ( IIii , wgform = oOo0O00O0ooo , controlmod = ii1iI1I , doors = I1i )
 else :
  oOo0O00O0ooo = Addextern_tasklistForm ( request . form )
  if oOo0O00O0ooo . submitcancel . data :
   return redirect ( url_for ( OO00 ) )
  if oOo0O00O0ooo . validate ( ) :
   OooOoo0OO0OO0 = oOo0O00O0ooo . f_Id . data
   IiIi1Ii1111 = oOo0O00O0ooo . f_Notes . data
   if 95 - 95: I1I * Ooo0Ooo + i1iiIII111 . i1iiIII111 % Oo * oOo0O00
   if 65 - 65: Ooo0Ooo * ooo000 + oOo0O00
   i1I11i11 = oOo0O00O0ooo . f_Monday . data
   OoOOoO000O = oOo0O00O0ooo . f_Tuesday . data
   O0o0O0o0o = oOo0O00O0ooo . f_Wednesday . data
   Oo0 = oOo0O00O0ooo . f_Thursday . data
   ooooo = oOo0O00O0ooo . f_Friday . data
   oO00o00OO = oOo0O00O0ooo . f_Saturday . data
   o00o = oOo0O00O0ooo . f_Sunday . data
   Ii11I = oOo0O00O0ooo . f_BeginYMD . data
   iIi = oOo0O00O0ooo . f_EndYMD . data
   if 60 - 60: O000o % i1iiIII111 % ii - i1I1 * O000o - iI1iII1I1I1i
   IIi1I1I1i = vwAppConfig . getDateTimeFromStr (
 "{} {}" . format ( oOo0O00O0ooo . f_BeginYMD . data , oOo0O00O0ooo . f_OperateTime . data ) )
   O0O = oOo0O00O0ooo . f_DoorControl . data
   II1iiii = iI111iiIi11i
   Ii11I = vwAppConfig . getDateTimeFromStr ( Ii11I )
   iIi = vwAppConfig . getDateTimeFromStr ( iIi )
   oooOOO0OOooOO = request . form
   IiIIII111 = "0"
   if "f_Door_All" in oooOOO0OOooOO :
    IiIIII111 = "0"
   else :
    IIIIi = [ ]
    for Oooo0o in oooOOO0OOooOO :
     if "f_Door_" in Oooo0o :
      IIIIi . append ( request . form . get ( Oooo0o ) )
    if len ( IIIIi ) > 0 :
     IiIIII111 = "," . join ( IIIIi )
     if 50 - 50: ooo000 * I1Ii1I1 * iI1iII1I1I1i
     if 17 - 17: Iii1i % O0OO0OooooOo - Iii1i % Ooo0Ooo . OooOoo
   oO = TBControllertasklist4floor . query . filter_by ( f_Id = OooOoo0OO0OO0 ) . first ( )
   if oO :
    flash ( "Task number duplicated" )
    return render_template ( IIii , wgform = oOo0O00O0ooo , controlmod = ii1iI1I , doors = I1i )
    if 49 - 49: iI1iII1I1I1i / i1iiIII111 + ooo000
    if 36 - 36: i1i1i1111I + Iii1i - O000o * Ii
    if 45 - 45: i1i1i1111I * Ii
    if 97 - 97: i1
    if 26 - 26: ii
    if 20 - 20: IIiIIiIi11I1 / Oo
    if 73 - 73: ooOOO - IiIIii11Ii
    if 22 - 22: Oo % oOo0O00 / O0OO0OooooOo . oOo0O00 . O0OO0OooooOo
   Ooo000oo0O00o = TBControllertasklist4floor ( f_Id = OooOoo0OO0OO0 , f_Notes = IiIi1Ii1111 ,
 f_Monday = i1I11i11 ,
 f_Tuesday = OoOOoO000O ,
 f_Wednesday = O0o0O0o0o ,
 f_Thursday = Oo0 ,
 f_Friday = ooooo ,
 f_Saturday = oO00o00OO ,
 f_Sunday = o00o ,
 f_BeginYMD = Ii11I ,
 f_EndYMD = iIi ,
 f_OperateTime = IIi1I1I1i ,
 f_FloorNames = IiIIII111 ,
 f_DoorControl = O0O ,
 f_DoorID = II1iiii ,

   # IiIIii11Ii . Ooo0Ooo % IiIIii11Ii * i1I1 . i1iiIII111
   # Ooo0Ooo
   )
   try :
    db . session . add ( Ooo000oo0O00o )
    db . session . commit ( )
    flash ( "Added successfully! Takes effect after uploading settings" )
    vwAppConfig . vwlog ( '{}--{}' . format ( g . user . f_OperatorName ,
 "Task {} added successfully!" . format (
 OooOoo0OO0OO0 ) ) )
    return redirect ( url_for ( OO00 ) )
   except Exception as oO0O0oOo :
    print ( oO0O0oOo )
    if 94 - 94: ooOOO * O000o % iI1iII1I1I1i - O0OO0OooooOo - ooOOO
    db . session . rollback ( )
    flash ( " Add Failed ！" )
    vwAppConfig . vwlog ( '{}--{}[{}]' . format ( g . user . f_OperatorName ,
 "Task {} failed to add!" . format ( OooOoo0OO0OO0 ) ,
 oO0O0oOo ) )
    return render_template ( IIii , wgform = oOo0O00O0ooo , controlmod = ii1iI1I , doors = I1i )
  else :
   for oOO in oOo0O00O0ooo . messages :
    flash ( oOO )
   return render_template ( IIii , wgform = oOo0O00O0ooo , controlmod = ii1iI1I , doors = I1i )
   if 32 - 32: ii % ooo000 * Iii1i + IIiIIiIi11I1
@ bp . route ( '/extern_tasklist_add4floor' , methods = [ 'GET' , 'POST' ] )
@ login_required
def web_extern_tasklist_add4floor ( ) :
 IIii = "wgcomm/extern-tasklist-add4floor.html"
 OO00 = "wgcomm_extern_tasklist.web_extern_tasklist_list"
 ii1iI1I = [ "0. Door Controlled" ,
 "1. Door Open" ,
 "2. Door Closed" ,

 # IIiIIiIi11I1 / IiIIii11Ii / ooOOO
 # ii + ooOOO * O000o
 # i1I1
 # i1 . Ooo0Ooo
 # i1 % IIiIIiIi11I1 * IIiIIiIi11I1 * iI1iII1I1I1i
 # i1i1i1111I
 # ooo000 / i1 * oOo0O00
 # IiIIii11Ii % O000o - IiIIii11Ii % O000o - IiIIii11Ii + iI1iII1I1I1i
 # ooOOO + Oo / I1I
 ]
 if 41 - 41: O000o
 i11IiIIiii1II = db . session . query ( TBDoor . f_DoorID , TBDoor . f_DoorName , TBFloor . f_FloorNO , TBFloor . f_FloorName , TBFloor . f_FloorId
 ) . join ( TBFloor ,
 TBFloor . f_DoorID == TBDoor . f_DoorID ,
 isouter = False ) . order_by ( TBDoor . f_DoorName ) . order_by ( TBFloor . f_FloorNO )
 I1i = i11IiIIiii1II . all ( )
 if 98 - 98: I1I / IIiIIiIi11I1 / O0OO0OooooOo + ii % Oo + I1I
 if request . method == 'GET' :
  oOo0O00O0ooo = Addextern_tasklistForm ( )
  oOo0O00O0ooo . f_Id . data = 1
  i11iIii = TBControllertasklist4floor . query . order_by ( TBControllertasklist4floor . f_Id ) . all ( )
  if 38 - 38: I1Ii1I1 + oOo0O00
  O0ooooOoo0O = 1
  if i11iIii :
   if 2 - 2: OooOoo % Ii + O000o . OooOoo + IIiIIiIi11I1 * Oo
   for Oooo0o in i11iIii :
    if Oooo0o . f_Id >= O0ooooOoo0O :
     O0ooooOoo0O = Oooo0o . f_Id + 1
  oOo0O00O0ooo . f_Id . data = O0ooooOoo0O
  if 2 - 2: IIiIIiIi11I1 + iI1iII1I1I1i - I1Ii1I1 + ooOOO . IIiIIiIi11I1
  return render_template ( IIii , wgform = oOo0O00O0ooo , controlmod = ii1iI1I , doors = I1i )
 else :
  oOo0O00O0ooo = Addextern_tasklistForm ( request . form )
  if oOo0O00O0ooo . submitcancel . data :
   return redirect ( url_for ( OO00 ) )
  if oOo0O00O0ooo . validate ( ) :
   OooOoo0OO0OO0 = oOo0O00O0ooo . f_Id . data
   IiIi1Ii1111 = oOo0O00O0ooo . f_Notes . data
   if 15 - 15: ooo000
   if 63 - 63: O0OO0OooooOo
   i1I11i11 = oOo0O00O0ooo . f_Monday . data
   OoOOoO000O = oOo0O00O0ooo . f_Tuesday . data
   O0o0O0o0o = oOo0O00O0ooo . f_Wednesday . data
   Oo0 = oOo0O00O0ooo . f_Thursday . data
   ooooo = oOo0O00O0ooo . f_Friday . data
   oO00o00OO = oOo0O00O0ooo . f_Saturday . data
   o00o = oOo0O00O0ooo . f_Sunday . data
   Ii11I = oOo0O00O0ooo . f_BeginYMD . data
   iIi = oOo0O00O0ooo . f_EndYMD . data
   if 81 - 81: OooOoo . O0OO0OooooOo / i1i1i1111I + Oo / Ooo0Ooo % ii
   IIi1I1I1i = vwAppConfig . getDateTimeFromStr (
 "{} {}" . format ( oOo0O00O0ooo . f_BeginYMD . data , oOo0O00O0ooo . f_OperateTime . data ) )
   O0O = oOo0O00O0ooo . f_DoorControl . data
   II1iiii = OoOoo0o
   Ii11I = vwAppConfig . getDateTimeFromStr ( Ii11I )
   iIi = vwAppConfig . getDateTimeFromStr ( iIi )
   oooOOO0OOooOO = request . form
   IiIIII111 = "0"
   if "f_Door_All" in oooOOO0OOooOO :
    IiIIII111 = "0"
   else :
    IIIIi = [ ]
    for Oooo0o in oooOOO0OOooOO :
     if "f_Door_" in Oooo0o :
      IIIIi . append ( request . form . get ( Oooo0o ) )
    if len ( IIIIi ) > 0 :
     IiIIII111 = "," . join ( IIIIi )
     if 77 - 77: i1I1 / iI1iII1I1I1i - oOo0O00 - Ooo0Ooo % oOo0O00
     if 73 - 73: ii . Oo * I1I / i1i1i1111I + I1Ii1I1
   oO = TBControllertasklist4floor . query . filter_by ( f_Id = OooOoo0OO0OO0 ) . first ( )
   if oO :
    flash ( "Task number duplicated" )
    return render_template ( IIii , wgform = oOo0O00O0ooo , controlmod = ii1iI1I , doors = I1i )
    if 31 - 31: i1i1i1111I % I1Ii1I1
    if 1 - 1: ii - oOo0O00 - i1 . oOo0O00
    if 91 - 91: iI1iII1I1I1i * i1 . ooOOO
    if 81 - 81: I1I * Oo - i1 % OooOoo * ooOOO
    if 19 - 19: Ii
    if 22 - 22: O0OO0OooooOo % iI1iII1I1I1i + Oo
    if 60 - 60: ooo000 + i1I1 + IIiIIiIi11I1 % i1i1i1111I - Ii % Ooo0Ooo
    if 95 - 95: ooOOO % i1i1i1111I . i1
   Ooo000oo0O00o = TBControllertasklist4floor ( f_Id = OooOoo0OO0OO0 , f_Notes = IiIi1Ii1111 ,
 f_Monday = i1I11i11 ,
 f_Tuesday = OoOOoO000O ,
 f_Wednesday = O0o0O0o0o ,
 f_Thursday = Oo0 ,
 f_Friday = ooooo ,
 f_Saturday = oO00o00OO ,
 f_Sunday = o00o ,
 f_BeginYMD = Ii11I ,
 f_EndYMD = iIi ,
 f_OperateTime = IIi1I1I1i ,
 f_FloorNames = IiIIII111 ,
 f_DoorControl = O0O ,
 f_DoorID = II1iiii ,

   # O0OO0OooooOo % ooOOO . Ii % IIiIIiIi11I1 / iI1iII1I1I1i % ooOOO
   # Ooo0Ooo % IIiIIiIi11I1
   )
   try :
    db . session . add ( Ooo000oo0O00o )
    db . session . commit ( )
    flash ( "Added successfully! Takes effect after uploading settings" )
    vwAppConfig . vwlog ( '{}--{}' . format ( g . user . f_OperatorName ,
 "Task {} added successfully!" . format (
 OooOoo0OO0OO0 ) ) )
    return redirect ( url_for ( OO00 ) )
   except Exception as oO0O0oOo :
    print ( oO0O0oOo )
    if 12 - 12: Ooo0Ooo + i1iiIII111 + Oo * I1Ii1I1
    db . session . rollback ( )
    flash ( " Add Failed ！" )
    vwAppConfig . vwlog ( '{}--{}[{}]' . format ( g . user . f_OperatorName ,
 "Task {} failed to add!" . format ( OooOoo0OO0OO0 ) ,
 oO0O0oOo ) )
    return render_template ( IIii , wgform = oOo0O00O0ooo , controlmod = ii1iI1I , doors = I1i )
  else :
   for oOO in oOo0O00O0ooo . messages :
    flash ( oOO )
   return render_template ( IIii , wgform = oOo0O00O0ooo , controlmod = ii1iI1I , doors = I1i )
   if 43 - 43: IIiIIiIi11I1 * ooo000 + Ii % iI1iII1I1I1i
@ bp . route ( '/extern_tasklist_del' , methods = [ 'POST' ] )
@ login_required
def web_extern_tasklist_del ( ) :
 OooOoo0OO0OO0 = request . form . get ( "primaryID" )
 OO00 = "wgcomm_extern_tasklist.web_extern_tasklist_list"
 if OooOoo0OO0OO0 :
  try :
   TBControllertasklist4floor . query . filter_by ( f_Id = OooOoo0OO0OO0 ) . delete ( )
   db . session . commit ( )
   flash ( "Deleted successfully! Takes effect after uploading settings" )
   vwAppConfig . vwlog ( '{}--{}' . format ( g . user . f_OperatorName ,
 "Task {} deleted successfully!" . format ( OooOoo0OO0OO0 ) ) )
  except Exception as oO0O0oOo :
   vwAppConfig . vwlog ( '{}--{}[{}]' . format ( g . user . f_OperatorName ,
 "Task {} failed to delete!" . format ( OooOoo0OO0OO0 ) ,
 oO0O0oOo ) )
 return redirect ( url_for ( OO00 ) )
 if 12 - 12: i1iiIII111 + ooo000 . i1I1
 if 1 - 1: iI1iII1I1I1i % Ii - i1I1 / ii + iI1iII1I1I1i - Ii
@ bp . route ( '/extern_tasklist_edit' , methods = [ 'POST' ] )
@ login_required
def web_extern_tasklist_edit ( ) :
 II1iiii = request . form . get ( "f_DoorID" )
 if II1iiii is not None and int ( II1iiii ) == OoOoo0o :
  return web_extern_tasklist_edit4floor ( )
  if 27 - 27: OooOoo % iI1iII1I1I1i + IIiIIiIi11I1
 IIii = "wgcomm/extern-tasklist-edit.html"
 OO00 = "wgcomm_extern_tasklist.web_extern_tasklist_list"
 if request . form . get ( "submitcancel" ) is not None :
  return redirect ( url_for ( OO00 ) )
 ii1iI1I = [ "0. Door Controlled" ,
 "1. Door Open" ,
 "2. Door Closed" ,
 "3. Disable Time Profile" ,
 "4. Enable Time Profile" ,
 "5. Card - NoPassword" ,
 "6. (In) Card + Password" ,
 "7. (In-Out) Card + Password" ,
 "8. MoreCard Disable" ,
 "9. MoreCard Enable" ,
 "10. Trigger Once" ,
 "11. PushButtons Disable" ,
 "12. PushButtons Enable" , ]
 iI1i1I = TBController . query . all ( )
 iI1i1I = [ x . f_ControllerID for x in iI1i1I if not ( x . f_ControllerSN > 170000000 and x . f_ControllerSN < 180000000 ) ]
 if 16 - 16: ii
 I1i = TBDoor . query . filter_by ( f_DoorEnabled = True ) . filter ( TBDoor . f_ControllerID . in_ ( iI1i1I ) ) . order_by ( TBDoor . f_DoorName ) . all ( )
 OooOoo0OO0OO0 = request . form . get ( "f_Id" )
 if OooOoo0OO0OO0 is not None and int ( OooOoo0OO0OO0 ) > 0 and request . form . get ( "submitsave" ) is None :
  if 31 - 31: oOo0O00 / Iii1i % Ooo0Ooo % i1 . iI1iII1I1I1i . Oo
  oOo0O00O0ooo = Addextern_tasklistForm ( )
  oOo0O00O0ooo . f_Id . data = OooOoo0OO0OO0
  oO = TBControllertasklist4floor . query . filter_by ( f_Id = OooOoo0OO0OO0 ) . first ( )
  if oO :
   if 83 - 83: oOo0O00 - i1I1
   oOo0O00O0ooo . f_Id . data = oO . f_Id
   oOo0O00O0ooo . f_Notes . data = oO . f_Notes
   if 91 - 91: IIiIIiIi11I1 - i1 - iI1iII1I1I1i
   oOo0O00O0ooo . f_Monday . data = oO . f_Monday
   oOo0O00O0ooo . f_Tuesday . data = oO . f_Tuesday
   oOo0O00O0ooo . f_Wednesday . data = oO . f_Wednesday
   oOo0O00O0ooo . f_Thursday . data = oO . f_Thursday
   oOo0O00O0ooo . f_Friday . data = oO . f_Friday
   oOo0O00O0ooo . f_Saturday . data = oO . f_Saturday
   oOo0O00O0ooo . f_Sunday . data = oO . f_Sunday
   oOo0O00O0ooo . f_BeginYMD . data = vwAppConfig . getStrOfDatetimeYMD ( oO . f_BeginYMD )
   oOo0O00O0ooo . f_EndYMD . data = vwAppConfig . getStrOfDatetimeYMD ( oO . f_EndYMD )
   oOo0O00O0ooo . f_OperateTime . data = vwAppConfig . getStrOfDatetimeHHMM ( oO . f_OperateTime )
   oOo0O00O0ooo . f_DoorControl . data = oO . f_DoorControl
   oOo0O00O0ooo . f_FloorNames . data = oO . f_FloorNames
   if 71 - 71: I1I - ii
   if 66 - 66: i1i1i1111I / Ooo0Ooo + i1I1 + Iii1i + oOo0O00 + O0OO0OooooOo
   if 75 - 75: OooOoo - O000o - IiIIii11Ii - O000o + ooo000 % iI1iII1I1I1i
   if 42 - 42: i1 * O0OO0OooooOo
   if 50 - 50: Ii - i1iiIII111
   if 96 - 96: ooo000 * OooOoo - Ii - OooOoo
   if 65 - 65: Oo + Oo - iI1iII1I1I1i % OooOoo . Ooo0Ooo
   if 84 - 84: IIiIIiIi11I1 . ooOOO
   if 44 - 44: ooo000 * i1i1i1111I * O000o + i1iiIII111 - IIiIIiIi11I1
   if 70 - 70: ii
   if 9 - 9: oOo0O00 * i1
   if 96 - 96: Ooo0Ooo
   if 13 - 13: Oo * I1Ii1I1 - oOo0O00 * Ii . Ii + oOo0O00
   if 46 - 46: OooOoo - i1I1 / Ooo0Ooo
   if 73 - 73: I1Ii1I1 / i1i1i1111I / ooo000 % i1 % O0OO0OooooOo - OooOoo
   if 30 - 30: ooOOO * ooOOO - Iii1i * iI1iII1I1I1i
   if 37 - 37: I1Ii1I1 % iI1iII1I1I1i . O0OO0OooooOo + Ooo0Ooo + ooOOO * iI1iII1I1I1i
   if 39 - 39: IIiIIiIi11I1 - Oo
   if 31 - 31: IiIIii11Ii % oOo0O00 % oOo0O00 * Iii1i
   if 85 - 85: Iii1i + Ii % IIiIIiIi11I1 % oOo0O00
   if 100 - 100: IiIIii11Ii % i1
   if 82 - 82: ooOOO % OooOoo
   if 81 - 81: Ii
   if 40 - 40: O0OO0OooooOo . OooOoo + oOo0O00 . i1iiIII111
   if 96 - 96: I1I / O000o / i1I1 + i1I1
   if 35 - 35: IIiIIiIi11I1 + oOo0O00
   if 96 - 96: iI1iII1I1I1i . OooOoo . i1
   if 87 - 87: ooo000 * IiIIii11Ii % ooo000 . ooOOO . Oo % iI1iII1I1I1i
   if 48 - 48: ooOOO * ooo000 % IiIIii11Ii * i1 . Iii1i - ii
   if 72 - 72: i1 % i1i1i1111I * iI1iII1I1I1i
   if 90 - 90: Ooo0Ooo * OooOoo . Ii
   if 5 - 5: Oo - i1 . O000o
   if 18 - 18: IiIIii11Ii - O000o * O0OO0OooooOo - OooOoo
   if 54 - 54: IIiIIiIi11I1 . Ooo0Ooo % Ii + IiIIii11Ii * iI1iII1I1I1i / iI1iII1I1I1i
   if 31 - 31: IiIIii11Ii . IiIIii11Ii % Ii
   if 51 - 51: Oo / i1i1i1111I - I1I
   if 83 - 83: Iii1i % i1iiIII111 . OooOoo / I1I % O000o . I1I
   if 76 - 76: i1iiIII111 / OooOoo
   if 77 - 77: ooOOO
   if 19 - 19: ooOOO % I1Ii1I1
   if 15 - 15: OooOoo . IiIIii11Ii . O0OO0OooooOo / Iii1i + ooOOO / Ii
   if 17 - 17: i1I1 - i1i1i1111I . iI1iII1I1I1i - i1I1 + Oo % iI1iII1I1I1i
  return render_template ( IIii , wgform = oOo0O00O0ooo , controlmod = ii1iI1I , doors = I1i )
 else :
  oOo0O00O0ooo = Addextern_tasklistForm ( request . form )
  if oOo0O00O0ooo . submitcancel . data :
   return redirect ( url_for ( OO00 ) )
  if oOo0O00O0ooo . validate ( ) :
   OooOoo0OO0OO0 = oOo0O00O0ooo . f_Id . data
   IiIi1Ii1111 = oOo0O00O0ooo . f_Notes . data
   if 65 - 65: Ii % i1I1
   if 39 - 39: Iii1i * IIiIIiIi11I1 . Ooo0Ooo - Oo
   i1I11i11 = oOo0O00O0ooo . f_Monday . data
   OoOOoO000O = oOo0O00O0ooo . f_Tuesday . data
   O0o0O0o0o = oOo0O00O0ooo . f_Wednesday . data
   Oo0 = oOo0O00O0ooo . f_Thursday . data
   ooooo = oOo0O00O0ooo . f_Friday . data
   oO00o00OO = oOo0O00O0ooo . f_Saturday . data
   o00o = oOo0O00O0ooo . f_Sunday . data
   Ii11I = oOo0O00O0ooo . f_BeginYMD . data
   iIi = oOo0O00O0ooo . f_EndYMD . data
   if 63 - 63: i1i1i1111I - i1iiIII111 . OooOoo % OooOoo . ii + O0OO0OooooOo
   IIi1I1I1i = vwAppConfig . getDateTimeFromStr (
 "{} {}" . format ( oOo0O00O0ooo . f_BeginYMD . data , oOo0O00O0ooo . f_OperateTime . data ) )
   O0O = oOo0O00O0ooo . f_DoorControl . data
   II1iiii = iI111iiIi11i
   if 71 - 71: ooo000 + i1I1 % iI1iII1I1I1i + ii % Oo - Oo
   if 84 - 84: I1I % iI1iII1I1I1i - Ooo0Ooo / iI1iII1I1I1i + Ooo0Ooo - Oo
   if 41 - 41: ooOOO + OooOoo + IIiIIiIi11I1 * i1i1i1111I
   if 12 - 12: i1i1i1111I
   if 56 - 56: IiIIii11Ii
   if 17 - 17: O0OO0OooooOo . O000o % Oo + IiIIii11Ii - Ooo0Ooo
   if 93 - 93: oOo0O00
   if 77 - 77: Oo + i1I1 % I1I
   if 20 - 20: i1 - IiIIii11Ii . IiIIii11Ii % ooOOO . i1 % Ooo0Ooo
   if 72 - 72: O000o % ii . ooOOO * I1Ii1I1 . ooOOO
   if 90 - 90: IiIIii11Ii + I1Ii1I1 . OooOoo
   if 73 - 73: i1i1i1111I - Iii1i / i1I1 . ooo000 / iI1iII1I1I1i - i1iiIII111
   Ii11I = vwAppConfig . getDateTimeFromStr ( Ii11I )
   iIi = vwAppConfig . getDateTimeFromStr ( iIi )
   oooOOO0OOooOO = request . form
   IiIIII111 = "0"
   if "f_Door_All" in oooOOO0OOooOO :
    IiIIII111 = "0"
   else :
    IIIIi = [ ]
    for Oooo0o in oooOOO0OOooOO :
     if "f_Door_" in Oooo0o :
      IIIIi . append ( request . form . get ( Oooo0o ) )
    if len ( IIIIi ) > 0 :
     IiIIII111 = "," . join ( IIIIi )
     if 21 - 21: i1iiIII111 + ii % i1i1i1111I
   oO = TBControllertasklist4floor . query . filter_by ( f_Id = OooOoo0OO0OO0 ) . first ( )
   if oO :
    TBControllertasklist4floor . query . filter_by ( f_Id = OooOoo0OO0OO0 ) . delete ( )
    db . session . commit ( )
    if 7 - 7: ii / Ii
    if 87 - 87: ooOOO
    if 57 - 57: IIiIIiIi11I1 - iI1iII1I1I1i % ooOOO - i1I1 / IiIIii11Ii . Ooo0Ooo
   Ooo000oo0O00o = TBControllertasklist4floor ( f_Id = OooOoo0OO0OO0 , f_Notes = IiIi1Ii1111 ,
 f_Monday = i1I11i11 ,
 f_Tuesday = OoOOoO000O ,
 f_Wednesday = O0o0O0o0o ,
 f_Thursday = Oo0 ,
 f_Friday = ooooo ,
 f_Saturday = oO00o00OO ,
 f_Sunday = o00o ,
 f_BeginYMD = Ii11I ,
 f_EndYMD = iIi ,
 f_OperateTime = IIi1I1I1i ,
 f_FloorNames = IiIIII111 ,
 f_DoorControl = O0O ,
 f_DoorID = II1iiii ,

   # oOo0O00
   # O0OO0OooooOo * i1I1 - oOo0O00 * i1 . ii - Ii
   )
   try :
    db . session . add ( Ooo000oo0O00o )
    db . session . commit ( )
    flash ( "Modified successfully! Takes effect after uploading settings." )
    vwAppConfig . vwlog ( '{}--{}' . format ( g . user . f_OperatorName ,
 "Task {} modified successfully!" . format (
 OooOoo0OO0OO0 ) ) )
    return redirect ( url_for ( OO00 ) )
   except Exception as oO0O0oOo :
    print ( oO0O0oOo )
    if 1 - 1: I1I + OooOoo
    db . session . rollback ( )
    flash ( " Edit Failed ！" )
    vwAppConfig . vwlog ( '{}--{}[{}]' . format ( g . user . f_OperatorName ,
 "Task {} failed to modify!" . format ( OooOoo0OO0OO0 ) ,
 oO0O0oOo ) )
    return render_template ( IIii , wgform = oOo0O00O0ooo , controlmod = ii1iI1I , doors = I1i )
  else :
   for oOO in oOo0O00O0ooo . messages :
    flash ( oOO )
   return render_template ( IIii , wgform = oOo0O00O0ooo , controlmod = ii1iI1I , doors = I1i )
   if 98 - 98: i1iiIII111 + Iii1i . IIiIIiIi11I1
   if 96 - 96: OooOoo / O000o - i1 * i1I1
@ bp . route ( '/extern_tasklist_edit4floor' , methods = [ 'POST' ] )
@ login_required
def web_extern_tasklist_edit4floor ( ) :
 IIii = "wgcomm/extern-tasklist-edit4floor.html"
 OO00 = "wgcomm_extern_tasklist.web_extern_tasklist_list"
 if request . form . get ( "submitcancel" ) is not None :
  return redirect ( url_for ( OO00 ) )
 ii1iI1I = [ "0. Door Controlled" ,
 "1. Door Open" ,
 "2. Door Closed" ,

 # IiIIii11Ii * ooo000 . Ii * Iii1i - iI1iII1I1I1i
 # i1iiIII111
 # O0OO0OooooOo - Ooo0Ooo - Oo + Iii1i - i1iiIII111
 # iI1iII1I1I1i % IiIIii11Ii
 # Ooo0Ooo
 # i1
 # ooo000 % i1i1i1111I % oOo0O00 - i1iiIII111
 # I1Ii1I1 + i1i1i1111I
 # Oo * i1I1 % IiIIii11Ii / OooOoo + i1
 ]
 if 14 - 14: I1I + I1Ii1I1
 i11IiIIiii1II = db . session . query ( TBDoor . f_DoorID , TBDoor . f_DoorName , TBFloor . f_FloorNO , TBFloor . f_FloorName , TBFloor . f_FloorId
 ) . join ( TBFloor ,
 TBFloor . f_DoorID == TBDoor . f_DoorID ,
 isouter = False ) . order_by ( TBDoor . f_DoorName ) . order_by ( TBFloor . f_FloorNO )
 I1i = i11IiIIiii1II . all ( )
 OooOoo0OO0OO0 = request . form . get ( "f_Id" )
 if OooOoo0OO0OO0 is not None and int ( OooOoo0OO0OO0 ) > 0 and request . form . get ( "submitsave" ) is None :
  if 78 - 78: i1i1i1111I * I1Ii1I1
  oOo0O00O0ooo = Addextern_tasklistForm ( )
  oOo0O00O0ooo . f_Id . data = OooOoo0OO0OO0
  oO = TBControllertasklist4floor . query . filter_by ( f_Id = OooOoo0OO0OO0 ) . first ( )
  if oO :
   if 99 - 99: iI1iII1I1I1i - O0OO0OooooOo % O0OO0OooooOo - ii * i1iiIII111 + OooOoo
   oOo0O00O0ooo . f_Id . data = oO . f_Id
   oOo0O00O0ooo . f_Notes . data = oO . f_Notes
   if 57 - 57: IIiIIiIi11I1
   oOo0O00O0ooo . f_Monday . data = oO . f_Monday
   oOo0O00O0ooo . f_Tuesday . data = oO . f_Tuesday
   oOo0O00O0ooo . f_Wednesday . data = oO . f_Wednesday
   oOo0O00O0ooo . f_Thursday . data = oO . f_Thursday
   oOo0O00O0ooo . f_Friday . data = oO . f_Friday
   oOo0O00O0ooo . f_Saturday . data = oO . f_Saturday
   oOo0O00O0ooo . f_Sunday . data = oO . f_Sunday
   oOo0O00O0ooo . f_BeginYMD . data = vwAppConfig . getStrOfDatetimeYMD ( oO . f_BeginYMD )
   oOo0O00O0ooo . f_EndYMD . data = vwAppConfig . getStrOfDatetimeYMD ( oO . f_EndYMD )
   oOo0O00O0ooo . f_OperateTime . data = vwAppConfig . getStrOfDatetimeHHMM ( oO . f_OperateTime )
   oOo0O00O0ooo . f_DoorControl . data = oO . f_DoorControl
   oOo0O00O0ooo . f_FloorNames . data = oO . f_FloorNames
   if 57 - 57: ooOOO + Ii % i1I1 + oOo0O00 . iI1iII1I1I1i - Ii
   if 8 - 8: i1i1i1111I + i1i1i1111I * ii
  return render_template ( IIii , wgform = oOo0O00O0ooo , controlmod = ii1iI1I , doors = I1i )
 else :
  oOo0O00O0ooo = Addextern_tasklistForm ( request . form )
  if oOo0O00O0ooo . submitcancel . data :
   return redirect ( url_for ( OO00 ) )
  if oOo0O00O0ooo . validate ( ) :
   OooOoo0OO0OO0 = oOo0O00O0ooo . f_Id . data
   IiIi1Ii1111 = oOo0O00O0ooo . f_Notes . data
   if 77 - 77: iI1iII1I1I1i - O000o % Ii * O0OO0OooooOo - I1I
   if 42 - 42: i1I1 - Ii / Oo - i1i1i1111I + i1I1
   i1I11i11 = oOo0O00O0ooo . f_Monday . data
   OoOOoO000O = oOo0O00O0ooo . f_Tuesday . data
   O0o0O0o0o = oOo0O00O0ooo . f_Wednesday . data
   Oo0 = oOo0O00O0ooo . f_Thursday . data
   ooooo = oOo0O00O0ooo . f_Friday . data
   oO00o00OO = oOo0O00O0ooo . f_Saturday . data
   o00o = oOo0O00O0ooo . f_Sunday . data
   Ii11I = oOo0O00O0ooo . f_BeginYMD . data
   iIi = oOo0O00O0ooo . f_EndYMD . data
   if 83 - 83: i1 . iI1iII1I1I1i
   IIi1I1I1i = vwAppConfig . getDateTimeFromStr (
 "{} {}" . format ( oOo0O00O0ooo . f_BeginYMD . data , oOo0O00O0ooo . f_OperateTime . data ) )
   O0O = oOo0O00O0ooo . f_DoorControl . data
   II1iiii = OoOoo0o
   if 57 - 57: ii % IiIIii11Ii / oOo0O00 + Ooo0Ooo - i1iiIII111
   Ii11I = vwAppConfig . getDateTimeFromStr ( Ii11I )
   iIi = vwAppConfig . getDateTimeFromStr ( iIi )
   oooOOO0OOooOO = request . form
   IiIIII111 = "0"
   if "f_Door_All" in oooOOO0OOooOO :
    IiIIII111 = "0"
   else :
    IIIIi = [ ]
    for Oooo0o in oooOOO0OOooOO :
     if "f_Door_" in Oooo0o :
      IIIIi . append ( request . form . get ( Oooo0o ) )
    if len ( IIIIi ) > 0 :
     IiIIII111 = "," . join ( IIIIi )
     if 87 - 87: i1iiIII111 . i1iiIII111 . O000o . ooo000 * oOo0O00
   oO = TBControllertasklist4floor . query . filter_by ( f_Id = OooOoo0OO0OO0 ) . first ( )
   if oO :
    TBControllertasklist4floor . query . filter_by ( f_Id = OooOoo0OO0OO0 ) . delete ( )
    db . session . commit ( )
    if 33 - 33: ii * i1iiIII111 / O0OO0OooooOo . OooOoo * oOo0O00 + ooo000
    if 17 - 17: i1i1i1111I * O000o + i1iiIII111 - i1I1 / i1i1i1111I
    if 83 - 83: i1I1 - Iii1i + oOo0O00 + I1I / IIiIIiIi11I1 + I1I
   Ooo000oo0O00o = TBControllertasklist4floor ( f_Id = OooOoo0OO0OO0 , f_Notes = IiIi1Ii1111 ,
 f_Monday = i1I11i11 ,
 f_Tuesday = OoOOoO000O ,
 f_Wednesday = O0o0O0o0o ,
 f_Thursday = Oo0 ,
 f_Friday = ooooo ,
 f_Saturday = oO00o00OO ,
 f_Sunday = o00o ,
 f_BeginYMD = Ii11I ,
 f_EndYMD = iIi ,
 f_OperateTime = IIi1I1I1i ,
 f_FloorNames = IiIIII111 ,
 f_DoorControl = O0O ,
 f_DoorID = II1iiii ,

   # OooOoo / i1i1i1111I
   # i1I1 . i1I1 % Ii
   )
   try :
    db . session . add ( Ooo000oo0O00o )
    db . session . commit ( )
    flash ( "Modified successfully! Takes effect after uploading settings." )
    vwAppConfig . vwlog ( '{}--{}' . format ( g . user . f_OperatorName ,
 "Task {} modified successfully!" . format (
 OooOoo0OO0OO0 ) ) )
    return redirect ( url_for ( OO00 ) )
   except Exception as oO0O0oOo :
    print ( oO0O0oOo )
    if 85 - 85: OooOoo % ooo000 % OooOoo
    db . session . rollback ( )
    flash ( " Edit Failed ！" )
    vwAppConfig . vwlog ( '{}--{}[{}]' . format ( g . user . f_OperatorName ,
 "Task {} failed to modify!" . format ( OooOoo0OO0OO0 ) ,
 oO0O0oOo ) )
    return render_template ( IIii , wgform = oOo0O00O0ooo , controlmod = ii1iI1I , doors = I1i )
  else :
   for oOO in oOo0O00O0ooo . messages :
    flash ( oOO )
   return render_template ( IIii , wgform = oOo0O00O0ooo , controlmod = ii1iI1I , doors = I1i )
# dd678faae9ac167bc83abf78e5cb2f3f0688d3a3
