def for_student(student_id, date_from = None, date_to = None): """ Retrives lessons for student filtered by date Keyword arguments: student_id - int ID of a student date_from - date in iso format string (!) or None (default: None) date_to - date in iso format string (!) or None (default: None) """ # Check if student exists try: Student.get_by_id(student_id) except Student.DoesNotExist: raise NoSuchDBRecordException("Student with id {} does not exist in database".format(student_id)) query = (Lesson .select(Lesson.name, Lesson.start, Lesson.end, Lesson.date, Room.name, Room.address, Group.name) .join(Group) .join(StudentToGroup) .join(Student) .switch(Lesson) .join(Room) .switch(Lesson) .where(Student.id == student_id) .order_by(Lesson.date, Lesson.start) ) if date_from != None: query = query.where(Lesson.date > date.fromisoformat(date_from)) if date_to != None: query = query.where(Lesson.date < date.fromisoformat(date_to)) return query_to_json_mapper(query)
def update(): #values = url.split('?')[-1] pk = int(request.args.get('id')) print pk student = Student( name=request.args.get('name'), gender=request.args.get('gender'), teacher=request.args.get('teacher'), grade=int(request.args.get('grade')), ) student.update().where(Student.id == pk) return render_template('index.html')
def create_student(): body = json.loads(request.data) email = body["email"] club_ids = body["club_ids"] student = Student( email=email ) existing_student = Student.query.filter_by(email=email).first() if existing_student is not None: db.session.delete(existing_student) club_list = [] for id in club_ids: club = Club.query.filter_by(id=id).first() if club is not None: student.clubs.append(club) club_list.append(club.name) else: return json.dumps({"Success": False, "data": "Club does not exist!"}), 201 db.session.add(student) db.session.commit() EMAIL_ADDRESS = '*****@*****.**' EMAIL_PASSWORD = '******' smtplibObj = smtplib.SMTP('smtp.gmail.com', 587) smtplibObj.ehlo() smtplibObj.starttls() smtplibObj.login(EMAIL_ADDRESS, EMAIL_PASSWORD) club_message = '' for club in club_list: club_message += club + '\n ' subject = 'Clubby confirmation email' body = ' You have successfully registered in our Clubby notification system! Here is a list of ' + ( 'project teams you subscribed: \n\n ') + club_message + '\n You will receive email notification when ' + ( 'these teams update their application info.') msg = f'Subject: {subject}\n\n{body}' try: smtplibObj.sendmail(EMAIL_ADDRESS, email, msg) except: print("Internal error") return json.dumps({"Success": False, "data": "Email is not valid!"}), 400 return json.dumps({"Success": True, "data": student.serialize()}), 201
def add(): try: student = Student( name=request.args.get('name'), gender=request.args.get('gender'), teacher=request.args.get('teacher'), grade=int(request.args.get('grade')), ) student.save() flash("%s 已增加" % student.name) except Exception as e: flash(str(e)) return redirect(url_for('index'))
def add_student_to_user(user_id): body = json.loads(request.data) if body.get("description") is None: return failure_response( missing_parameter_response(body, ["description"])) user = User.query.filter_by(id=user_id).first() if user is None: return failure_response("Given user id is not associated with a user!") desc = body.get("description") new_student = Student(user_id=user_id, description=desc) user.student.append(new_student) DB.session.add(new_student) DB.session.commit() return success_response(new_student.serialize(), 201)
def create(data, fail_silently=False): students_affected = ( Student.select(Student.id) .join(StudentToGroup) .join(Group) .where(Group.id == data['group']) ) count_conflict_lessons = ( Lesson.select() .join(Room).switch(Lesson) .join(Lecturer).switch(Lesson) .join(Group).join(StudentToGroup).join(Student).switch(Lesson) .where( (Lesson.date == data['date']) & ( (data['start'] >= Lesson.start) & (data['start'] <= Lesson.end) | (data['end'] >= Lesson.start) & ( data['end'] <= Lesson.end) ) & ( (Lesson.room == data['room']) | (Lesson.lecturer == data['lecturer']) | (Lesson.group == data['group']) ) ) .group_by(Lesson) .count() ) if (count_conflict_lessons == 0): l = Lesson(**data) l.save() elif not fail_silently: raise Exception(f'Lessons conflicting: {count_conflict_lessons}')
def select(): try: pk = int(request.args.get('id')) student = Student.select().where(Student.id == pk) return render_template('update.html', student=student[0]) except Exception as e: flash(str(e))
def save(): email_adress = request.form["email_adress"] dob = request.form["dob"] course = request.form["course"] names = request.form["names"] gender = request.form["gender"] country = request.form["country"] try: Student.create(email_adress=email_adress, dob=dob, course=course, names=names, gender=gender, country=country) except peewee.IntegrityError: return "Record alreasdy exists" return render_template("form.html")
def run(args, db): from db import Student, TranscriptEntry as Entry id = args.student if id.startswith('0') or id.startswith('2'): s = Student.get(student_id=int(id)) else: s = Student.get(username=id) print('%-20s %09d %s' % (s.name(), s.student_id, s.email())) for e in Entry.select().where(Entry.student == s.student_id).order_by(Entry.year, Entry.term): if e.mark is None: continue print('%4s %-4s %04d%02d %3d' % ( e.subject, e.code, e.year, e.term, e.mark))
def rm(): try: pk = int(request.args.get('id')) student = Student.get(id=pk) student.delete_instance() flash("%s 已删除" % student.name) except Exception as e: flash(str(e)) return redirect(url_for('index'))
def menu(): print "Welcome!" while 1: print "1. Add a student" print "2. Delete student data" print "3. Modify student details" print "4. List all students" print "5. Add a course" print "6. Delete course data" print "7. Modify course details" print "8. List all courses" print "9. Enroll student in course" print "10. Show enrollments of a student" print "11. Show enrollments of a course" print "12. Archive old enrollments" print "13. Exit" ch = raw_input("What would you like to do? ") if ch == "1": Student.new_student(students, branches) elif ch == "2": Student.delete_student(students, enrollments) elif ch == "3": Student.modify_student(students) elif ch == "4": Student.list_students(students, branches) elif ch == "5": Course.new_course(courses, branches) elif ch == "6": Course.delete_course(courses, enrollments) elif ch == "7": Course.modify_course(courses) elif ch == "8": Course.list_courses(courses, branches) elif ch == "9": Enrollment.new_enrollment(enrollments, students, courses) elif ch == "10": Enrollment.list_enrollments_stu(enrollments, archived_enrolls, students, courses) elif ch == "11": Enrollment.list_enrollments_cou(enrollments, archived_enrolls, students, courses) elif ch == "12": Enrollment.archive_enrollments(enrollments, archived_enrolls) elif ch == "13": print "\nBye!\n" break else: print "\nNot Valid Choice! Try again!\n" save()
def add(): info = raw_input('请输入学员信息(姓名,性别,年龄,所在地,qq号)各项信息之间用逗号分隔:') if ',' in info: columns = info.split(',') elif ',' in info: columns = info.split(',') db = get_db() if db: no = max(db.keys()) + 1 # 编号递增 else: no = 1 columns.insert(0, no) student = Student(*columns) db[no] = student save_db(db)
def update(no=None): if not no: try: no = int(raw_input("输入学员编号:")) except TypeError: print '编号类型错误' update() info = raw_input('请输入学员信息(姓名,性别,年龄,所在地,qq号)各项信息之间用逗号分隔:') if ',' in info: columns = info.split(',') elif ',' in info: columns = info.split(',') columns = map(str.strip, columns) db = get_db() columns.insert(0, no) student = Student(*columns) db[no] = student save_db(db)
def insert(): rooms = [{ 'name': '1', 'address': 'address1', 'id': 1 }, { 'name': '10', 'address': 'address1', 'id': 2 }, { 'name': '20', 'address': 'address1', 'id': 3 }, { 'name': '30', 'address': 'address1', 'id': 4 }, { 'name': '40', 'address': 'address1', 'id': 5 }, { 'name': '1', 'address': 'address2', 'id': 6 }, { 'name': '5', 'address': 'address2', 'id': 7 }, { 'name': '10', 'address': 'address2', 'id': 8 }, { 'name': '15', 'address': 'address2', 'id': 9 }, { 'name': '20', 'address': 'address2', 'id': 10 }] Room.insert_many(rooms).execute() lecturers = [{ 'name': 'Lecturer One' }, { 'name': 'Lecturer One' }, { 'name': 'Lecturer Two' }, { 'name': 'Lecturer Three' }, { 'name': 'Lecturer Four' }] Lecturer.insert_many(lecturers).execute() groups = [{ 'name': 'stream1', 'id': 1 }, { 'name': 'stream2', 'id': 2 }, { 'name': 'group1', 'parentGroupId': 1, 'id': 3 }, { 'name': 'group2', 'parentGroupId': 1, 'id': 4 }, { 'name': 'group3', 'parentGroupId': 2, 'id': 5 }, { 'name': 'group4', 'parentGroupId': 2, 'id': 6 }, { 'name': 'group5', 'id': 7 }] Group.insert_many(groups).execute() students = [{'id': i, 'name': 'student ' + str(i)} for i in range(1, 41)] Student.insert_many(students).execute() stg = [{'StudentID': i, 'GroupID': 1} for i in range(1, 21)] stg += [{'StudentID': i, 'GroupID': 2} for i in range(21, 41)] stg += [{'StudentID': i, 'GroupID': 3} for i in range(1, 11)] stg += [{'StudentID': i, 'GroupID': 4} for i in range(11, 21)] stg += [{'StudentID': i, 'GroupID': 5} for i in range(21, 31)] stg += [{'StudentID': i, 'GroupID': 6} for i in range(31, 41)] stg += [{'StudentID': i, 'GroupID': 7} for i in range(1, 41, 5)] StudentToGroup.insert_many(stg).execute() dates = [ date(2020, 2, 10), date(2020, 2, 11), date(2020, 2, 12), date(2020, 2, 13) ] times = [(time(9, 30), time(11, 5)), (time(11, 15), time(12, 50)), (time(13, 40), time(15, 15))] lessons = [] for d in dates: (s, e) = times[0] #print(e) lessons.append({ 'group': 1, 'room': 1, 'lecturer': 1, 'name': 'Lecture', 'start': s, 'end': e, 'date': d }) lessons.append({ 'group': 2, 'room': 2, 'lecturer': 2, 'name': 'Lecture', 'start': s, 'end': e, 'date': d }) (s, e) = times[1] lessons.append({ 'group': 3, 'room': 3, 'lecturer': 3, 'name': 'Practice', 'start': s, 'end': e, 'date': d }) lessons.append({ 'group': 4, 'room': 4, 'lecturer': 4, 'name': 'Practice', 'start': s, 'end': e, 'date': d }) lessons.append({ 'group': 5, 'room': 1, 'lecturer': 1, 'name': 'Practice', 'start': s, 'end': e, 'date': d }) lessons.append({ 'group': 6, 'room': 2, 'lecturer': 2, 'name': 'Practice', 'start': s, 'end': e, 'date': d }) (s, e) = times[2] lessons.append({ 'group': 7, 'room': 3, 'lecturer': 3, 'name': 'Elective', 'start': s, 'end': e, 'date': d }) print(lessons) Lesson.insert_many(lessons).execute()
def students(): return Student.select()
def home(): students = Student.select() return render_template("users_table.html", students=students)
def deleting_students(id): s = Student.get(Student.id == id) s.delete_instance() return redirect(url_for('home'))
def index(): students = Student.select() return render_template('index.html', students=students)
def lessons_students(student_id): return render_template('lessons/student.html', student=Student.get_by_id(student_id))