Exemplo n.º 1
0
    def get_queryset(self):
        '''Show submissions to the given exhibition.'''
        qs = Submission.can_see_queryset(user=self.request.user,
                                         exhibition=self._get_exhibition_id())

        # Show most recently submitted first
        order = self._get_order_by()
        if order == 'score':
            qs = qs.order_by('-score')
        else:
            qs = qs.order_by('-created_at')
        return qs
Exemplo n.º 2
0
    def get_queryset(self):
        '''Show submissions to the given exhibition.'''
        qs = Submission.can_see_queryset(
                user=self.request.user, 
                exhibition=self._get_exhibition_id())

        # Show most recently submitted first
        order = self._get_order_by()
        if order == 'score':
            qs = qs.order_by('-score')
        else:
            qs = qs.order_by('-created_at')
        return qs
    def test_can_see_queryset(self):

        exhibition0 = Exhibition.objects.create(
            title='Exhibition No Cohort', 
            description='description goes here',
            cohort=None,
            author=self.user)
        artwork0 = Artwork.objects.create(
            title='New Artwork', 
            code='// code goes here', 
            author=self.user)
        submission0 = Submission.objects.create(
            exhibition=exhibition0, 
            artwork=artwork0, 
            submitted_by=self.user)

        exhibition1 = Exhibition.objects.create(
            title='Exhibition One', 
            description='description goes here',
            cohort=self.cohort1,
            author=self.user)
        artwork1 = Artwork.objects.create(
            title='New Artwork', 
            code='// code goes here', 
            author=self.user)
        submission1 = Submission.objects.create(
            exhibition=exhibition1, 
            artwork=artwork1, 
            submitted_by=self.user)

        exhibition2 = Exhibition.objects.create(
            title='Exhibition Two', 
            description='description goes here',
            cohort=self.cohort2,
            author=self.user)
        artwork2 = Artwork.objects.create(
            title='New Artwork', 
            code='// code goes here', 
            author=self.user)
        submission2 = Submission.objects.create(
            exhibition=exhibition2, 
            artwork=artwork2, 
            submitted_by=self.user)


        # Everyone sees submissions in no-cohort and default exhibitions
        submissions = Submission.can_see_queryset().all()
        self.assertEqual(len(submissions), 2)
        self.assertEqual(submissions[0], submission0)
        self.assertEqual(submissions[1], submission1)

        # Users see no-cohort and exhibitions in their own cohort
        submissions = Submission.can_see_queryset(user=self.no_cohort_user).all()
        self.assertEqual(len(submissions), 2)
        self.assertEqual(submissions[0], submission0)
        self.assertEqual(submissions[1], submission1)

        submissions = Submission.can_see_queryset(user=self.cohort1_user).all()
        self.assertEqual(len(submissions), 2)
        self.assertEqual(submissions[0], submission0)
        self.assertEqual(submissions[1], submission1)

        submissions = Submission.can_see_queryset(user=self.cohort2_user).all()
        self.assertEqual(len(submissions), 2)
        self.assertEqual(submissions[0], submission0)
        self.assertEqual(submissions[1], submission2)

        # Unless you filter by exhibition
        submissions = Submission.can_see_queryset(exhibition=exhibition1).all()
        self.assertEqual(len(submissions), 1)
        self.assertEqual(submissions[0], submission1)

        submissions = Submission.can_see_queryset(exhibition=exhibition1.id).all()
        self.assertEqual(len(submissions), 1)
        self.assertEqual(submissions[0], submission1)

        submissions = Submission.can_see_queryset(exhibition=exhibition2).all()
        self.assertEqual(len(submissions), 1)
        self.assertEqual(submissions[0], submission2)

        submissions = Submission.can_see_queryset(exhibition=exhibition2.id).all()
        self.assertEqual(len(submissions), 1)
        self.assertEqual(submissions[0], submission2)

        # Test user+exhibition permutations
        submissions = Submission.can_see_queryset(user=self.no_cohort_user, exhibition=exhibition1).all()
        self.assertEqual(len(submissions), 1)
        self.assertEqual(submissions[0], submission1)

        submissions = Submission.can_see_queryset(user=self.cohort1_user, exhibition=exhibition1).all()
        self.assertEqual(len(submissions), 1)
        self.assertEqual(submissions[0], submission1)

        submissions = Submission.can_see_queryset(user=self.cohort2_user, exhibition=exhibition1).all()
        self.assertEqual(len(submissions), 1)
        self.assertEqual(submissions[0], submission1)

        submissions = Submission.can_see_queryset(user=self.no_cohort_user, exhibition=exhibition2).all()
        self.assertEqual(len(submissions), 1)
        self.assertEqual(submissions[0], submission2)

        submissions = Submission.can_see_queryset(user=self.cohort1_user, exhibition=exhibition2).all()
        self.assertEqual(len(submissions), 1)
        self.assertEqual(submissions[0], submission2)

        submissions = Submission.can_see_queryset(user=self.cohort2_user, exhibition=exhibition2).all()
        self.assertEqual(len(submissions), 1)
        self.assertEqual(submissions[0], submission2)
    def test_can_see_queryset(self):

        # Everyone can see submissions
        exhibition1 = Exhibition.objects.create(
            title='Exhibition One', 
            description='description goes here',
            author=self.user)
        artwork1 = Artwork.objects.create(
            title='New Artwork', 
            code='// code goes here', 
            author=self.user)
        submission1 = Submission.objects.create(
            exhibition=exhibition1, 
            artwork=artwork1, 
            submitted_by=self.user)

        exhibition2 = Exhibition.objects.create(
            title='Exhibition Two', 
            description='description goes here',
            author=self.user)
        artwork2 = Artwork.objects.create(
            title='New Artwork', 
            code='// code goes here', 
            author=self.user)
        submission2 = Submission.objects.create(
            exhibition=exhibition2, 
            artwork=artwork2, 
            submitted_by=self.user)

        # By default, all submissions are included in the can_see queryset
        submissions = Submission.can_see_queryset().all()
        self.assertEqual(len(submissions), 2)
        self.assertEqual(submissions[0], submission1)
        self.assertEqual(submissions[1], submission2)

        # Same for all users
        submissions = Submission.can_see_queryset(user=self.user).all()
        self.assertEqual(len(submissions), 2)
        self.assertEqual(submissions[0], submission1)
        self.assertEqual(submissions[1], submission2)

        submissions = Submission.can_see_queryset(user=self.staff_user).all()
        self.assertEqual(len(submissions), 2)
        self.assertEqual(submissions[0], submission1)
        self.assertEqual(submissions[1], submission2)

        # Unless you filter by exhibition
        submissions = Submission.can_see_queryset(exhibition=exhibition1).all()
        self.assertEqual(len(submissions), 1)
        self.assertEqual(submissions[0], submission1)

        submissions = Submission.can_see_queryset(exhibition=exhibition1.id).all()
        self.assertEqual(len(submissions), 1)
        self.assertEqual(submissions[0], submission1)

        submissions = Submission.can_see_queryset(exhibition=exhibition2).all()
        self.assertEqual(len(submissions), 1)
        self.assertEqual(submissions[0], submission2)

        submissions = Submission.can_see_queryset(exhibition=exhibition2.id).all()
        self.assertEqual(len(submissions), 1)
        self.assertEqual(submissions[0], submission2)