From 455fd36ff66746aecd66095080ae00a547337a8c Mon Sep 17 00:00:00 2001 From: Elrond Date: Fri, 25 Jan 2013 22:41:28 +0100 Subject: [PATCH] Use GenerateSlugMixin for collections. Use the new way of generating slugs also for collections. Also drop the dummy_db arg to check_collection_slug_used. --- mediagoblin/db/mixin.py | 15 +++------------ mediagoblin/db/util.py | 2 +- mediagoblin/edit/views.py | 2 +- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/mediagoblin/db/mixin.py b/mediagoblin/db/mixin.py index a55a1905..f2c2932c 100644 --- a/mediagoblin/db/mixin.py +++ b/mediagoblin/db/mixin.py @@ -242,22 +242,13 @@ class MediaCommentMixin(object): return cleaned_markdown_conversion(self.content) -class CollectionMixin(object): - def generate_slug(self): +class CollectionMixin(GenerateSlugMixin): + def check_slug_used(self, slug): # import this here due to a cyclic import issue # (db.models -> db.mixin -> db.util -> db.models) from mediagoblin.db.util import check_collection_slug_used - self.slug = slugify(self.title) - - duplicate = check_collection_slug_used(mg_globals.database, - self.creator, self.slug, self.id) - - if duplicate: - if self.id is not None: - self.slug = u"%s-%s" % (self.id, self.slug) - else: - self.slug = None + return check_collection_slug_used(self.creator, slug, self.id) @property def description_html(self): diff --git a/mediagoblin/db/util.py b/mediagoblin/db/util.py index 529ef8b9..6ffec44d 100644 --- a/mediagoblin/db/util.py +++ b/mediagoblin/db/util.py @@ -59,7 +59,7 @@ def clean_orphan_tags(commit=True): Session.commit() -def check_collection_slug_used(dummy_db, creator_id, slug, ignore_c_id): +def check_collection_slug_used(creator_id, slug, ignore_c_id): filt = (Collection.creator == creator_id) \ & (Collection.slug == slug) if ignore_c_id is not None: diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index 0b1cda98..34b7aaca 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -308,7 +308,7 @@ def edit_collection(request, collection): if request.method == 'POST' and form.validate(): # Make sure there isn't already a Collection with such a slug # and userid. - slug_used = check_collection_slug_used(request.db, collection.creator, + slug_used = check_collection_slug_used(collection.creator, form.slug.data, collection.id) # Make sure there isn't already a Collection with this title -- 2.25.1