Skip to content

Commit

Permalink
Merge pull request #768 from Ilhasoft/feature/ai-filters
Browse files Browse the repository at this point in the history
adding new filters
  • Loading branch information
barbosajackson authored Mar 2, 2023
2 parents 880ae5c + d4754ae commit 71ebf13
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
17 changes: 16 additions & 1 deletion bothub/api/v2/repository/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class RepositoriesFilter(filters.FilterSet):
class Meta:
model = Repository
fields = ["name", "categories", "owner_id", "nickname"]
fields = ["name", "categories", "owner_id", "nickname", "recommended"]

language = filters.CharFilter(
field_name="language", method="filter_language", help_text=_("Language")
Expand All @@ -35,6 +35,12 @@ class Meta:
nickname = filters.CharFilter(
method="filter_nickname", help_text=_("Repository Owner Nickname")
)
categories = filters.CharFilter(
method="filter_categories", help_text=_("Repository category")
)
recommended = filters.CharFilter(
method="filter_recommended", help_text=_("Weni AIs Recommended")
)

def __filter_by_owner(self, queryset, owner):
try:
Expand All @@ -59,6 +65,15 @@ def filter_nickname(self, queryset, name, value):
owner = get_object_or_404(RepositoryOwner, nickname=value)
return self.__filter_by_owner(queryset, owner)

def filter_categories(self, queryset, name, value):
return queryset.filter(categories__name=value)

def filter_recommended(self, queryset, name, value):
if value == "True":
uuids = [uuid for uuid in settings.RECOMMENDED_AIS.get("AI_UUID") if len(uuid) > 0]
return queryset.filter(uuid__in=uuids)
return queryset


class RepositoryAuthorizationFilter(filters.FilterSet):
class Meta:
Expand Down
37 changes: 37 additions & 0 deletions bothub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@
CSP_WORKER_SRC=(tuple, "CSP_WORKER_SRC"),
CSP_IMG_SRC=(tuple, "CSP_IMG_SRC"),
USE_CONNECT_V2=(bool, False),
AI_BINARY_ANSWERS=(str, ""),
AI_FAREWELL_N_GREETINGS=(str, ""),
AI_CRISTAL=(str, ""),
AI_NAME_IDENTIFICATION=(str, ""),
AI_SUSANA_V3=(str, ""),
AI_SHORT_FAREWELL_N_GREETINGS=(str, ""),
AI_NAME_CALLING_IDENTIFICATION=(str, ""),
AI_ODONTOLOGICAL_PLAN=(str, ""),
AI_FINANCE_LEADS=(str, ""),
AI_SENTIMENT_ANALYSIS=(str, ""),
)

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
Expand Down Expand Up @@ -638,3 +648,30 @@
TEST_REPOSITORY_ID = env("TEST_REPOSITORY_ID", default=None)

USE_CONNECT_V2 = env.bool("USE_CONNECT_V2")


AI_BINARY_ANSWERS = env.str("AI_BINARY_ANSWERS")
AI_FAREWELL_N_GREETINGS = env.str("AI_FAREWELL_N_GREETINGS")
AI_CRISTAL = env.str("AI_CRISTAL")
AI_NAME_IDENTIFICATION = env.str("AI_NAME_IDENTIFICATION")
AI_SUSANA_V3 = env.str("AI_SUSANA_V3")
AI_SHORT_FAREWELL_N_GREETINGS = env.str("AI_SHORT_FAREWELL_N_GREETINGS")
AI_NAME_CALLING_IDENTIFICATION = env.str("AI_NAME_CALLING_IDENTIFICATION")
AI_ODONTOLOGICAL_PLAN = env.str("AI_ODONTOLOGICAL_PLAN")
AI_FINANCE_LEADS = env.str("AI_FINANCE_LEADS")
AI_SENTIMENT_ANALYSIS = env.str("AI_SENTIMENT_ANALYSIS")

RECOMMENDED_AIS = {
"AI_UUID": [
AI_BINARY_ANSWERS,
AI_FAREWELL_N_GREETINGS,
AI_CRISTAL,
AI_NAME_IDENTIFICATION,
AI_SUSANA_V3,
AI_SHORT_FAREWELL_N_GREETINGS,
AI_NAME_CALLING_IDENTIFICATION,
AI_ODONTOLOGICAL_PLAN,
AI_FINANCE_LEADS,
AI_SENTIMENT_ANALYSIS,
]
}

0 comments on commit 71ebf13

Please sign in to comment.