コード例 #1
0
def config_reg():
    form = StudentsAccessForm()
    form.semester.choices = [(semester['_id'], semester['semester'])
                             for semester in Database.db["semester"].find({})]
    if request.method == 'GET':
        return render_template("reg_portal.html", form=form)
    else:
        students_list = request.files['students']
        students = []
        if students_list.filename.split('.')[
                len(students_list.filename.split('.')) - 1] != "txt":
            Message.valid_file_upload_fail()
        else:
            for line in students_list.readlines():
                reg_nums = re.search(pattern="[0-9]{2}[A-Z]{3}[0-9]{4}",
                                     string=line.decode("UTF-8"))
                if reg_nums:
                    students.append(reg_nums.group())
            semester = request.form['semester']
            Database.db["course_registration_access"].update_one(
                {'semester': semester}, {
                    '$set': {
                        'students_allowed':
                        list(
                            set(students + Database.
                                db["course_registration_access"].find_one(
                                    {'semester': semester})['students_allowed']
                                if Database.db["course_registration_access"].
                                find_one({'semester': semester}
                                         ) is not None else students))
                    }
                },
                upsert=True)
        return redirect("/")
コード例 #2
0
def update_semester():
    if Semester.update_semester(
            database=Database.db,
            id=request.form['sem-id'],
            semester=request.form['semester']).matched_count != 1:
        Message.update_semester_fail()
    return redirect("/")
コード例 #3
0
def delete_teacher():
    if Teacher.delete_teacher(
            database=Database.db,
            prof_id=request.form["prof-id"]).deleted_count == 1:
        Message.delete_teacher_record_success()
    else:
        Message.delete_teacher_record_fail()
    return redirect("/")
コード例 #4
0
def delete_course():
    if Courses.delete_course(
            database=Database.db,
            course_id=request.form["course-id"]).deleted_count == 1:
        Message.delete_course_success()
    else:
        Message.delete_course_fail()
    return redirect("/")
コード例 #5
0
def delete_student():
    if Student.delete_student(
            database=Database.db,
            reg_no=request.form["student-reg-no"]).deleted_count == 1:
        Message.delete_student_record_success()
    else:
        Message.delete_student_record_fail()
    return redirect("/")
コード例 #6
0
def add_semester():
    semester = Semester(sem_id=request.form['sem-id'],
                        semester=request.form['semester'],
                        database=Database.db)
    if semester.is_id_available:
        semester.save_to_mongo(database=Database.db)
    else:
        Message.add_semester_fail()
    return redirect("/")
コード例 #7
0
def update_course():
    if Courses.update_course(
            database=Database.db,
            course_id=request.form["course-id"],
            course_title=request.form["course-title"]).matched_count == 1:
        Message.update_course_success()
    else:
        Message.update_course_fail()
    return redirect("/")
コード例 #8
0
def add_course():
    course = Courses(db=Database.db,
                     course_id=request.form["course-id"],
                     course_title=request.form["course-title"])
    if course.is_success:
        Message.add_course_success()
        course.save_to_mongo(database=Database.db)
    else:
        Message.add_course_fail()
    return redirect("/")
コード例 #9
0
def add_batch():
    courses = [course for course in Database.db["courses"].find({})]
    teachers = get_prof(course_id=courses[0]['_id'])
    semesters = [semester for semester in Database.db["semester"].find({})]
    form = AddBatchForm(courses=courses)
    form.course.choices = [(course['_id'], course['course_title'])
                           for course in courses]
    form.teacher.choices = [(teacher['_id'], teacher['name'])
                            for teacher in teachers]
    form.semester.choices = [(semester['_id'], semester['semester'])
                             for semester in semesters]
    if request.method == 'GET':
        return render_template("add_batch.html", form=form)
    else:
        is_slot_available = True

        prof_id = request.form['teacher']
        prof_name = Database.db['teacher_details'].find_one({'_id':
                                                             prof_id})['name']
        course_id = request.form['course']
        course_title = Database.db['courses'].find_one({'_id': course_id
                                                        })['course_title']
        available_seats = request.form['seats']
        semester_id = request.form['semester']
        slot = request.form['slot']
        temp = Database.db["teacher_slots"].find({
            'semester_id': semester_id,
            'teacher': prof_id
        })
        for t in temp:
            temp_slot = t['slot']
            if slot in clashing_slots.get(temp_slot, []):
                is_slot_available = False

        if is_slot_available:
            Batch(prof_id=prof_id,
                  prof_name=prof_name,
                  course_id=course_id,
                  course_title=course_title,
                  available_seats=available_seats,
                  slot=slot,
                  semester=semester_id).save_to_mongo(database=Database.db)
            Database.db["teacher_slots"].insert_one({
                'semester_id':
                request.form['semester'],
                'teacher':
                request.form['teacher'],
                'slot':
                request.form['slot']
            })
        else:
            Message.add_batch_fail()

        return redirect("/")
コード例 #10
0
def update_student():
    if Student.update_details(database=Database.db,
                              reg_no=request.form["student-reg-no"],
                              name=request.form["student-name"],
                              phone_no=request.form["student-phone-number"],
                              address=request.form["student-address"],
                              mother_name=request.form["student-mother-name"],
                              father_name=request.form["student-father-name"]
                              ).matched_count == 1:
        Message.update_student_success()
    else:
        Message.update_student_fail()
    return redirect("/")
コード例 #11
0
def add_student():
    student = Student(db=Database.db,
                      reg_no=request.form["student-reg-no"],
                      name=request.form["student-name"],
                      password=request.form["student-initial-password"],
                      phone_no=request.form["student-phone-number"],
                      address=request.form["student-address"],
                      mother_name=request.form["student-mother-name"],
                      father_name=request.form["student-father-name"])
    if student.is_success:
        Message.add_student_record_success()
        student.save_to_mongo(Database.db)
        return redirect("/")
    else:
        Message.add_student_record_fail()
        return redirect("/")
コード例 #12
0
def update_teacher():
    courses = [course for course in request.form["teacher-courses"].split(',')]
    if Courses.check_courses(database=Database.db, courses=courses):
        Message.course_found_success()
    else:
        Message.course_found_fail()
    temp = Teacher.update_teacher(database=Database.db,
                                  prof_id=request.form["prof-id"],
                                  name=request.form["teacher-name"],
                                  phone_no=request.form["teacher-phone-no"],
                                  address=request.form["teacher-address"],
                                  courses=courses)
    if temp.matched_count == 1:
        Message.update_teacher_record_success()
    else:
        Message.update_teacher_record_fail()
    return redirect("/")
コード例 #13
0
def delete_semester():
    if Semester.delete_semester(database=Database.db,
                                id=request.form['sem-id']).deleted_count != 1:
        Message.delete_semester_fail()
    return redirect("/")
コード例 #14
0
def add_teacher():
    teacher = Teacher(db=Database.db,
                      prof_id=request.form["prof-id"],
                      name=request.form["teacher-name"],
                      phone_no=request.form["teacher-phone-no"],
                      address=request.form["teacher-address"],
                      password=request.form["teacher-password"],
                      courses=request.form["teacher-courses"])
    if teacher.is_success and teacher.is_course:
        Message.add_teacher_record_success()
        Message.course_found_success()
        teacher.save_to_mongo(database=Database.db)
    elif not teacher.is_course and teacher.is_success:
        Message.course_found_fail()
    elif not teacher.is_success and teacher.is_course:
        Message.add_teacher_record_fail()
    elif not teacher.is_success and not teacher.is_course:
        Message.add_teacher_record_fail()
        Message.course_found_fail()
    return redirect("/")