def home(request): if request.user.is_authenticated == True: return redirect('/questions/') else: all_questions = Question.get_published()[:10] return render(request, 'core/splash.html', {'questions': all_questions})
def write(request): if request.method == 'POST': form = QuestionForm(request.POST) if form.is_valid(): question = Question() question.create_user = request.user question.title = form.cleaned_data.get('title') question.content = form.cleaned_data.get('content') status = form.cleaned_data.get('status') if status in [Question.PUBLISHED, Question.DRAFT]: question.status = form.cleaned_data.get('status') question.save() tags = form.cleaned_data.get('tags') question.create_tags(tags) return redirect('/questions/') else: form = QuestionForm() return render(request, 'questions/write.html', {'form': form})
def edit(request, id): tags = '' if id: question = get_object_or_404(Question, pk=id) for tag in question.get_tags(): tags = u'{0} {1}'.format(tags, tag.tag) tags = tags.strip() else: question = Question(create_user=request.user) if request.POST: form = QuestionForm(request.POST, instance=question) if form.is_valid(): form.save() return redirect('/questions/') else: form = QuestionForm(instance=question, initial={'tags': tags}) return render(request, 'questions/edit.html', {'form': form})
def questions(request): all_questions = Question.get_published() return _questions(request, all_questions)
def home(request): if request.user.is_authenticated(): return redirect('/questions/') else: all_questions = Question.get_published()[:10] return render(request, 'core/splash.html', {'questions': all_questions})