Dot-Notation for MediaEntry.slug
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Sun, 4 Dec 2011 18:57:42 +0000 (19:57 +0100)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Mon, 5 Dec 2011 20:08:58 +0000 (21:08 +0100)
mediagoblin/db/models.py
mediagoblin/edit/views.py

index 7af76b9f403c24731b327ea534d277fd7eace775..aeee69dd5d555bec406440741e0d468c9d67a83d 100644 (file)
@@ -249,13 +249,13 @@ class MediaEntry(Document):
         pass
 
     def generate_slug(self):
-        self['slug'] = url.slugify(self.title)
+        self.slug = url.slugify(self.title)
 
         duplicate = mg_globals.database.media_entries.find_one(
-            {'slug': self['slug']})
+            {'slug': self.slug})
 
         if duplicate:
-            self['slug'] = "%s-%s" % (self._id, self['slug'])
+            self.slug = "%s-%s" % (self._id, self.slug)
 
     def url_for_self(self, urlgen):
         """
@@ -269,7 +269,7 @@ class MediaEntry(Document):
             return urlgen(
                 'mediagoblin.user_pages.media_home',
                 user=uploader.username,
-                media=self['slug'])
+                media=self.slug)
         else:
             return urlgen(
                 'mediagoblin.user_pages.media_home',
@@ -287,7 +287,7 @@ class MediaEntry(Document):
         if cursor.count():
             return urlgen('mediagoblin.user_pages.media_home',
                           user=self.get_uploader().username,
-                          media=unicode(cursor[0]['slug']))
+                          media=unicode(cursor[0].slug))
 
     def url_to_next(self, urlgen):
         """
@@ -301,7 +301,7 @@ class MediaEntry(Document):
         if cursor.count():
             return urlgen('mediagoblin.user_pages.media_home',
                           user=self.get_uploader().username,
-                          media=unicode(cursor[0]['slug']))
+                          media=unicode(cursor[0].slug))
 
     def get_uploader(self):
         return self.db.User.find_one({'_id': self.uploader})
index feda397df52daa666b247379f397a54a69f26ac8..51661a21afcbf8ac816235fc9808f7a662ddc08b 100644 (file)
@@ -44,7 +44,7 @@ def edit_media(request, media):
 
     defaults = dict(
         title=media.title,
-        slug=media['slug'],
+        slug=media.slug,
         description=media['description'],
         tags=media_tags_as_string(media['tags']))
 
@@ -72,7 +72,7 @@ def edit_media(request, media):
             media['description_html'] = cleaned_markdown_conversion(
                 media['description'])
 
-            media['slug'] = unicode(request.POST['slug'])
+            media.slug = unicode(request.POST['slug'])
             media.save()
 
             return exc.HTTPFound(