Issue #362 - Simple comments - Changes based on feedback recieved from #mediagoblin
authorJoar Wandborg <git@wandborg.com>
Fri, 1 Jul 2011 13:26:29 +0000 (15:26 +0200)
committerJoar Wandborg <git@wandborg.com>
Fri, 1 Jul 2011 13:26:29 +0000 (15:26 +0200)
*   `db.models` - Removed `MediaEntry.get_comments()` and replaced it with a helper
    which just returns a cursor for the comments query
*   `media.html` - Added `{% set comment_author = comment.author() %}`
*   `user_pages.views` - media_home() now passes `MediaEntry.get_comments()`
    directly to `Pagination`, handles pagination for comments.
    *   Added `MEDIA_COMMENTS_PER_PAGE` to define the number of comments per page
        in the `media_home()` view.

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

index bf825a2391bc82b20b7bb4989b92d76c325b6e66..1d91a14bbed0042958f43ae4267e7ec2423e89d3 100644 (file)
@@ -23,7 +23,6 @@ from mediagoblin.auth import lib as auth_lib
 from mediagoblin import mg_globals
 from mediagoblin.db import migrations
 from mediagoblin.db.util import DESCENDING, ObjectId
-from mediagoblin.util import Pagination
 
 ###################
 # Custom validators
@@ -109,24 +108,13 @@ class MediaEntry(Document):
 
     migration_handler = migrations.MediaEntryMigration
 
+    def get_comments(self):
+        return self.db.MediaComment.find({
+                'media_entry': self['_id']}).sort('created', DESCENDING)
+
     def main_mediafile(self):
         pass
-    
-    def get_comments(self, page):
-        cursor = self.db.MediaComment.find({
-                'media_entry': self['_id']}).sort('created', DESCENDING)
-        
-        pagination = Pagination(page, cursor)
-        comments = pagination()
-        
-        data = list()
-        for comment in comments:
-            comment['author'] = self.db.User.find_one({
-                    '_id': comment['author']})
-            data.append(comment)
-            
-        return (data, pagination)
-        
+
     def generate_slug(self):
         self['slug'] = util.slugify(self['title'])
 
index cd0bb76477e79b483bded046bdce16d3f8dfb948..4ed1bd02fde17f23bbc904de62c341d96d52749f 100644 (file)
     {% if comments %}
       <h3>Comments</h3>
       {% for comment in comments %}
+      {% set comment_author = comment.author() %}
         <div class="comment_wrapper" id="comment-{{ comment['_id'] }}">
          <div class="comment_author">By: 
            <a href="{{ request.urlgen('mediagoblin.user_pages.user_home',
-                                        user = comment['author']['username']) }}">
-             {{ comment['author']['username'] }}
+                                        user = comment_author['username']) }}">
+             {{ comment_author['username'] }}
            </a>
          </div>
          <div class="comment_datetime">
index 399d20203fd7db0360314be61a00a4a8da5f83fe..012d27a3c44c8f4bfc099cb3bd14b87f73fd2cdf 100644 (file)
@@ -82,17 +82,19 @@ def user_gallery(request, page):
          'media_entries': media_entries,
          'pagination': pagination})
 
+MEDIA_COMMENTS_PER_PAGE = 50
 
 @get_user_media_entry
 @uses_pagination
-def media_home(request, media, **kwargs):
+def media_home(request, media, page, **kwargs):
     """
     'Homepage' of a MediaEntry()
     """
 
-    comment_form = user_forms.MediaCommentForm(request.POST)
+    pagination = Pagination(page, media.get_comments(), MEDIA_COMMENTS_PER_PAGE)
+    comments = pagination()
 
-    (comments, pagination) = media.get_comments(kwargs.get('page'))
+    comment_form = user_forms.MediaCommentForm(request.POST)
 
     return render_to_response(
         request,