def test_get_carousel_resources(self): ResourceFactory.create( title='first', likes=UserFactory.create_batch(size=10), status=RESOURCE_APPROVED ) second = ResourceFactory.create( title='second', tried=UserFactory.create_batch(size=5), hits=20, status=RESOURCE_APPROVED, ) resources = Resource.get_carousel_resources(limit=1) self.assertIn(second, resources)
def get_context_data(self, **kwargs): context = super().get_context_data() context['carousel_resources'] = Resource.get_carousel_resources( self.request.user) context['latest_resource'] = Resource.get_latest(self.request.user) most_tried_resource = Resource.get_most_tried( self.request.user).first() context['most_tried'] = most_tried_resource kwargs = {'user': self.request.user} if most_tried_resource: kwargs.update({'exclude': most_tried_resource.id}) context['most_liked'] = Resource.get_most_liked(**kwargs).first() context['most_published'] = Organisation.get_most_published_this_week() return context