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, })
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)
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 })
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})
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})
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 })
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})