Beispiel #1
0
def tag(request, tag):
    context = {}
    context.update({'user': get_authenticate_user(request)})
    questions = Logic.get_tag(tag=tag)
    page = paginate(request, questions)
    context.update({'question_list': page, 'tag': tag})
    response = render(request, 'index.html', context)
    return response
Beispiel #2
0
def tag(request, tag):
    context = {}
    context.update({'user': get_authenticate_user(request)})
    questions = Logic.get_tag(tag=tag)
    page = paginate(request, questions)
    last_month = datetime.today() - timedelta(days=90)
    # tags = Tag.objects.annotate(
    #     Tags=Count('question__tags')).order_by('-Tags').filter(question__created__gte=last_month)[:10]
    context.update({'question_list': page, 'tag': tag, })
    response = render(request, 'index.html', context)
    return response
Beispiel #3
0
def question(request, question_id):
    context = {}
    try:
        question_ = Question.objects.get(pk=question_id)
    except ObjectDoesNotExist:
        raise Http404
    form = AnswerForm()
    user = get_authenticate_user(request)
    answers = Logic.get_order(question=question_)
    last_month = datetime.today() - timedelta(days=90)
    # tags = Tag.objects.annotate(
    #     Tags=Count('question__tags')).order_by('-Tags').filter(question__created__gte=last_month)[:10]
    # users = CustomUser.objects.annotate(
    #     Users=Count('question__author', distinct=True)).order_by('-Users').filter(question__created__gte=last_month)[:10]
    page = paginate(request, answers)
    if user:
        if request.method == 'POST':
            form = AnswerForm(request.POST)
        if form.is_valid():
            answer = Answer.objects.create(
                                author=user,
                                content=form.cleaned_data.get('content'),
                                created=datetime.now(),
                                question=question_)
            answer.save()
            context.update({'anchor': answer.id})
            answers = Logic.get_order(question=question_)
            page_number = 1
            for index, item in enumerate(answers):
                if item.id == answer.id:
                    page_number = ((index + 1) / 5) + 1
            paginator = Paginator(answers, 5)
            page = paginator.page(page_number)

    context.update({'question': question_, 'answer_list': page, 'user': user, })
    response = render(request, 'questions.html', context)
    return response
Beispiel #4
0
def question(request, question_id):
    context = {}
    try:
        question_ = Question.objects.get(pk=question_id)
    except ObjectDoesNotExist:
        raise Http404
    form = AnswerForm()
    user = get_authenticate_user(request)
    if user:
        if request.method == 'POST':
            form = AnswerForm(request.POST)
        if form.is_valid():
            answer = Answer.objects.create(
                                author=user,
                                content=form.cleaned_data.get('content'),
                                created=datetime.now(),
                                question=question_)
            answer.save()

    answers = Logic.get_order(question=question_)
    page = paginate(request, answers)
    context.update({'question': question_, 'answer_list': page, 'user': user})
    response = render(request, 'questions.html', context)
    return response