Пример #1
0
def nouv_art(request):
    sauvegarde = False
    form = NouvAlb(request.POST or None, request.FILES)
    if form.is_valid():
        artwork = Artwork()
        artwork.title = form.cleaned_data["title"]
        artwork.photo = form.cleaned_data["photo"]
        artwork.reference = form.cleaned_data["reference"]
        artwork.created_at = form.cleaned_data["created_at"]
        artwork.available = form.cleaned_data["available"]
        artwork.save()
        sauvegarde = True

    return render(request, 'art_form.html', {
        'form': form,
        'sauvegarde': sauvegarde
    })
    def test_save_unique(self):

        exhibition = Exhibition(
            title='New Exhibition',
            description='description goes here',
            released_at=timezone.now(),
            author=self.user)
        exhibition.save()
        artwork = Artwork(title='New Artwork', code='// code goes here', author=self.user)
        artwork.save()
        submission1 = Submission(exhibition=exhibition, artwork=artwork, submitted_by=self.user)
        submission2 = Submission(exhibition=exhibition, artwork=artwork, submitted_by=self.user)

        # submissions must be unique
        self.assertEqual(submission1.save(), None)
        self.assertRaisesRegexp(
            IntegrityError,
            'columns exhibition_id, artwork_id are not unique',
            submission2.save)
Пример #3
0
    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)
Пример #4
0
    def test_can_see_private_queryset(self):
        student = Artwork(
            author=self.user,
            title='Empty code',
            code='// code goes here')
        student.save()

        staff = Artwork(
            author=self.staff_user,
            title='Empty code',
            code='// code goes here')
        staff.save()

        superuser = Artwork(
            author=self.super_user,
            title='Empty code',
            code='// code goes here')
        superuser.save()

        public_qs = Artwork.can_see_queryset()
        self.assertEqual(len(public_qs.all()), 0)

        student_qs = Artwork.can_see_queryset(user=self.user)
        self.assertEqual(len(student_qs.all()), 1)
        self.assertEqual(student_qs.all()[0].id, student.id)

        staff_qs = Artwork.can_see_queryset(user=self.staff_user)
        self.assertEqual(len(staff_qs.all()), 1)
        self.assertEqual(staff_qs.all()[0].id, staff.id)

        super_qs = Artwork.can_see_queryset(user=self.super_user)
        self.assertEqual(len(super_qs.all()), 1)
        self.assertEqual(super_qs.all()[0].id, superuser.id)