Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
beygorghor committed Dec 18, 2024
1 parent bc5ae52 commit 962eda4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions iaso/api/org_unit_types/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ class Meta:
# Fixme make this directly in db !
def get_units_count(self, obj: OrgUnitType):
# Show count if it's a detail view OR if with_units_count parameter is present
if self.context.get('view_action') == 'retrieve' or self.context["request"].query_params.get("with_units_count"):
if self.context.get("view_action") == "retrieve" or self.context["request"].query_params.get(
"with_units_count"
):
orgUnits = OrgUnit.objects.filter_for_user_and_app_id(
self.context["request"].user, self.context["request"].query_params.get("app_id")
).filter(Q(validated=True) & Q(org_unit_type__id=obj.id))
Expand Down Expand Up @@ -189,7 +191,9 @@ class Meta:
# Fixme make this directly in db !
def get_units_count(self, obj: OrgUnitType):
# Show count if it's a detail view OR if with_units_count parameter is present
if self.context.get('view_action') == 'retrieve' or self.context["request"].query_params.get("with_units_count"):
if self.context.get("view_action") == "retrieve" or self.context["request"].query_params.get(
"with_units_count"
):
orgUnits = OrgUnit.objects.filter_for_user_and_app_id(
self.context["request"].user, self.context["request"].query_params.get("app_id")
).filter(Q(validation_status=OrgUnit.VALIDATION_VALID) & Q(org_unit_type__id=obj.id))
Expand Down Expand Up @@ -257,7 +261,9 @@ def validate(self, data: typing.Mapping):

def to_representation(self, instance):
# Remove units_count from fields if not requested
if not self.context.get('view_action') == 'retrieve' and not self.context["request"].query_params.get("with_units_count"):
if not self.context.get("view_action") == "retrieve" and not self.context["request"].query_params.get(
"with_units_count"
):
self.fields.pop("units_count", None)
return super().to_representation(instance)

Expand Down
4 changes: 2 additions & 2 deletions iaso/api/org_unit_types/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get_queryset(self):

def get_serializer_context(self):
context = super().get_serializer_context()
context['view_action'] = self.action
context["view_action"] = self.action
return context


Expand Down Expand Up @@ -109,5 +109,5 @@ def dropdown(self, request, *args):

def get_serializer_context(self):
context = super().get_serializer_context()
context['view_action'] = self.action
context["view_action"] = self.action
return context

0 comments on commit 962eda4

Please sign in to comment.