cursor.execute("SELECT dow FROM dates WHERE date=%s",(currDate,))
dow=cursor.fetchone()[0]
cursor=db.cursor()
cursor.execute("SELECT period, subject, teacher FROM schedule WHERE grade=%s AND class_=%s AND dow=%s",(currRoom[0],currRoom[1],dow))
scheduleSQL=cursor.fetchall()
schedule={}
foriinscheduleSQL:
schedule[i[0]]={
"subject":i[1],
"teacher":i[2],
}
cursor=db.cursor()
cursor.execute("SELECT period, subject, teacher FROM specschedule WHERE grade=%s AND class_=%s AND date=%s",(currRoom[0],currRoom[1],currDate))
specScheduleSQL=cursor.fetchall()
foriinspecScheduleSQL:
schedule[i[0]]={
"subject":i[1],
"teacher":i[2],
"special":True
}
cursor=db.cursor()
cursor.execute("SELECT period, signature, notes, ds1,ds2,ds3,ds4,ds5,ds6,ds7 FROM submission WHERE grade=%s AND class_=%s AND date=%s",(currRoom[0],currRoom[1],currDate))
submissionSQL=cursor.fetchall()
submission={}
cursor=db.cursor()
cursor.execute("SELECT period, num, note FROM ds WHERE grade=%s AND class_=%s AND date=%s",(currRoom[0],currRoom[1],currDate))
idvDSSQL=cursor.fetchall()
idvDS={}
foriinidvDSSQL:
ifi[0]notinidvDS:
idvDS[i[0]]={}
idvDS[i[0]][i[1]]=i[2]
foriinsubmissionSQL:
ifi[0]=='c':
submission[i[0]]={
"signature":i[1],
"notes":i[2]
}
elifschedule[i[0]]["subject"]=="GP":
submission[i[0]]=OrderedDict()
signatures=json.loads(i[1])
forjinsignatures:
submission[i[0]][j]={
"signature":signatures[j],
}
submission[i[0]]["notes"]=i[2]
else:
submission[i[0]]={
"signature":i[1],
"notes":i[2],
"ds1":i[3],
"ds2":i[4],
"ds3":i[5],
"ds4":i[6],
"ds5":i[7],
"ds6":i[8],
"ds7":i[9]
}
cursor=db.cursor()
cursor.execute("SELECT period, num, status, note FROM absent WHERE grade=%s AND class_=%s AND date=%s",(currRoom[0],currRoom[1],currDate))
cursor.execute("SELECT about FROM gpclasses WHERE subclass=%s AND category=%s",
(c[1],c[0]))
cclass={
"name":cursor.fetchone()[0],
"category":c[0],
"class_id":c[1]
}
data[cclass['category']+''+cclass['class_id']]={
"cdata":cclass,
}
# get student list
cursor.execute("SELECT grade,class_,num,name,ename FROM students WHERE classes LIKE "+'\'%\"'+cclass['category']+'\": \"'+cclass['class_id']+'\"%\''+" ORDER BY grade ASC,class_ ASC,num ASC")
students=cursor.fetchall()
# get student homerooms
homerooms=[]
forxinstudents:
if(str(x[0])+'^'+str(x[1]))notinhomerooms:
homerooms.append(str(x[0])+'^'+str(x[1]))
# get periods
forhinhomerooms:
hs=h.split('^')
cursor.execute("SELECT period FROM schedule WHERE grade=%s AND class_=%s AND dow=%s AND teacher=%s",(hs[0],hs[1],dow,cclass['category']))
scheduleSQL=cursor.fetchall()
cursor.execute("SELECT period FROM specschedule WHERE grade=%s AND class_=%s AND date=%s AND teacher=%s",(hs[0],hs[1],currDate,cclass['category']))
specNTPSQL=cursor.fetchall()
forsinspecNTPSQL:
scheduleSQL.append(s)
cursor.execute("SELECT period FROM specschedule WHERE grade=%s AND class_=%s AND date=%s AND teacher!=%s",(hs[0],hs[1],currDate,cclass['category']))
cursor.execute("SELECT dow FROM dates WHERE date=%s",(currDate,))
dow=cursor.fetchone()[0]
cursor=db.cursor()
cursor.execute("SELECT period, subject, teacher FROM schedule WHERE grade=%s AND class_=%s AND dow=%s",(currRoom[0],currRoom[1],dow))
scheduleSQL=cursor.fetchall()
schedule={}
foriinscheduleSQL:
schedule[i[0]]={
"subject":i[1],
"teacher":i[2],
}
cursor=db.cursor()
cursor.execute("SELECT period, subject, teacher FROM specschedule WHERE grade=%s AND class_=%s AND date=%s",(currRoom[0],currRoom[1],currDate))
specScheduleSQL=cursor.fetchall()
foriinspecScheduleSQL:
schedule[i[0]]={
"subject":i[1],
"teacher":i[2],
"special":True
}
cursor=db.cursor()
cursor.execute("SELECT period, signature, notes, ds1,ds2,ds3,ds4,ds5,ds6,ds7 FROM submission WHERE grade=%s AND class_=%s AND date=%s",(currRoom[0],currRoom[1],currDate))
submissionSQL=cursor.fetchall()
cursor=db.cursor()
cursor.execute("SELECT period, num, note FROM ds WHERE grade=%s AND class_=%s AND date=%s",(currRoom[0],currRoom[1],currDate))
idvDSSQL=cursor.fetchall()
idvDS={}
foriinidvDSSQL:
ifi[0]notinidvDS:
idvDS[i[0]]={}
idvDS[i[0]][i[1]]=i[2]
submission={}
foriinsubmissionSQL:
ifi[0]=='c':
submission[i[0]]={
"signature":i[1],
"notes":i[2]
}
elifschedule[i[0]]["subject"]=="GP":
submission[i[0]]=OrderedDict()
signatures=json.loads(i[1])
forjinsignatures:
submission[i[0]][j]={
"signature":signatures[j],
}
submission[i[0]]["notes"]=i[2]
else:
submission[i[0]]={
"signature":i[1],
"notes":i[2],
"ds1":i[3],
"ds2":i[4],
"ds3":i[5],
"ds4":i[6],
"ds5":i[7],
"ds6":i[8],
"ds7":i[9],
}
cursor=db.cursor()
cursor.execute("SELECT period, num, status, note FROM absent WHERE grade=%s AND class_=%s AND date=%s",(currRoom[0],currRoom[1],currDate))
cursor.execute("SELECT date, period, num, status, note FROM absent WHERE grade=%s AND class_=%s AND num=%s ORDER BY date DESC, period DESC, num ASC",(session['grade'],session['class'],session['num']))
absentDataSQL=cursor.fetchall()
returnrender_template("list.html",title="Student Absent List | 學生缺勤紀錄",mode='STUDABS',data=absentDataSQL,currRoom=[session['grade'],session['class']],name=session['name'],num=session['num'])
cursor.execute("SELECT date, period, num, note FROM ds WHERE grade=%s AND class_=%s AND num=%s ORDER BY date DESC, period DESC, num ASC",(session['grade'],session['class'],session['num']))
dsDataSQL=cursor.fetchall()
print(dsDataSQL)
returnrender_template("list.html",title="Student DS List | 學生定心紀錄",mode='STUDDS',data=dsDataSQL,currRoom=[session['grade'],session['class']],name=session['name'],num=session['num'])
@manage.route('/manage/abs',methods=['GET'])
defshowAllAbs():
if(check_login_status()):
returnredirect('/logout')
refresh_token()
currRoom=session['homeroom'].split('^')
db=refresh_db()
cursor=db.cursor()
cursor.execute("SELECT num,name,ename FROM students WHERE grade=%s AND class_=%s ORDER BY num ASC",(currRoom[0],currRoom[1]))
studentsSQL=cursor.fetchall()
students={}
forstinstudentsSQL:
students[st[0]]={
'name':st[1],
'ename':st[2],
}
cursor=db.cursor()
cursor.execute("SELECT date, period, num, status, note FROM absent WHERE grade=%s AND class_=%s ORDER BY date DESC, period DESC, num ASC",(currRoom[0],currRoom[1]))
absentDataSQL=cursor.fetchall()
returnrender_template("list.html",title="Absent List | 缺勤紀錄",mode='ABS',students=students,data=absentDataSQL,currRoom=currRoom)
@manage.route('/manage/ds',methods=['GET'])
defshowAllDS():
if(check_login_status()):
returnredirect('/logout')
refresh_token()
currRoom=session['homeroom'].split('^')
db=refresh_db()
cursor=db.cursor()
cursor.execute("SELECT num,name,ename FROM students WHERE grade=%s AND class_=%s ORDER BY num ASC",(currRoom[0],currRoom[1]))
studentsSQL=cursor.fetchall()
students={}
forstinstudentsSQL:
students[st[0]]={
'name':st[1],
'ename':st[2],
}
cursor=db.cursor()
cursor.execute("SELECT date, period, num, note FROM ds WHERE grade=%s AND class_=%s ORDER BY date DESC, period DESC, num ASC",(currRoom[0],currRoom[1]))
dsDataSQL=cursor.fetchall()
returnrender_template("list.html",title="DS List | 定心紀錄",mode='DS',students=students,data=dsDataSQL,currRoom=currRoom)
cursor.execute("SELECT about FROM gpclasses WHERE category=%s AND subclass=%s",
(cclass['category'],cclass['class_id']))
cclass["name"]=cursor.fetchone()[0]
cursor.execute("SELECT grade,class_,num,name,ename FROM students WHERE classes LIKE "+'\'%\"'+cclass['category']+'\": \"'+cclass['class_id']+'\"%\''+" ORDER BY grade ASC,class_ ASC,num ASC")