Skip to content

Commit

Permalink
Mypy error fixes.
Browse files Browse the repository at this point in the history
backend/content/serializers.py:49: error: Function is missing a type annotation  [no-untyped-def]
backend/content/views.py:304: error: Missing type parameters for generic type "ModelViewSet"  [type-arg]
backend/content/views.py:309: error: Function is missing a type annotation  [no-untyped-def]
  • Loading branch information
mattburnett-repo committed Feb 27, 2025
1 parent c9f2745 commit c36a575
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
4 changes: 3 additions & 1 deletion backend/communities/organizations/urls.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# SPDX-License-Identifier: AGPL-3.0-or-later

from rest_framework import routers

from . import views
Expand All @@ -9,4 +11,4 @@
basename="organization-images",
)

urlpatterns = router.urls
urlpatterns = router.urls
20 changes: 11 additions & 9 deletions backend/content/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Serializers for the content app.
"""

from typing import Dict, Union
from typing import Any, Dict, Union

from django.utils.translation import gettext as _
from rest_framework import serializers
Expand Down Expand Up @@ -46,25 +46,27 @@ def validate(self, data: Dict[str, Union[str, int]]) -> Dict[str, Union[str, int
raise serializers.ValidationError("No file was submitted.")
return data

def create(self, validated_data):
# Using 'Any' type until a more correct type is determined.
def create(self, validated_data: Dict[str, Any]) -> Image:
# Handle file upload properly
file_obj = self.context["request"].FILES.get("file_object")
if file_obj:
validated_data["file_object"] = file_obj

# Create the image first
image = super().create(validated_data)

# Get the organization from the request
organization_id = self.context['request'].data.get('organization_id')
organization_id = self.context["request"].data.get("organization_id")
if organization_id:
# Create OrganizationImage with next sequence index
from communities.organizations.models import OrganizationImage
next_index = OrganizationImage.objects.filter(org_id=organization_id).count()

next_index = OrganizationImage.objects.filter(
org_id=organization_id
).count()
OrganizationImage.objects.create(
org_id=organization_id,
image=image,
sequence_index=next_index
org_id=organization_id, image=image, sequence_index=next_index
)
return image

Expand Down
7 changes: 5 additions & 2 deletions backend/content/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
# mypy: disable-error-code="override"
from typing import Any

from django.db.models import Q
from rest_framework import status, viewsets
from rest_framework.parsers import FormParser, MultiPartParser
Expand Down Expand Up @@ -301,12 +303,13 @@ def destroy(self, request: Request, pk: str | None = None) -> Response:
return Response(status=status.HTTP_204_NO_CONTENT)


class ImageViewSet(viewsets.ModelViewSet):
class ImageViewSet(viewsets.ModelViewSet[Image]):
queryset = Image.objects.all()
serializer_class = ImageSerializer
parser_classes = (MultiPartParser, FormParser)

def create(self, request, *args, **kwargs):
# Using 'Any' type until a more correct type is determined.
def create(self, request: Request, *args: Any, **kwargs: Any) -> Response:
serializer = self.get_serializer(
data=request.data,
context={"request": request}, # Pass request to serializer
Expand Down

0 comments on commit c36a575

Please sign in to comment.