Coverage for api/serializers/source_serializers.py: 100%
19 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 06:14 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 06:14 +0000
1from rest_framework import serializers
3from drf_spectacular.utils import extend_schema_serializer
5from api.models import ContentSource
8@extend_schema_serializer(
9 deprecate_fields=["logo_url"],
10)
11class SourceSerializer(serializers.ModelSerializer):
12 source_name = serializers.CharField(
13 source="source_identifier",
14 help_text="The source of the media, e.g. flickr",
15 )
16 display_name = serializers.CharField(
17 source="source_name",
18 help_text="The name of content source, e.g. Flickr",
19 )
20 source_url = serializers.URLField(
21 source="domain_name",
22 help_text="The URL of the source, e.g. https://www.flickr.com",
23 )
24 logo_url = serializers.SerializerMethodField(
25 help_text="The URL to a logo for the source.",
26 )
27 media_count = serializers.SerializerMethodField(
28 help_text="The number of media items indexed from the source.",
29 )
31 @staticmethod
32 def get_logo_url(*_) -> str | None:
33 return None
35 class Meta:
36 model = ContentSource
37 fields = [
38 "source_name",
39 "display_name",
40 "source_url",
41 "logo_url",
42 "media_count",
43 ]
45 def get_media_count(self, obj) -> int:
46 source_counts = self.context.get("source_counts")
47 return source_counts.get(obj.source_identifier)