示例#1
0
文件: views.py 项目: ayata777/sample
def apply(request):
    if request.method == "POST":
        form = QuestionForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            return redirect('app:index')
    else:
        form = QuestionForm()
        return render(request, 'app/apply.html', {'form': form})
def home(request):
    if request.method == 'POST':
        form = QuestionForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect(home)
    else:
        form = QuestionForm()
    questions = Question.objects.all()
    return render(request, 'home.html', {
        'questions': questions,
        'form': form,
    })
示例#3
0
def ask(request):
    if request.method == 'POST':
        form = QuestionForm(request.user.profile, data=request.POST)
        if form.is_valid():
            q = form.save()
            return redirect(reverse('question', kwargs={'qid': q.id}))
    return render(request, 'ask.html', tags_and_users)
示例#4
0
def question_new(request):
    message = ""
    if request.method == "POST":
        form = QuestionForm(request.POST)

        minNumChoices = 2
        maxNumChoices = 4
        validNumChoices = int(
            request.POST["num_choices"]) >= minNumChoices and int(
                request.POST["num_choices"]) <= maxNumChoices
        validCorrectChoice = int(request.POST["correct_choice"]) >= 1 and int(
            request.POST["correct_choice"]) <= int(request.POST["num_choices"])

        if not validNumChoices:
            message = "El número de respuestas debe ser entre " + str(
                minNumChoices) + " y " + str(maxNumChoices)
        elif not validCorrectChoice:
            message = "El número de la respuesta correcta debe estar entre 1 y " + request.POST[
                "num_choices"]
        elif form.is_valid():
            question = form.save(commit=False)
            question.pub_date = datetime.now()
            question.save()
            message = "Pregunta añadida!"
            #return redirect('detail', pk=question_id)
            #return render(request, 'polls/index.html', {'title':'Respuestas posibles','question': question})
    else:
        form = QuestionForm()

    return render(request, 'polls/question_new.html', {
        'form': form,
        'message': message
    })
示例#5
0
def question_new(request):
        if request.method == "POST":
            form = QuestionForm(request.POST)
            if form.is_valid():
                question = form.save(commit=False)
                question.pub_date=datetime.now()
                question.save()
        else:
            form = QuestionForm()
        return render(request, 'polls/question_new.html', {'form': form})
示例#6
0
文件: views.py 项目: HADSG14/HADSG14
def question_new(request):
    if request.method == "POST":
        form = QuestionForm(request.POST)
        if form.is_valid():
            question = form.save(commit=False)
            question.pub_date = datetime.now()
            question.save()
            #return redirect('detail', pk=question_id)
            #return render(request, 'polls/index.html', {'title':'Respuestas posibles','question': question})
    else:
        form = QuestionForm()
    return render(request, 'polls/question_new.html', {'form': form})
示例#7
0
def new_question(request):
    if request.method == 'POST':
        form = QuestionForm(data=request.POST, profile=request.user.profile)
        if form.is_valid():
            question = form.save()
            return redirect(reverse('question', kwargs={'id': question.id}))

    else:
        form = QuestionForm(None)

    return render(request, 'new_question_page.html', {
        'title': 'New question',
        'form': form
    })
示例#8
0
def question_new(request):
        if request.method == "POST":
            form = QuestionForm(request.POST)
            if form.is_valid():
                question = form.save(commit=False)
                question.pub_date=datetime.now()
                question.save()
                #return redirect('detail', pk=question_id)
                #return render(request, 'polls/index.html', {'title':'Respuestas posibles','question': question})
        else:
            form = QuestionForm()
        return render(request, 'polls/question_new.html', {
                                                            'form': form,
                                                            'title' : 'Pagina para añadir un apregunta',
                                                            'message' : 'Pregunta lo que sea.',
                                                            'year' : datetime.now().year})