One class, multiple users

This commit is contained in:
Aaron Lee 2021-10-03 11:22:53 +08:00
parent 3f345d55d3
commit 88c5e7e90e

View file

@ -84,13 +84,16 @@ def upload_homeroom():
csv_dict = csv.DictReader(file) csv_dict = csv.DictReader(file)
for row in csv_dict: for row in csv_dict:
if row['number'] == 'teacher': if row['number'] == 'teacher':
accs = row['name'].split(',')
for key in allUsers: for key in allUsers:
if (allUsers[key]['origUsername'] == row['name']): if accs == []:
break
if (allUsers[key]['origUsername'] in accs):
db.child("Users").child(key).child("accounts").child("homeroom^"+gradec+classc+'^'+randint(10000)).update({ db.child("Users").child(key).child("accounts").child("homeroom^"+gradec+classc+'^'+randint(10000)).update({
"homeroom": gradec + '^' + classc, "homeroom": gradec + '^' + classc,
"type": 'homeroom' "type": 'homeroom'
}, session['token']) }, session['token'])
break accs.remove(allUsers[key]['origUsername'])
else: else:
db.child("Homerooms").child(gradec).child( db.child("Homerooms").child(gradec).child(
classc).child(row['number']).set(row, session['token']) classc).child(row['number']).set(row, session['token'])
@ -125,13 +128,16 @@ def upload_gp_classes():
if j % 5 == 0: if j % 5 == 0:
db.child("Classes").child("GP_Class").child(csv_dict.columns[i+1]).child("Class").child( 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] + " : " + tmp_csv[j+2] + " (" + tmp_csv[j+3] + ")", session['token']) tmp_csv[j]).child("name").set(tmp_csv[j+1] + " : " + tmp_csv[j+2] + " (" + tmp_csv[j+3] + ")", session['token'])
accs = tmp_csv[j+4].split(',')
for key in allUsers: for key in allUsers:
if (allUsers[key]['origUsername'] == tmp_csv[j+4]): if accs == []:
break
if (allUsers[key]['origUsername'] in accs):
db.child("Users").child(key).child("accounts").child("GP_Class^"+csv_dict.columns[i+1]+'^'+randint(10000)).update({ db.child("Users").child(key).child("accounts").child("GP_Class^"+csv_dict.columns[i+1]+'^'+randint(10000)).update({
csv_dict.columns[i+1]: tmp_csv[j], csv_dict.columns[i+1]: tmp_csv[j],
"type": 'group' "type": 'group'
}, session['token']) }, session['token'])
break accs.remove(allUsers[key]['origUsername'])
os.remove(filepath) os.remove(filepath)
except Exception as e: except Exception as e:
os.remove(filepath) os.remove(filepath)