Esempio n. 1
0
def OneQuestion(request, qnum):
    quest = Question.objects.get(id=qnum)
    page = request.GET.get('page')
    answ = Answer.objects.filter(question=quest)

    if request.user.is_authenticated:
        #us = request.user
        if request.method == 'POST':

            form = AnswerForm(request.POST)
            is_val = form.is_valid()
            data = form.cleaned_data
            t = data['text']
            print '____________________'
            print t
            print request.user.profile
            print quest
            if is_val:
                answer = Answer.objects.create(
                    user = request.user.profile,
                    question = quest,
                    text = data['text'],
                )
                answer.save()

                return HttpResponseRedirect(qnum)
        else:
            form = AnswerForm()
    else:
        return HttpResponseRedirect('/sign_in/')
    return render(request, 'one_question.html', {'questions': quest, 'paginator': paginate(answ, page), 'form': form})
Esempio n. 2
0
def tag(request):
    tagg = Tag.objects.get(name=request.GET.get('tag'))
    data = Question.objects.filter(tag=tagg)
    print data
    page = request.GET.get('page')
    #for i in Question.objects.all().filter(tag=tagg):
        #data.append(i)
    return render(request, 'questions.html', {'data': paginate(data, page)})
Esempio n. 3
0
def Questions(request):
    questions = Question.objects.all()
    page = request.GET.get('page')
    context = {
        'questions': questions,
        'data': paginate(questions, page),
    }

    return render(request, 'questions.html', context)
Esempio n. 4
0
def scroll(request):
    print('inscroll')
    data = Question.objects.all()
   # page = paginate(data, request)
    page = request.GET.get('page')
    print page

    print('pagination done')
    return render(request, 'list.html', {'data': paginate(data, page)})
Esempio n. 5
0
def Hot(request):
    data = []

    for i in xrange(1, 30):
        data.append(
            {
                'title': 'title' + str(i),
                'text': 'text' + str(i),
                'likecount': i % 20,
            }
        )

    data.sort(key=lambda  x: x["likecount"], reverse=True)


    page = request.GET.get('page')
    return render(request, 'questions.html', {
        'hot':True,
        'questions': data,
        'paginator': paginate(data, page),
    })
Esempio n. 6
0
def ListingByTag(request):
    questions = Question.objects.all()

    page = request.GET.get('page')
    return render(request, 'questions.html', {'questions': questions, 'paginator': paginate(questions, page)})