def import_csv(self): msg = QMessageBox() msg.setIcon(QMessageBox.Critical) try: path, _ = QtWidgets.QFileDialog.getOpenFileName( self.student_list_window, "Open Image", ".", "Image Files (*.csv)") with open(path, "r") as f_obj: reader = csv.reader(f_obj) student = Student() students = student.show_name(self.session, self.group_number) for row in reader: fio = row[0] number = row[1] note = row[2] flag_s = 0 for s in students: if fio == s: flag_s = 1 break if flag_s == 0: student.add(self.session, fio, number, note, self.group_number) number_row = self.tableWidget.rowCount() self.tableWidget.setRowCount(number_row + 1) self.tableWidget.setItem( number_row, 0, QtWidgets.QTableWidgetItem(fio)) self.tableWidget.setItem( number_row, 1, QtWidgets.QTableWidgetItem(str(number))) self.tableWidget.setItem( number_row, 2, QtWidgets.QTableWidgetItem(str(note))) self.tableWidget.resizeColumnsToContents() msg.setText("Импорт выполнен") msg.setInformativeText('Импорт данных из CSV выполнен.') msg.setWindowTitle("Импорт выполнен") except: msg.setText("Импорт не выполнен") msg.setInformativeText('Импорт данных из CSV не выполнен.') msg.setWindowTitle("Импорт не выполнен") msg.exec_()
def show_add_safety_student_window(self): student = Student() s_name = student.show_name(self.session, self.group_number) self.add_safety_student_ui.comboBox.clear() self.add_safety_student_ui.comboBox.addItems(s_name) safety = Safety() safe_name = safety.all_name(self.session, self.discipline_name, self.group_number) self.add_safety_student_ui.comboBox_2.clear() self.add_safety_student_ui.comboBox_2.addItems(safe_name) date_now = self.add_safety_student_ui.dateEdit.date().currentDate() self.add_safety_student_ui.dateEdit.setDate(date_now) self.add_safety_student_ui.group_number = self.group_number self.add_safety_student_ui.discipline_name = self.discipline_name self.add_safety_student_window.show()