diff options
author | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2011-06-02 17:43:54 +0200 |
---|---|---|
committer | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2011-06-02 17:43:54 +0200 |
commit | 0732236e9c816dd2b04f5a9e97632a861de225ad (patch) | |
tree | fc421202b6e71cd54ded9c47b6fbfc12efcbfcff | |
parent | 8cd5d4f8c3de634905651b1d1e8cd1355b7f3a99 (diff) | |
download | mediagoblin-0732236e9c816dd2b04f5a9e97632a861de225ad.tar.lz mediagoblin-0732236e9c816dd2b04f5a9e97632a861de225ad.tar.xz mediagoblin-0732236e9c816dd2b04f5a9e97632a861de225ad.zip |
Handle Exceptions from save(); Move may_edit_media
Turn .save() excpetions into a HTTPConflict. Not nice, but
at least the user gets the error. Until there is a proper
way to validate things and get nice errors.
Move may_edit_media() to lib.py, as it's not a view.
-rw-r--r-- | mediagoblin/edit/lib.py | 8 | ||||
-rw-r--r-- | mediagoblin/edit/views.py | 15 |
2 files changed, 13 insertions, 10 deletions
diff --git a/mediagoblin/edit/lib.py b/mediagoblin/edit/lib.py new file mode 100644 index 00000000..293a0547 --- /dev/null +++ b/mediagoblin/edit/lib.py @@ -0,0 +1,8 @@ + +def may_edit_media(request, media): + """Check, if the request's user may edit the media details""" + if media['uploader'] == request.user['_id']: + return True + if request.user['is_admin']: + return True + return False diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index a0afaa30..b8e28e29 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -3,18 +3,10 @@ from webob import Response, exc from mediagoblin.edit import forms +from mediagoblin.edit.lib import may_edit_media from mediagoblin.decorators import require_active_login, get_user_media_entry -def may_edit_media(request, media): - """Check, if the request's user may edit the media details""" - if media['uploader'] == request.user['_id']: - return True - if request.user['is_admin']: - return True - return False - - @get_user_media_entry @require_active_login def edit_media(request, media): @@ -30,7 +22,10 @@ def edit_media(request, media): media['title'] = request.POST['title'] media['description'] = request.POST['description'] media['slug'] = request.POST['slug'] - media.save() + try: + media.save() + except Exception as e: + return exc.HTTPConflict(detail = str(e)) # redirect return exc.HTTPFound( |