diff options
| -rw-r--r-- | pydis_site/apps/api/serializers.py | 8 | ||||
| -rw-r--r-- | pydis_site/apps/api/viewsets/bot/infraction.py | 11 | ||||
| -rw-r--r-- | pydis_site/apps/api/viewsets/bot/nomination.py | 5 | ||||
| -rw-r--r-- | pydis_site/apps/api/viewsets/bot/off_topic_channel_name.py | 10 | 
4 files changed, 19 insertions, 15 deletions
| diff --git a/pydis_site/apps/api/serializers.py b/pydis_site/apps/api/serializers.py index 442f6209..5466b06b 100644 --- a/pydis_site/apps/api/serializers.py +++ b/pydis_site/apps/api/serializers.py @@ -66,7 +66,7 @@ class MessageDeletionContextSerializer(ModelSerializer):          fields = ('actor', 'creation', 'id', 'deletedmessage_set')          depth = 1 -    def create(self, validated_data): +    def create(self, validated_data: dict) -> MessageDeletionContext:          """          Return a `MessageDeletionContext` based on the given data. @@ -106,7 +106,7 @@ class InfractionSerializer(ModelSerializer):              'id', 'inserted_at', 'expires_at', 'active', 'user', 'actor', 'type', 'reason', 'hidden'          ) -    def validate(self, attrs): +    def validate(self, attrs: dict) -> dict:          """Validate data constraints for the given data and abort if it is invalid."""          infr_type = attrs.get('type') @@ -129,7 +129,7 @@ class ExpandedInfractionSerializer(InfractionSerializer):      serializer also attaches the `user` and `actor` fields when serializing.      """ -    def to_representation(self, instance): +    def to_representation(self, instance: Infraction) -> dict:          """Return the dictionary representation of this infraction."""          ret = super().to_representation(instance) @@ -166,7 +166,7 @@ class OffTopicChannelNameSerializer(ModelSerializer):          model = OffTopicChannelName          fields = ('name',) -    def to_representation(self, obj): +    def to_representation(self, obj: OffTopicChannelName) -> str:          """          Return the representation of this `OffTopicChannelName`. diff --git a/pydis_site/apps/api/viewsets/bot/infraction.py b/pydis_site/apps/api/viewsets/bot/infraction.py index c471ca2c..edec0a1e 100644 --- a/pydis_site/apps/api/viewsets/bot/infraction.py +++ b/pydis_site/apps/api/viewsets/bot/infraction.py @@ -1,3 +1,4 @@ +from django.http.request import HttpRequest  from django_filters.rest_framework import DjangoFilterBackend  from rest_framework.decorators import action  from rest_framework.exceptions import ValidationError @@ -123,7 +124,7 @@ class InfractionViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge      search_fields = ('$reason',)      frozen_fields = ('id', 'inserted_at', 'type', 'user', 'actor', 'hidden') -    def partial_update(self, request, *_args, **_kwargs): +    def partial_update(self, request: HttpRequest, *_args, **_kwargs) -> Response:          """Method that handles the nuts and bolts of updating an Infraction."""          for field in request.data:              if field in self.frozen_fields: @@ -137,7 +138,7 @@ class InfractionViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge          return Response(serializer.data)      @action(url_path='expanded', detail=False) -    def list_expanded(self, *args, **kwargs): +    def list_expanded(self, *args, **kwargs) -> Response:          """          DRF method for listing Infraction entries. @@ -147,7 +148,7 @@ class InfractionViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge          return self.list(*args, **kwargs)      @list_expanded.mapping.post -    def create_expanded(self, *args, **kwargs): +    def create_expanded(self, *args, **kwargs) -> Response:          """          DRF method for creating an Infraction. @@ -157,7 +158,7 @@ class InfractionViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge          return self.create(*args, **kwargs)      @action(url_path='expanded', url_name='detail-expanded', detail=True) -    def retrieve_expanded(self, *args, **kwargs): +    def retrieve_expanded(self, *args, **kwargs) -> Response:          """          DRF method for retrieving a specific Infraction. @@ -167,7 +168,7 @@ class InfractionViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge          return self.retrieve(*args, **kwargs)      @retrieve_expanded.mapping.patch -    def partial_update_expanded(self, *args, **kwargs): +    def partial_update_expanded(self, *args, **kwargs) -> Response:          """          DRF method for updating an Infraction. diff --git a/pydis_site/apps/api/viewsets/bot/nomination.py b/pydis_site/apps/api/viewsets/bot/nomination.py index 8d551697..cf6e262f 100644 --- a/pydis_site/apps/api/viewsets/bot/nomination.py +++ b/pydis_site/apps/api/viewsets/bot/nomination.py @@ -1,5 +1,6 @@  from collections import ChainMap +from django.http.request import HttpRequest  from django.utils import timezone  from django_filters.rest_framework import DjangoFilterBackend  from rest_framework import status @@ -151,7 +152,7 @@ class NominationViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge      frozen_fields = ('id', 'actor', 'inserted_at', 'user', 'ended_at')      frozen_on_create = ('ended_at', 'end_reason', 'active', 'inserted_at') -    def create(self, request, *args, **kwargs): +    def create(self, request: HttpRequest, *args, **kwargs) -> Response:          """          DRF method for creating a Nomination. @@ -176,7 +177,7 @@ class NominationViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge          headers = self.get_success_headers(serializer.data)          return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers) -    def partial_update(self, request, *args, **kwargs): +    def partial_update(self, request: HttpRequest, *args, **kwargs) -> Response:          """          DRF method for updating a Nomination. diff --git a/pydis_site/apps/api/viewsets/bot/off_topic_channel_name.py b/pydis_site/apps/api/viewsets/bot/off_topic_channel_name.py index d977aade..d6da2399 100644 --- a/pydis_site/apps/api/viewsets/bot/off_topic_channel_name.py +++ b/pydis_site/apps/api/viewsets/bot/off_topic_channel_name.py @@ -1,3 +1,5 @@ +from django.db.models.query import QuerySet +from django.http.request import HttpRequest  from django.shortcuts import get_object_or_404  from rest_framework.exceptions import ParseError  from rest_framework.mixins import DestroyModelMixin @@ -54,7 +56,7 @@ class OffTopicChannelNameViewSet(DestroyModelMixin, ViewSet):      lookup_field = 'name'      serializer_class = OffTopicChannelNameSerializer -    def get_object(self): +    def get_object(self) -> OffTopicChannelName:          """          Returns the OffTopicChannelName entry for this request, if it exists. @@ -64,11 +66,11 @@ class OffTopicChannelNameViewSet(DestroyModelMixin, ViewSet):          name = self.kwargs[self.lookup_field]          return get_object_or_404(queryset, name=name) -    def get_queryset(self): +    def get_queryset(self) -> QuerySet:          """Returns a queryset that covers the entire OffTopicChannelName table."""          return OffTopicChannelName.objects.all() -    def create(self, request): +    def create(self, request: HttpRequest) -> Response:          """          DRF method for creating a new OffTopicChannelName. @@ -86,7 +88,7 @@ class OffTopicChannelNameViewSet(DestroyModelMixin, ViewSet):                  'name': ["This query parameter is required."]              }) -    def list(self, request): +    def list(self, request: HttpRequest) -> Response:          """          DRF method for listing OffTopicChannelName entries. | 
