Example #1
0
def ask_question():
    form = QuestionForm(request.form)
    if request.method == 'POST' and form.validate() and g.user:
        title = form.title.data
        body = form.body.data
        tags = form.tags.data
        if tags == '':
            tags = []
        else:
            tags = [tag.strip().replace(' ', '-') for tag in tags.split(',')]
        new_question = Question(title = title, body = body, 
                    author = g.user,
                    tags = tags)
        new_question.save()
        return redirect('/questions/%s/' % new_question.id)
    elif not g.user:
        flash("Please login")
    elif request.method == 'POST':
        flash("Put it some data please")

    return render_template('ask.html', form = form, title = 'Ask a question')
Example #2
0
def questions_by_tag(tag):
    return render_template('index.html', title = 'Questions tagged with "%s"' % tag, 
                                        questions = Question.objects(tags__contains=tag))
Example #3
0
def unanswered_questions():
    return render_template('index.html', questions = Question.objects(answers__size = 0), 
                                        title = 'Unanswered Questions')