forked from rc/aircox
cfr #121 Co-authored-by: Christophe Siraut <d@tobald.eu.org> Co-authored-by: bkfox <thomas bkfox net> Co-authored-by: Thomas Kairos <thomas@bkfox.net> Reviewed-on: rc/aircox#131 Co-authored-by: Chris Tactic <ctactic@noreply.git.radiocampus.be> Co-committed-by: Chris Tactic <ctactic@noreply.git.radiocampus.be>
This commit is contained in:
16
aircox_streamer/viewsets.py
Normal file → Executable file
16
aircox_streamer/viewsets.py
Normal file → Executable file
@ -43,8 +43,10 @@ class ControllerViewSet(viewsets.ViewSet):
|
||||
if station_pk is None:
|
||||
station_pk = self.request.station.pk
|
||||
self.streamers.fetch()
|
||||
if station_pk is None:
|
||||
return None
|
||||
if station_pk not in self.streamers:
|
||||
raise Http404("station not found")
|
||||
raise Http404(f"station not found: {station_pk}")
|
||||
return self.streamers[station_pk]
|
||||
|
||||
def get_serializer(self, **kwargs):
|
||||
@ -58,7 +60,8 @@ class ControllerViewSet(viewsets.ViewSet):
|
||||
return serializer.data
|
||||
|
||||
def dispatch(self, request, *args, station_pk=None, **kwargs):
|
||||
self.streamer = self.get_streamer(station_pk)
|
||||
if not self.streamer:
|
||||
self.streamer = self.get_streamer(station_pk)
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
@ -78,7 +81,10 @@ class StreamerViewSet(ControllerViewSet):
|
||||
def dispatch(self, request, *args, pk=None, **kwargs):
|
||||
if pk is not None:
|
||||
kwargs.setdefault("station_pk", pk)
|
||||
self.streamer = self.get_streamer(request, **kwargs)
|
||||
if pk := kwargs.get("station_pk"):
|
||||
kwargs["station_pk"] = int(pk)
|
||||
|
||||
self.streamer = self.get_streamer(**kwargs)
|
||||
self.object = self.streamer
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
@ -86,6 +92,8 @@ class StreamerViewSet(ControllerViewSet):
|
||||
class SourceViewSet(ControllerViewSet):
|
||||
serializer_class = SourceSerializer
|
||||
model = controllers.Source
|
||||
lookup_field = "pk"
|
||||
lookup_value_converter = "str"
|
||||
|
||||
def get_sources(self):
|
||||
return (s for s in self.streamer.sources if isinstance(s, self.model))
|
||||
@ -137,7 +145,7 @@ class QueueSourceViewSet(SourceViewSet):
|
||||
model = controllers.QueueSource
|
||||
|
||||
def get_sound_queryset(self, request):
|
||||
return Sound.objects.station(request.station).archive()
|
||||
return Sound.objects.station(request.station)
|
||||
|
||||
@action(detail=True, methods=["POST"])
|
||||
def push(self, request, pk):
|
||||
|
Reference in New Issue
Block a user