Exemple #1
0
    def verifyCredentials(self):
        conn = connect()
        # only allow login as student for the time being
        username_query = """SELECT DISTINCT username, password, studentid FROM student"""
        rs = conn.execute(username_query)
        usernames = rs.fetchall()

        # Allow 3 attempts to correctly enter username
        user = self.enterUsername(usernames)
        name_count = 1
        while user is None:
            print("Please try again.")
            if name_count == 3:
                print(
                    "You have exceeded the number of tries for this session.")
                return
            user = self.enterUsername(usernames)
            name_count += 1

        # Allow 3 attempts to correctly enter password
        pass_count = 1
        student_id = self.enterPassword(user)
        while student_id is None:
            print("Please try again.")
            if pass_count == 3:
                print(
                    "You have exceeded the number of tries for this session.")
                return
            student_id = self.enterPassword(user)
            pass_count += 1

        return student_id
def make_course(courseid):
    conn = connect()
    query = select_query + where_clause
    rs = conn.execute(query.format('course', 'courseid', courseid))
    course = rs.fetchone()

    if course is not None:
        courseid = course[0]
        dept = course[1]
        title = course[2]

        cb = CourseBuilder()
        cb.course = Course()
        cb.getId(courseid)
        cb.getTitle(title)
        cb.getDepartment(dept)
        cb.getSections(
            make_sections(conn, section_query, enrollment_query, courseid,
                          "'" + current_term() + "'"))
        cb.getEnrollmentUpdates()
        cb.getPrereqs(prereqs(conn, cb.course._coursenum))
        c = cb.getItem()
    else:
        c = None

    return c
 def addSection(self, studentid, courseid, db=True):
     if self.enrollment is None:
         self.enrollment = []
     self.enrollment.append(studentid)
     if db:
         value = "(" + str(studentid) + "," + str(courseid) + "," + str(
             self._sectionid) + ",'" + self.term + "')"
         add(connect(), 'grades', '(studentid, courseid, sectionid, term)',
             value)
 def viewCourses(self):
     if len(self.currentCourses) == 0:
         print("You are not registered for any courses this term.")
     else:
         course_input = ', '.join(
             [str(coursenum) for coursenum in self.currentCourses])
         print(course_input)
         print("You are currently enrolled in: ")
         view_courses(connect(), course_input)
def make_students():
    # call function with no arguments
    conn = connect()
    rs = conn.execute(select_query.format('student'))
    students = rs.fetchall()

    student_obj = {}
    for student in students:
        studentid = student[0]
        firstname = student[1]
        lastname = student[2]
        username = student[3]
        password = student[4]

        pastGrades = {}
        currentCourses = []
        crs = conn.execute(grades_query.format(studentid))
        courses = crs.fetchall()
        for course in courses:
            courseid = course[0]
            title = course[1]
            sectionid = course[2]
            term = course[3]
            grade = course[4]

            if grade is None:
                currentCourses.append(courseid)
            else:
                if term not in pastGrades:
                    pastGrades[term] = []
                pastGrades[term].append(
                    list((courseid, title, sectionid, grade)))

        sb = StudentBuilder()
        sb.person = Student()
        sb.getId(studentid)
        sb.getFirstname(firstname)
        sb.getLastname(lastname)
        sb.getUsername(username)
        sb.getPassword(password)
        sb.getPastGrades(pastGrades)
        sb.getCurrentCourses(currentCourses)
        s = sb.getPerson()
        student_obj[s._studentid] = s

    return student_obj
 def __init__(self):
     self.conn = db.connect()
 def dropSection(self, studentid, coursenum, db=True):
     self.enrollment.remove(studentid)
     if db:
         drop(connect(), studentid, coursenum)
 def changePassword(self, db=True):
     super().changePassword()
     if db:
         update(connect(), 'student', 'password',
                "'" + self._password + "'", 'studentid', self._studentid)
 def generateUsername(self, db=True):
     self.username = super().generateUsername()
     if db:
         update(connect(), 'student', 'username', "'" + self.username + "'",
                'studentid', self._studentid)
 def changePassword(self):
     super().changePassword()
     update(connect(), 'instructor', 'password', "'" + self._password + "'",
            'instructorid', self._instructorid)
 def generateUsername(self):
     self.username = super().generateUsername()
     update(connect(), 'instructor', 'username', "'" + self.username + "'",
            'instructorid', self._instructorid)