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:
parent
29c65044bf
commit
455fd36ff6
@ -242,22 +242,13 @@ class MediaCommentMixin(object):
|
|||||||
return cleaned_markdown_conversion(self.content)
|
return cleaned_markdown_conversion(self.content)
|
||||||
|
|
||||||
|
|
||||||
class CollectionMixin(object):
|
class CollectionMixin(GenerateSlugMixin):
|
||||||
def generate_slug(self):
|
def check_slug_used(self, slug):
|
||||||
# import this here due to a cyclic import issue
|
# import this here due to a cyclic import issue
|
||||||
# (db.models -> db.mixin -> db.util -> db.models)
|
# (db.models -> db.mixin -> db.util -> db.models)
|
||||||
from mediagoblin.db.util import check_collection_slug_used
|
from mediagoblin.db.util import check_collection_slug_used
|
||||||
|
|
||||||
self.slug = slugify(self.title)
|
return check_collection_slug_used(self.creator, slug, self.id)
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def description_html(self):
|
def description_html(self):
|
||||||
|
@ -59,7 +59,7 @@ def clean_orphan_tags(commit=True):
|
|||||||
Session.commit()
|
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) \
|
filt = (Collection.creator == creator_id) \
|
||||||
& (Collection.slug == slug)
|
& (Collection.slug == slug)
|
||||||
if ignore_c_id is not None:
|
if ignore_c_id is not None:
|
||||||
|
@ -308,7 +308,7 @@ def edit_collection(request, collection):
|
|||||||
if request.method == 'POST' and form.validate():
|
if request.method == 'POST' and form.validate():
|
||||||
# Make sure there isn't already a Collection with such a slug
|
# Make sure there isn't already a Collection with such a slug
|
||||||
# and userid.
|
# 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)
|
form.slug.data, collection.id)
|
||||||
|
|
||||||
# Make sure there isn't already a Collection with this title
|
# Make sure there isn't already a Collection with this title
|
||||||
|
Loading…
x
Reference in New Issue
Block a user