Exemple #1
0
    def get(self, request):
        request.session.modified = True

        page = 1
        history_api = api.history_my()
        history_api = self.api_set_user_id(request, history_api)

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

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

        return Response(
            data=history_api.index(page)
        )
Exemple #2
0
    def get(self, request):
        request.session.modified = True

        page = 1
        history_api = api.history()
        history_api = self.api_set_user_id(request, history_api)

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

            if not form.cleaned_data["count"] is None:
                history_api.set_count(form.cleaned_data["count"])
            if not form.cleaned_data["page"] is None:
                page = form.cleaned_data["page"]
        response = history_api.index(page)
        if request.user.is_authenticated():
            if request.user.groups.filter(
                    name="Default Playlist Managers").exists():
                response["CanManageDefault"] = True
            if not request.user.username == "guest":
                response["CanFave"] = True

        return Response(data=response)