コード例 #1
0
ファイル: bot.py プロジェクト: rukarangi/CustomReacter
async def deleteUser(message, m):
    """
	Delete user by name --Admin only
	"""
    admin = message.channel.permissions_for(message.author).administrator
    if admin:
        content = message.content
        command = re.search("\$\w+\s\w+$", content).group()[1:]
        name = command.split(" ")[1]

        user = dbSession.query(User).filter_by(name=name).first()

        #print(user)

        if user:
            dbSession.query(User).filter_by(name=name).delete()
            dbSession.commit()
        else:
            await message.channel.send("This user does not exist")

        print(command, name)
    else:
        await message.channel.send(
            "You do not have permission to use that command.")

    return
コード例 #2
0
ファイル: views.py プロジェクト: aminkashiri/ArabiMahar
def register():
    if request.method == 'POST':
        user_name = request.form['user_name']
        password = request.form['password']
        email = request.form['email']
        phone_number = str(request.form['phone_number'])
        error = None
        if not user_name:
            error = 'Please enter user name'
        elif not password:
            error = 'Please enter password'
        elif not email:
            error = 'Please enter your e-mail'
        elif not phone_number:
            error = 'Please enter your phone number'
        else:
            user = dbSession.query(User).filter_by(username=user_name).first()
            if user is not None:
                error = 'username is taken'
            # cursor.execute('SELECT ID FROM users WHERE username = %s' ,(user_name,))
            # a = cursor.fetchone()
            # if a is not None:
        if error is None:
            # cursor.execute('INSERT INTO users (username,password) VALUES(%s,%s)' , (user_name,generate_password_hash(password) ,) )
            # dbSession.add(User(username = user_name,password = generate_password_hash(password) , email = email , phone_number = phone_number))
            dbSession.add(
                User(username=user_name,
                     password=generate_password_hash(password),
                     phone_number=phone_number))
            dbSession.commit()
            return redirect(url_for('verification.login'))
        else:
            flash(error)
    return render_template('auth/register.html')
コード例 #3
0
ファイル: views.py プロジェクト: aminkashiri/ArabiMahar
def answer(testid, response):
    if is_logined():
        test = dbSession.query(Test).filter(Test.id == testid).first()
        test.current_question = test.current_question + 1
        if response == 'True':
            test.correct_answers = test.correct_answers + 1
            dbSession.commit()
        if test.current_question < test.question_count:
            question = test.questions[test.current_question]
            return render_template('test_page/test_page.html',
                                   test_title=test.title,
                                   test_id=testid,
                                   question=question)
        else:
            corrects = test.correct_answers
            all_count = test.question_count
            lesson_id = test.lesson_id
            grade_id = dbSession.query(Lesson).filter(
                Lesson.id == lesson_id).first().grade_id
            return render_template('test_page/result_page.html',
                                   test=test,
                                   corrects=corrects,
                                   all_count=all_count,
                                   grade_id=grade_id,
                                   lesson_id=lesson_id)
    else:
        return redirect(url_for('verification.login'))
コード例 #4
0
ファイル: views.py プロジェクト: aminkashiri/ArabiMahar
def test_page(grade_number, lesson_number):
    if is_logined():
        # def rowdict(row):
        #     d = {}
        #     for column in row:
        #         d[column.question_text] = column.definition

        #     return d

        grade = dbSession.query(Grade).filter_by(id=grade_number).first()
        try:
            lesson = grade.lessons[lesson_number - 1]
            test = Test(user_id=g.user.id,
                        title=lesson.title,
                        question_count=len(lesson.questions),
                        current_question=0,
                        correct_answers=0,
                        lesson_id=lesson.id)
            test.questions = lesson.questions
            question = test.questions[0]
            dbSession.add(test)
            dbSession.commit()
            return render_template('test_page/test_page.html',
                                   test_title=test.title,
                                   test_id=test.id,
                                   question=question)
            # return render_template('test_page/test_page.html' , test_id = test.id , question = question)
        except IndexError as e:
            print(e)
            return render_template('test_page/no_question.html')
    else:
        return redirect(url_for('verification.login'))
コード例 #5
0
ファイル: views.py プロジェクト: aminkashiri/ArabiMahar
def mregister():
    b = True
    if request.method == 'POST':
        user_name = request.form['user_name']
        password = request.form['password']
        try:
            phone_number = request.form['phone_number']
        except:
            print('no phone number')
        error = None
        if not user_name:
            error = 'لطفا اسمتو وارد کن'
        elif not password:
            error = 'لطفا رمزتو وارد کن'
        else:
            user = dbSession.query(User).filter_by(username=user_name).first()
            if user is not None:
                error = 'اسمت تکراریه'
        if error is None:
            user = User(username=user_name,
                        password=generate_password_hash(password),
                        phone_number=phone_number,
                        bought=0)
            dbSession.add(user)
            # user_server_id = dbSession.query(User).filter_by(id=user_server_id).first()
            dbSession.commit()
            b = False

    returnDict = {"error": b, "errorMessage": error, 'user_server_id': user.id}
    return returnDict
コード例 #6
0
def addUser(name, id, admin):
    user = User(name=name, discordid=id, admin=admin)
    try:
        dbSession.add(user)
        dbSession.commit()
        print(f"added user: {name}")
    except:
        print(f"user: {name} id already in the database")

    return
コード例 #7
0
ファイル: bot.py プロジェクト: rukarangi/CustomReacter
async def clearUsers(message, m):
    """
	Print out all users saved to db --Admin only
	"""
    admin = message.channel.permissions_for(message.author).administrator
    if admin:
        dbSession.query(User).delete()
        dbSession.commit()
        await message.channel.send("Database has been removed of users.")
    else:
        await message.channel.send(
            "You do not have permission to use that command.")

    return
コード例 #8
0
ファイル: views.py プロジェクト: aminkashiri/ArabiMahar
def add():
    if request.method == 'POST':
        b = True
        user_name = request.form['user_name']
        city = request.form['city']
        province = request.form['province']
        buy_number = int(request.form['buy_number'])
        error = None
        if not city:
            error = 'لطفا شهرت رو وارد کن'
            print(error)
        elif not province:
            error = 'لطفا استانت رو وارد کن'
            print(error)
        elif not buy_number:
            error = 'کدوم درس رو بخرم؟'
            print(error)
        elif buy_number > 4:
            error = 'تو خرید درس مشکل داشتیم'
            print(error)
        else:
            user = dbSession.query(User).filter_by(username=user_name).first()
            if user is None:
                error = 'انگار ثبت نام نکردی'
                print(error)
        if error is None:
            user.city = city
            user.province = province

            if buy_number == 4:
                user.bought = 7
            else:
                user.bought = user.bought + buy_number
            dbSession.commit()
            b = False

        return_dict = {'error': b, 'errorMessage': error}
        return return_dict
コード例 #9
0
ファイル: views.py プロジェクト: aminkashiri/ArabiMahar
def first_term_random(grade_number):
    if is_logined():
        grade = dbSession.query(Grade).filter(Grade.id == grade_number).first()
        first_lesson_id = grade.lessons[0].id
        size = int(len(grade.lessons) / 2)
        questions_list = dbSession.query(Question).filter(
            Question.lesson_id >= first_lesson_id, Question.lesson_id <=
            (first_lesson_id + size)).order_by(func.random()).limit(10).all()
        test = Test(user_id=g.user.id,
                    title='مرور نیم سال اول',
                    question_count=len(questions_list),
                    current_question=0,
                    correct_answers=0)
        test.questions = questions_list
        dbSession.add(test)
        dbSession.commit()
        question = questions_list[0]
        return render_template('test_page/test_page.html',
                               test_title=test.title,
                               test_id=test.id,
                               question=question)
    else:
        return redirect(url_for('verification.login'))
コード例 #10
0
# with current_app.open_resource('scripts/initialize.sql') as f:
#         table = f.read().decode('utf8').split(';')
#         f.close()
#         for t in table:
#                 t = t + ';'
#                 dbSession.execute(t)
#                 dbSession.commit()
#         dbSession.commit()

with current_app.open_resource('scripts/initialize.sql') as f:
    table = f.read().decode('utf8').split(';')
    f.close()
    for t in table:
        t = t + ';'
        dbSession.execute(t)
        dbSession.commit()
    dbSession.commit()

# print(result.lenght)

# print(grade7.title)
# print(type(grade7.lessons[0]))

# result = dbSession.query(Grade).order_by('id').all()
# for i in range(7,13):
#     grade = result[i-7]
#     # print(len(grade.lessons))
#     for j in range(0,len(grade.lessons)):
#         lesson = grade.lessons[j]
#         # print(dictionary_of_questions['grade'+str(i)]['lesson'+str(j+1)])
#         # print(i,j)