diff options
author | Christopher Allan Webber <cwebber@dustycloud.org> | 2013-01-15 16:11:15 -0600 |
---|---|---|
committer | Christopher Allan Webber <cwebber@dustycloud.org> | 2013-01-15 16:11:15 -0600 |
commit | 985871095e873aca1e160a7eea4ad97f4b80de18 (patch) | |
tree | e18a3836b345b3ea1c7c4cd76c18db31de742486 | |
parent | 88de830fcfb3fb02af4b2d71b82efaa8c83df665 (diff) | |
download | mediagoblin-985871095e873aca1e160a7eea4ad97f4b80de18.tar.lz mediagoblin-985871095e873aca1e160a7eea4ad97f4b80de18.tar.xz mediagoblin-985871095e873aca1e160a7eea4ad97f4b80de18.zip |
Simplifying string concatenation in generate_slug and fixing docstring
- made the mistake of copying some commit message things into the
docstring. Fixed.
- elrond points out that += is nicer and we don't need u"" in this
case since we're not concatenating a variable, we're concatenating
a known ascii string.
-rw-r--r-- | mediagoblin/db/mixin.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/mediagoblin/db/mixin.py b/mediagoblin/db/mixin.py index 7cb530e4..0e000324 100644 --- a/mediagoblin/db/mixin.py +++ b/mediagoblin/db/mixin.py @@ -55,11 +55,13 @@ class UserMixin(object): class MediaEntryMixin(object): def generate_slug(self): """ + Generate a unique slug for this MediaEntry. + This one does not *force* slugs, but usually it will probably result in a niceish one. - The end *result* of the algorithm will (presumably, I have not tested - it) result in these resolutions for these situations: + The end *result* of the algorithm will result in these resolutions for + these situations: - If we have a slug, make sure it's clean and sanitized, and if it's unique, we'll use that. - If we have a title, slugify it, and if it's unique, we'll use that. @@ -99,7 +101,7 @@ class MediaEntryMixin(object): # Can we just append the object's id to the end? if self.id: - slug_with_id = "%s-%s" % (self.slug, self.id) + slug_with_id = u"%s-%s" % (self.slug, self.id) if not check_media_slug_used(self.uploader, slug_with_id, self.id): self.slug = slug_with_id @@ -107,9 +109,9 @@ class MediaEntryMixin(object): # okay, still no success; # let's whack junk on there till it's unique. - self.slug = self.slug + u'-' + self.slug += '-' while check_media_slug_used(self.uploader, self.slug, self.id): - self.slug = self.slug + unicode(uuid4())[1:4] + self.slug += uuid4()[1:4] @property def description_html(self): |