aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mediagoblin/db/models.py22
-rw-r--r--mediagoblin/templates/mediagoblin/user_pages/media.html5
-rw-r--r--mediagoblin/user_pages/views.py8
3 files changed, 13 insertions, 22 deletions
diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py
index bf825a23..1d91a14b 100644
--- a/mediagoblin/db/models.py
+++ b/mediagoblin/db/models.py
@@ -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'])
diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html
index 55c8f145..e84c9872 100644
--- a/mediagoblin/templates/mediagoblin/user_pages/media.html
+++ b/mediagoblin/templates/mediagoblin/user_pages/media.html
@@ -57,6 +57,7 @@
{% if comments %}
{% for comment in comments %}
+ {% set comment_author = comment.author() %}
<div class="comment_wrapper" id="comment-{{ comment['_id'] }}">
<div class="comment_content">
{% autoescape False %}
@@ -65,8 +66,8 @@
</div>
<div class="comment_author">&mdash;
<a href="{{ request.urlgen('mediagoblin.user_pages.user_home',
- user = comment['author']['username']) }}">
- {{ comment['author']['username'] }}</a> at
+ user = comment_author['username']) }}">
+ {{ comment_author['username'] }}</a> at
<!--</div>
<div class="comment_datetime">-->
<a href="#comment-{{ comment['_id'] }}">
diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py
index 399d2020..012d27a3 100644
--- a/mediagoblin/user_pages/views.py
+++ b/mediagoblin/user_pages/views.py
@@ -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,