diff options
Diffstat (limited to 'pydis_site/apps')
| -rw-r--r-- | pydis_site/apps/api/serializers.py | 18 | ||||
| -rw-r--r-- | pydis_site/apps/api/viewsets/bot/infraction.py | 6 | ||||
| -rw-r--r-- | pydis_site/apps/api/viewsets/bot/nomination.py | 2 | ||||
| -rw-r--r-- | pydis_site/apps/content/utils.py | 4 | ||||
| -rw-r--r-- | pydis_site/apps/resources/resources/software_design_by_example.yaml | 26 | 
5 files changed, 39 insertions, 17 deletions
| diff --git a/pydis_site/apps/api/serializers.py b/pydis_site/apps/api/serializers.py index 87fd6190..cfd975c9 100644 --- a/pydis_site/apps/api/serializers.py +++ b/pydis_site/apps/api/serializers.py @@ -151,12 +151,9 @@ class MessageDeletionContextSerializer(ModelSerializer):          """          messages = validated_data.pop('deletedmessage_set')          deletion_context = MessageDeletionContext.objects.create(**validated_data) -        for message in messages: -            DeletedMessage.objects.create( -                deletion_context=deletion_context, -                **message -            ) - +        DeletedMessage.objects.bulk_create( +            DeletedMessage(deletion_context=deletion_context, **message) for message in messages +        )          return deletion_context @@ -508,13 +505,8 @@ class ExpandedInfractionSerializer(InfractionSerializer):          """Return the dictionary representation of this infraction."""          ret = super().to_representation(instance) -        user = User.objects.get(id=ret['user']) -        user_data = UserSerializer(user).data -        ret['user'] = user_data - -        actor = User.objects.get(id=ret['actor']) -        actor_data = UserSerializer(actor).data -        ret['actor'] = actor_data +        ret['user'] = UserSerializer(instance.user).data +        ret['actor'] = UserSerializer(instance.actor).data          return ret diff --git a/pydis_site/apps/api/viewsets/bot/infraction.py b/pydis_site/apps/api/viewsets/bot/infraction.py index 09c05a74..8da82822 100644 --- a/pydis_site/apps/api/viewsets/bot/infraction.py +++ b/pydis_site/apps/api/viewsets/bot/infraction.py @@ -230,7 +230,11 @@ class InfractionViewSet(                  })              additional_filters['type__in'] = [i.strip() for i in filter_types.split(",")] -        return self.queryset.filter(**additional_filters) +        qs = self.queryset.filter(**additional_filters) +        if self.serializer_class is ExpandedInfractionSerializer: +            return qs.prefetch_related('actor', 'user') + +        return qs      @action(url_path='expanded', detail=False)      def list_expanded(self, *args, **kwargs) -> Response: diff --git a/pydis_site/apps/api/viewsets/bot/nomination.py b/pydis_site/apps/api/viewsets/bot/nomination.py index 953513e0..d083464c 100644 --- a/pydis_site/apps/api/viewsets/bot/nomination.py +++ b/pydis_site/apps/api/viewsets/bot/nomination.py @@ -170,7 +170,7 @@ class NominationViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge      """      serializer_class = NominationSerializer -    queryset = Nomination.objects.all() +    queryset = Nomination.objects.all().prefetch_related('entries')      filter_backends = (DjangoFilterBackend, SearchFilter, OrderingFilter)      filterset_fields = ('user__id', 'active')      frozen_on_create = ('ended_at', 'end_reason', 'active', 'inserted_at', 'reviewed') diff --git a/pydis_site/apps/content/utils.py b/pydis_site/apps/content/utils.py index cfd73d67..9c949a93 100644 --- a/pydis_site/apps/content/utils.py +++ b/pydis_site/apps/content/utils.py @@ -206,9 +206,9 @@ def record_tags(tags: list[Tag]) -> None:              # pretend it's previous state is the current state              old_tag = new_tag -        if old_tag.sha == new_tag.sha and old_tag.last_commit is not None: +        if old_tag.sha == new_tag.sha and old_tag.last_commit_id is not None:              # We still have an up-to-date commit entry -            new_tag.last_commit = old_tag.last_commit +            new_tag.last_commit_id = old_tag.last_commit_id          new_tag.save() diff --git a/pydis_site/apps/resources/resources/software_design_by_example.yaml b/pydis_site/apps/resources/resources/software_design_by_example.yaml new file mode 100644 index 00000000..8cdfd625 --- /dev/null +++ b/pydis_site/apps/resources/resources/software_design_by_example.yaml @@ -0,0 +1,26 @@ +name: Software Design by Example +description: A tool-based introduction to Software Design with Python. This book teaches +  design by explaining examples of small versions of familiar tools to show how +  experienced software designers think. It introduces some fundamental ideas in computer +  science that many self-taught programmers haven’t encountered. +icon_image: https://third-bit.com/sdxpy/logo.svg +icon_size: 50 +title_url: https://third-bit.com/sdxpy/ +urls: +- icon: branding/goodreads +  url: https://www.goodreads.com/book/show/199430059-software-design-by-example +  color: black +- icon: branding/github +  url: https://github.com/gvwilson/sdxpy +  color: black +tags: +  topics: +    - general +    - software design +  payment_tiers: +    - free +    - paid +  difficulty: +    - intermediate +  type: +    - book | 
