def accept(self) -> None: self.popup = MessagePopup() if self.IDInput.text() == "" or (self.IDInput.text() == "" and self.barcodeInput.text() == ""): message = "Enter valid ID (8 digits) or barcode (14 digits)" self.popup.show_message(message) self.IDInput.setFocus() return if self.firstnameInput.text() == "" or self.lastnameInput.text() == "": message = "Enter first name and last name" self.popup.show_message(message) self.firstnameInput.setFocus() return if self.classTable.rowCount() == 0: message = "Select a class" self.popup.show_message(message) self.classListComboBox.setFocus() return success = Database.add_student(self.IDInput.text(), self.firstnameInput.text(), self.lastnameInput.text(), self.barcodeInput.text(), self.emailInput.text()) message = "" if success: count = 0 while count < self.classTable.rowCount(): self.classTable.selectRow(count) selected_class = self.classTable.selectedItems() result = Database.register_student(self.IDInput.text(), self.firstnameInput.text(), self.lastnameInput.text(), selected_class[0].text(), selected_class[1].text(), selected_class[2].text()) a_class = combine_into_class(selected_class[0].text(), selected_class[1].text(), selected_class[2].text()) if type(result) is tuple and result == (True, True): message += "Student was successfully registered for " + a_class + "\n" count += 1 elif type(result) is tuple and result == (True, False): message += "Student is already registered for " + a_class + "\n" elif type(result) is not tuple and result == False: message += "The class " + a_class + " does not exist\n" else: message = "Student could not be added to system because student is already in the system" print(message) self.popup.show_message(message) self.close()
def add_button_clicked(self): if self.windowTitle() == "Add Student": result = Database.add_student(self.EIDInput.text(), self.firstNameInput.text(), self.lastNameInput.text(), self.barcodeInput.text(), self.emailInput.text()) if result is True: self.accept() else: print("could not add student") else: result = Database.add_professor(self.firstNameInput.text(), self.lastNameInput.text(), self.emailInput.text()) if result is True: self.accept() else: print("could not add professor")
def fill_table(self): model = QtGui.QStandardItemModel() model.setHorizontalHeaderItem(0, QtGui.QStandardItem("Empl ID")) model.setHorizontalHeaderItem(1, QtGui.QStandardItem("Last Name")) model.setHorizontalHeaderItem(2, QtGui.QStandardItem("First Name")) model.setHorizontalHeaderItem(3, QtGui.QStandardItem("Barcode")) model.setHorizontalHeaderItem(4, QtGui.QStandardItem("Email")) students = Database.get_all_students() count = 0 for student in students: self.studentsTable.setRowCount(count + 1) self.studentsTable.setItem(count, 0, QtWidgets.QTableWidgetItem(student["eid"])) self.studentsTable.setItem(count, 1, QtWidgets.QTableWidgetItem(student["last_name"])) self.studentsTable.setItem(count, 2, QtWidgets.QTableWidgetItem(student["first_name"])) self.studentsTable.setItem(count, 3, QtWidgets.QTableWidgetItem(student["barcode"])) self.studentsTable.setItem(count, 4, QtWidgets.QTableWidgetItem(student["email"])) model.setItem(count, 0, QtGui.QStandardItem(student["eid"])) model.setItem(count, 1, QtGui.QStandardItem(student["last_name"])) model.setItem(count, 2, QtGui.QStandardItem(student["first_name"])) model.setItem(count, 3, QtGui.QStandardItem(student["barcode"])) model.setItem(count, 4, QtGui.QStandardItem(student["email"])) count += 1 self.numStudentsLabel.setText(str(self.studentsTable.rowCount())) completer = QtWidgets.QCompleter() completer.setFilterMode(QtCore.Qt.MatchContains) completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive) completer.setModel(model) completer.setPopup(QtWidgets.QTableView()) completer.popup().setMinimumHeight(250) self.searchbar.setCompleter(completer)
def sign_in_button_clicked(self): login_time = datetime.datetime.utcnow() logout_time = "" selected_class = self.classTable.selectedItems() student = { "eid": self.studentEIDLabel.text(), "barcode": self.studentBarcodeLabel.text(), "first_name": self.student_name["first"], "last_name": self.student_name["last"], "subject": selected_class[0].text(), "catalog": selected_class[1].text(), "section": selected_class[2].text(), "login_time": login_time, "logout_time": logout_time, "service": self.serviceList.currentItem().text() } if Database.signn_in(student): self.popup = MessagePopup() self.popup.fill_in(self.studentNameLabel.text(), "SIGN IN SUCCESS") self.popup.show() self.close() QtCore.QTimer.singleShot(5000, self.popup.close) else: print("Failed to sign in student")
def fill_in(self): self.courseNameLabel.setText(self.subject + " " + self.catalog + " - " + self.section) model = QtGui.QStandardItemModel() model.setHorizontalHeaderItem(0, QtGui.QStandardItem("Empl ID")) model.setHorizontalHeaderItem(1, QtGui.QStandardItem("Last Name")) model.setHorizontalHeaderItem(2, QtGui.QStandardItem("First Name")) students = Database.get_class_roster(self.subject, self.catalog, self.section) count = 0 for stud in students["class_roster"]: self.studentsTable.setRowCount(count + 1) self.studentsTable.setItem(count, 0, QtWidgets.QTableWidgetItem(stud["student_eid"])) self.studentsTable.setItem(count, 1, QtWidgets.QTableWidgetItem(stud["student_last_name"])) self.studentsTable.setItem(count, 2, QtWidgets.QTableWidgetItem(stud["student_first_name"])) model.setItem(count, 0, QtGui.QStandardItem(stud["student_eid"])) model.setItem(count, 1, QtGui.QStandardItem(stud["student_last_name"])) model.setItem(count, 2, QtGui.QStandardItem(stud["student_first_name"])) count += 1 self.numStudentsLabel.setText(str(self.studentsTable.rowCount())) completer = QtWidgets.QCompleter() completer.setFilterMode(QtCore.Qt.MatchContains) completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive) completer.setModel(model) completer.setPopup(QtWidgets.QTableView()) completer.popup().setMinimumHeight(230) self.searchbar.setCompleter(completer) self.searchbar.completer().activated[QtCore.QModelIndex].connect(self.handle_activated)
def init_ui(self): model = QtGui.QStandardItemModel() model.setHorizontalHeaderItem(0, QtGui.QStandardItem("Last Name")) model.setHorizontalHeaderItem(1, QtGui.QStandardItem("First Name")) model.setHorizontalHeaderItem(2, QtGui.QStandardItem("Email")) profs = Database.get_all_professors() count = 0 for prof in profs: model.setItem(count, 0, QtGui.QStandardItem(prof["last_name"])) model.setItem(count, 1, QtGui.QStandardItem(prof["first_name"])) model.setItem(count, 2, QtGui.QStandardItem(prof["email"])) count += 1 completer = QtWidgets.QCompleter() completer.setFilterMode(QtCore.Qt.MatchContains) completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive) completer.setModel(model) popup = QtWidgets.QTableView() popup.setModel(model) popup.setMinimumSize(320, 250) completer.setPopup(popup) self.newProfessorDropDown.setCompleter(completer) self.newProfessorDropDown.setModel(model) self.newProfessorDropDown.setView(QtWidgets.QTableView()) self.cancelButton.clicked.connect(self.cancel_button_clicked) self.okButton.clicked.connect(self.ok_button_clicked) self.newProfessorDropDown.activated.connect(self.dropdown_activated) self.newProfessorDropDown.completer().activated[ QtCore.QModelIndex].connect(self.completer_activated) self.newSubjectInput.textEdited.connect(self.edit_subject_text) self.newCatalogInput.textEdited.connect(self.edit_catalog_text) self.newSectionInput.textEdited.connect(self.edit_section_text)
def ok_button_clicked(self): if self.windowTitle() == "Edit Student": student = {"eid": self.newEIDInput.text(), "barcode": self.newBarcodeInput.text(), "last_name": self.newLastNameInput.text(), "first_name": self.newFirstNameInput.text(), "email": self.newEmailInput.text()} result = Database.update_student(self.ogEIDInput.text(), student) if result is True: self.accept() else: print("couldn't update student") else: og_prof = {"last_name": self.ogLastNameInput.text(), "first_name": self.ogFirstNameInput.text(), "email": self.ogEmailInput.text()} professor = {"last_name": self.newLastNameInput.text(), "first_name": self.newFirstNameInput.text(), "email": self.newEmailInput.text()} result = Database.update_professor(og_prof, professor) if result is True: self.accept() else: print("couldn't update professor")
def delete_button_clicked(self): if self.windowTitle() == "Delete Student": result = Database.remove_student(self.eid) if result is True: self.accept() else: print("could not delete student") elif self.windowTitle() == "Delete Professor?": result = Database.remove_professor(self.first, self.last, self.email) if result is True: self.accept() else: print("could not delete professor") else: result = Database.remove_class(self.subject, self.catalog, self.section) if result is True: self.accept() else: print("could not delete course")
def add_button_clicked(self): professor = { "first_name": self.prof_first, "last_name": self.prof_last, "email": self.prof_email } result = Database.add_class(self.subjectInput.text(), self.catalogInput.text(), self.sectionInput.text(), professor) if result is True: self.accept() else: print("could not add course")
def fill_in(self, student): # some students have more than one name as a first name so store their name from the db to ensure it's correct # for later use self.student_name["first"] = student["first_name"] self.student_name["last"] = student["last_name"] self.studentEIDLabel.setText(student["eid"]) self.studentBarcodeLabel.setText(student["barcode"]) self.studentNameLabel.setText(student["first_name"] + " " + student["last_name"]) self.semesterList.addItem(Database.get_semester_name()) self.semesterList.setCurrentRow(0) services = Database.get_all_services() for service in services: self.serviceList.addItem(service["service"]) self.serviceList.sortItems(0) self.serviceList.setCurrentRow(0) self.classTable.setRowCount(len(student["enrolled_list"])) count = 0 while count < len(student["enrolled_list"]): self.classTable.setItem( count, 0, QtWidgets.QTableWidgetItem( student["enrolled_list"][count]["subject"])) self.classTable.setItem( count, 1, QtWidgets.QTableWidgetItem( student["enrolled_list"][count]["catalog"])) self.classTable.setItem( count, 2, QtWidgets.QTableWidgetItem( student["enrolled_list"][count]["section"])) count += 1 self.classTable.sortItems(0) self.classTable.selectRow(0)
def init_ui(self): self.closeWindowButton.clicked.connect(self.close_button_clicked) self.checked_in_list = Database.get_current_logins() self.loginList.setRowCount(self.checked_in_list.count()) self.numberOfStudents.setText(str(self.checked_in_list.count())) count = 0 for student in self.checked_in_list: self.loginList.setItem(count, 0, QtWidgets.QTableWidgetItem(student["last_name"])) self.loginList.setItem(count, 1, QtWidgets.QTableWidgetItem(student["first_name"])) self.loginList.setItem(count, 2, QtWidgets.QTableWidgetItem(convert_time(student["login_time"]))) self.loginList.setItem(count, 3, QtWidgets.QTableWidgetItem(student["logout_time"])) a_class = combine_into_class(student["subject"], student["catalog"], student["section"]) self.loginList.setItem(count, 4, QtWidgets.QTableWidgetItem(a_class)) self.loginList.setItem(count, 5, QtWidgets.QTableWidgetItem(student["service"])) count += 1 self.loginList.sortItems(0)
def init_ui(self): class_list = Database.get_all_class_names() formatted_class_list = [] for a_class in class_list: formatted_class_list.append( combine_into_class(a_class["subject"], a_class["catalog"], a_class["section"])) self.classes.append(a_class) self.classListComboBox.addItems(formatted_class_list) completer = QtWidgets.QCompleter(formatted_class_list) completer.setFilterMode(QtCore.Qt.MatchContains) completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive) self.classListComboBox.setCompleter(completer) self.classListComboBox.setCurrentIndex(-1) self.classListComboBox.currentIndexChanged.connect( self.add_class_to_table) self.classTable.itemDoubleClicked.connect( self.table_item_double_clicked)
def ok_button_clicked(self): professor = { "first_name": self.prof_first, "last_name": self.prof_last, "email": self.prof_email } course = { "subject": self.newSubjectInput.text(), "catalog": self.newCatalogInput.text(), "section": self.newSectionInput.text(), "professor": professor } old_course = { "subject": self.ogSubjectInput.text(), "catalog": self.ogCatalogInput.text(), "section": self.ogSectionInput.text() } result = Database.update_class(old_course, course) if result is True: self.accept() else: print("couldn't update course")
def fill_in(self, student_id, first, last): self.EIDInput.setText(student_id) self.firstNameInput.setText(first) self.lastNameInput.setText(last) classes = Database.get_student_classes(student_id) count = 0 for a_class in classes["enrolled_list"]: self.classesTable.setRowCount(count + 1) self.classesTable.setItem( count, 0, QtWidgets.QTableWidgetItem(a_class["subject"])) self.classesTable.setItem( count, 1, QtWidgets.QTableWidgetItem(a_class["catalog"])) self.classesTable.setItem( count, 2, QtWidgets.QTableWidgetItem(a_class["section"])) # this has to be changed self.classesTable.setItem( count, 3, QtWidgets.QTableWidgetItem( (a_class["registered_by"]))) self.classesTable.setItem( count, 4, QtWidgets.QTableWidgetItem(a_class["registered_date"])) count += 1
def fill_table(self): model = QtGui.QStandardItemModel() model.setHorizontalHeaderItem(0, QtGui.QStandardItem("Last Name")) model.setHorizontalHeaderItem(1, QtGui.QStandardItem("First Name")) model.setHorizontalHeaderItem(2, QtGui.QStandardItem("Email")) profs = Database.get_all_professors() count = 0 for prof in profs: self.professorsTable.setRowCount(count + 1) self.professorsTable.setItem( count, 0, QtWidgets.QTableWidgetItem(prof["last_name"])) self.professorsTable.setItem( count, 1, QtWidgets.QTableWidgetItem(prof["first_name"])) self.professorsTable.setItem( count, 2, QtWidgets.QTableWidgetItem(prof["email"])) model.setItem(count, 0, QtGui.QStandardItem(prof["last_name"])) model.setItem(count, 1, QtGui.QStandardItem(prof["first_name"])) model.setItem(count, 2, QtGui.QStandardItem(prof["email"])) count += 1 self.numProfessorsLabel.setText(str(self.professorsTable.rowCount())) completer = QtWidgets.QCompleter() completer.setFilterMode(QtCore.Qt.MatchContains) completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive) completer.setModel(model) popup = QtWidgets.QTableView() popup.setModel(model) popup.setMinimumWidth(530) popup.setMinimumHeight(250) popup.setColumnWidth(0, 150) popup.setColumnWidth(1, 150) popup.setColumnWidth(2, 215) completer.setPopup(popup) self.searchbar.setCompleter(completer)
def accept(self) -> None: if self.studentIDInput.hasAcceptableInput( ) or self.studentIDInput.text() == "": result = Database.get_student_data(self.studentIDInput.text()) if result is None: if len(self.studentIDInput.text()) == 8: message = "No student with ID " + self.studentIDInput.text( ) + " found" else: message = "No student with barcode " + self.studentIDInput.text( ) + " found" self.popup = MessagePopup() self.popup.show_message(message) return else: checkouts = MediaDatabase.get_student_checkouts(result["eid"]) self.media_checkout_page = MediaCheckoutPage() self.media_checkout_page.enter_data(result["eid"], result["barcode"], result["first_name"], result["last_name"], checkouts) self.media_checkout_page.show() self.hide()
def evaluate_input(self, student_id): return Database.evaluate_input(student_id)
def test_db_uri_2(self): actual = Database.db_uri('/path with space', 'file.db') self.assertEqual(actual, 'sqlite:////path with space/file.db')
from tkinter import * from server import Database database=Database("books.db") # Button command functions def get_selected_row(event): try: global selected_tuple index=list1.curselection()[0] selected_tuple=list1.get(index) e1.delete(0,END) e1.insert(END,selected_tuple[1]) e2.delete(0,END) e2.insert(END,selected_tuple[2]) e3.delete(0,END) e3.insert(END,selected_tuple[3]) e4.delete(0,END) e4.insert(END,selected_tuple[4]) except IndexError: pass def view_command(): list1.delete(0,END) for row in database.view(): list1.insert(END,row) def search_command(): list1.delete(0,END) for row in database.search(title_text.get(),author_text.get(),year_text.get(),isbn_text.get()): list1.insert(END,row) def add_command(): database.insert(title_text.get(),author_text.get(),year_text.get(),isbn_text.get())
def fill_table(self): model = QtGui.QStandardItemModel() model.setHorizontalHeaderItem(0, QtGui.QStandardItem("Subject")) model.setHorizontalHeaderItem(1, QtGui.QStandardItem("Catalog")) model.setHorizontalHeaderItem(2, QtGui.QStandardItem("Section")) model.setHorizontalHeaderItem(3, QtGui.QStandardItem("# of Students")) model.setHorizontalHeaderItem(4, QtGui.QStandardItem("Professor")) model.setHorizontalHeaderItem(5, QtGui.QStandardItem("Professor Email")) model.setHorizontalHeaderItem(6, QtGui.QStandardItem("Course")) model.setHorizontalHeaderItem(7, QtGui.QStandardItem("UniqueIndex")) courses = Database.get_classes_with_size() count = 0 for course in courses: self.coursesTable.setRowCount(count + 1) self.coursesTable.setItem( count, 0, QtWidgets.QTableWidgetItem(course["subject"])) self.coursesTable.setItem( count, 1, QtWidgets.QTableWidgetItem(course["catalog"])) self.coursesTable.setItem( count, 2, QtWidgets.QTableWidgetItem(course["section"])) self.coursesTable.setItem( count, 3, QtWidgets.QTableWidgetItem(str(course["count"]))) if course["professor"] != {}: self.coursesTable.setItem( count, 4, QtWidgets.QTableWidgetItem( course["professor"]["first_name"] + " " + course["professor"]["last_name"])) self.coursesTable.setItem( count, 5, QtWidgets.QTableWidgetItem(course["professor"]["email"])) else: self.coursesTable.setItem(count, 4, QtWidgets.QTableWidgetItem("")) self.coursesTable.setItem(count, 5, QtWidgets.QTableWidgetItem("")) self.coursesTable.setItem( count, 6, QtWidgets.QTableWidgetItem(course["subject"] + course["catalog"] + course["section"])) model.setItem(count, 0, QtGui.QStandardItem(course["subject"])) model.setItem(count, 1, QtGui.QStandardItem(course["catalog"])) model.setItem(count, 2, QtGui.QStandardItem(course["section"])) model.setItem(count, 3, QtGui.QStandardItem(str(course["count"]))) if course["professor"] != {}: model.setItem( count, 4, QtGui.QStandardItem(course["professor"]["first_name"] + " " + course["professor"]["last_name"])) model.setItem( count, 5, QtGui.QStandardItem(course["professor"]["email"])) else: model.setItem(count, 4, QtGui.QStandardItem("")) model.setItem(count, 5, QtGui.QStandardItem("")) model.setItem( count, 6, QtGui.QStandardItem( combine_into_class(course["subject"], course["catalog"], course["section"]))) model.setItem( count, 7, QtGui.QStandardItem(course["subject"] + course["catalog"] + course["section"])) count += 1 self.coursesTable.setColumnHidden(6, True) self.numCoursesLabel.setText(str(self.coursesTable.rowCount())) completer = QtWidgets.QCompleter() completer.setFilterMode(QtCore.Qt.MatchContains) completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive) completer.setModel(model) popup = QtWidgets.QTableView() popup.setModel(model) popup.setColumnHidden(6, True) popup.setColumnHidden(7, True) popup.setMinimumWidth(805) popup.setMinimumHeight(300) popup.setColumnWidth(4, 170) popup.setColumnWidth(5, 220) completer.setPopup(popup) self.searchbar.setCompleter(completer) self.searchbar.completer().setCompletionColumn(6)