Exemple #1
0
def question():
    print('question page')
    if request.method == 'GET':
        return render_template('question.html')
    else:
        submitted_question = Question()
        submitted_question.title = request.form.get('title')
        submitted_question.content = request.form.get('content')
        submitted_question.create_time = datetime.now()
        submitted_question.author_id = session.get('user_id')
        db.session.add(submitted_question)
        db.session.commit()
        return redirect(url_for('index'))
    def fetchQuestions(self, start, count):
        query = (
            "SELECT id, owner_id, content, c_time FROM questions ORDER BY c_time DESC LIMIT %s OFFSET %s;"
        )
        cursor = self.db.cursor()

        ret = []
        cursor.execute(query, (int(count), int(start)))
        for (id, owner_id, content, c_time) in cursor:
            question = Question()
            question.id = id
            question.owner_id = owner_id
            question.content = content
            question.create_time = c_time
            ret.append(question)
        cursor.close()
        return ret