コード例 #1
0
def test_get_user():
    user = User()
    user.username = u"test"
    user.set_password("test123")

    assert user.save()
    assert user._id

    q = Question()
    q.question = u"test"
    q.author = u"anon"
    q.user = user.username

    assert q.save(validate=True)
    assert q._id

    user_from_question = q.get_user()

    assert user_from_question._id == user._id

    q.user = u"anon!"

    q.save()

    assert not q.get_user()
コード例 #2
0
def question():
    if request.method == 'GET':
        question_id = request.args.get('id', -1, type=int)
        if question_id == -1:
            return render_template('question.html', id=question_id)
        else:
            question = Question.query.filter(
                Question.id == question_id).first()
            return render_template('question.html',
                                   id=question_id,
                                   question=question)
    else:
        name = request.form.get('todo')
        if name == 'add':
            title = request.form.get('title')
            content = request.form.get('content')
            question = Question(title=title, content=content)
            question.author = g.user
            db.session.add(question)
            db.session.commit()
            return redirect(url_for('index'))
        elif name == 'update':
            question_id = request.form.get('question_id')
            print question_id
            question = Question.query.filter(
                Question.id == question_id).first()
            question.title = request.form.get('title')
            question.content = request.form.get('content')
            db.session.commit()
            return redirect(url_for('index'))
コード例 #3
0
ファイル: zlktqa.py プロジェクト: Always-like-this/Onelab
def question():
    permission = Permission.query.filter(Permission.author_id == g.user.id).first()
    if permission.permission == 'admin' or permission.permission == 'update':
        if request.method == 'GET':
            types = Type.query.all()
            backgroud_model = Backgroud.query.filter(Backgroud.author == g.user).first()
            return render_template('question.html', types=types, backgroud=backgroud_model,permission=permission)
        else:
            title = request.form.get('title')
            content = request.form.get('content')
            type = request.form.get('type')
            assginee = request.form.get('assginee')
            question = Question(title=title, content=content)
            type = Type.query.filter(Type.type == type).first()
            estimated = request.form.get('estimated')
            if estimated:
                question.estimated = estimated
                question.remaining = estimated
            if assginee:
                question.assignee = assginee
                question.status_id = 1
            else:
                question.status_id = 7
            question.log = 0
            question.type_id = type.id
            question.author = g.user
            question.reporter = g.user.username
            db.session.add(question)
            db.session.commit()
            return redirect(url_for('index'))
    else:
        return "您没有权限创建任务,请联系管理员"
コード例 #4
0
ファイル: hitchat.py プロジェクト: pc-phoenix/HITChat
def question():
    if request.method == 'GET':
        return render_template('question.html', usermsg=g.user, picid=str(g.user.picid))
    else:
        title = request.form.get('title')
        label = request.form.get('label')
        content = request.form.get('content')
        T = title
        if T.strip() == "":
            title = label
        # for i in content:
        #     print i
        # Listcontent = list(content)
        # content = ""
        # for i in range(len(Listcontent)):
        #      if(Listcontent[i] == '\n'):
        #          content += "<br/>"
        #          print "hhh"
        #      else:
        #          content += Listcontent[i]
        # print title,content
        question = Question(title=title,label=label,content=content)
        question.author = g.user
        db.session.add(question)
        db.session.commit()
        return redirect(url_for('index'))
コード例 #5
0
def question():
    if request.method == 'GET':
        return render_template('question.html')
    else:
        contact = request.form.get('contact')
        address = request.form.get('address')
        city = request.form.get('city')
        state = request.form.get('state')
        zipcode = request.form.get('zipcode')
        price = request.form.get('price')
        bath = request.form.get('bath')
        bed = request.form.get('bed')
        content = request.form.get('content')
        question = Question(contact=contact,
                            address=address,
                            city=city,
                            state=state,
                            zipcode=zipcode,
                            price=price,
                            bath=bath,
                            bed=bed,
                            content=content)
        user_id = session.get('user_id')
        user = User.query.filter(User.id == user_id).first()
        question.author = user
        db.session.add(question)
        db.session.commit()
        return redirect(url_for('index'))
コード例 #6
0
ファイル: forum.py プロジェクト: huang-ju-git/BDIC-forum
def question():
    if request.method == 'GET':
        user_id = session.get('user_id')
        user = User.query.filter(User.id == user_id).first()
        return render_template('question.html', user=user)
    else:
        title = request.form.get('title')
        content = request.form.get('content')
        type = request.form.get('type')
        # if type:
        #     return type
        # else:
        #     return u'no type'
        if type == '1':
            kind = 1
        elif type == '2':
            kind = 2
        elif type == '3':
            kind = 3
        elif type == '4':
            kind = 4
        elif type == '5':
            kind = 5
        elif type == '6':
            kind = 6
        elif type == '7':
            kind = 7
        else:
            kind = 8
        question = Question(title=title,
                            content=content,
                            report_reasons_and_times='A@0|B@0|C@0|D@0',
                            report_total=0,
                            type=kind)
        user_id = session.get('user_id')
        user = User.query.filter(User.id == user_id).first()

        user.number_of_post = user.number_of_post + 1
        user.point = user.point + 20

        if user.point >= 50 and user.point < 100:
            user.grade = 2
        elif user.point >= 100 and user.point < 200:
            user.grade = 3
        elif user.point >= 200 and user.point < 500:
            user.grade = 4
        else:
            user.grade = 5

        question.author = user
        # question.author_id = user_id
        flask_whooshalchemyplus.index_one_model(Question)
        db.session.add(question)
        db.session.commit()
        return redirect(url_for('index'))
コード例 #7
0
def question():
    if request.method == 'GET':
        return render_template('question.html')
    else:
        title = request.form.get('title')
        content = request.form.get('content')
        question = Question(title=title, content=content)
        question.author = g.user
        db.session.add(question)
        db.session.commit()
        return redirect(url_for('index'))
コード例 #8
0
ファイル: zhihu.py プロジェクト: camouflages/py_flask
def question():
    if request.method == 'GET':
        return render_template('question.html')
    else:
        title = request.form.get('title')
        content = request.form.get('content')
        question = Question(title=title, content=content)
        user_id = session.get('use_id')
        user = User.query.filter(User.id == user_id).first()
        question.author = user
        db.session.add(question)
        db.session.commit()
コード例 #9
0
def question():
    if request.method == 'GET':
        context = {'questions': Question.query.order_by('id').all()}
        return render_template('question.html', **context)
    else:
        title = request.form.get('title')
        content = request.form.get('content')
        question = Question(title=title, content=content)
        question.author = g.user
        db.session.add(question)
        db.session.commit()
        return redirect(url_for('question'))
コード例 #10
0
def question():
    if request.method == 'GET':
        return render_template('question.html')
    else:
        title = request.form.get("title")
        content = request.form.get("content")
        question = Question(title=title, content=content)
        user = User.query.filter(User.id == session.get("user_id")).first()
        question.author = user
        db.session.add(question)
        db.session.commit()
        return redirect(url_for('index'))
コード例 #11
0
def question():
    #如果是post方法就返回tinymce生成html代码,否则渲染editor.html
    if request.method == 'POST':
        title = request.form.get('title')
        content = request.form.get('content')
        question = Question(title=title, content=content)
        user_id = session.get('user_id')
        question.author = User.query.filter(User.id == user_id).first()
        db.session.add(question)
        db.session.commit()
        return redirect(url_for('index'))

    return render_template('question.html')
コード例 #12
0
ファイル: flask_test.py プロジェクト: bhfwg/Python
def push_article():
    if request.method == 'GET':
        return render_template('push.html')
    else:
        title = request.form.get('title')
        content = request.form.get('content')
        question = Question(title=title, content=content)
        user_id = session.get('user_id')
        user = User.query.filter(User.id == user_id).first()
        question.author = user
        db.session.add(question)
        db.session.commit()
        return redirect(url_for('index'))
コード例 #13
0
def question():
    if request.method == 'GET':
        return render_template('question.html')
    else:
        title = request.form.get('title')
        content = request.form.get('content')
        question1 = Question(title=title, content=content)  # 前台获取标题和内容
        user_id = session.get('user_id')
        user = User.query.filter(User.id == user_id).first()
        question1.author = user  # 使用relationship设置外键的用户
        db.session.add(question1)
        db.session.commit()
        return redirect(url_for('index'))
コード例 #14
0
def question():
    if request.method == "GET":
        return render_template("question.html")
    else:
        title = request.form.get("title")
        content = request.form.get("content")
        question = Question(title = title, content=content)
        user_id = session.get('user_id')
        user = User.query.filter(User.id == user_id).first()
        question.author = user
        db.session.add(question)
        db.session.commit()
        return redirect(url_for("index"))
コード例 #15
0
def question():
    if request.method == 'GET':
        return render_template('question.html')
    else:
        title = request.form.get('title')
        content = request.form.get('content')
        q = Question(title=title, content=content)
        # user_id = session.get('user_id')
        # user = User.query.filter_by(id=user_id).first()
        q.author = g.user
        db.session.add(q)
        db.session.commit()
        return redirect(url_for('index'))
コード例 #16
0
ファイル: app.py プロジェクト: 10969aimyon/bolg
def question():
    if request.method == 'GET':
        return render_template('question.html')
    else:
        title = request.form.get('title')
        content = request.form.get('content')
        if content:
            question1 = Question(title=title, content=content)
            user_id = session['user_id']
            user1 = User.query.filter(User.id == user_id).first()
            question1.author = user1
            db.session.add(question1)
            db.session.commit()
        return redirect(url_for('index'))
コード例 #17
0
ファイル: zlktqa.py プロジェクト: wzccoder/git_learn
def question():
    if request.method == "GET":
        return render_template("question.html")
    else:
        title = request.form.get('title')
        content = request.form.get('content')
        question = Question(title=title, content=content)
        # user_id = session.get('user_id')
        # user = User.query.filter(User.id == user_id).first()
        question.author = g.user
        db.session.add(question)
        db.session.commit()
        # 重定向到首页
        return redirect(url_for('index'))
コード例 #18
0
def question():
    if request.method == "GET":
        return render_template('question.html')
    else:
        title = request.form.get('title')
        content = request.form.get('content')
        user_id = session.get('user_id')
        ques = Question(title=title, content=content)
        user = User.query.filter(User.id == user_id).first()
        ques.author = user
        # question.author_id=user_id 不用查询,直接写user_id应该也行吧
        db.session.add(ques)
        db.session.commit()
        return redirect(url_for('index'))
コード例 #19
0
def question():
    if request.method == "GET":
        return render_template("question.html")
    else:
        title = request.form.get("title")
        content = request.form.get("content")

        question = Question(title = title,content = content)

        #谁发的问题
        question.author = g.user
        db.session.add(question)
        db.session.commit()
        return redirect(url_for("index"))
コード例 #20
0
def question():
    if request.method == 'GET':
        return render_template('question.html')
    else:
        # 获取发布问答表单的数据
        title = request.form.get('title')
        content = request.form.get('content')
        question = Question(title=title, content=content)
        # 获取符合条件的用户值
        # user_id = session.get('user_id')
        # user = User.query.filter(User.id == user_id).first()
        question.author = g.user
        # 保存数据到库中
        db.session.add(question)
        db.session.commit()
        return redirect(url_for('index'))
コード例 #21
0
ファイル: daodao.py プロジェクト: Bxiaoyu/share
def question():
    form = RichTextForm()
    if request.method == 'GET':
        return render_template('question.html', form=form)
    else:
        #title = request.form.get('title')
        #content = request.form.get('content')
        if form.validate_on_submit():
            title = form.title.data
            content = form.body.data
            question = Question(title=title, content=content)
            question.author = g.user
            db.session.add(question)
            db.session.commit()
            return redirect(url_for('index'))
            return render_template('post.html', title=title, body=content)
    return render_template('question.html', form=form)
コード例 #22
0
def question():
    if request.method == "GET":
        return render_template("question.html")
    else:
        # 获取title
        title = request.form.get("title")
        # 获取content
        content = request.form.get("content")
        # 放入model
        question = Question(title=title, content=content)
        # 获取user_id=author
        question.author = g.user
        # 提交事务
        db.session.add(question)
        db.session.commit()
        # 跳转首页
        return redirect(url_for("index"))
コード例 #23
0
def question():
    if request.method == 'GET':
        return render_template('question.html')
    else:
        # 获取用户要发布的问答信息
        title = request.form.get('title')
        content = request.form.get('content')
        question = Question(title=title, content=content)

        # 优化代码1,将其写在before_request钩子函数中,并使用g对象
        # user_id = session.get('user_id')
        # user = User.query.filter(User.id == user_id).first()

        question.author = g.user
        db.session.add(question)
        db.session.commit()
        return redirect(url_for('index'))
コード例 #24
0
ファイル: qaapp.py プロジェクト: lymadalin/arcqa
def question():
    form = QuestionForm()
    if request.method == "GET":
        return render_template("richquestion.html", form=form)
        # 暂时注销
        # return render_template('question.html')
    else:
        if form.validate_on_submit():
            title = form.title.data
            content = form.body.data
            question1 = Question(title=title, content=content)
            user_id = session.get('user_id')
            user = User.query.filter(User.id == user_id).first()
            question1.author = user
            db.session.add(question1)
            db.session.commit()
            return redirect(url_for('index'))
コード例 #25
0
ファイル: zlktqa.py プロジェクト: ZHANGDINGREN123/gitTUT
def question():
    if request.method == 'GET':
        return render_template('question.html')
    else:
        title = request.form.get('title')
        content = request.form.get('content')
        question = Question(title=title, content=content)

        # 从数据库读取用户数据,确认是那个作者在发布问题

        question.author = g.user
        question.content = content
        db.session.add(question)
        db.session.commit()

        #完成后返回首页
        return redirect(url_for('index'))
コード例 #26
0
ファイル: zlkt.py プロジェクト: jack161616/zlkt_flask
def question():
    if request.method == 'GET':
        context = {'title':u'发布问答'}
        return render_template('question.html',**context)
    else:
        title = request.form.get('title')
        content = request.form.get('content')
        question = Question(title=title,content=content)
        user_id = session.get('user_id')
        user = User.query.filter(User.id==user_id).first()
        question.author = user
        # question.author_id = user_id
        db.session.add(question)
        db.session.commit()
        # print 'question.author.telephone:',question.author.telephone

        return redirect(url_for('index'))
コード例 #27
0
def question():
    if request.method == 'GET':
        return render_template('question.html')
    else:
        title = request.form.get('title')
        content = request.form.get('content')
        if '' == title or '' == content:
            return '输入不能为空!'
        else:
            new_question = Question(title=title, content=content)
            # user_id = session.get('user_id')
            # user = User.query.filter(User.id == user_id).first()
            user = g.user
            new_question.author = user
            db.session.add(new_question)
            db.session.commit()
            return redirect(url_for('index'))
コード例 #28
0
def question():
    if request.method == 'GET':
        return render_template('question.html')
    else:
        title = request.form.get('title')
        content = request.form.get('content')
        question = Question(title=title, content=content)
        user_id = session.get('user_id')
        #易错点:这里的user = db.session.query(User).get(user_id)不可以写为uer =
        # User.query.filter(User.id == user_id).first
        # 原因是这里从User里再次实例化了一个对象,即有两个session
        # flask 会报错
        user = db.session.query(User).get(user_id)
        question.author = user
        db.session.add(question)
        db.session.commit()
        return redirect(url_for('index'))
コード例 #29
0
ファイル: app.py プロジェクト: BobXGY/bobqa
def question():
    """
    GET请求则返回发帖页面
    POST则是创建帖子
    :return:
    """
    if request.method == 'GET':
        return render_template('question.html')
    else:
        title = request.form.get('title')
        content = request.form.get('content')
        question_ = Question(title=title, content=content)
        user_id = session.get('user_id')
        user = User.query.filter(User.id == user_id).first()
        question_.author = user
        db.session.add(question_)
        db.session.commit()
        return redirect(url_for('index'))
コード例 #30
0
ファイル: user_tests.py プロジェクト: fernandotakai/questions
def test_get_unanswered_questions():
    user = User()
    user.username = u"test"
    user.set_password("test123")

    assert user.save()
    assert user._id

    q = Question()
    q.question = u"test"
    q.author = u"anon"
    q.user = user.username

    assert q.save(validate=True)
    assert q._id
     
    user_from_db = User.one({'username': '******'})

    assert user_from_db.unanswered_questions().count() == 1
コード例 #31
0
def question():
    if request.method == 'GET':
        # 判断是否登陆
        user_id = session.get('user_id')
        if user_id:
            return render_template('question.html')
        else:
            return redirect(url_for('login'))
    else:
        title = request.form.get('title')
        content = request.form.get('content')
        question = Question(title=title, content=content)
        user_id = session.get('user_id')
        user = User.query.filter(User.id == user_id).first()
        question.author = user
        db.session.add(question)
        db.session.commit()
        # 发布后跳转到首页
        return redirect(url_for('index'))
コード例 #32
0
def question():
    # is_login = session.get('username')
    # if is_login:
        if request.method == 'GET':
            return render_template('question.html')
        else:
            title = request.form.get('title')
            content = request.form.get('content')
            if title == '' or content == '':
                return '输入内容不能为空!'
            else:
                # author = User.query.filter(User.username == is_login).first()
                question = Question(title=title, content=content)
                # question.author = author
                question.author = g.user
                db.session.add(question)
                db.session.commit()
                flash('发布成功!')
                return redirect(url_for('index'))
コード例 #33
0
 def save(self):
     question = Question(**self.cleaned_data)
     question.author = self._user
     question.save()
     return question