def journal(): #app.logger.info("message") if request.method == 'POST': #app.logger.info('Post smth') Journal.insert(request.form['student'], request.form['subject'], request.form['mark']) return render_template('journal.html', jrnl = Journal.get_all(), students = Students.get_all(), subjects = Subjects.get_all())
def add_student(): data = json.loads(request.data) group = Group.query.filter_by(id=int(data["group"])).one() rest = group.restReturn print(data, file=sys.stderr) try: for i in rest["students"]: if i["email"] == data["email"]: user = Users.query.filter_by(id=data["teacher_id"]).one() temp = user.restReturn temp.update({ "status": "FAILED", "reason": "Student already exists in group" }) return jsonify(temp) try: parent = Parents.query.filter_by(email=data["pemail"]).one() except: print("Parent does not exist adding to the db", file=sys.stderr) parent = Parents(name=data["fname"], email=data["pemail"], telephone=data["ptel"]) db.session.add(parent) db.session.commit() finally: parent = Parents.query.filter_by(email=data["pemail"]).one() newStudent = Students(parent_id=parent.id, name=data["name"], email=data["email"], teacher_id=int(data["teacher_id"]), group_id=int(data["group"])) db.session.add(newStudent) db.session.commit() newStudent = Students.query.filter_by(email=data["email"], group_id=group.id).one() try: theRange = rest["students"][0]["grades"] toAdd = [] for i in range(len(theRange)): toAdd = Grades(student_id=newStudent.id, name=theRange[i]["test"], grade=0) db.session.add(toAdd) if toAdd: db.session.commit() except: print("No prior grades where detected in the group", file=sys.stderr) user = Users.query.filter_by(id=int(data["teacher_id"])).one() temp = user.restReturn temp.update({ "status": "SUCCESS" }) return jsonify(temp) except: e = sys.exc_info() traceback.print_exception(*e)
def stat(): studid = 1 subjid = 1 if request.method == 'POST': studid = int(request.form['student']) subjid = int(request.form['subject']) #app.logger.info("%s %s" %( studavg, subjavg)) #else: studid = subjid =None studavg = Journal.st_avg(studid) subjavg = Journal.disc_avg(subjid) return render_template('stat.html', students = Students.get_all(), subjects = Subjects.get_all(), studavg = studavg, subjavg = subjavg, studid = studid, subjid = subjid)
def stud_list(): if request.method == 'POST': Students.insert(request.form['name'], request.form['surname']) return render_template('index.html', students = Students.get_all())
def view_did_press_add_button(self, view, data): print(f"view_did_press_add_button: {data}") if isinstance(view, AddStudentView): self._db_manager.add( Students(id_student=data["Numer indeksu"], imie=data["Imię"], nazwisko=data["Nazwisko"], telefon=data["Telefon"], email=data["Email"])) elif isinstance(view, AddResearcherView): id_stopien_naukowy = self._db_manager.query(f""" SELECT id_stopienNaukowy FROM StopienNaukowy WHERE nazwaStopniaNaukowego = '{data["Stopień naukowy"]}' """)[0][0] id_katedra = self._db_manager.query(f""" SELECT id_Katedra FROM Katedra WHERE nazwaKatedry = '{data["Katedra"]}' """)[0][0] self._db_manager.add( Researchers(imie=data["Imię"], nazwisko=data["Nazwisko"], telefon=data["Telefon"], email=data["Email"], id_stopienNaukowy=id_stopien_naukowy, id_katedra=id_katedra)) elif isinstance(view, AddThesisView): id_promotor = self._db_manager.query(f""" SELECT id_pracownikNaukowy FROM PracownicyNaukowi WHERE CONCAT(imie, ' ', nazwisko) = '{data["Promotor"]}' """)[0][0] id_kierunek_studiow = self._db_manager.query(f""" SELECT id_kierunek FROM KierunekStudiow WHERE nazwaKierunku = '{data["Kierunek studiów"]}' """)[0][0] self._db_manager.add( Theses(tytul=data["Temat"], id_promotor=id_promotor, id_kierunekStudiow=id_kierunek_studiow)) id_praca = self._db_manager.query(f""" SELECT id_praca FROM PraceDyplomowe WHERE tytul = '{data["Temat"]}' AND id_kierunekStudiow = {id_kierunek_studiow} AND id_promotor = {id_promotor} """)[0][0] for reviewer in data["Recenzenci"]: id_recenzujacy = self._db_manager.query(f""" SELECT id_pracownikNaukowy FROM PracownicyNaukowi WHERE CONCAT(imie, ' ', nazwisko) = '{reviewer}' """)[0][0] self._db_manager.add( Review(id_praca=id_praca, id_recenzujacy=id_recenzujacy)) for author in data["Autorzy"]: id_author = self._db_manager.query(f""" SELECT id_student FROM Studenci WHERE CONCAT(imie, ' ', nazwisko) = '{author}' """)[0][0] self._db_manager.add( ThesesAuthors(id_student=id_author, id_praca=id_praca)) for word in data["Słowa kluczowe"].split(","): word = word.lstrip().rstrip() id_slowo_kluczowe = self._db_manager.query(f""" SELECT id_slowoKluczowe FROM SlowaKluczowe WHERE slowoKluczowe = '{word}' """) if not id_slowo_kluczowe: self._db_manager.add(Keywords(slowoKluczowe=word)) id_slowo_kluczowe = self._db_manager.query(f""" SELECT id_slowoKluczowe FROM SlowaKluczowe WHERE slowoKluczowe = '{word}' """) self._db_manager.add( ThesesKeywords(id_slowoKluczowe=id_slowo_kluczowe[0][0], id_praca=id_praca)) elif isinstance(view, AddDefenseView): id_praca = self._db_manager.query(f""" SELECT id_praca FROM PraceDyplomowe WHERE tytul = '{data["Praca dyplomowa"]}' """)[0][0] id_komisja = self._db_manager.query(f""" SELECT KD.id_komisja FROM KomisjaDyplomowa KD INNER JOIN PracownicyNaukowi PN on KD.id_przewodniczacy = PN.id_pracownikNaukowy WHERE CONCAT(PN.imie, ' ', PN.nazwisko) = '{data["Przewodniczący komisji"]}' """)[0][0] id_lokalizacja = self._db_manager.query(f""" SELECT id_lokalizacja FROM Lokalizacja WHERE CONCAT(budynek, ', ', sala) = '{data["Miejsce obrony"]}' """) self._db_manager.add( Defense(data=data["Data obrony"], id_praca=id_praca, id_komisja=id_komisja, id_lokalizacja=id_lokalizacja)) elif isinstance(view, AddReviewView): id_praca = self._db_manager.query(f""" SELECT id_praca FROM PraceDyplomowe WHERE tytul = '{data["Praca dyplomowa"]}' """)[0][0] id_recenzujacy = self._db_manager.query(f""" SELECT id_recenzujacy FROM Recenzja LEFT JOIN PracownicyNaukowi PN on Recenzja.id_recenzujacy = PN.id_pracownikNaukowy WHERE CONCAT(imie, ' ', nazwisko) = '{self._user.split(": ")[-1]}' """)[0][0] self._db_manager.add( Review(id_praca=id_praca, id_recenzujacy=id_recenzujacy, ocena=data["Ocena"], tekstRecenzji=data["Komentarz"], dataWystawienia=datetime.now()))
def get(self, *args, **kwargs): # 从数据库中提取数据 stus = Students.all() print(stus) # self.write("OK") self.render('students.html', stus=stus)
def add_entry(name, gender, age): student = Students(name, gender, age) db_session.add(student) db_session.commit()
def upload(): data = request.get_array(field_name="file") user_id = request.form["user_id"] ##First check; Does the first row contain just one column and if so is that group name ## taken in his account? print(data[0], file=sys.stderr) try: if first_row_excel_length(data[0])== 1: check_group = Group.query.filter_by(name=data[0][0], owner_id=user_id).count() if check_group == 0: new_group = Group(name=data[0][0], owner_id=int(user_id)) db.session.add(new_group) db.session.flush() else: return jsonify({ "status":"FAILED", "reason":"The Name given to the group already exists in your account" }) ##Second Check: check that the length of the second row equals 5 if first_row_excel_length(data[1])== 5: #We will now add the entries to the data base destination_group = Group.query.filter_by(name=data[0][0], owner_id=user_id).one() emails_used = [] email_info_objects = [] for indx, value in enumerate(data): if indx == 0 or indx == 1: continue else: #Check if parent information exists check_parent = Parents.query.filter_by(email=value[4]).count() the_parent_id = None if check_parent == 1 : parent = Parents.query.filter_by(email = value[4]).one() if value[2] == parent.name: the_parent_id = parent.id print(str(the_parent_id), file=sys.stderr) else: return jsonify({ "status":"FAILED", "reason":"parent email in row "+ str(indx+1)+" is already in " "use" }) else: new_parent = Parents(name=value[2], email=value[4], telephone=value[3]) db.session.add(new_parent) db.session.flush() the_parent_id = Parents.query.filter_by(email=value[4]).one().id ## Now we must add the student print(value[1] in emails_used, file=sys.stderr) if value[1] not in emails_used: new_student = Students(name=value[0], email=value[1], parent_id=the_parent_id, teacher_id=user_id, group_id=destination_group.id) db.session.add(new_student) db.session.flush() emails_used.append(value[1]) email_info_objects.append({ "row":indx + 1, "email":value[1] }) print(emails_used, file=sys.stderr) else: the_index_email = emails_used.index(value[1]) print("Inside else", file=sys.stderr) print(emails_used[the_index_email], file=sys.stderr) return jsonify({ "status":"FAILED", "reason":"the student email in row: "+str(indx + 1)+" " "already exists in row: "+ str(email_info_objects[the_index_email]["row"]) }) db.session.commit() user = Users.query.filter_by(id=int(user_id)).one().restReturn user.update({ "status":"SUCCESS" }) return jsonify(user) else: return jsonify({ "status":"FAILED", "reason": "The header should be of length 5; found " + str(first_row_excel_length(data[1])) }) else: return jsonify({ "status":"FAILED", "reason":"First Row in excel document should contain only one column, instead found " +str(first_row_excel_length(data[0])) }) except: e = sys.exc_info() traceback.print_exception(*e) return "Error Sending message"