Skip to content

Commit

Permalink
feat: retrieve single rfc, including text (#8346)
Browse files Browse the repository at this point in the history
* feat: retrieve single rfc

Use RFC number instead of doc PK as id

* feat: include text in single-rfc response

* chore: drop doc id from api response
  • Loading branch information
jennifer-richards authored Dec 19, 2024
1 parent d245312 commit d60dba1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 8 additions & 4 deletions ietf/doc/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ietf.name.models import StreamName
from ietf.utils.timezone import RPC_TZINFO
from .models import Document, DocEvent, RelatedDocument
from .serializers import RfcMetadataSerializer, RfcStatus
from .serializers import RfcMetadataSerializer, RfcStatus, RfcSerializer


class RfcLimitOffsetPagination(LimitOffsetPagination):
Expand Down Expand Up @@ -50,8 +50,9 @@ class RfcFilter(filters.FilterSet):

class RfcViewSet(ListModelMixin, RetrieveModelMixin, GenericViewSet):
permission_classes: list[BasePermission] = []
lookup_field = "rfc_number"
queryset = (
Document.objects.filter(type_id="rfc")
Document.objects.filter(type_id="rfc", rfc_number__isnull=False)
.annotate(
published_datetime=Subquery(
DocEvent.objects.filter(
Expand Down Expand Up @@ -81,9 +82,12 @@ class RfcViewSet(ListModelMixin, RetrieveModelMixin, GenericViewSet):
),
)
) # default ordering - RfcFilter may override

serializer_class = RfcMetadataSerializer
pagination_class = RfcLimitOffsetPagination
filter_backends = [filters.DjangoFilterBackend, drf_filters.SearchFilter]
filterset_class = RfcFilter
search_fields = ["title", "abstract"]

def get_serializer_class(self):
if self.action == "retrieve":
return RfcSerializer
return RfcMetadataSerializer
13 changes: 12 additions & 1 deletion ietf/doc/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class RelatedRfcSerializer(serializers.Serializer):


class RfcMetadataSerializer(serializers.ModelSerializer):
"""Serialize metadata of an RFC"""

number = serializers.IntegerField(source="rfc_number")
published = serializers.DateField()
status = RfcStatusSerializer(source="*")
Expand All @@ -128,7 +130,6 @@ class RfcMetadataSerializer(serializers.ModelSerializer):
class Meta:
model = Document
fields = [
"id",
"number",
"title",
"published",
Expand All @@ -152,3 +153,13 @@ def get_identifiers(self, doc: Document):
DocIdentifier(type="doi", value=f"10.17487/RFC{doc.rfc_number:04d}")
)
return DocIdentifierSerializer(instance=identifiers, many=True).data


class RfcSerializer(RfcMetadataSerializer):
"""Serialize an RFC, including its metadata and text content if available"""

text = serializers.CharField(allow_null=True)

class Meta:
model = RfcMetadataSerializer.Meta.model
fields = RfcMetadataSerializer.Meta.fields + ["text"]

0 comments on commit d60dba1

Please sign in to comment.