def aggregated_feed(request):
    '''
    Items pinned by the people you follow
    '''
    context = RequestContext(request)
    feed = manager.get_feeds(request.user.id)['aggregated']
    if request.REQUEST.get('delete'):
        feed.delete()
    activities = list(feed[:25])
    if request.REQUEST.get('raise'):
        raise Exception, activities
    context['feed_pins'] = enrich_aggregated_activities(activities)
    response = render_to_response('core/aggregated_feed.html', context)
    return response
    def setUp(self):
        TestCase.setUp(self)

        self.bogus_user = bogus_user = get_user_model().objects.get(username="bogus")
        self.bogus_user2 = bogus_user2 = get_user_model().objects.get(username="bogus2")
        # start by resetting the feeds
        for u in [self.bogus_user, self.bogus_user2]:
            user_feed = manager.get_user_feed(u.id)
            user_feed.delete()
            for name, feed in manager.get_feeds(u.id).items():
                feed.delete()

        # login the user
        rf = RequestMock()
        self.rf = rf
        self.client = Client()
        self.auth_client = Client()
        self.auth_client2 = Client()
        auth_response = self.auth_client.login(username="bogus", password="bogus")
        self.assertTrue(auth_response)
        auth_response = self.auth_client2.login(username="bogus2", password="bogus")
        self.assertTrue(auth_response)
    def test_aggregated_add_many(self):
        # setup the pins and activity chunk
        t = timer()
        admin_user_id = 1
        aggregated = manager.get_feeds(admin_user_id)["aggregated"]
        pins = list(Pin.objects.filter(user=admin_user_id)[:3])
        activities = []
        base_activity = pins[0].create_activity()
        sample_size = 1000
        for x in range(1, sample_size):
            activity = copy.deepcopy(base_activity)
            activity.actor_id = x
            activity.object_id = x
            activities.append(activity)
        aggregated.insert_activities(activities)

        for activity in activities:
            aggregated.add_many([activity], trim=False)
        add_many_time = t.next()
        print "add many ran 10000 times, took %s" % add_many_time
        popular_user_time = 100000.0 / sample_size * add_many_time
        print "popular user fanout would take %s seconds" % popular_user_time