Example #1
0
async def questions_user(request):
    id = request.path_params["id"]
    results = await User.get(username=id)
    result = await Question.all().prefetch_related(
        "user", "tags").filter(user_id=results.id).order_by("-id")
    # Serialize the queryset
    questions = questions_schema.dump(result)
    return UJSONResponse({"questions": questions})
Example #2
0
async def tags(request):
    """
    All tags
    """
    tag = request.path_params["tag"]
    result = (await
              Question.all().prefetch_related("user",
                                              "tags").filter(tags__name=tag
                                                             ).order_by("-id"))
    # Serialize the queryset
    questions = questions_schema.dump(result)
    return UJSONResponse({"questions": questions})
Example #3
0
async def questions_solved(request):
    results = await Question.filter(accepted_answer=1
                                    ).prefetch_related("user",
                                                       "tags").order_by("-id")
    # Serialize the queryset
    questions = questions_schema.dump(results)
    answer_count = [
        (await
         Answer.all().prefetch_related("question").filter(question__id=row.id
                                                          ).count())
        for row in results
    ]
    for item, x in zip(questions, answer_count):
        item['answer_count'] = x
    return UJSONResponse({"questions": questions})
Example #4
0
async def dashboard(request):
    if request.user.is_authenticated:
        users = await User.all()
        results = users_schema.dump(users)
        qus = await Question.all().prefetch_related(
            "user", "tags").order_by('-id')
        questions = questions_schema.dump(qus)
        ans = await Answer.all().prefetch_related(
            "ans_user", "question").order_by('-id')
        answers = answers_schema.dump(ans)
        return UJSONResponse(
            {
                "results": results,
                "questions": questions,
                "answers": answers,
            }
        )