Merge branch 'feature_362-simple_comments'
This commit is contained in:
@@ -22,7 +22,8 @@ from mediagoblin import util
|
||||
from mediagoblin.auth import lib as auth_lib
|
||||
from mediagoblin import mg_globals
|
||||
from mediagoblin.db import migrations
|
||||
from mediagoblin.db.util import ObjectId
|
||||
from mediagoblin.db.util import DESCENDING, ObjectId
|
||||
from mediagoblin.util import Pagination
|
||||
|
||||
###################
|
||||
# Custom validators
|
||||
@@ -110,7 +111,22 @@ class MediaEntry(Document):
|
||||
|
||||
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'])
|
||||
|
||||
@@ -142,8 +158,32 @@ class MediaEntry(Document):
|
||||
def uploader(self):
|
||||
return self.db.User.find_one({'_id': self['uploader']})
|
||||
|
||||
class MediaComment(Document):
|
||||
__collection__ = 'media_comments'
|
||||
|
||||
REGISTER_MODELS = [MediaEntry, User]
|
||||
structure = {
|
||||
'media_entry': ObjectId,
|
||||
'author': ObjectId,
|
||||
'created': datetime.datetime,
|
||||
'content': unicode,
|
||||
'content_html': unicode}
|
||||
|
||||
required_fields = [
|
||||
'media_entry', 'author', 'created', 'content']
|
||||
|
||||
default_values = {
|
||||
'created': datetime.datetime.utcnow}
|
||||
|
||||
def media_entry(self):
|
||||
return self.db.MediaEntry.find_one({'_id': self['media_entry']})
|
||||
|
||||
def author(self):
|
||||
return self.db.User.find_one({'_id': self['author']})
|
||||
|
||||
REGISTER_MODELS = [
|
||||
MediaEntry,
|
||||
User,
|
||||
MediaComment]
|
||||
|
||||
|
||||
def register_models(connection):
|
||||
|
||||
Reference in New Issue
Block a user