def get(self, request, device_id=None):
        suggestion = get_suggested_channels()
        if device_id is not None:
            # Vengono rimossi dai suggeriti quelli già sottoscritti
            channel_names = SubscriberManager().get_device_subscriptions(device_id)
            suggestion = [sugg for sugg in suggestion if not sugg.name.lower() in channel_names]

        serializer = ChannelSerializer(suggestion, many=True)
        return Response(serializer.data, status=status.HTTP_200_OK)
    def get(self, request, device_id=None):
        suggestion = get_suggested_channels()
        if device_id is not None:
            # Vengono rimossi dai suggeriti quelli già sottoscritti
            channel_names = SubscriberManager().get_device_subscriptions(
                device_id)
            suggestion = [
                sugg for sugg in suggestion
                if not sugg.name.lower() in channel_names
            ]

        serializer = ChannelSerializer(suggestion, many=True)
        return Response(serializer.data, status=status.HTTP_200_OK)
示例#3
0
    def get(self, request):
        q = request.GET.get('term', '')

        if request.is_ajax():
            page = request.GET.get('page', None)
            sqs = search_public_channels(q)

            return HttpResponse(json.dumps([dict(name=q.name, image=q.image, kind=q.kind) for q in sqs]),
                                content_type="application/json")
        else:
            channels = []
            if q:
                channels = search_public_channels(q)
            else:

                channels = get_suggested_channels()
            return render_to_response('search.html',
                                      {
                                          'suggested': channels,
                                      },
                                      context_instance=RequestContext(request)
            )

        return HttpResponse()