def create_team(): user = session['user'] if user['type'] != 'Mentor': return redirect(url_for('index')) if request.method == 'POST': team_name = request.form['new_team_name'] chosen_members = [] member1 = request.form['member1'] member2 = request.form['member2'] member3 = request.form['member3'] member4 = request.form['member4'] if member1: chosen_members.append(Student.get_student_by_id(member1)) if member2: chosen_members.append(Student.get_student_by_id(member2)) if member3: chosen_members.append(Student.get_student_by_id(member3)) if member4: chosen_members.append(Student.get_student_by_id(member4)) if len(team_name) > 0: Team.add_new_team(team_name, chosen_members) return redirect('teams.html') return render_template('team_create.html', student_list=Student.get_list_of_students(), user=user)
def testRepoUpdate(self): student = Student(1,"asd",123) self.__repoStudents.add(student) newStudent = Student(1,"abc",123) self.__repoStudents.update(newStudent) students = self.__repoStudents.getAll() self.assertEqual(students[0].getName(),"abc")
def init_(): global conn conn = Connection_("my_new_test.db") conn._create_table() s = Student("aa", "bb", "cc", "gg") # conn.insert_new_student(s._generate_id(),s.get_student_name(),"b","c","d") # TODO: pass student_name object here, To avoid space or wrong name . print(conn.is_user_exists(s.get_student_name()))
def __uiAddStudent(self): print("Adding a student...\nID:") id = int(input()) print("Name:") name = input() print("Group:") group = input() self.__controllerStudents.addStudent(id, name, group) self.__undoAction.addToUndoList("1", Student(id, name, group)) self.__undoAction.addToRedoList("1", Student(id, name, group))
def add_student(student_name, class_id): try: student = Student(name=student_name) if class_id: student.class_id = class_id db.session.add(student) db.session.commit() return jsonify(student=student.serialize) except Exception as e: db.session.rollback() raise e
class TestModels(unittest.TestCase): def setUp(self): self.__test_student = Student(1,"Alin",123) self.__test_assignment = Assignment(2,"lab12","11/11/2034") def test_model_get_set(self): self.assertEqual(self.__test_student.getGroup(),123) self.__test_student.setGroup(134) self.assertEqual(self.__test_student.getGroup() ,134) self.assertEqual(self.__test_assignment.getDescription(),"lab12") self.__test_assignment.setDescription("asd") self.assertEqual(self.__test_assignment.getDescription(),"asd")
def remove_student(user_id): user = session['user'] if user['type'] == 'Manager' or 'Mentor' or "Employee": student = Student.get_student_by_id(user_id) student.delete() return redirect(url_for('student_list')) return redirect(url_for('error.html'))
def check_attendance(): user = session['user'] if user['type'] != 'Mentor': return redirect(url_for('index')) return render_template('check_attendance.html', students=Student.get_list_of_students(), user=user)
def add_checkpoint(): """ GET: returns add assistant formula POST: returns list of assistant with new assistant added """ user = user_session(session['user'], session['type']) if isinstance(user, Mentor): if request.method == 'POST': if request.form['add_checkpoint']: students = Student.list_students() checkpoint_name = request.form['checkpoint_name'] date = request.form['date'] Checkpoint.add_checkpoint_students( checkpoint_name, date, user_session(session['user'], session['type']).id, students) flash('Checkpoint was added') return redirect( url_for('checkpoint_controller.list_checkpoints')) return render_template('add_checkpoint.html', user=user_session(session['user'], session['type'])) return render_template('404.html', user=user_session(session['user'], session['type']))
def list_students(): """ GET to generate a list of students """ students = Student.list_students() return render_template('viewstudents.html', user=user_session(session['user'], session['type']), students=students)
def getRandomStudent(self): #ID = random.randint(10000, 99999) ID = random.randint(74180, 74190) group = random.randint(100, 999) name = str( random.choice(self.__randomFirstName) + " " + random.choice(self.__randomSecondName)) return Student(ID, group, name)
def testUndoRedoStudent(self): self.__controllerStudents.addStudent(1,"alex",123) self.__undoAction.addToUndoList("1",Student(1,"alex",123)) self.__undoAction.addToRedoList("1",Student(1,"alex",123)) self.__undoAction.undoController() students = self.__controllerStudents.getAllStudents() self.assertEqual(students,[]) self.__undoAction.redoController() students = self.__controllerStudents.getAllStudents() self.assertEqual(len(students),1) self.__controllerStudents.removeStudent(1,"alex",123) self.__undoAction.addToUndoList("2",Student(1,"alex",123)) self.__undoAction.addToRedoList("2",Student(1,"alex",123)) self.__undoAction.undoController() students = self.__controllerStudents.getAllStudents() self.assertEqual(len(students),1) pass
def create(cls, csv_file='checker.csv'): if not os.path.exists(csv_file): name_to_csv(csv_file) df = pd.read_csv(csv_file, encoding='utf-8') df = df.fillna('') students = [Student.create(row) for i, row in df.iterrows()] classes = Classes(students) return classes
def details_student(user_id): user = session['user'] if user['type'] == 'Manager' or 'Manager' or "Employee": student_url = "student_list" return render_template('details_student.html', person=Student.get_student_by_id(user_id), url=student_url, user=user) return redirect(url_for('error.html'))
def get_checkpoint_username(self): """ Get student name :return: List of objects """ student = Student.get_by_id(self.student_id) if student: return student.username return None
def testSave(self): mike = Student(name='Mike Bloom', password='******', username='******', email='*****@*****.**') mike.save() mike.class_ = '1900' mike.save() mike2 = Student.findUser('mikebloom', 'password') self.assertEqual(mike2.class_, '1900', "Object returned has correct properties")
def statistics(): """Return statistics.html with Student objects.""" students = Student.list_students() if session['type'] == 'Student': students = [ student for student in students if student.id == int(session['user']) ] return render_template('statistics.html', user=user_session(session['user'], session['type']), students=students)
def removeStudent(self, id, name, group): ''' class function for removing a student in - id - student id name - student name group - student group out - raises: repoError in case the element doesn't exist ''' student = Student(id, name, group) self.__repoStudents.remove(student)
def we_have_the_following_students(context): students = {} for row in context.table: student_id = row['student_id'] firstname = row['firstname'] lastname = row['lastname'] students[student_id] = Student(student_id, firstname, lastname) context.students = students for value in students.values(): print(str(value)) pass
def __uiUpdateStudent(self): print("Updating a student...\nID:") id = int(input()) print("Name:") name = input() print("Group:") group = input() oldStudent = self.__controllerStudents.getStudentByID(id) self.__controllerStudents.updateStudentGroup(id, name, group) self.__undoAction.addToUndoList("3", oldStudent) self.__undoAction.addToRedoList("3", Student(id, name, group))
def add_student(): user = session['user'] if user['type'] == 'Manager' or 'Mentor' or "Employee": student_url = "student_list" if request.method == "POST": user_id = None login = request.form['login'] email = request.form['email'] name = request.form['name'] surname = request.form['surname'] date_of_birth = None city = None phone = None team_id = None card = None new_student = Student(user_id, name, surname, email, date_of_birth, city, phone, login, team_id, card) new_student.save() return redirect(url_for(student_url)) return render_template('add_student.html', url=student_url, user=user) return redirect(url_for('error.html'))
def delete(student_id): """ Remove student from list(data base) :param student_id: int GET return list of students without removed student """ student = Student.get_by_id(student_id) if student: student.delete_student() flash('Student was deleted') return redirect(url_for('student_controller.list_students')) return redirect(url_for('student_controller.list_students'))
def grade_user_assignments(username): """ Grade assignment of user if you are mentor :param username: :return: """ if request.method == "POST": if request.form['grade_user'] == 'grade': assignment_id = request.form['assignment'] student_id = request.form['id'] assignment = Assignment.get_by_id(assignment_id) student = Student.get_by_id(student_id) student_submit = Submition.get_submit(student_id, assignment_id) return render_template('grade_user_assignments.html', user=user_session(session['user'], session['type']), student=student, assignment=assignment, student_submit=student_submit) elif request.form['grade_user'] == 'Save': submit_id = request.form['submit_id'] new_grade = request.form['new_grade'] assignment_id = request.form['assignment_id'] assignment = Assignment.get_by_id(assignment_id) submit = Submition.get_by_id(submit_id) if assignment.type == 'group': team_id = Student.get_by_id(submit.student_id).team_id team = Team.get_by_id(team_id) team_members = team.get_members() for student in team_members: submit = Submition.get_submit(student.id, assignment_id) submit.update_grade(new_grade) else: submit.update_grade(new_grade) return redirect( url_for('assignment_controller.grade_assignment', assignmentID=assignment_id)) return render_template('404.html', user=user_session(session['user'], session['type']))
def addStudent(self, id, name, group): ''' class function for adding a student in - id - student id name - student name group - student group out - raises: repoError in case the element already exists validError in case the input is invalid ''' student = Student(id, name, group) self.__validatorStudents.validateStudent(student) self.__repoStudents.add(student)
def updateStudentGroup(self, id, name, newGroup): ''' class function for updating a student in - id - student id name - student name newGroup - student group to be updated out - raises: repoError in case the element doesn't exist validError in case the input is invalid ''' newStudent = Student(id, name, newGroup) self.__validatorStudents.validateStudent(newStudent) self.__repoStudents.update(newStudent)
def assigments(): user = session['user'] if user['type'] not in ('Mentor', 'Student'): return redirect(url_for('index')) assigments_list = Assigment.get_list_of_assigments() if user['type'] == 'Student': student = Student.get_student_by_id(user['id']) return render_template('assignment_list.html', assigments_list=assigments_list, user=user, student=student) return render_template('assignment_list.html', assigments_list=assigments_list, user=user)
def user_session(id, class_name): """Return object with given class name in class_name and id""" if class_name == "Student": return Student.get_by_id(id) elif class_name == "Mentor": return Mentor.get_by_id(id) elif class_name == "Employee": return Employee.get_by_id(id, 'assistant') elif class_name == "Manager": return Manager.get_by_id(id) return None
def __readStudents(self): ''' Class method to read the students from a file. This method will form a list of objects of type Student and return it. ''' file = open(self.__fileName, "r") content = file.readlines() students = IterableStructure() for line in content: line.strip() line = line.replace('\n', '') line = line.split(';') students.append(Student(int(line[0]), line[1], line[2])) file.close() return students
def add_user(self, username, password, is_student, course): if is_student: if username not in self.students.keys(): if self.users_database.add_student(username, password, course): self.students[username] = Student(username, password, course) return True return False else: if username not in self.valuers.keys(): if self.users_database.add_valuer(username, password): self.valuers[username] = Valuer(username, password) return True return False
def removeAssignedToGroup(self, group): ''' A function that removes a certain assignment that has been assigned to a group, to be used in the undo part. ''' grades = self.getAllGrades() ok = True while ok == True: ok = False for grade in grades: Student = self.__repoStudents.searchByID(grade.getStudentID()) if Student.getGroup() == group: try: self.__repoGrades.remove(grade) ok = True break except RepoError: return
def get(self): student = Student.get('name') self.render('user.html', student = student)
# encoding=utf-8 from peewee import fn from model.student import Student, db # 全部查询 print [(i.name, i.password, i.address, i.score) for i in Student.select()] # select()中可以选择要查询的列 # 条件查询 print [(i.name, i.password, i.address, i.score) for i in Student.select().where(Student.name == 'yanyu')] # 更新 query = Student.update(password='******').where(Student.name == 'yanyu') query.execute() # 插入数据(very fast) data_source = [ {'name': 'python', 'password': '******', 'address': 'Suzhou', 'score': 81}, {'name': 'golang', 'password': '******', 'address': 'Changzhou', 'score': 89}, {'name': 'ruby', 'password': '******', 'address': 'Taizhou', 'score': 54}, {'name': 'erlang', 'password': '******', 'address': 'Nantong', 'score': 71}, ] with db.atomic(): Student.insert_many(data_source).execute() # 排序 print [i.name for i in Student.select(Student.name).order_by(Student.score)] # 升序 print [i.name for i in Student.select(Student.name).order_by(+Student.score)] # 升序(第二种写法) print [i.name for i in Student.select(Student.name).order_by(Student.score.desc())] # 降序