Skip to content

Commit

Permalink
fix url and viewset bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
raylrui committed Dec 5, 2024
1 parent 59ee470 commit b25f0c7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from rest_framework import serializers

from sequence_run_manager.models import State
from sequence_run_manager.models import State, Sequence
from sequence_run_manager.serializers.base import SerializersBase, OptionalFieldsMixin

class StateBaseSerializer(SerializersBase):
Expand All @@ -10,3 +10,8 @@ class StateSerializer(StateBaseSerializer):
class Meta:
model = State
fields = "__all__"

def to_representation(self, instance):
representation = super().to_representation(instance)
representation['sequence'] = Sequence.orcabus_id_prefix + representation['sequence']
return representation
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@

router = OptionalSlashDefaultRouter()
router.register(r"sequence", SequenceViewSet, basename="sequence")
router.register("sequence/(?P<orcabus_id>[^/.]+)/state", StateViewSet, basename="sequence-state")
router.register("sequence/(?P<orcabus_id>[^/.]+)/comment", CommentViewSet, basename="sequence-comment")

router.register("sequence/<str:orcabus_id>/comment", CommentViewSet, basename="sequence-comment")
router.register("sequence/<str:orcabus_id>/state", StateViewSet, basename="sequence-states")

urlpatterns = [
path(f"{api_base}", include(router.urls)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
from sequence_run_manager.models.sequence import Sequence
from sequence_run_manager.serializers.comment import CommentSerializer


class CommentViewSet(mixins.CreateModelMixin, mixins.UpdateModelMixin, mixins.DestroyModelMixin, GenericViewSet):
class CommentViewSet(mixins.CreateModelMixin, mixins.UpdateModelMixin, mixins.ListModelMixin, GenericViewSet):
serializer_class = CommentSerializer
search_fields = Comment.get_base_fields()
orcabus_id_prefix = Comment.orcabus_id_prefix
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from rest_framework.viewsets import GenericViewSet
from rest_framework import mixins

from sequence_run_manager.models.state import State
from sequence_run_manager.serializers.state import StateSerializer


class StateViewSet(GenericViewSet):
class StateViewSet(mixins.ListModelMixin, GenericViewSet):
serializer_class = StateSerializer
search_fields = State.get_base_fields()
orcabus_id_prefix = State.orcabus_id_prefix
http_method_names = ['get']
pagination_class = None

def get_queryset(self):
return State.objects.filter(sequence=self.kwargs["orcabus_id"])

0 comments on commit b25f0c7

Please sign in to comment.