Exemplo n.º 1
0
 def post(self):
     data = request.get_json()
     header = request.headers.get("Authorization")
     status = auth.Manageidentify(auth.getTokenFromHeader(header))
     if status:
         db.students.update(
             {"id": int(data["id"])},
             {
                 "$set": {
                     "account":
                     data["account"],
                     "student_name":
                     data["student_name"],
                     "student_class":
                     data["student_class"],
                     "student_number":
                     data["student_number"],
                     "password":
                     data["password"],
                     "enable":
                     data["enable"],
                     "results": [{
                         "club": result["club"],
                         "year": result["year"]
                     } for result in data["results"]],
                 }
             },
         )
         return jsonify({"status": 200})
     else:
         return jsonify({"status": 401})
Exemplo n.º 2
0
 def get(self, token):
     status = auth.Manageidentify(token)
     if not status:
         return jsonify({"status": 401})
     year = config.year()
     obj = db.students.find({"enable": 1, "year": status["permission"]})
     data = []
     table = OrderedDict()
     data.append(["學號", "班級", "姓名"])
     for item in obj:
         count = 0
         for i in item["chooses"]:
             if i["year"] == year:
                 count += 1
         if count == 0:
             data.append([
                 item["account"], item["student_class"],
                 item["student_name"]
             ])
     table.update({"Sheet 1": data})
     save_data("/tmp/tables.ods", table)
     return send_from_directory(
         "/tmp",
         "tables.ods",
         as_attachment=True,
         mimetype="application/file",
         attachment_filename=f"{year}未選課名單.ods",
     )
Exemplo n.º 3
0
 def get(self):
     header = request.headers.get("Authorization")
     status = auth.Manageidentify(auth.getTokenFromHeader(header))
     if status:
         try:
             data = []
             year = config.year()
             obj = db.students.find({
                 "enable": 1,
                 "year": status["permission"]
             })
             for item in obj:
                 count = 0
                 for i in item["chooses"]:
                     if i["year"] == year:
                         count += 1
                 if count == 0:
                     data.append({
                         "id": item["id"],
                         "account": item["account"],
                         "class": item["student_class"],
                         "name": item["student_name"],
                     })
             return jsonify(data)
         except Exception as e:
             print(e)
             return jsonify({"status": 401})
     else:
         return jsonify({"status": 401})
Exemplo n.º 4
0
 def get(self):
     header = request.headers.get("Authorization")
     status = auth.Manageidentify(auth.getTokenFromHeader(header))
     if status:
         return jsonify({"status": 200, **status})
     else:
         return jsonify({"status": 401})
Exemplo n.º 5
0
 def get(self, id):
     header = request.headers.get("Authorization")
     status = auth.Manageidentify(auth.getTokenFromHeader(header))
     if status:
         if int(status["permission"]) > 10:
             for i in range(1, config.getConf("maxchooses") + 1):
                 print(i)
         return jsonify({"status": 200})
     else:
         return jsonify({"status": 401})
Exemplo n.º 6
0
 def post(self):
     data = request.get_json()
     header = request.headers.get("Authorization")
     status = auth.Manageidentify(auth.getTokenFromHeader(header))
     if status:
         year = int(status["permission"])
         data["_id"] = year
         db.config.delete_one({"_id": year})
         db.config.insert_one(data)
         return jsonify({"status": 200})
     else:
         return jsonify({"status": 401})
Exemplo n.º 7
0
 def get(self, id=0):
     header = request.headers.get("Authorization")
     status = auth.Manageidentify(auth.getTokenFromHeader(header))
     if status:
         try:
             data = []
             obj = db.chooses.find({})
             for i in obj:
                 data.append({"club": i["club"], "step": i["step"]})
             return jsonify(data)
         except Exception as e:
             print(e)
             return jsonify({"status": 401})
     else:
         return jsonify({"status": 401})
Exemplo n.º 8
0
 def get(self, id=None):
     header = request.headers.get("Authorization")
     status = auth.Manageidentify(auth.getTokenFromHeader(header))
     if status:
         if id == None:
             try:
                 data = []
                 for stu in db.students.find({}):
                     data.append({
                         "id": stu["id"],
                         "account": stu["account"],
                         "class": stu["student_class"],
                         "name": stu["student_name"],
                     })
                 return jsonify(data)
             except Exception as e:
                 print(e)
                 return jsonify({"status": 401})
         else:
             try:
                 data = []
                 for stu in db.students.find({"id": int(id)}):
                     data.append({
                         "id": stu["id"],
                         "account": stu["account"],
                         "student_name": stu["student_name"],
                         "student_class": stu["student_class"],
                         "student_number": stu["student_number"],
                         "year": stu["year"],
                         "password": stu["password"],
                         "enable": stu["enable"],
                         "results": stu["results"],
                     })
                 return jsonify(data)
             except Exception as e:
                 print(e)
                 return jsonify({"status": 401})
     else:
         return jsonify({"status": 401})
Exemplo n.º 9
0
 def get(self, token):
     status = auth.Manageidentify(token)
     if not status:
         return jsonify({"status": 401})
     obj = db.students.find({})
     data = []
     table = OrderedDict()
     data.append(["學號", "班級", "姓名"])
     for item in obj:
         count = 0
         if item["enable"] != 1:
             continue
         data.append(
             [item["account"], item["student_class"], item["student_name"]])
     table.update({"Sheet 1": data})
     save_data("/tmp/tables.ods", table)
     return send_from_directory(
         "/tmp",
         "tables.ods",
         as_attachment=True,
         mimetype="application/file",
         attachment_filename="學生名單.ods",
     )