Esempio n. 1
0
    def get(self, request):
        request.session.modified = True

        page = 1
        queue_api = api.queue()
        queue_api = self.set_user_id(request, queue_api)

        form = forms.QueueForm(request.GET)
        if form.is_valid():
            if (not form.cleaned_data["order_by"] == "" and
                not form.cleaned_data["order_direction"] == ""):
                queue_api.set_order_by(
                    form.cleaned_data["order_by"],
                    form.cleaned_data["order_direction"]
                )
            elif not form.cleaned_data["order_by"] == "":
                queue_api.set_order_by(form.cleaned_data["order_by"])

            if not form.cleaned_data["count"] is None:
                queue_api.set_count(form.cleaned_data["count"])
            if not form.cleaned_data["page"] is None:
                page = form.cleaned_data["page"]

        result = queue_api.index(page)
        for k, v in enumerate(result["itemList"]):
            result["itemList"][k]["url"] = reverse(
                "jukebox_api_queue_item",
                kwargs={"song_id": v["id"]}
            )
        return result
Esempio n. 2
0
    def get(self, request):
        request.session.modified = True

        page = 1
        queue_api = api.queue()
        queue_api = self.api_set_user_id(request, queue_api)

        form = forms.QueueForm(request.GET)
        if form.is_valid():
            if (not form.cleaned_data["order_by"] == "" and
                not form.cleaned_data["order_direction"] == ""):
                queue_api.set_order_by(
                    form.cleaned_data["order_by"],
                    form.cleaned_data["order_direction"]
                )
            elif not form.cleaned_data["order_by"] == "":
                queue_api.set_order_by(form.cleaned_data["order_by"])

            if not form.cleaned_data["count"] is None:
                queue_api.set_count(form.cleaned_data["count"])
            if not form.cleaned_data["page"] is None:
                page = form.cleaned_data["page"]

        result = queue_api.index(page)
        for k, v in enumerate(result["itemList"]):
            result["itemList"][k]["url"] = reverse(
                "jukebox_api_queue_item",
                kwargs={"song_id": v["id"]}
            )
        return Response(
            data=result
        )
Esempio n. 3
0
    def post(self, request):
        request.session.modified = True

        queue_api = api.queue()
        queue_api = self.api_set_user_id(request, queue_api)

        try:
            song_id = queue_api.add(self.request.POST["id"])
            if song_id == -1:
                return Response(
                    status=status.HTTP_201_CREATED,
                    data={
                        'id': -1
                    })
            return Response(
                status=status.HTTP_201_CREATED,
                data={
                    'id': int(self.request.POST['id'])
                },
                headers={"Location": reverse(
                    "jukebox_api_queue_item",
                    kwargs={"song_id": song_id}
                )}
            )
        except ObjectDoesNotExist:
            return Response(status=status.HTTP_404_NOT_FOUND)
        except Exception, e:
            print e
            return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Esempio n. 4
0
    def delete(self, request, song_id):
        request.session.modified = True

        queue_api = api.queue()
        queue_api = self.set_user_id(request, queue_api)

        try:
            return queue_api.remove(song_id)
        except ObjectDoesNotExist:
            return Response(status.HTTP_404_NOT_FOUND)
        except:
            return Response(status.HTTP_500_INTERNAL_SERVER_ERROR)
Esempio n. 5
0
    def delete(self, request, song_id):
        request.session.modified = True

        queue_api = api.queue()
        queue_api = self.api_set_user_id(request, queue_api)

        try:
            return Response(data=queue_api.remove(song_id))
        except ObjectDoesNotExist:
            return Response(status=status.HTTP_404_NOT_FOUND)
        except:
            return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Esempio n. 6
0
    def get(self, request, song_id):
        request.session.modified = True

        queue_api = api.queue()
        queue_api = self.api_set_user_id(request, queue_api)

        try:
            item = queue_api.get(song_id)
            item["url"] = reverse("jukebox_api_queue_item",
                                  kwargs={"song_id": item["id"]})
            return Response(data=item)
        except ObjectDoesNotExist:
            return Response(status=status.HTTP_404_NOT_FOUND)
        except Exception, e:
            print e
            return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Esempio n. 7
0
    def get(self, request, song_id):
        request.session.modified = True

        queue_api = api.queue()
        queue_api = self.set_user_id(request, queue_api)

        try:
            item = queue_api.get(song_id)
            item["url"] = reverse(
                "jukebox_api_queue_item",
                kwargs={"song_id": item["id"]}
            )
            return item
        except ObjectDoesNotExist:
            return Response(status.HTTP_404_NOT_FOUND)
        except:
            return Response(status.HTTP_500_INTERNAL_SERVER_ERROR)
Esempio n. 8
0
    def post(self, request):
        request.session.modified = True

        queue_api = api.queue()
        queue_api = self.set_user_id(request, queue_api)

        try:
            song_id = queue_api.add(self.CONTENT["id"])
            return Response(
                status.HTTP_201_CREATED,
                self.CONTENT,
                {"Location": reverse(
                    "jukebox_api_queue_item",
                    kwargs={"song_id": song_id}
                )}
            )
        except ObjectDoesNotExist:
            return Response(status.HTTP_404_NOT_FOUND)
        except:
            return Response(status.HTTP_500_INTERNAL_SERVER_ERROR)
Esempio n. 9
0
    def post(self, request):
        request.session.modified = True

        queue_api = api.queue()
        queue_api = self.api_set_user_id(request, queue_api)

        try:
            song_id = queue_api.add(self.request.POST["id"])
            return Response(status=status.HTTP_201_CREATED,
                            data={'id': int(self.request.POST['id'])},
                            headers={
                                "Location":
                                reverse("jukebox_api_queue_item",
                                        kwargs={"song_id": song_id})
                            })
        except ObjectDoesNotExist:
            return Response(status=status.HTTP_404_NOT_FOUND)
        except Exception, e:
            print e
            return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)