aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/edit/views.py
diff options
context:
space:
mode:
authorElrond <elrond+mediagoblin.org@samba-tng.org>2012-01-24 21:47:40 +0100
committerElrond <elrond+mediagoblin.org@samba-tng.org>2012-03-05 21:37:05 +0100
commitb62b3b982a2543fb881c93570c544fbef61dd97e (patch)
treec07f4bb1a60b91310a82df3ab8cd8b89cd92218a /mediagoblin/edit/views.py
parentc65cbf9514278fd624ff6f1ccbac93cca8e31764 (diff)
downloadmediagoblin-b62b3b982a2543fb881c93570c544fbef61dd97e.tar.lz
mediagoblin-b62b3b982a2543fb881c93570c544fbef61dd97e.tar.xz
mediagoblin-b62b3b982a2543fb881c93570c544fbef61dd97e.zip
Generic check_media_slug_used db utility.
In two cases (generating a new slug and editing the slug) it is nice to know in advance (before the db gets angry) that the slug is used/free. So created a db utility function to check for this on mongo and sql: check_media_slug_used()
Diffstat (limited to 'mediagoblin/edit/views.py')
-rw-r--r--mediagoblin/edit/views.py9
1 files changed, 4 insertions, 5 deletions
diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py
index d21ef03a..2df8f9ab 100644
--- a/mediagoblin/edit/views.py
+++ b/mediagoblin/edit/views.py
@@ -36,6 +36,7 @@ from mediagoblin.tools.text import (
clean_html, convert_to_tag_list_of_dicts,
media_tags_as_string)
from mediagoblin.tools.licenses import SUPPORTED_LICENSES
+from mediagoblin.db.util import check_media_slug_used
@get_user_media_entry
@@ -58,12 +59,10 @@ def edit_media(request, media):
if request.method == 'POST' and form.validate():
# Make sure there isn't already a MediaEntry with such a slug
# and userid.
- existing_user_slug_entries = request.db.MediaEntry.find(
- {'slug': request.POST['slug'],
- 'uploader': media.uploader,
- '_id': {'$ne': media._id}}).count()
+ slug_used = check_media_slug_used(request.db, media.uploader,
+ request.POST['slug'], media.id)
- if existing_user_slug_entries:
+ if slug_used:
form.slug.errors.append(
_(u'An entry with that slug already exists for this user.'))
else: