Example #1
0
 def s_enroll_course_data(self):
     '''populates general course information for student to view'''
     self.ui.stackedWidget_2.setCurrentIndex(1)
     info = sql.get(
         "SELECT course_name, hours, department FROM university.course")
     for row_number, row_data in enumerate(info):
         for column_number, data in enumerate(row_data):
             self.ui.s_enroll_enroll_table.setItem(
                 row_number, column_number, qtw.QTableWidgetItem(str(data)))
     self.ui.s_enroll_enroll_table.resizeColumnsToContents()
Example #2
0
 def s_classgrades_enrolled_classes(self, username):
     '''gets a list of classes student is enrolled in upon login'''
     class_list = []
     table_info = sql.get(
         "SELECT class_id \
                                       FROM university.enrolled \
                                       WHERE user_id=%s", username)
     for tuple in table_info:
         class_list = class_list + list(tuple)
     self.ui.s_classgrades_class_drop.addItems(class_list)
     return class_list
Example #3
0
 def t_profile_profile_data(self):
     '''populates teacher users info from sql db onto table'''
     self.ui.stackedWidget_3.setCurrentIndex(0)
     username = self.ui.l_username_field.text()
     info = sql.get(
         "SELECT f_name, l_name, address, city, state, dob, phone, email \
                                 FROM university.person WHERE user_id=%s",
         username)
     for row_number, row_data in enumerate(info):
         for column_number, data in enumerate(row_data):
             self.ui.t_profile_table.setItem(
                 row_number, column_number, qtw.QTableWidgetItem(str(data)))
     self.ui.t_profile_table.resizeColumnsToContents()
Example #4
0
 def t_grades_grade_data(self):
     '''obtains test grades for each teacher's class and displays message if there are no test grades for the class'''
     self.ui.t_grades_allgrades_table.clearContents()
     self.ui.t_grades_nogrades_label.clear()
     course = self.ui.t_grades_class_drop.currentText()
     info = sql.get(
         "SELECT user_id, test_number, test_date, grade FROM university.grades WHERE class_id=%s",
         (course))
     if info == ():
         self.ui.t_grades_nogrades_label.setText("No test grades available")
     for row_number, row_data in enumerate(info):
         for column_number, data in enumerate(row_data):
             self.ui.t_grades_allgrades_table.setItem(
                 row_number, column_number, qtw.QTableWidgetItem(str(data)))
Example #5
0
 def login(self):
     '''logs into main window based on role (student, teacher, admin)'''
     if self.ui.l_username_field.text() and self.ui.l_password_field.text():
         username = self.ui.l_username_field.text()
         password = self.ui.l_password_field.text()
     else:
         return self.message("Missing Information",
                             "Please enter a username and password")
     info = sql.get(
         "SELECT user_id, password FROM university.login WHERE user_id=%s AND password=%s",
         (username, password))
     if info != ():
         query = sql.get(
             "SELECT role_id, f_name, l_name FROM university.person WHERE user_id=%s",
             username)
         role, first, last = query[0]
         if role == 1:
             self.ui.stackedWidget.setCurrentIndex(2)
             self.ui.stackedWidget_2.setCurrentIndex(0)
             self.ui.s_userwelcome_field.setText("{} {}".format(
                 first, last))
             self.s_classgrades_enrolled_classes(username)
             self.s_profile_profile_data()
             self.showMaximized()
             return username
         elif role == 2:
             self.ui.stackedWidget.setCurrentIndex(3)
             self.ui.stackedWidget_3.setCurrentIndex(0)
             self.ui.t_userwelcome_field.setText("{} {}".format(
                 first, last))
             self.t_grades_teacher_classes(username)
             self.t_profile_profile_data()
             self.showMaximized()
             return username
     else:
         self.message("Invalid Username/Password",
                      "No Such Username/Password")
Example #6
0
 def t_get_student_names_edit(self):
     '''Fetches test numbers for selected student'''
     self.ui.t_editgrade_testno_drop.clear()
     course = self.ui.t_editgrade_class_drop.currentText()
     info = sql.get(
         "SELECT user_id, test_number \
                                 FROM university.grades \
                                 WHERE class_id=%s", (course))
     name = self.ui.t_editgrade_name_drop.currentText()
     number = []
     for tuple in info:
         if tuple[0] == name:
             n = str(tuple[1])
             number.append(n)
     self.ui.t_editgrade_testno_drop.addItems(number)
Example #7
0
 def s_courseenroll_class_data(self, row):
     '''populates specific classes available to enroll in selected general course'''
     self.ui.stackedWidget_2.setCurrentIndex(2)
     course = self.ui.s_enroll_enroll_table.item(row, 0).text()
     self.ui.s_courseenroll_coursename_field.setText(course)
     info = sql.get(
         "SELECT hours, course_description FROM university.course WHERE course_name = %s",
         course)
     hours, course_description = info[0]
     self.ui.s_courseenroll_credits_field.setText(str(hours))
     self.ui.s_courseenroll_coursedesc_field.setText(course_description)
     self.ui.s_profile_profile_table.resizeColumnsToContents()
     table_info = sql.get(
         "SELECT c.start_date, c.end_date, c.room, c.instructor, o.course_number \
                                       FROM university.class c \
                                       JOIN university.course o ON c.course_number = o.course_number \
                                       WHERE o.course_name=%s \
                                       AND c.start_date>%s",
         [course, datetime.date.today()])
     self.ui.s_courseenroll_classes_table.setRowCount(len(table_info))
     for row_number, row_data in enumerate(table_info):
         for column_number, data in enumerate(row_data):
             self.ui.s_courseenroll_classes_table.setItem(
                 row_number, column_number, qtw.QTableWidgetItem(str(data)))
Example #8
0
 def t_get_students_add(self):
     '''Fetches student names for the selected class'''
     self.ui.t_addgrade_name_drop.clear()
     course = self.ui.t_addgrade_class_drop.currentText()
     info = sql.get(
         "SELECT user_id, test_number \
                                 FROM university.grades \
                                 WHERE class_id=%s", (course))
     name = []
     if info == ():
         self.message("No Students Exist",
                      "No students currently enrolled in this class")
     for tuple in info:
         if tuple[0] not in name:
             name.append(tuple[0])
     self.ui.t_addgrade_name_drop.addItems(name)
Example #9
0
 def t_grades_teacher_classes(self, username):
     '''gets a list of classes teacher is instructor of upon login and adds to drop downs'''
     class_list = []
     table_info = sql.get(
         "SELECT c.class_id \
                                       FROM university.class c \
                                       JOIN university.person p ON c.instructor = p.user_id \
                                       WHERE p.user_id=%s", username)
     for tuple in table_info:
         class_list = class_list + list(tuple)
     self.ui.t_grades_class_drop.addItems(class_list)
     # Populates addgrade_class_drop combo box with class list
     self.ui.t_addgrade_class_drop.addItems(class_list)
     # Populates editgrade_class_drop combo box with class list
     self.ui.t_editgrade_class_drop.addItems(class_list)
     return class_list
Example #10
0
 def t_addgrade(self):
     '''Adds student test grade to class db'''
     course = self.ui.t_addgrade_class_drop.currentText()
     name = self.ui.t_addgrade_name_drop.currentText()
     test = self.ui.t_addgrade_testno_field.text()
     test = int(test)
     date = self.ui.t_addgrade_testdate_field.text()
     grade = self.ui.t_addgrade_grade_field.text()
     query = sql.get(
         "SELECT class_id, user_id, test_number \
                                 FROM university.grades \
                                 WHERE class_id=%s AND user_id=%s AND test_number=%s",
         (course, name, test))
     if query == ():
         sql.write(
             "INSERT INTO university.grades (class_id, user_id, test_number, test_date, grade) VALUES (%s,%s,%s,%s,%s)",
             (course, name, test, date, grade))
         self.message("Grade Added", "Test grade added")
     else:
         self.message("Error",
                      "Student already has grade entered for test number")
Example #11
0
 def t_editgrade(self):
     '''Edits existing student test grade to class db'''
     course = self.ui.t_editgrade_class_drop.currentText()
     name = self.ui.t_editgrade_name_drop.currentText()
     test = self.ui.t_editgrade_testno_drop.currentText()
     test = int(test)
     grade = self.ui.t_editgrade_grade_field.text()
     query = sql.get(
         "SELECT class_id, user_id, test_number \
                                 FROM university.grades \
                                 WHERE class_id=%s AND user_id=%s AND test_number=%s",
         (course, name, test))
     if query != ():
         sql.write(
             "UPDATE university.grades SET grade=%s \
                            WHERE class_id=%s AND user_id=%s AND test_number=%s",
             (grade, course, name, test))
         self.message("Grade Added", "Test grade updated")
     else:
         self.message(
             "No Test",
             "Cannot update a test that doesn't exist. Add grade first")
Example #12
0
 def s_classgrades_test_grade_data(self):
     '''obtains test grades for student and determines course overall grade'''
     self.ui.s_classgrades_grades_table.clearContents()
     course = self.ui.s_classgrades_class_drop.currentText()
     username = self.ui.l_username_field.text()
     info = sql.get(
         "SELECT test_date, grade FROM university.grades WHERE user_id=%s AND class_id=%s",
         (username, course))
     if info == ():
         self.ui.s_classgrades_totalgrade_field.setText(
             "No grade available")
     else:
         lis = []
         for x in range(len(info)):
             lis.append(info[x][1])
             avg = sum(lis) / len(lis)
         self.ui.s_classgrades_totalgrade_field.setText(
             "CLASS GRADE: {:.1f}%".format(avg))
         for row_number, row_data in enumerate(info):
             for column_number, data in enumerate(row_data):
                 self.ui.s_classgrades_grades_table.setItem(
                     row_number, column_number,
                     qtw.QTableWidgetItem(str(data)))
Example #13
0
 def s_courseenroll_enroll_in_class(self):
     row = self.ui.s_courseenroll_classes_table.currentRow()
     username = self.ui.l_username_field.text()
     start = self.ui.s_courseenroll_classes_table.item(row, 0).text()
     course = self.ui.s_courseenroll_classes_table.item(row, 4).text()
     query = sql.get_one(
         "SELECT class_id FROM university.class \
                                       WHERE course_number=%s AND start_date=%s",
         (course, start))
     course_number = query[0]
     query = sql.get(
         "SELECT role_id FROM university.enrolled WHERE user_id=%s AND class_id=%s",
         (username, course_number))
     if query == ():
         sql.write(
             "INSERT INTO university.enrolled (user_id, class_id, role_id) VALUES (%s,%s,1)",
             (username, course_number))
         self.ui.s_classgrades_class_drop.clear()
         self.s_classgrades_enrolled_classes(username)
         self.message("Student Enrolled", "You are enrolled in " + course)
     else:
         self.message("Enrollment Error",
                      "You are already enrolled in this class")