def student_register(username, password): stu_obj = Student.select(username) if stu_obj: return False, "学生已存在" Student(username, password) return True, "学生%s注册成功" % username
def next(self): group_number = self.comboBox.currentText() student = Student() student_name = student.all_name(self.session, group_number) self.student_analytics_ui.comboBox.clear() self.student_analytics_ui.comboBox.addItems(student_name) self.student_analytics_ui.update(self.dark_theme) self.student_analytics_ui.group = group_number self.student_analytics_window.show()
def delete(self): items = self.tableWidget.selectedItems() for i in items: row = self.tableWidget.row(i) record_book = self.tableWidget.item(row, 1).text() student = Student() student.delete(self.session, record_book) self.tableWidget.removeRow(row)
def update(self): name = self.lineEdit.text() record_book = self.lineEdit_2.text() student = Student() student.update(self.session, self.update_value, name, record_book) self.table.setItem(self.row, 0, QtWidgets.QTableWidgetItem(name)) self.table.setItem(self.row, 1, QtWidgets.QTableWidgetItem(record_book)) self.update_student_window.close()
def show_student_list(self): student = Student() group_number: str = self.comboBox.currentText() ls_all: list = student.all(self.session, group_number) ls_all: np.ndarray = np.array(ls_all) self.student_list_ui.tableWidget = set_items_to_table( self.student_list_ui.tableWidget, ls_all, DARK_THEME=self.dark_theme) self.student_list_ui.update_window(self.dark_theme) self.student_list_ui.tableWidget.resizeColumnsToContents() self.student_list_ui.label.setText("Список группы: №" + str(group_number)) self.student_list_ui.group_number = str(group_number) self.student_list_window.show()
def check_score(name): stu_obj = Student.select(name) if not stu_obj.score: return False return stu_obj.score
def add(self): name = self.lineEdit.text() record_book = self.lineEdit_2.text() student = Student() student.add(self.session, name, record_book, self.group_number) number = self.table.rowCount() self.table.setRowCount(number + 1) self.table.setItem(number, 0, QtWidgets.QTableWidgetItem(name)) self.table.setItem(number, 1, QtWidgets.QTableWidgetItem(record_book)) self.lineEdit.clear() self.lineEdit_2.clear() self.add_student_window.close()
def go_page2(self, event): name = self.inpt_name.GetValue() name = name.replace(' ', '') familia = self.inpt_familia.GetValue() if len(familia) == 0: self.empty_pole() return group = self.inpt_group.GetValue() if len(group) == 0: self.empty_pole() return zach_number = self.inpt_zachetka.GetValue() zach_number = zach_number.replace(' ', '') if len(zach_number) == 0: self.empty_pole() return fio = str(familia).lower() + ' ' + str(name).lower() new_session = Session() if new_session.query(exists().where(Student.fname == fio). where(Student.group == group).where(Student.zach_number == zach_number)).scalar(): print("ЗАГРУЖАЮ ВАШЕ ЗАДАНИЕ") else: print("пора занести вас в базу и придумать для вас задание") student = Student(fname=fio, group=group, zach_number=zach_number) new_session.add(student) new_session.commit() from gui import SecondPage SecondPage.SecondPage.OnInit(SecondPage) self.Destroy()
def choose_course(student_name, course_name): stu_obj = Student.select(student_name) if course_name in stu_obj.courses: return False, "学生已选择过此课程" stu_obj.choose_course(course_name) return True, "选择课程%s成功" % course_name
def choose_school(student_name, school_name): stu_obj = Student.select(student_name) if stu_obj.school_name: return False, "学生已选择过学校" stu_obj.choose_school(school_name) return True, "选择校区%s" % school_name
def import_from_csv(self): # msg = QMessageBox() # msg.setIcon(QMessageBox.Critical) # try: path, _ = QtWidgets.QFileDialog.getOpenFileName(self.student_window, "Open Image", ".", "Image Files (*.csv)") with open(path, "r") as f_obj: reader = csv.reader(f_obj) for row in reader: name = row[0] record_book = int(row[1]) student = Student() student.add(self.session, name, record_book) number = self.tableWidget.rowCount() self.tableWidget.setRowCount(number + 1) self.tableWidget.setItem(number, 0, QtWidgets.QTableWidgetItem(name)) self.tableWidget.setItem(number, 1, QtWidgets.QTableWidgetItem(str(record_book))) self.tableWidget.resizeColumnsToContents()
def test_list_students(self): session = SessionLocal() session.add_all([ Student(name=f'fake name {i}', email=f'fake email {i}') for i in range(10) ]) session.commit() response = self.client.get('/students/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertIsInstance(response.json(), list) self.assertEqual(len(response.json()), 10)
def modify_student_score(course_name, student_name, score: int): stu_obj = Student.select(student_name) Teacher.modify_student_score(stu_obj, course_name, score) return True, "修改%s的%s成绩为%s成功" % (student_name, course_name, str(score))
def get_courses_list(stu_name): stu_obj = Student.select(stu_name) school_obj = School.select(stu_obj.school_name) return school_obj.courses
def parser_moodle(address, login, password, session) -> int: # address = 'https://cp29191-wordpress-8.tw1.ru' # login = "******" # password = "******" login_address = address + "/login/index.php" chrome_options = webdriver.ChromeOptions() chrome_options.add_argument("--ignore-certificate-errors") driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=chrome_options) try: driver.get(login_address) username = driver.find_element_by_id('username') username.click() username.send_keys(login) password_ = driver.find_element_by_id("password") password_.click() password_.send_keys(password) submit = driver.find_element_by_id("loginbtn") submit.click() time.sleep(1) number_course = 0 while number_course != -1: courses = driver.find_elements_by_class_name( 'list-group-item-action') flag = 0 this_number_course = 0 flag_number_course = 0 for course in courses: if flag == 1 and this_number_course == number_course: # Синхронизация дисциплин c = course c.click() title = driver.title name_course = title.split('Курс: ')[1] d = Discipline() discipline = d.all(session) flag_d = 0 for d in discipline: if d.name == name_course: flag_d = 1 break if not flag_d: d.add(session, discipline) driver.find_element_by_partial_link_text( "Участники").click() time.sleep(5) # Синхронизация групп и студентов i = 0 flag_e = 0 id_template = "user-index-participants-4_r" while flag_e == 0: try: id = id_template + str(i) tr = driver.find_element_by_id(id) i += 1 name = tr.find_elements_by_class_name('c1') name = name[0].text role = tr.find_elements_by_class_name('c3') role = role[0].text group = tr.find_elements_by_class_name('c4') group = group[0].text if role == 'Студент': g = Group() g_names = g.show_name(session) g_flag = 0 for g_name in g_names: if g_name == group: g_flag = 1 break if g_flag == 0: g.add(session, group, 'Информационная безопасность') s = Student() s_names = s.all(session, group) s_flag = 0 for s_name in s_names: if s_name == name: s_flag = 1 break if s_flag == 0: record_book = randint(100000, 999999) s.add(session, name, record_book, group) except: flag_e = 1 driver.back() time.sleep(3) driver.back() time.sleep(3) number_course += 1 flag_number_course = 1 break elif flag == 1: this_number_course += 1 if course.text == "Личные файлы": flag = 1 if flag_number_course == 0: number_course = -1 driver.close() return 0 except: driver.close() return 1
def stu_register(name, pwd): if Student.select(name): return False, '学生已存在' stu_obj = Student(name, pwd) stu_obj.save() return True, f'学生{name}注册成功'
def create(self, name: str, email: str) -> Student: db_student = Student(name=name, email=email) self.db.add(db_student) self.db.commit() self.db.refresh(db_student) return db_student
def check_school(name): stu_obj = Student.select(name) if not stu_obj.school_name: return False, "学生还没有选择学校" return True, "学校已选择"
async def post(self): """ 注册weid,其中kyc认证部分暂时忽略,后续可自行调整 :return: """ r_dict = {'respBody': '', 'errorCode': 200, 'errorMessage': 'success'} category = int(self.get_i_argument('category')) if category == 0: stuId = self.get_i_argument('stuId') name = self.get_i_argument('name') school = self.get_i_argument('school') id_card = self.get_i_argument('id_card') try: res = requests.post(host, json=Args.register_weid).json() print(res) _, tx_hash = fisco_client.fisco_add_data( 'insertStudent', [res['respBody'], stuId, id_card, name, school]) student = Student() student.weid = res['respBody'] student.school = school student.name = name student.stuId = stuId student.idCard = id_card student.tx_hash = tx_hash await student.save() r_dict['respBody'] = res['respBody'] except Exception: logger.error(traceback.format_exc()) return r_dict elif category == 1: name = self.get_i_argument('name') location = self.get_i_argument('location') business = self.get_i_argument('business') try: res = requests.post(host, json=Args.register_weid).json() print(res) _, tx_hash = fisco_client.fisco_add_data( 'insertCompany', [res['respBody'], name, location, business]) company = Company() company.name = name company.location = location company.business = business company.weid = res['respBody'] company.tx_hash = tx_hash await company.save() r_dict['respBody'] = res['respBody'] except Exception: logger.error(traceback.format_exc()) return r_dict else: name = self.get_i_argument('name') school = self.get_i_argument('school') teacher_id = self.get_i_argument('teacher_id') try: res = requests.post(host, json=Args.register_weid).json() # fisco_client.fisco_add_data('insetCompany', [name, location, business, res['respBody']]) teacher = Teacher() teacher.weid = res['respBody'] teacher.school = school teacher.name = name teacher.teacher_id = teacher_id await teacher.save() res['user_cid'] = teacher.cid res['category'] = 2 r_dict['respBody'] = res['respBody'] except Exception: pass return r_dict
def add_new_student(first_name, last_name): student = Student(first_name=first_name.capitalize(), last_name=last_name.capitalize()) db.session.add(student) return student
def admin(request): try: if (not 'uid' in request.session) or (request.session['group']!='a'): return HttpResponseRedirect('/login/') except KeyError: return HttpResponseRedirect('/login/') hint = '' if 'box' in request.GET: boxlist = request.GET.getlist('box') for j in boxlist: para = int(j) classID = Class_Course_Relation.objects.filter(cID = para) for i in classID: t = Assignment.objects.filter(clID = i.clID) for k in t: u = AssignmentFile.objects.filter(asID = k.asID) for l in u: default_storage.delete('/home/tunghsu/workspace/SAMS/media/'+str(AssignmentFile.objects.get(asfID=l.asfID).asFile)) AssignmentFile.objects.filter(asID = k.asID).delete() Assignment.objects.filter(clID = i.clID).delete() Student_Class_Relation.objects.filter(clID = i.clID).delete() Class_Course_Relation.objects.filter(cID = j).delete() Course.objects.filter(cID = j).delete() hint = 'Course Deleted' if 'q' in request.POST:#需要后台检测字符转换数字 if request.POST['q'] == 'student': instance = Student(sID=request.POST['uid'], sName=request.POST['name'],sPasswd=request.POST['passwd'],sMail=request.POST['mail']) instance.save() hint = 'Add Student Done!' elif request.POST['q'] == 'teacher': instance = Teacher(tID=request.POST['uid'], tName=request.POST['name'],tPasswd=request.POST['passwd'],tMail=request.POST['mail']) instance.save() hint = 'Add Teacher Done!' elif request.POST['q'] == 'admin': instance = Administrator(aID=request.POST['uid'], aName=request.POST['name'],aPasswd=request.POST['passwd'],aMail=request.POST['mail']) instance.save() hint = 'Add Admin Done!' if 'id' in request.POST: para = int (request.POST['id']) instance = Course(cID=para, cName=request.POST['name']) instance.save() hint = 'Add Course Done!' if 'amount' in request.POST: instance = Class_Course_Relation(cID=request.POST['courseID'], clID=request.POST['classID'],tID=request.POST['teacher'],cPopu=request.POST['amount']) instance.save() hint = 'Add class Done!' if 'className' in request.POST: num = Student_Class_Relation.objects.filter(sID = request.POST['uid']).order_by('-sClID')[0]+1 instance = Student_Class_Relation(sID=request.POST['uid'], clID=request.POST['className'],sClID=num) instance.save() hint = 'Add Student to Class Done!' m = Course.objects.all().order_by("cID") line ={} matrix = [] for i in m: line['courseName'] = i.cName line['courseID'] = i.cID tmp ='%d' % i.cID line['viewcourse'] = 'http://localhost:8000/download/course/'+tmp matrix.append(dict(line)) return render_to_response('admin.html', {'title': "管理页面", 'hint':hint, 'matrix':matrix})