Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementación filtros NPS #1474

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions breathecode/feedback/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,37 @@ def get_average(answers: QuerySet[Answer]) -> float:
"cohort": cohort,
"mentors": sorted(mentors, key=lambda x: x["name"]),
}


def filter_answer_by_question(answers, question_type):
question_type = question_type.upper()
if question_type == "MENTORSHIP_SESSION":
return answers.filter(mentorship_session__isnull=False)
elif question_type == "EVENT":
return answers.filter(event__isnull=False, mentorship_session__isnull=True)
elif question_type == "MENTOR":
return answers.filter(mentor__isnull=False, event__isnull=True, mentorship_session__isnull=True)
elif question_type == "COHORT":
return answers.filter(
cohort__isnull=False, mentor__isnull=True, event__isnull=True, mentorship_session__isnull=True
)
elif question_type == "ACADEMY":
return answers.filter(
academy__isnull=False,
cohort__isnull=True,
mentor__isnull=True,
event__isnull=True,
mentorship_session__isnull=True,
)
elif question_type == "CONTENT_AND_PLATFORM":
return (
answers.filter(question_by_slug__isnull=False)
.exclude(question_by_slug="")
.filter(
cohort__isnull=True,
mentor__isnull=True,
event__isnull=True,
mentorship_session__isnull=True,
)
)
return answers
5 changes: 5 additions & 0 deletions breathecode/feedback/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from breathecode.utils.find_by_full_name import query_like_by_full_name
from capyc.rest_framework.exceptions import ValidationException

from .actions import filter_answer_by_question
from .caches import AnswerCache
from .models import Answer, Review, ReviewPlatform, Survey
from .serializers import (
Expand Down Expand Up @@ -123,6 +124,10 @@ def get(self, request, format=None, academy_id=None):
if surveys is not None and surveys != "":
items = items.filter(survey__id__in=surveys.split(","))

question_filter = request.GET.get("question", None)
if question_filter is not None and question_filter != "":
items = filter_answer_by_question(items, question_filter)

items = items.filter(**lookup)

like = request.GET.get("like", None)
Expand Down
Loading