Ejemplo n.º 1
0
def get_channel(request):
    if not ('id' in request.GET or 'url' in request.GET):
        return error_response(request, 'MISSING_ARGUMENT',
                              "get_channel requires either an id or a URL")
    channels = []
    for value in request.GET.getlist('id'):
        try:
            channels.append(api_utils.get_channel(
                                                  int(value)))
        except (LookupError, ValueError):
            return error_response(request, 'CHANNEL_NOT_FOUND',
                                  'Channel %s not found' % value)
    for value in request.GET.getlist('url'):
        try:
            channels.append(api_utils.get_channel_by_url(
                                                         value))
        except LookupError:
            return error_response(request, 'CHANNEL_NOT_FOUND',
                                  'Channel %s not found' % value)
    if request.user.is_authenticated():
        for channel in channels:
            channel.score = api_utils.get_rating(
                                                 request.user,
                                                 channel)
    if len(channels) == 1:
        data = data_for_channel(channels[0])
    else:
        data = map(data_for_channel, channels)
    return response_for_data(request, data)
Ejemplo n.º 2
0
def get_channel(request):
    if not ('id' in request.GET or 'url' in request.GET):
        return error_response(request, 'MISSING_ARGUMENT',
                              "get_channel requires either an id or a URL")
    channels = []
    for value in request.GET.getlist('id'):
        try:
            channels.append(api_utils.get_channel(int(value)))
        except (LookupError, ValueError):
            return error_response(request, 'CHANNEL_NOT_FOUND',
                                  'Channel %s not found' % value)
    for value in request.GET.getlist('url'):
        try:
            channels.append(api_utils.get_channel_by_url(value))
        except LookupError:
            return error_response(request, 'CHANNEL_NOT_FOUND',
                                  'Channel %s not found' % value)
    if request.user.is_authenticated():
        for channel in channels:
            channel.score = api_utils.get_rating(request.user, channel)
    if len(channels) == 1:
        data = data_for_channel(channels[0])
    else:
        data = map(data_for_channel, channels)
    return response_for_data(request, data)
Ejemplo n.º 3
0
def rate(request):
    try:
        channel = api_utils.get_channel(int(request.GET.get('id')))
    except (LookupError, ValueError):
        return error_response(request, 'CHANNEL_NOT_FOUND',
                              'Channel %s not found' % request.GET.get('id'))
    if 'rating' in request.GET:
        api_utils.rate(request.user, channel, request.GET['rating'])
    return response_for_data(
        request, {'rating': api_utils.get_rating(request.user, channel)})
Ejemplo n.º 4
0
def rate(request):
    try:
        channel = api_utils.get_channel(
                                        int(request.GET.get('id')))
    except (LookupError, ValueError):
        return error_response(request, 'CHANNEL_NOT_FOUND',
                              'Channel %s not found' % request.GET.get('id'))
    if 'rating' in request.GET:
        api_utils.rate(request.user, channel, request.GET['rating'])
    return response_for_data(request,
                             {'rating':
                                  api_utils.get_rating(
                request.user, channel)})
Ejemplo n.º 5
0
    def test_get_channel(self):
        """
        utils.get_channel(conection, id) should return a full channel object,
        with categories, tags, and items.
        """
        # add a rating
        rating, created = Rating.objects.get_or_create(
            channel=self.channels[0], user=self.owner)
        rating.rating = 3
        rating.save()

        call_command('refresh_stats_table')

        obj = utils.get_channel(self.channels[0].id)
        self.assertEquals(obj.id, self.channels[0].id)
        self.assertEquals(obj.url, self.channels[0].url)
        self.assertEquals(obj.owner.username, 'owner')
        self.assertEquals(len(obj.categories.all()), 2)
        self.assertEquals(len(obj.tags.all()), 2)
        self.assertEquals(len(obj.items.all()), 2)
        self.assertEquals(obj.stats.subscription_count_today, 1)
        self.assertEquals(obj.stats.subscription_count_month, 2)
        self.assertEquals(obj.stats.subscription_count, 2)
        self.assertEquals(obj.rating.average, 3)
Ejemplo n.º 6
0
    def test_get_channel(self):
        """
        utils.get_channel(conection, id) should return a full channel object,
        with categories, tags, and items.
        """
        # add a rating
        rating, created = Rating.objects.get_or_create(
            channel=self.channels[0], user=self.owner)
        rating.rating = 3
        rating.save()

        call_command('refresh_stats_table')

        obj = utils.get_channel(self.channels[0].id)
        self.assertEquals(obj.id, self.channels[0].id)
        self.assertEquals(obj.url, self.channels[0].url)
        self.assertEquals(obj.owner.username, 'owner')
        self.assertEquals(len(obj.categories.all()), 2)
        self.assertEquals(len(obj.tags.all()), 2)
        self.assertEquals(len(obj.items.all()), 2)
        self.assertEquals(obj.stats.subscription_count_today, 1)
        self.assertEquals(obj.stats.subscription_count_month, 2)
        self.assertEquals(obj.stats.subscription_count, 2)
        self.assertEquals(obj.rating.average, 3)