Example #1
0
def edit_media(request, media_id, media_type="image"):
    """Edit media means only changing the description, for now."""
    media, media_format = _get_media_info(media_id, media_type)

    check_media_permissions(media, request.user, "change")

    if media_type == "image":
        media_form = _init_media_form(ImageForm, request, media, ("locale", "title"))
    else:
        raise Http404

    if request.method == "POST" and media_form.is_valid():
        media = media_form.save(update_user=request.user, is_draft=False)
        return HttpResponseRedirect(reverse("gallery.media", args=[media_type, media_id]))

    return render(
        request,
        "gallery/edit_media.html",
        {
            "media": media,
            "media_format": media_format,
            "form": media_form,
            "media_type": media_type,
        },
    )
Example #2
0
def delete_media(request, media_id, media_type='image'):
    """Delete media and redirect to gallery view."""
    media, media_format = _get_media_info(media_id, media_type)

    check_media_permissions(media, request.user, 'delete')

    if request.method == 'GET':
        # Render the confirmation page
        return render(request, 'gallery/confirm_media_delete.html', {
            'media': media,
            'media_type': media_type,
            'media_format': media_format})

    # Handle confirm delete form POST
    log.warning('User %s is deleting %s with id=%s' %
                (request.user, media_type, media.id))
    media.delete()
    # Rebuild KB
    schedule_rebuild_kb()
    return HttpResponseRedirect(reverse('gallery.gallery', args=[media_type]))
Example #3
0
def delete_media(request, media_id, media_type='image'):
    """Delete media and redirect to gallery view."""
    media, media_format = _get_media_info(media_id, media_type)

    check_media_permissions(media, request.user, 'delete')

    if request.method == 'GET':
        # Render the confirmation page
        return render(request, 'gallery/confirm_media_delete.html', {
            'media': media,
            'media_type': media_type,
            'media_format': media_format})

    # Handle confirm delete form POST
    log.warning('User %s is deleting %s with id=%s' %
                (request.user, media_type, media.id))
    media.delete()
    # Rebuild KB
    schedule_rebuild_kb()
    return HttpResponseRedirect(reverse('gallery.gallery', args=[media_type]))
Example #4
0
def delete_media(request, media_id, media_type="image"):
    """Delete media and redirect to gallery view."""
    media, media_format = _get_media_info(media_id, media_type)

    check_media_permissions(media, request.user, "delete")

    if request.method == "GET":
        # Render the confirmation page
        return render(
            request,
            "gallery/confirm_media_delete.html",
            {"media": media, "media_type": media_type, "media_format": media_format},
        )

    # Handle confirm delete form POST
    log.warning("User %s is deleting %s with id=%s" % (request.user, media_type, media.id))
    media.delete()
    # Rebuild KB
    schedule_rebuild_kb()
    return HttpResponseRedirect(reverse("gallery.gallery", args=[media_type]))
Example #5
0
def edit_media(request, media_id, media_type='image'):
    """Edit media means only changing the description, for now."""
    media, media_format = _get_media_info(media_id, media_type)

    check_media_permissions(media, request.user, 'change')

    if media_type == 'image':
        media_form = _init_media_form(ImageForm, request, media,
                                      ('locale', 'title'))
    else:
        raise Http404

    if request.method == 'POST' and media_form.is_valid():
        media = media_form.save(update_user=request.user, is_draft=False)
        return HttpResponseRedirect(
            reverse('gallery.media', args=[media_type, media_id]))

    return render(request, 'gallery/edit_media.html', {
        'media': media,
        'media_format': media_format,
        'form': media_form,
        'media_type': media_type})
Example #6
0
def edit_media(request, media_id, media_type='image'):
    """Edit media means only changing the description, for now."""
    media, media_format = _get_media_info(media_id, media_type)

    check_media_permissions(media, request.user, 'change')

    if media_type == 'image':
        media_form = _init_media_form(ImageForm, request, media,
                                      ('locale', 'title'))
    else:
        raise Http404

    if request.method == 'POST' and media_form.is_valid():
        media = media_form.save(update_user=request.user)
        return HttpResponseRedirect(
            reverse('gallery.media', args=[media_type, media_id]))

    return render(request, 'gallery/edit_media.html', {
        'media': media,
        'media_format': media_format,
        'form': media_form,
        'media_type': media_type})
Example #7
0
 def test_check_has_perm(self):
     """User with django permission has perm to change video."""
     vid = VideoFactory(creator=self.user)
     u = UserFactory()
     add_permission(u, Video, "change_video")
     check_media_permissions(vid, u, "change")
Example #8
0
 def test_check_not_own_object(self):
     """tagger cannot delete an image s/he doesn't own."""
     img = ImageFactory()
     # This should raise
     check_media_permissions(img, self.user, "delete")
Example #9
0
 def test_check_own_object(self):
     """tagger can edit a video s/he doesn't own."""
     vid = VideoFactory(creator=self.user)
     check_media_permissions(vid, self.user, "change")
Example #10
0
 def test_check_has_perm(self):
     """User with django permission has perm to change video."""
     vid = video(creator=self.user)
     u = user(save=True)
     add_permission(u, Video, 'change_video')
     check_media_permissions(vid, u, 'change')
Example #11
0
 def test_check_not_own_object(self):
     """tagger cannot delete an image s/he doesn't own."""
     img = image()
     fn = lambda: check_media_permissions(img, self.user, 'delete')
     self.assertRaises(PermissionDenied, fn)
Example #12
0
 def test_check_own_object(self):
     """tagger can edit a video s/he doesn't own."""
     vid = video(creator=self.user)
     check_media_permissions(vid, self.user, 'change')
Example #13
0
 def test_check_has_perm(self):
     """User with django permission has perm to change video."""
     vid = video(creator=self.user)
     u = user(save=True)
     add_permission(u, Video, 'change_video')
     check_media_permissions(vid, u, 'change')
Example #14
0
 def test_check_not_own_object(self):
     """tagger cannot delete an image s/he doesn't own."""
     img = image()
     fn = lambda: check_media_permissions(img, self.user, 'delete')
     self.assertRaises(PermissionDenied, fn)
Example #15
0
 def test_check_not_own_object(self):
     """tagger cannot delete an image s/he doesn't own."""
     img = image()
     # This should raise
     check_media_permissions(img, self.user, 'delete')
Example #16
0
 def test_check_has_perm(self):
     """User with django permission has perm to change video."""
     vid = VideoFactory(creator=self.user)
     u = UserFactory()
     add_permission(u, Video, 'change_video')
     check_media_permissions(vid, u, 'change')