Beispiel #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:
        media_form = _init_media_form(VideoForm, request, media,
                                      ('locale', 'title'))

    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 jingo.render(
        request, 'gallery/edit_media.html', {
            'media': media,
            'media_format': media_format,
            'form': media_form,
            'media_type': media_type
        })
Beispiel #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 jingo.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()
    return HttpResponseRedirect(reverse('gallery.gallery', args=[media_type]))
Beispiel #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 jingo.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()
    return HttpResponseRedirect(reverse('gallery.gallery', args=[media_type]))
Beispiel #4
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:
        media_form = _init_media_form(VideoForm, request, media, ("locale", "title"))

    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 jingo.render(
        request,
        "gallery/edit_media.html",
        {"media": media, "media_format": media_format, "form": media_form, "media_type": media_type},
    )
Beispiel #5
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 jingo.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]))
Beispiel #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:
        media_form = _init_media_form(VideoForm, request, media,
                                      ('locale', 'title'))

    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 jingo.render(request, 'gallery/edit_media.html',
                        {'media': media,
                         'media_format': media_format,
                         'form': media_form,
                         'media_type': media_type})
Beispiel #7
0
 def test_check_has_perm(self):
     """Admin has perm to change video."""
     u = User.objects.get(username='******')
     vid = video(creator=u)
     check_media_permissions(vid, u, 'change')
Beispiel #8
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)
Beispiel #9
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')
Beispiel #10
0
 def test_check_has_perm(self):
     """Admin has perm to change video."""
     u = User.objects.get(username='******')
     vid = video(creator=u)
     check_media_permissions(vid, u, 'change')
Beispiel #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)
Beispiel #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')
Beispiel #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')