コード例 #1
0
ファイル: views.py プロジェクト: kal/pireader
def feed(request, feed_id='0'):
    store = FeedStore()
    try:
        feed = Feed.objects.get(id=int(feed_id))
    except Feed.DoesNotExist:
        print "Cannot find the feed"
        return Http404
    if not feed.owner_id == request.user.id:
        return HttpResponse('Unauthorized', status=401)
    if request.method == "GET":
        skip = 0
        take = None
        if request.GET.has_key('skip'):
            skip = int(request.GET['skip'])
        if request.GET.has_key('take'):
            take = int(request.GET['take'])
        entries = store.get_entries(feed_id, skip=skip, take=take)
        return HttpResponse(json.dumps(entries, cls=TimeHandlingEncoder), mimetype='application/json')
    elif request.method == "POST":
        data = request.read()
        feed_update = json.loads(data)
        store = FeedStore()
        responseData = {}
        if 'keep' in feed_update:
            for item in feed_update['keep']:
                try:
                    store.keep(feed_id, item)
                except EntryDoesNotExist:
                    pass;
        if 'unkeep' in feed_update:
            for item in feed_update['unkeep']:
                try:
                    store.unkeep(feed_id, item)
                except EntryDoesNotExist:
                    pass;
        if 'read' in feed_update:
            feed.unread_count = store.mark_read(feed_id, feed_update['read'])
            feed.save()
            responseData['unread_count'] = feed.unread_count
        if 'read_all' in feed_update:
            if feed_update['read_all'] < 0:
                store.mark_all_read(feed_id)
                feed.unread_count = 0
                feed.save()
        if 'restore_all' in feed_update:
            store.restore_all_items(feed_id)
            entries = store.get_entries(feed_id)
            return HttpResponse(json.dumps(entries, cls=TimeHandlingEncoder), mimetype='application/json')
        if 'refresh' in feed_update:
            feedprocessor.process_feed(feed_id)
            entries = store.get_entries(feed_id)
            return HttpResponse(json.dumps(entries, cls=TimeHandlingEncoder), mimetype='application/json')
        return HttpResponse(json.dumps(responseData))
    elif request.method == "DELETE":
        feed.is_deleted = True
        feed.save()
        #if 'tag' in feed_update:
        #    for item_tag in feed_update['tag']:
        #        store.tag_item(item_tag['item'], item_tag['tag'])
        return HttpResponse()
コード例 #2
0
ファイル: tests.py プロジェクト: kal/pireader
 def test_real_feed(self):
     feed = self.create_feed("Techquila", "http://techquila.com/tech/feed/")
     feedprocessor.process_feed(feed, self.store)
     counts = self.store.get_counts(str(feed.id))
     self.assertGreater(counts['unread'], 0, 'Expected more than 0 items for feed {0} after import from feed'.format(feed.id))
     self.assertEqual(0, counts['keep'])