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.
This commit is contained in:
Elrond 2013-01-25 22:41:28 +01:00
parent 29c65044bf
commit 455fd36ff6
3 changed files with 5 additions and 14 deletions

View File

@ -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):

View File

@ -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:

View File

@ -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