Exemplo n.º 1
0
def ask(request):
    if request.method == 'POST':
        form = QuestionForm(request.POST)
        if form.is_valid():
            question = Question()
            question.user = request.user
            question.title = form.cleaned_data.get('title')
            question.description = form.cleaned_data.get('description')
            caretaker = QuestionCareTaker()
            caretaker.question = question
            caretaker.save()
            question.caretaker = caretaker
            question.save()
            question.caretaker.save()
            tags = form.cleaned_data.get('tags')
            question.create_tags(tags)
            return redirect('/questions/')

        else:
            return render(request, 'questions/ask.html', {'form': form})

    else:
        form = QuestionForm()

    return render(request, 'questions/ask.html', {'form': form})
Exemplo n.º 2
0
def ask(request):
    # 提问按钮
    if request.method == 'POST':
        # post是提交问题
        form = QuestionForm(request.POST)
        if form.is_valid():
            question = Question()
            question.user = request.user
            question.title = form.cleaned_data.get('title')
            question.description = form.cleaned_data.get('description')
            question.save()
            tags = form.cleaned_data.get('tags')
            question.create_tags(tags)

            # 重定向到提问页面
            return redirect('/questions/')

        else:
            return render(request, 'questions/ask.html', {'form': form})

    else:
        # get是显示提问页面
        form = QuestionForm()

    return render(request, 'questions/ask.html', {'form': form})
Exemplo n.º 3
0
def ask(request):
    if request.method == "POST":
        form = QuestionForm(request.POST)
        if form.is_valid():
            question = Question()
            question.user = request.user
            question.title = form.cleaned_data.get("title")
            question.description = form.cleaned_data.get("description")
            question.save()
            tags = form.cleaned_data.get("tags")
            question.create_tags(tags)
            return redirect("/questions/")
        else:
            return render(request, "questions/ask.html", {"form": form})
    else:
        form = QuestionForm()
    return render(request, "questions/ask.html", {"form": form})
Exemplo n.º 4
0
def ask(request):
    if request.method == 'POST':
        form = QuestionForm(request.POST)
        if form.is_valid():
           question = Question()
           question.user = request.user
           question.title = form.cleaned_data.get('Titel')
           question.description = form.cleaned_data.get('Beschreibung')
           question.save()
           tags = form.cleaned_data.get('Schlagworte')
           question.create_tags(tags)
           return redirect('/questions/')
        else:
            return render(request, 'questions/ask.html', {'form': form})
    else:
        form = QuestionForm()
    return render(request, 'questions/ask.html', {'form': form})
Exemplo n.º 5
0
 def test_question_answered_question(self):
     self.assertEqual(self.question_two, Question.get_answered()[0])
Exemplo n.º 6
0
 def test_question_non_answered_question(self):
     self.assertEqual(self.question_one, Question.get_unanswered()[0])
Exemplo n.º 7
0
def unanswered(request):
    questions = Question.get_unanswered()
    return _questions(request, questions, 'unanswered')
Exemplo n.º 8
0
def answered(request):
    questions = Question.get_answered()
    return _questions(request, questions, 'answered')
Exemplo n.º 9
0
def unanswered(request):
    questions = Question.get_unanswered()
    return render(request, 'questions/questions.html', {
        'questions': questions,
        'active': 'unanswered'
    })
Exemplo n.º 10
0
 def test_question_answered_question(self):
     self.assertEqual(self.question_two, Question.get_answered()[0])
Exemplo n.º 11
0
def unanswered(request):
    questions = Question.get_unanswered()
    return render(request, 'questions/questions.html', {'questions': questions, 'active': 'unanswered'})
Exemplo n.º 12
0
def all(request):
    tag = request.session.get('TRIBE_TAG')
    questions = Question.get_all(tag)
    return _questions(request, questions, 'all')
Exemplo n.º 13
0
def unanswered(request):
    tag = request.session.get('TRIBE_TAG')
    questions = Question.get_unanswered(tag)
    return _questions(request, questions, 'unanswered')
Exemplo n.º 14
0
def unanswered(request):
    questions = Question.get_unanswered()
    return render(request, "questions/questions.html", {"questions": questions, "active": "unanswered"})
Exemplo n.º 15
0
def answered(request):
    questions = Question.get_answered()
    return _questions(request, questions, 'answered')
Exemplo n.º 16
0
def unanswered(request):
    questions = Question.get_unanswered()
    return _questions(request, questions, 'unanswered')
Exemplo n.º 17
0
 def test_question_non_answered_question(self):
     self.assertEqual(self.question_one, Question.get_unanswered()[0])