mirror of
https://github.com/aaronleetw/Attendance.git
synced 2024-11-14 19:11:39 -08:00
Done with upload format
This commit is contained in:
parent
419a71be2b
commit
745b43dff3
5 changed files with 278 additions and 212 deletions
114
app.py
114
app.py
|
@ -41,6 +41,10 @@ def check_login_status():
|
|||
(datetime.now(tz) - session['loginTime']).total_seconds() > 3600)
|
||||
|
||||
|
||||
def check_permission():
|
||||
return db.child('Users').child(session['uid']).child('permission').get().val() == 'admin'
|
||||
|
||||
|
||||
def manageProcess(fCommand, fData):
|
||||
if (check_login_status()):
|
||||
return redirect('/logout')
|
||||
|
@ -65,6 +69,7 @@ def manageProcess(fCommand, fData):
|
|||
homeroomData = homerooms[currRoom[0]][currRoom[1]]
|
||||
absData = homeroomData["Absent"]
|
||||
homeroomData.pop('Absent')
|
||||
if 'placeholder' in homeroomData:
|
||||
homeroomData.pop('placeholder')
|
||||
currDate = ""
|
||||
if fCommand != "":
|
||||
|
@ -85,8 +90,6 @@ def manageProcess(fCommand, fData):
|
|||
"GP_Class").child(i).get().val()
|
||||
cclass = {
|
||||
"name": cateData['Class'][classes[i]]['name'],
|
||||
"teacher": cateData['Class'][classes[i]]['teacher'],
|
||||
"classroom": cateData['Class'][classes[i]]['classroom'],
|
||||
"category": i,
|
||||
"class_id": classes[i]
|
||||
}
|
||||
|
@ -100,6 +103,7 @@ def manageProcess(fCommand, fData):
|
|||
hrData = db.child("Homerooms").child(h[0]).child(h[1]).get().val()
|
||||
tmpAbsData = hrData['Absent']
|
||||
hrData.pop('Absent')
|
||||
if 'placeholder' in hrData:
|
||||
hrData.pop('placeholder')
|
||||
periods = []
|
||||
dow = ""
|
||||
|
@ -196,6 +200,7 @@ def manageProcess(fCommand, fData):
|
|||
break
|
||||
absData = homeroomData["Absent"]
|
||||
homeroomData.pop('Absent')
|
||||
if 'placeholder' in homeroomData:
|
||||
homeroomData.pop('placeholder')
|
||||
currDate = ""
|
||||
if fCommand == 'date':
|
||||
|
@ -221,7 +226,7 @@ def index():
|
|||
if check_login_status():
|
||||
try:
|
||||
user = auth.sign_in_with_email_and_password(
|
||||
request.form['username'] + "@group-attendence.fhjh.tp.edu.tw", request.form['password'])
|
||||
request.form['username'] + "@group-attendance.fhjh.tp.edu.tw", request.form['password'])
|
||||
session['is_logged_in'] = True
|
||||
session['email'] = user['email']
|
||||
session['uid'] = user['localId']
|
||||
|
@ -297,7 +302,6 @@ def group_teach_publish():
|
|||
h = h.split('^')
|
||||
db.child("Homerooms").child(h[0]).child(h[1]).child(
|
||||
"Absent").child(date).child(period).child("signature").update({cclass['class_id']: str(storage.child(os.path.join('signatures', rand)).get_url(None))})
|
||||
# upload notes
|
||||
currPeriodData = db.child("Homerooms").child(h[0]).child(h[1]).child(
|
||||
"Absent").child(date).child(period).get().val()
|
||||
if 'notes' in currPeriodData:
|
||||
|
@ -306,6 +310,8 @@ def group_teach_publish():
|
|||
else:
|
||||
db.child("Homerooms").child(h[0]).child(h[1]).child(
|
||||
"Absent").child(date).child(period).update({'notes': notes})
|
||||
|
||||
# upload notes
|
||||
os.remove(os.path.join('temp', rand))
|
||||
return redirect('/manage')
|
||||
|
||||
|
@ -368,10 +374,11 @@ def homeroom_confirm():
|
|||
return redirect('/manage')
|
||||
|
||||
|
||||
@ app.route('/upload/homeroom', methods=['GET', 'POST'])
|
||||
@ app.route('/upload/1', methods=['GET', 'POST'])
|
||||
def upload_homeroom():
|
||||
if ((not check_login_status()) and check_permission()):
|
||||
if request.method == 'GET':
|
||||
return render_template('uploadcsv.html', title="Homeroom List", url="/upload/homeroom")
|
||||
return render_template('uploadcsv.html', title="Homeroom List", url="/upload/1")
|
||||
elif request.method == 'POST':
|
||||
try:
|
||||
# get csv
|
||||
|
@ -383,6 +390,17 @@ def upload_homeroom():
|
|||
with open(filepath) as file:
|
||||
csv_dict = csv.DictReader(file)
|
||||
for row in csv_dict:
|
||||
if row['number'] == 'password':
|
||||
auth.create_user_with_email_and_password(
|
||||
gradec + '^' + classc + "@group-attendance.fhjh.tp.edu.tw", row['name'])
|
||||
user = auth.sign_in_with_email_and_password(
|
||||
gradec + '^' + classc + "@group-attendance.fhjh.tp.edu.tw", row['name'])
|
||||
db.child("Users").child(user['localId']).update({
|
||||
"permission": 'homeroom',
|
||||
"username": gradec + '^' + classc,
|
||||
"homeroom": gradec + '^' + classc
|
||||
})
|
||||
else:
|
||||
db.child("Homerooms").child(gradec).child(
|
||||
classc).child(row['number']).set(row)
|
||||
# row['class'] row['number'] row['name'] row['eng_name']
|
||||
|
@ -391,12 +409,15 @@ def upload_homeroom():
|
|||
os.remove(filepath)
|
||||
return "Error. Please try again\n("+str(e)+")"
|
||||
return "Successfully uploaded " + gradec + "-" + classc
|
||||
else:
|
||||
return redirect('/logout')
|
||||
|
||||
|
||||
@ app.route('/upload/gp_classes', methods=['GET', 'POST'])
|
||||
@ app.route('/upload/2', methods=['GET', 'POST'])
|
||||
def upload_gp_classes():
|
||||
if ((not check_login_status()) and check_permission()):
|
||||
if request.method == 'GET':
|
||||
return render_template('uploadcsv.html', title="Group Classes", url="/upload/gp_classes")
|
||||
return render_template('uploadcsv.html', title="Group Classes", url="/upload/2")
|
||||
elif request.method == 'POST':
|
||||
try:
|
||||
csv_file = request.files['csv']
|
||||
|
@ -409,24 +430,34 @@ def upload_gp_classes():
|
|||
for j in range(len(tmp_csv)):
|
||||
if type(tmp_csv[j]) == float:
|
||||
break
|
||||
if j % 4 == 0:
|
||||
if j % 5 == 0:
|
||||
db.child("Classes").child("GP_Class").child(csv_dict.columns[i+1]).child("Class").child(
|
||||
tmp_csv[j]).child("name").set(tmp_csv[j+1])
|
||||
db.child("Classes").child("GP_Class").child(csv_dict.columns[i+1]).child("Class").child(
|
||||
tmp_csv[j]).child("teacher").set(tmp_csv[j+2])
|
||||
db.child("Classes").child("GP_Class").child(csv_dict.columns[i+1]).child("Class").child(
|
||||
tmp_csv[j]).child("classroom").set(tmp_csv[j+3])
|
||||
tmp_csv[j]).child("name").set(tmp_csv[j+1] + " : " + tmp_csv[j+2] + " (" + tmp_csv[j+3] + ")")
|
||||
auth.create_user_with_email_and_password(
|
||||
csv_dict.columns[i+1] + "^" + tmp_csv[j] + "@group-attendance.fhjh.tp.edu.tw", tmp_csv[j+4])
|
||||
user = auth.sign_in_with_email_and_password(
|
||||
csv_dict.columns[i+1] + "^" + tmp_csv[j] + "@group-attendance.fhjh.tp.edu.tw", tmp_csv[j+4])
|
||||
db.child("Users").child(user['localId']).update({
|
||||
"permission": 'group',
|
||||
"username": csv_dict.columns[i+1] + "^" + tmp_csv[j],
|
||||
"class": {
|
||||
csv_dict.columns[i+1]: tmp_csv[j],
|
||||
}
|
||||
})
|
||||
os.remove(filepath)
|
||||
except Exception as e:
|
||||
os.remove(filepath)
|
||||
return "Error. Please try again\n("+str(e)+")"
|
||||
return "Successfully uploaded"
|
||||
else:
|
||||
return redirect('/logout')
|
||||
|
||||
|
||||
@ app.route('/upload/stud_in_group', methods=['GET', 'POST'])
|
||||
@ app.route('/upload/3', methods=['GET', 'POST'])
|
||||
def upload_stud_in_group():
|
||||
if ((not check_login_status()) and check_permission()):
|
||||
if request.method == 'GET':
|
||||
return render_template('uploadcsv.html', title="Student in Group List", url="/upload/stud_in_group")
|
||||
return render_template('uploadcsv.html', title="Student in Group List", url="/upload/3")
|
||||
elif request.method == 'POST':
|
||||
try:
|
||||
gradec = request.form['gradeCode']
|
||||
|
@ -450,12 +481,15 @@ def upload_stud_in_group():
|
|||
os.remove(filepath)
|
||||
return "Error. Please try again\n("+str(e)+")"
|
||||
return "Successfully uploaded " + gradec + "-" + classc
|
||||
else:
|
||||
return redirect('/logout')
|
||||
|
||||
|
||||
@ app.route('/upload/period_list', methods=['GET', 'POST'])
|
||||
@ app.route('/upload/4', methods=['GET', 'POST'])
|
||||
def upload_period_list():
|
||||
if ((not check_login_status()) and check_permission()):
|
||||
if request.method == 'GET':
|
||||
return render_template('uploadcsv.html', title="Period List", url="/upload/period_list")
|
||||
return render_template('uploadcsv.html', title="Period List", url="/upload/4")
|
||||
elif request.method == 'POST':
|
||||
try:
|
||||
# get csv
|
||||
|
@ -485,10 +519,13 @@ def upload_period_list():
|
|||
os.remove(filepath)
|
||||
return "Error. Please try again\n("+str(e)+")"
|
||||
return "Successfully uploaded " + gradec + "-" + classc
|
||||
else:
|
||||
return redirect('/logout')
|
||||
|
||||
|
||||
@ app.route('/upload/dates', methods=['GET', 'POST'])
|
||||
def upload_dates():
|
||||
if ((not check_login_status()) and check_permission()):
|
||||
if request.method == 'GET':
|
||||
return render_template('uploadcsv.html', title="School Days", url="/upload/dates")
|
||||
elif request.method == 'POST':
|
||||
|
@ -517,19 +554,38 @@ def upload_dates():
|
|||
os.remove(filepath)
|
||||
return "Error. Please try again\n("+str(e)+")"
|
||||
return "Successfully uploaded dates"
|
||||
else:
|
||||
return redirect('/logout')
|
||||
|
||||
|
||||
# @ app.route('/upload/rm_all_data_of_class', methods=['GET', "POST"])
|
||||
# def rm_all_data_of_class():
|
||||
# if request.method == 'GET':
|
||||
# return render_template('uploadcsv.html', title="Remove all data of class", url="/upload/rm_all_data_of_class")
|
||||
# elif request.method == 'POST':
|
||||
# try:
|
||||
# classc = request.form['classcode']
|
||||
# db.child("Homerooms").child(classc).remove()
|
||||
# except Exception as e:
|
||||
# return "Error. Please try again\n("+str(e)+")"
|
||||
# return "Successfully removed " + classc
|
||||
@app.route('/upload/admin_acc', methods=['GET', 'POST'])
|
||||
def upload_admin_acc():
|
||||
if ((not check_login_status()) and check_permission()):
|
||||
if request.method == 'GET':
|
||||
return render_template('uploadcsv.html', title="Admin Accounts", url="/upload/admin_acc")
|
||||
elif request.method == 'POST':
|
||||
try:
|
||||
csv_file = request.files['csv']
|
||||
filepath = os.path.join('./temp', csv_file.filename)
|
||||
csv_file.save(filepath)
|
||||
with open(filepath) as file:
|
||||
csv_dict = csv.DictReader(file)
|
||||
for row in csv_dict:
|
||||
auth.create_user_with_email_and_password(
|
||||
row['username'] + '@group-attendance.fhjh.tp.edu.tw', row['password'])
|
||||
user = auth.sign_in_with_email_and_password(
|
||||
row['username'] + '@group-attendance.fhjh.tp.edu.tw', row['password'])
|
||||
db.child("Users").child(user['localId']).update({
|
||||
'permission': 'admin',
|
||||
'username': row['username']
|
||||
})
|
||||
os.remove(filepath)
|
||||
except Exception as e:
|
||||
os.remove(filepath)
|
||||
return "Error. Please try again\n("+str(e)+")"
|
||||
return "Successfully uploaded admin accounts"
|
||||
else:
|
||||
return redirect('/logout')
|
||||
|
||||
|
||||
@ app.route('/logout', methods=['GET'])
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 45 KiB |
|
@ -52,6 +52,7 @@
|
|||
</form>
|
||||
</div>
|
||||
<div class="col">
|
||||
<div class="sticky-top" style="background-color: white;">
|
||||
<div class="row title">
|
||||
<div class="col">HR</div>
|
||||
<div class="col">Number</div>
|
||||
|
@ -87,6 +88,7 @@
|
|||
<div class="col">{{absData[currDate][i]['teacher']}}</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% if data != None %}
|
||||
{% for i in homeroomData %}
|
||||
<div class="row">
|
||||
|
@ -128,7 +130,7 @@
|
|||
{% endfor %}
|
||||
{% endif %}
|
||||
{% for c in range(periods|length + 1) %}
|
||||
{% if c % 2 == 0 %}
|
||||
{% if c % 4 == 0 %}
|
||||
<div class="row signatures">
|
||||
{% endif %}
|
||||
<div class="col half">
|
||||
|
@ -140,7 +142,8 @@
|
|||
{% if 'signature' in absData[currDate][periods[c-1]] %}
|
||||
{% for i in absData[currDate][periods[c-1]]['signature'] %}
|
||||
<div class="row">{{periods[c-1]}}: {{absData[currDate][periods[c-1]]['teacher']}}: {{i}}</div>
|
||||
<div class="row"><img src="{{absData[currDate][periods[c-1]]['signature'][i]}}" alt=""></div>
|
||||
<div class="row"><img src="{{absData[currDate][periods[c-1]]['signature'][i]}}" alt=""><br>備註:
|
||||
{{absData[currDate][periods[c-1]]['notes']}}</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<div class="row">{{periods[c-1]}}: {{absData[currDate][periods[c-1]]['teacher']}}: No Signature
|
||||
|
@ -151,11 +154,12 @@
|
|||
<div class="row">{{periods[c-1]}}: {{absData[currDate][periods[c-1]]['name']}}:
|
||||
{{absData[currDate][periods[c-1]]['teacher']}}
|
||||
</div>
|
||||
<div class="row"><img src="{{absData[currDate][periods[c-1]]['signature']}}" alt=""></div>
|
||||
<div class="row"><img src="{{absData[currDate][periods[c-1]]['signature']}}"
|
||||
alt=""><br>備註:{{absData[currDate][periods[c-1]]['notes']}}</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if c % 2 == 1 %}
|
||||
{% if c % 4 == 3 %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Homeroom_View</title>
|
||||
<title>Attendance | Homeroom</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css" rel="stylesheet"
|
||||
integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="/static/allpages.css">
|
||||
|
@ -14,9 +14,9 @@
|
|||
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Homeroom_View</h1>
|
||||
<h1>Attendance | Homeroom</h1>
|
||||
<h2>{{homeroomCode[0]}}: {{homeroomCode[1]}}</h2>
|
||||
<h2>Status: ({{currDate}}, 星期{{absData[currDate]['dow']}})</h2>
|
||||
<h2>{{currDate}}, 依照 星期{{absData[currDate]['dow']}} 課表</h2>
|
||||
<a href="/logout"><button class="btn btn-primary">Logout 登出</button></a>
|
||||
<form action="/manage/date" id="dateSelForm" method="post">
|
||||
<select name="date" id="date" class="form-select" onchange="chgDate();">
|
||||
|
@ -137,10 +137,10 @@
|
|||
</form>
|
||||
{% if 'confirm' in absData[currDate] %}
|
||||
<button class="btn btn-primary margin-top afterSelButton" onclick="homeroomCfrm()" disabled="disabled">
|
||||
Already Confirmed</button>
|
||||
Homeroom Teacher Already Confirmed | 班導已確認</button>
|
||||
{% else %}
|
||||
<button class="btn btn-primary margin-top afterSelButton" onclick="homeroomCfrm()">Homeroom
|
||||
Teacher Confirm</button>
|
||||
Teacher Confirm | 班導已確認</button>
|
||||
{% endif %}
|
||||
<div id="finalCheck" hidden="hidden">
|
||||
<!-- show warning -->
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
<div class="col-md-4 offset-md-4">
|
||||
<h1 class="text-center">Upload {{title}}</h1>
|
||||
<!-- upload csv -->
|
||||
<form action="{{url}}" method="post" enctype="multipart/form-data">
|
||||
<form action="{{url}}" id="uploadCsvForm" method="post" enctype="multipart/form-data">
|
||||
<!-- input class code -->
|
||||
<div class="form-group">
|
||||
<label for="gradeCode">Grade Code</label>
|
||||
|
@ -34,7 +34,7 @@
|
|||
<label for="csv">{{title}}</label>
|
||||
<input type="file" class="form-control-file" id="csv" name="csv">
|
||||
</div>
|
||||
<button onclick="loadingAnimation()" type="submit" class="btn btn-primary">Upload</button>
|
||||
<button onclick="loadingAnimation()" type="button" class="btn btn-primary">Upload</button>
|
||||
</form>
|
||||
<!-- show danger zone -->
|
||||
<div class="alert alert-danger" role="alert">
|
||||
|
@ -61,6 +61,12 @@
|
|||
<script type="text/javascript" src="/static/jquery.min.js"></script>
|
||||
<script>
|
||||
function loadingAnimation() {
|
||||
// if csv is empty
|
||||
if ($("#csv").val() == "") {
|
||||
alert("Please select a file!");
|
||||
return;
|
||||
}
|
||||
$('#uploadCsvForm').submit();
|
||||
$('.container').hide();
|
||||
$('#loading').show();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue