def test_can_save_shared_queryset(self): student = Artwork( author=self.user, title='Empty code', shared=1, code='// code goes here') student.save() staff = Artwork( author=self.staff_user, title='Empty code', shared=1, code='// code goes here') staff.save() superuser = Artwork( author=self.super_user, title='Empty code', shared=1, code='// code goes here') superuser.save() public_qs = Artwork.can_save_queryset() self.assertEqual(len(public_qs.all()), 0) student_qs = Artwork.can_save_queryset(user=self.user) self.assertEqual(len(student_qs.all()), 0) staff_qs = Artwork.can_save_queryset(user=self.staff_user) self.assertEqual(len(staff_qs.all()), 0) super_qs = Artwork.can_save_queryset(user=self.super_user) self.assertEqual(len(super_qs.all()), 0)
def get_context_data(self, **kwargs): context = super(CreateSubmissionView, self).get_context_data(**kwargs) # Restrict list of artwork the current user can submit context['form'].fields['artwork'].queryset = Artwork.can_save_queryset( context['form'].fields['artwork'].queryset, self.request.user) # Restrict to specific artwork if given artwork_id = self.kwargs.get('artwork') exclude_exhibitions = [] if artwork_id: context['form'].fields['artwork'].queryset =\ context['form'].fields['artwork'].queryset.filter(id=artwork_id) # Fetch the exhibitions this artwork has already been submitted to exclude_exhibitions = Submission.objects.filter( artwork__exact=artwork_id).order_by('-created_at').values_list( 'exhibition', flat=True) # Restrict list of exhibitions the current user can see, # and exclude exhibitions this artwork has already been submitted to context['form'].fields[ 'exhibition'].queryset = Exhibition.can_see_queryset( context['form'].fields['exhibition'].queryset, self.request.user).exclude(id__in=exclude_exhibitions) return context
def get_context_data(self, **kwargs): context = super(CreateSubmissionView, self).get_context_data(**kwargs) # Restrict list of artwork the current user can submit context['form'].fields['artwork'].queryset = Artwork.can_save_queryset( context['form'].fields['artwork'].queryset, self.request.user) # Restrict to specific artwork if given artwork_id = self.kwargs.get('artwork') exclude_exhibitions = [] if artwork_id: context['form'].fields['artwork'].queryset =\ context['form'].fields['artwork'].queryset.filter(id=artwork_id) # Fetch the exhibitions this artwork has already been submitted to exclude_exhibitions = Submission.objects.filter( artwork__exact=artwork_id).order_by('-created_at').values_list('exhibition', flat=True) # Restrict list of exhibitions the current user can see, # and exclude exhibitions this artwork has already been submitted to context['form'].fields['exhibition'].queryset = Exhibition.can_see_queryset( context['form'].fields['exhibition'].queryset, self.request.user).exclude(id__in=exclude_exhibitions) return context