Use media.url_for_self instead of calling urlgen directly
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Tue, 20 Dec 2011 17:47:33 +0000 (18:47 +0100)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Tue, 27 Dec 2011 19:41:31 +0000 (20:41 +0100)
Replace
urlgen('ID', user=media.get_uploader().username, media=media.*)
by
media.url_for_self(urlgen)
in a few places.
It's just a lot nicer!

mediagoblin/db/mongo/models.py
mediagoblin/templates/mediagoblin/user_pages/media.html

index b068fb06a645574325784ea3a9ebfbfb3cb75bb8..8cd0da1b40e52f1de8f22756df989d8d6acba519 100644 (file)
@@ -282,10 +282,8 @@ class MediaEntry(Document):
                                           'uploader': self.uploader,
                                           'state': 'processed'}).sort(
                                                     '_id', ASCENDING).limit(1)
-        if cursor.count():
-            return urlgen('mediagoblin.user_pages.media_home',
-                          user=self.get_uploader().username,
-                          media=unicode(cursor[0].slug))
+        for media in cursor:
+            return media.url_for_self(urlgen)
 
     def url_to_next(self, urlgen):
         """
@@ -296,10 +294,8 @@ class MediaEntry(Document):
                                           'state': 'processed'}).sort(
                                                     '_id', DESCENDING).limit(1)
 
-        if cursor.count():
-            return urlgen('mediagoblin.user_pages.media_home',
-                          user=self.get_uploader().username,
-                          media=unicode(cursor[0].slug))
+        for media in cursor:
+            return media.url_for_self(urlgen)
 
     def get_uploader(self):
         return self.db.User.find_one({'_id': self.uploader})
index c171dd5abc7c2206abd24b476f967cfcee464bc7..77461983ef30d5286ebe013f9cefb5fd84aac94b 100644 (file)
                 </div>
               </div>
         {% endfor %}
-      {{ render_pagination(request, pagination, 
-                 request.urlgen('mediagoblin.user_pages.media_home',
-                 user = media.get_uploader().username,
-                 media = media._id)) }}
+      {{ render_pagination(request, pagination,
+                 media.url_for_self(request.urlgen)) }}
     {% endif %}
   </div>
   <div class="grid_5 omega">