aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/user_pages
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/user_pages')
-rw-r--r--mediagoblin/user_pages/__init__.py2
-rw-r--r--mediagoblin/user_pages/forms.py7
-rw-r--r--mediagoblin/user_pages/routing.py5
-rw-r--r--mediagoblin/user_pages/views.py46
4 files changed, 53 insertions, 7 deletions
diff --git a/mediagoblin/user_pages/__init__.py b/mediagoblin/user_pages/__init__.py
index a8eeb5ed..576bd0f5 100644
--- a/mediagoblin/user_pages/__init__.py
+++ b/mediagoblin/user_pages/__init__.py
@@ -1,5 +1,5 @@
# GNU MediaGoblin -- federated, autonomous media hosting
-# Copyright (C) 2011 Free Software Foundation, Inc
+# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mediagoblin/user_pages/forms.py b/mediagoblin/user_pages/forms.py
index 25001019..57061d34 100644
--- a/mediagoblin/user_pages/forms.py
+++ b/mediagoblin/user_pages/forms.py
@@ -1,5 +1,5 @@
# GNU MediaGoblin -- federated, autonomous media hosting
-# Copyright (C) 2011 Free Software Foundation, Inc
+# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
@@ -23,3 +23,8 @@ class MediaCommentForm(wtforms.Form):
comment_content = wtforms.TextAreaField(
_('Comment'),
[wtforms.validators.Required()])
+
+
+class ConfirmDeleteForm(wtforms.Form):
+ confirm = wtforms.BooleanField(
+ _('I am sure I want to delete this'))
diff --git a/mediagoblin/user_pages/routing.py b/mediagoblin/user_pages/routing.py
index 65c0fa64..3586d9cd 100644
--- a/mediagoblin/user_pages/routing.py
+++ b/mediagoblin/user_pages/routing.py
@@ -1,5 +1,5 @@
# GNU MediaGoblin -- federated, autonomous media hosting
-# Copyright (C) 2011 Free Software Foundation, Inc
+# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
@@ -32,6 +32,9 @@ user_routes = [
Route('mediagoblin.edit.attachments',
'/{user}/m/{media}/attachments/',
controller="mediagoblin.edit.views:edit_attachments"),
+ Route('mediagoblin.user_pages.media_confirm_delete',
+ "/{user}/m/{media}/confirm-delete/",
+ controller="mediagoblin.user_pages.views:media_confirm_delete"),
Route('mediagoblin.user_pages.atom_feed', '/{user}/atom/',
controller="mediagoblin.user_pages.views:atom_feed"),
Route('mediagoblin.user_pages.media_post_comment',
diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py
index 2d9bcd21..f60bd186 100644
--- a/mediagoblin/user_pages/views.py
+++ b/mediagoblin/user_pages/views.py
@@ -1,5 +1,5 @@
# MediaGoblin -- federated, autonomous media hosting
-# Copyright (C) 2011 Free Software Foundation, Inc
+# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
@@ -20,11 +20,12 @@ from mediagoblin import messages, mg_globals
from mediagoblin.db.util import DESCENDING, ObjectId
from mediagoblin.util import (
Pagination, render_to_response, redirect, cleaned_markdown_conversion,
- render_404)
+ render_404, delete_media_files)
+from mediagoblin.util import pass_to_ugettext as _
from mediagoblin.user_pages import forms as user_forms
from mediagoblin.decorators import (uses_pagination, get_user_media_entry,
- require_active_login)
+ require_active_login, user_may_delete_media)
from werkzeug.contrib.atom import AtomFeed
@@ -130,7 +131,7 @@ def media_post_comment(request):
comment = request.db.MediaComment()
comment['media_entry'] = ObjectId(request.matchdict['media'])
comment['author'] = request.user['_id']
- comment['content'] = request.POST['comment_content']
+ comment['content'] = unicode(request.POST['comment_content'])
comment['content_html'] = cleaned_markdown_conversion(comment['content'])
@@ -145,6 +146,43 @@ def media_post_comment(request):
user = request.matchdict['user'])
+@get_user_media_entry
+@require_active_login
+@user_may_delete_media
+def media_confirm_delete(request, media):
+
+ form = user_forms.ConfirmDeleteForm(request.POST)
+
+ if request.method == 'POST' and form.validate():
+ if form.confirm.data is True:
+ username = media.uploader()['username']
+
+ # Delete all files on the public storage
+ delete_media_files(media)
+
+ media.delete()
+
+ return redirect(request, "mediagoblin.user_pages.user_home",
+ user=username)
+ else:
+ return redirect(request, "mediagoblin.user_pages.media_home",
+ user=media.uploader()['username'],
+ media=media['slug'])
+
+ if ((request.user[u'is_admin'] and
+ request.user[u'_id'] != media.uploader()[u'_id'])):
+ messages.add_message(
+ request, messages.WARNING,
+ _("You are about to delete another user's media. "
+ "Proceed with caution."))
+
+ return render_to_response(
+ request,
+ 'mediagoblin/user_pages/media_confirm_delete.html',
+ {'media': media,
+ 'form': form})
+
+
ATOM_DEFAULT_NR_OF_UPDATED_ITEMS = 15
def atom_feed(request):