def add_question(request): form = AskForm(request.POST) if form.is_valid(): question = form.save() url = question.get_url() return HttpResponseRedirect(url) else: return HttpResponseRedirect(r'/')
def newquestion(request, *args, **kwargs): if request.method == 'POST': form = AskForm(request.POST) if form.is_valid(): form.user = request.user question_id = form.save() return HttpResponseRedirect(reverse('question', kwargs={'question_id': question_id, })) else: form = AskForm() return render(request, 'newquestion.html', {'form': form})
def ask(request): if request.method == 'POST': form = AskForm(request.POST) if form.is_valid(): q = form.save() url = '/question/%s/' % q.pk return HttpResponseRedirect(url) else: form = AskForm() return render(request, 'qa/ask.html', {'form': form})
def ask(request, *args, **kwargs): if request.method == "GET": form = AskForm() elif request.method == "POST": form = AskForm(request.POST) if form.is_valid(): form.cleaned_data['author'] = request.user q = form.save() return HttpResponseRedirect(q.get_absolute_url()) return render(request, "form.html", {'url':request.path, 'form':form})
def ask(request): if request.method == "POST": form = AskForm(request.POST) if form.is_valid(): question = form.save(commit=False) question.author = request.user question.save() return redirect(question) else: form = AskForm() return render(request, 'qa/ask.html', {'form': form})
def ask(request): if request.method == 'POST': form = AskForm(request.POST) form._user = request.user if form.is_valid(): question = form.save() url = question.get_url() return HttpResponseRedirect(url) else: form = AskForm() return render(request, 'ask.html', {'form': form})
def ask_form(request): if request.method == 'POST': form = AskForm(request.POST) if form.is_valid(): question = form.save() url = question.get_url() return HttpResponsePermanentRedirect(url) else: form = AskForm() return render(request, 'ask/ask_add.html', { 'form': form, })
def ask_add(request): if request.method == 'POST': form = AskForm(request.POST) if form.is_valid(): form._user = request.user question = form.save() # url = question.get_url() # return HttpResponseRedirect(reverse(url)) return HttpResponseRedirect(reverse('question', args=[question.id])) else: form = AskForm() return render(request, 'ask_add_page.html', {'form': form})
def post_ask_add(request, *args): if request.method == "POST": form = AskForm(request.POST) form._user = request.user if form.is_valid(): post = form.save() #url = post.get_url() return HttpResponseRedirect('/question/'+str(post.id)+'/') else: form = AskForm() return render(request, 'tpl_post_ask_add.html', { 'form': form })
def ask(request): if request.method == "POST": form = AskForm(request.POST) if form.is_valid(): user_id = request.COOKIES['sessionid'] question = form.save(user_id) url = question.get_url() return HttpResponseRedirect(url) else: form = AskForm() return render(request, 'ask.html', { 'form': form })
def question_add(request): if request.method == "POST": form = AskForm(request.POST) # form = AskForm(initial={'question': question_id}) if form.is_valid(): ques = form.save() url = ques.get_url() print 'redirect to %s' % (url) return HttpResponseRedirect(url) print 'qa if but not valid' else: form = AskForm() print 'qa else' return render(request, 'qa/question_add.html', {'form': form})
def ask(request): if request.method == "POST": form = AskForm(request.POST) if form.is_valid(): question = form.save() question.author = request.user question.save() url = question.get_url() return HttpResponseRedirect(url) else: #form = AskForm(initial={'author': request.user.id}) form = AskForm() return render(request, 'ask.html', { 'form': form })
def ask(request, *args, **kwargs): if (request.method == 'GET'): form = AskForm() else: form = AskForm(request.POST) form._user = request.user if (form.is_valid()): post = form.save() url = post.get_absolute_url() return HttpResponseRedirect(url) return render(request, 'ask.html',{ "form": form, "_user" : request.user })
def ask(request): if request.method == "POST": try: form = AskForm(request.POST) if form.is_valid(): form._user = request.user post = form.save() redirect_url = post.get_absolute_url() print 'redirect to: ', redirect_url return HttpResponseRedirect(redirect_url) except Exception as error_message: print error_message else: form = AskForm() return render(request, 'ask.html', {'form': form})
def ask(request): if request.method == "POST": print "post:" form=AskForm(request.POST) form.author = 1 print form if form.is_valid(): print 'valid' question=form.save() redir_url = '/question/'+str(question.id) return HttpResponseRedirect("/question/"+str(question.id)) else: print "get:" # print request.session['name'] form = AskForm() if request.user.is_authenticated(): # form.author=request.user us=request.user else: us= User.objects.get(id=1) form.author=User.objects.get(id='1') form = AskForm(initial={'author':us}) print form return render(request, 'ask.html', {'form': form})
def ask(request): if request.method == "POST": ask_form = AskForm(request.POST or None) ask_form._user = request.user if ask_form.is_valid(): post = ask_form.save() url = post.get_url() print("____DEBUG: {}".format(url)) return HttpResponseRedirect(url) else: ask_form = AskForm() context = { "ask_form": ask_form, } return render(request, 'ask.html', context)
def base_pagin(request, *args, **kwargs): form = AskForm() paginator, page = pagination(request, Question, sorter='-added_at') return render(request, 'base_pagin.html', {'posts': page.object_list, 'paginator': paginator, 'page': page, 'form':form} )
def ask_view(request): if request.method == "POST": form = AskForm(request.POST) print('isvalid') if form.is_valid(): print('isvalid') question = form.save() url = '/question/' + str(question.id) #url = '/question/123' return HttpResponseRedirect(url) else: print('invalid') else: form = AskForm() c = { 'form':form } c.update(csrf(request)) return render(request, '/home/box/web/ask/qa/templates/ask.html', c)
def ask(request, *args, **kwargs): if request.method == 'POST': form = AskForm(request.POST) if form.is_valid(): form = form.save() url = form.get_url() return HttpResponseRedirect(url) else: form = AskForm() return render(request, 'ask.html', {'form': form})
def question_add(request): if request.method =='POST': form = AskForm(request.POST) form._user = request.user if form.is_valid(): question = form.save() url = question.get_url() return HttpResponseRedirect(url) else: form = AskForm() form._user = request.user return render(request, 'question-add.html', { 'form': form })
def add_question(request): if request.method == "POST": form = AskForm(request.POST) if form.is_valid(): form.cleaned_data['author'] = request.user ask = form.save() url = ask.get_url() return HttpResponseRedirect(url) else: form = AskForm() return render(request, 'question_form.html', {'form': form})
def ask(request): if request.method == "POST": form = AskForm(request.POST) form._user = request.user if form.is_valid(): question = form.save() url = question.get_url() return HttpResponseRedirect(url) else: form = AskForm() return render(request, 'qa/ask_form.html', {'form': form})
def ask(request): if request.method == "POST": form = AskForm(request.POST) if form.is_valid(): form._user = request.user post = form.save() #redirect_url = post.get_url() redirect_url = reverse('question_detail', args=[post.id]) return HttpResponseRedirect(redirect_url) else: form = AskForm() return render(request, 'ask.html', {'form': form})
def add_question(request): if request.method == 'POST': form = AskForm(request.POST) form._user = request.user if form.is_valid(): question = form.save() return HttpResponseRedirect(question.get_url()) else: form = AskForm() return render(request, 'add_question.html', { 'form': form, })
def askform(request): url = '/question/' if request.method == "POST": print(url) #print(request.USER) #if request.POST['author']: # author = request.POST['author'] #else: author = 'user_test_14483' print(1) ask = AskForm({ 'title': request.POST['title'], 'text': request.POST['text'], 'author': request.user, }) print(2) if ask.is_valid(): url = url + str( ask.save() ) + '/' print(3) return HttpResponseRedirect(url) ask = AskForm({'author': request.user}) return render(request, 'ask.html',{ 'ask': ask, },)
def ask(request): if request.method == 'POST': form = AskForm(request.POST) form.set_author(request.user) if form.is_valid(): post = form.save() return HttpResponseRedirect(post.get_url()) else: form = AskForm() return render(request, 'ask.html', {'form': form})
def ask_question(request): if request.method == 'POST': new_question = Question(author=request.user, create_date=timezone.now()) form = AskForm(request.POST, instance=new_question) if form.is_valid(): form.save() return redirect('index') else: pass else: form = AskForm() return render(request, 'answers/ask.html', {'form': form})
def ask_page(request): if request.method == 'POST': form = AskForm(request.POST) if form.is_valid(): question = form.save(request.user) url = '/question/' + str(question.id) + '/' return HttpResponseRedirect(url) else: form = AskForm() return render(request, 'question_add.html', { 'form': form, })
def ask_form(request): if request.method == 'POST': form = AskForm(request.POST) if form.is_valid(): question = form.save() url = question.get_url() return HttpResponsePermanentRedirect(url) else: form = AskForm() return render(request, 'ask/ask_add.html', { 'form': form, })
def question_add(request, *args, **kwargs): user = User.objects.first() if request.method == "POST": form = AskForm(request.POST) if form.is_valid(): question = form.save() url = question.get_url() return HttpResponseRedirect(url) else: return HttpResponse('OK') else: form = AskForm() return render(request, 'qa/ask.html', {'form': form})
def ask(request): if request.method == "POST": form = AskForm(request.POST) if form.is_valid(): question = form.save() question.author = request.user question.save() url = question.get_url() return HttpResponseRedirect(url) else: #form = AskForm(initial={'author': request.user.id}) form = AskForm() return render(request, 'ask.html', {'form': form})
def ask(request): if request.method == "POST": user = request.user if not user.is_authenticated(): return HttpResponseRedirect('/login/') form = AskForm(request.POST) form.setUser(user) if form.is_valid(): question = form.save() url = question.get_absolute_url() return HttpResponseRedirect(url) else: form = AskForm() return render(request, 'ask.html', {'form': form })
def question_add(request): if request.method == "POST": form = AskForm(request.POST) # form = AskForm(initial={'question': question_id}) if form.is_valid(): ques = form.save() url = ques.get_url() print 'redirect to %s' % (url) return HttpResponseRedirect(url) print 'qa if but not valid' else: form = AskForm() print 'qa else' return render(request, 'qa/question_add.html', {'form': form})
def question_add(request): if request.method == "POST": form = AskForm(request.POST) if form.is_valid(): question = form.save(commit=False) question.author_id = request.user.id question.rating = '1' question.save() url = reverse('question-with-answers', args=(question.id,)) return HttpResponseRedirect(url) else: form = AskForm() return render(request, 'question_add.html', { 'form' : form, })
def ask(request) : if request.method == "POST" : print("POST!!!!!!!!!!!!!!!!!!!!!!!!!") form = AskForm(request.POST) if form.is_valid(): print("FORM IS VALID!!!!!!!!!!!!") quest = form.save() print("QUEST IS CREATE!!!!!!!!!!") url = quest.get_absolute_url() print("URL = " + url +"!!!!!!!!!") return HttpResponseRedirect(url) else : form = AskForm() return render(request, 'ask_add.html', { 'form' : form })
def add_ask(request): if request.method == 'POST': if request.user.is_authenticated(): query = QueryDict(request.POST.urlencode(), mutable=True) query.__setitem__('author', str(request.user.id)) form = AskForm(query) if form.is_valid(): ask = form.save() url = ask.get_url() return HttpResponseRedirect(url) else: return HttpResponseRedirect(reverse('login')) else: form = AskForm() return render(request, 'add_ask.html', { 'form': form, })
def askform(request): url = '/question/' if request.method == "POST": if request.POST['author']: author = request.POST['author'] else: author = request.user ask = AskForm({ 'title': request.POST['title'], 'text': request.POST['text'], 'author': author, },) if ask.is_valid(): url = url + str( ask.save() ) + '/' return HttpResponseRedirect(url) ask = AskForm({'author': request.user}) return render(request, 'ask.html',{ 'ask': ask, },)
def ask(request): template = 'ask.html' if request.method == 'POST': ask_form = AskForm(request.POST) if ask_form.is_valid(): user = request.user if not user.is_authenticated(): return redirect('login') question = ask_form.save(user=user) return redirect('question', question.pk) else: ask_form = AskForm() context = { 'ask_form': ask_form, } return render(request, template, context)
def add_question_field(request): form = AskForm() return render(request, 'ask_form.html', {'form': form})