示例#1
0
def app():
    "Initialize the app in test mode, initialises the DB, and adds some test cases"
    app = create_app('test')
    with app.test_request_context():
        db.create_all()
        # create a user
        user = User('default', '*****@*****.**', 'password')
        db.session.add(user)
        db.session.flush()
        # create a new group
        test_group = Group('TestGroup', user)
        db.session.add(test_group)
        db.session.flush()
        # add an issue to the group
        issue = Issue('REF', 'Description', test_group.id)
        db.session.add(issue)
        # Make the user a member of the group
        membership = Membership(test_group, user)
        db.session.add(membership)
        existing_group = Group('GroupAlreadyExists', user)
        db.session.add(existing_group)
        # Second user
        user = User('bob', '*****@*****.**', 'password')
        db.session.add(user)
        db.session.commit()
    return app
示例#2
0
    def show_add_class_once_window(self):
        discipline = Discipline()
        d_name = discipline.show_name(self.session)
        self.add_class_once_ui.comboBox.clear()
        self.add_class_once_ui.comboBox.addItems(d_name)

        c = ClassFormat()
        c_name = c.show_name(self.session)
        self.add_class_once_ui.comboBox_2.clear()
        self.add_class_once_ui.comboBox_2.addItems(c_name)

        group = Group()
        ls_name = group.show_name(self.session)
        self.add_class_once_ui.comboBox_4.clear()
        self.add_class_once_ui.comboBox_4.addItems(ls_name)

        a = Audience()
        a_name = a.show_name(self.session)
        self.add_class_once_ui.comboBox_3.clear()
        self.add_class_once_ui.comboBox_3.addItems(a_name)

        date_now = self.add_class_once_ui.dateEdit.date().currentDate()
        self.add_class_once_ui.dateEdit.setDate(date_now)
        time_now = self.add_class_once_ui.timeEdit.time().currentTime()
        self.add_class_once_ui.timeEdit.setTime(time_now)

        self.add_class_once_window.show()
示例#3
0
 def show_group_list_window(self):
     group = Group()
     ls_all = group.show_all(self.session)
     ls_all = np.array(ls_all)
     self.group_list_ui.tableWidget = set_items_to_table(
         self.group_list_ui.tableWidget, ls_all)
     self.group_list_ui.tableWidget.resizeColumnsToContents()
     self.group_list_window.show()
示例#4
0
    def open_grade_window(self):
        discipline = Discipline()
        d_name = discipline.show_name(self.session)
        self.grade_ui.comboBox.clear()
        self.grade_ui.comboBox.addItems(d_name)

        group = Group()
        ls_name = group.show_name(self.session)
        self.grade_ui.comboBox_2.clear()
        self.grade_ui.comboBox_2.addItems(ls_name)
        self.grade_window.show()
示例#5
0
    def update(self):
        note = self.textEdit.toPlainText()
        number = self.lineEdit.text()
        spec: str = self.comboBox.currentText()

        group = Group()
        group.update(self.session, self.update_value, number, note, spec)

        self.table.setItem(self.row, 0, QtWidgets.QTableWidgetItem(spec))
        self.table.setItem(self.row, 1, QtWidgets.QTableWidgetItem(number))
        self.table.setItem(self.row, 2, QtWidgets.QTableWidgetItem(note))

        self.update_group_window.close()
示例#6
0
    def delete(self):
        items = self.tableWidget.selectedItems()
        for i in items:
            row = self.tableWidget.row(i)
            number = self.tableWidget.item(row, 1).text()

            group = Group()
            group.delete(self.session, number)

            self.tableWidget.removeRow(row)
            self.combo.clear()
            ls_name = group.show_name(self.session)
            self.combo.addItems(ls_name)
示例#7
0
    def test_get_active_group(self):

        test_student_id = 1

        group = admin.get_active_group(test_student_id)

        it(group).should.be_equal(Group.get_by_id(2))
示例#8
0
    def import_csv(self):
        msg = QMessageBox()
        msg.setIcon(QMessageBox.Critical)
        try:
            path, _ = QtWidgets.QFileDialog.getOpenFileName(
                self.group_list_window, "Open Image", ".",
                "Image Files (*.csv)")

            with open(path, "r") as f_obj:
                reader = csv.reader(f_obj)
                group = Group()
                groups = group.show_name(self.session)

                for row in reader:
                    specialty = row[0]
                    number = row[1]
                    note = row[2]
                    flag_g = 0
                    for g in groups:
                        if number == g:
                            flag_g = 1
                            break

                    if flag_g == 0:
                        group.add(self.session, number, note, specialty)
                        number_row = self.tableWidget.rowCount()
                        self.tableWidget.setRowCount(number_row + 1)
                        self.tableWidget.setItem(
                            number_row, 0,
                            QtWidgets.QTableWidgetItem(specialty))
                        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_()
示例#9
0
 def add_group(self, input_group_id):
     with ses_scope(self.__engine) as ses:
         instance = ses.query(Group).filter(Group.group_id == input_group_id).first()
         if instance:
             return "You are already subscribed"
         else:
             group = Group(group_id=input_group_id)
             ses.add(group)
             return "Subscribe this group to notify list"
示例#10
0
    def add(self):
        number = self.lineEdit.text()
        note = self.textEdit.toPlainText()
        spec: str = self.comboBox.currentText()

        group = Group()
        group.add(self.session, number, note, spec)

        row = self.table.rowCount()

        self.table.setRowCount(row + 1)
        self.table.setItem(row, 0, QtWidgets.QTableWidgetItem(spec))
        self.table.setItem(row, 1, QtWidgets.QTableWidgetItem(number))
        self.table.setItem(row, 2, QtWidgets.QTableWidgetItem(note))

        self.combo.addItem(number)

        self.add_group_window.close()
示例#11
0
    def show_add_class_window(self):
        discipline = Discipline()
        d_name = discipline.show_name(self.session)
        self.add_class_ui.comboBox.clear()
        self.add_class_ui.comboBox.addItems(d_name)

        group = Group()
        ls_name = group.show_name(self.session)
        self.add_class_ui.comboBox_6.clear()
        self.add_class_ui.comboBox_6.addItems(ls_name)

        c = ClassFormat()
        c_name = c.show_name(self.session)
        self.add_class_ui.comboBox_2.clear()
        self.add_class_ui.comboBox_2.addItems(c_name)

        a = Audience()
        a_name = a.show_name(self.session)
        self.add_class_ui.comboBox_5.clear()
        self.add_class_ui.comboBox_5.addItems(a_name)

        s = Settings()
        schedule_format = s.get(self.session)
        if schedule_format == 0:
            s_name = ['Каждую неделю']
        else:
            s_name = ['Каждую неделю', '1-ая неделя', '2-ая неделя']
        self.add_class_ui.comboBox_4.clear()
        self.add_class_ui.comboBox_4.addItems(s_name)

        date_now = self.add_class_ui.dateEdit.date().currentDate()
        self.add_class_ui.dateEdit.setDate(date_now)
        self.add_class_ui.dateEdit_2.setDate(date_now)
        time_now = self.add_class_ui.timeEdit.time().currentTime()
        self.add_class_ui.timeEdit.setTime(time_now)

        self.add_class_window.show()
示例#12
0
def create_group(groupname):
    user = User.query.filter_by(nickname='default').first()
    group = Group.query.filter_by(name=groupname).first()
    if group:
        body = {"message": "Group already exists"}
        code = 400
        return jsonify(body), code
    else:
        print("Creating new group {}".format(groupname))
        group = Group(groupname, user)
        db.session.add(group)
        db.session.commit()
        body = {}
        code = 201
        return jsonify({}), code, {
            'location': url_for('api.query_group', groupname=groupname)
        }
示例#13
0
def create_group():
	form = NewGroupForm()
	id = -1
	if form.validate_on_submit():
		user = current_user
		nickname = user.nickname
		user_query = User.query.filter_by(nickname=nickname)
		group_name = form.group_name.data
		group_query = Group.query.filter_by(name=group_name, user=user.id)
		if group_query.count() > 0:
			error_message = 'That group already exists. Please try a different name.'
			back_url = url_for('web.index')
			return render_template('generic-error.html', error_message=error_message, back_url=back_url), 400
		else:
			group = Group(group_name, user)
			db.session.add(group)
			db.session.flush()
			id = group.id
			membership = Membership(group, user)
			db.session.add(membership)
		db.session.commit()
		return redirect(url_for('web.view_group', id=id))
	return redirect(url_for('web.index'))
示例#14
0
    def show_update_window(self):
        discipline = Discipline()
        d_name = discipline.show_name(self.session)
        self.update_class_ui.comboBox.clear()
        self.update_class_ui.comboBox.addItems(d_name)

        group = Group()
        ls_name = group.show_name(self.session)
        self.update_class_ui.comboBox_3.clear()
        self.update_class_ui.comboBox_3.addItems(ls_name)

        c = ClassFormat()
        c_name = c.show_name(self.session)
        self.update_class_ui.comboBox_2.clear()
        self.update_class_ui.comboBox_2.addItems(c_name)

        a = Audience()
        a_name = a.show_name(self.session)
        self.update_class_ui.comboBox_4.clear()
        self.update_class_ui.comboBox_4.addItems(a_name)

        items_1 = self.tableWidget.selectedItems()
        items_2 = self.tableWidget_2.selectedItems()
        items_3 = self.tableWidget_3.selectedItems()
        items_4 = self.tableWidget_4.selectedItems()
        items_5 = self.tableWidget_5.selectedItems()
        items_6 = self.tableWidget_6.selectedItems()

        for i in items_1:
            row = self.tableWidget.row(i)
            time_item = self.tableWidget.item(row, 0).text()
            discipline = self.tableWidget.item(row, 1).text()
            group = self.tableWidget.item(row, 3).text()
            o = Occupation
            update_value = o.get(self.session, time_item, discipline, group)

        for i in items_2:
            row = self.tableWidget_2.row(i)
            time_item = self.tableWidget_2.item(row, 0).text()
            discipline = self.tableWidget_2.item(row, 1).text()
            group = self.tableWidget_2.item(row, 3).text()
            o = Occupation
            update_value = o.get(self.session, time_item, discipline, group)

        for i in items_3:
            row = self.tableWidget_3.row(i)
            time_item = self.tableWidget_3.item(row, 0).text()
            discipline = self.tableWidget_3.item(row, 1).text()
            group = self.tableWidget_3.item(row, 3).text()
            o = Occupation
            update_value = o.get(self.session, time_item, discipline, group)

        for i in items_4:
            row = self.tableWidget_4.row(i)
            time_item = self.tableWidget_4.item(row, 0).text()
            discipline = self.tableWidget_4.item(row, 1).text()
            group = self.tableWidget_4.item(row, 3).text()
            o = Occupation
            update_value = o.get(self.session, time_item, discipline, group)

        for i in items_5:
            row = self.tableWidget_5.row(i)
            time_item = self.tableWidget_5.item(row, 0).text()
            discipline = self.tableWidget_5.item(row, 1).text()
            group = self.tableWidget_5.item(row, 3).text()
            o = Occupation
            update_value = o.get(self.session, time_item, discipline, group)

        for i in items_6:
            row = self.tableWidget_6.row(i)
            time_item = self.tableWidget_6.item(row, 0).text()
            discipline = self.tableWidget_6.item(row, 1).text()
            group = self.tableWidget_6.item(row, 3).text()
            o = Occupation
            update_value = o.get(self.session, time_item, discipline, group)

        try:
            discipline = update_value.discipline.name
            self.update_class_ui.discipline_old = discipline
            index = self.update_class_ui.comboBox.findText(discipline)
            self.update_class_ui.comboBox.setCurrentIndex(index)

            class_format = update_value.class_format.name
            self.update_class_ui.class_format_old = class_format
            index = self.update_class_ui.comboBox_2.findText(class_format)
            self.update_class_ui.comboBox_2.setCurrentIndex(index)

            group = update_value.group.number
            self.update_class_ui.group_old = group
            index = self.update_class_ui.comboBox_3.findText(group)
            self.update_class_ui.comboBox_3.setCurrentIndex(index)

            audience = update_value.audience.corps + " " + update_value.audience.number
            index = self.update_class_ui.comboBox_4.findText(audience)
            self.update_class_ui.comboBox_4.setCurrentIndex(index)

            format = '%H:%M'
            time = datetime.datetime.strptime(time_item, format).time()
            self.update_class_ui.timeEdit.setTime(time)

        except:
            return

        self.update_class_window.show()
示例#15
0
文件: moodle.py 项目: ArtemyD/Journal
def moodle_group(address, login, password, session) -> int:

    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()
                    driver.find_element_by_partial_link_text(
                        "Участники").click()
                    time.sleep(5)

                    # Синхронизация групп и студентов
                    i = 0
                    flag_e = 0
                    id_template = "user-index-participants-2_r"
                    while flag_e == 0:
                        try:
                            id = id_template + str(i)
                            tr = driver.find_element_by_id(id)
                            i += 1

                            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, ' ', ' ')

                        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
示例#16
0
 def show_student_window(self):
     group = Group()
     ls_name = group.show_name(self.session)
     self.student_ui.comboBox.clear()
     self.student_ui.comboBox.addItems(ls_name)
     self.student_window.show()
示例#17
0
def test_group_repr(default_user):
	expected = '<Estimation group: GroupName>'
	group = Group('GroupName', default_user)
	assert expected == group.__repr__()