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.
This commit is contained in:
Christopher Allan Webber 2013-01-15 16:11:15 -06:00
parent 88de830fcf
commit 985871095e

View File

@ -55,11 +55,13 @@ class UserMixin(object):
class MediaEntryMixin(object): class MediaEntryMixin(object):
def generate_slug(self): def generate_slug(self):
""" """
Generate a unique slug for this MediaEntry.
This one does not *force* slugs, but usually it will probably result This one does not *force* slugs, but usually it will probably result
in a niceish one. in a niceish one.
The end *result* of the algorithm will (presumably, I have not tested The end *result* of the algorithm will result in these resolutions for
it) result in these resolutions for these situations: these situations:
- If we have a slug, make sure it's clean and sanitized, and if it's - If we have a slug, make sure it's clean and sanitized, and if it's
unique, we'll use that. unique, we'll use that.
- If we have a title, slugify it, 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? # Can we just append the object's id to the end?
if self.id: 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, if not check_media_slug_used(self.uploader,
slug_with_id, self.id): slug_with_id, self.id):
self.slug = slug_with_id self.slug = slug_with_id
@ -107,9 +109,9 @@ class MediaEntryMixin(object):
# okay, still no success; # okay, still no success;
# let's whack junk on there till it's unique. # 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): 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 @property
def description_html(self): def description_html(self):