aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/db
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/db')
-rw-r--r--mediagoblin/db/mixin.py10
-rw-r--r--mediagoblin/db/mongo/migrations.py7
-rw-r--r--mediagoblin/db/mongo/models.py8
-rw-r--r--mediagoblin/db/sql/convert.py2
-rw-r--r--mediagoblin/db/sql/models.py5
5 files changed, 22 insertions, 10 deletions
diff --git a/mediagoblin/db/mixin.py b/mediagoblin/db/mixin.py
index 4e3800ab..758f7e72 100644
--- a/mediagoblin/db/mixin.py
+++ b/mediagoblin/db/mixin.py
@@ -104,3 +104,13 @@ class MediaEntryMixin(object):
def get_license_data(self):
"""Return license dict for requested license"""
return licenses.SUPPORTED_LICENSES[self.license or ""]
+
+
+class MediaCommentMixin(object):
+ @property
+ def content_html(self):
+ """
+ the actual html-rendered version of the comment displayed.
+ Run through Markdown and the HTML cleaner.
+ """
+ return cleaned_markdown_conversion(self.content)
diff --git a/mediagoblin/db/mongo/migrations.py b/mediagoblin/db/mongo/migrations.py
index 57da7dd8..59035f3b 100644
--- a/mediagoblin/db/mongo/migrations.py
+++ b/mediagoblin/db/mongo/migrations.py
@@ -130,7 +130,12 @@ def mediaentry_add_license(database):
@RegisterMigration(9)
def remove_calculated_html(database):
"""
- Drop bio_html, description_html again and calculate things on the fly (and cache)
+ Drop pre-rendered html again and calculate things
+ on the fly (and cache):
+ - User.bio_html
+ - MediaEntry.description_html
+ - MediaComment.content_html
"""
drop_table_field(database, 'users', 'bio_html')
drop_table_field(database, 'media_entries', 'description_html')
+ drop_table_field(database, 'media_comments', 'content_html')
diff --git a/mediagoblin/db/mongo/models.py b/mediagoblin/db/mongo/models.py
index db38d502..57af137d 100644
--- a/mediagoblin/db/mongo/models.py
+++ b/mediagoblin/db/mongo/models.py
@@ -23,7 +23,7 @@ from mediagoblin.db.mongo import migrations
from mediagoblin.db.mongo.util import ASCENDING, DESCENDING, ObjectId
from mediagoblin.tools.pagination import Pagination
from mediagoblin.tools import url
-from mediagoblin.db.mixin import UserMixin, MediaEntryMixin
+from mediagoblin.db.mixin import UserMixin, MediaEntryMixin, MediaCommentMixin
###################
# Custom validators
@@ -251,7 +251,7 @@ class MediaEntry(Document, MediaEntryMixin):
return self.db.User.find_one({'_id': self.uploader})
-class MediaComment(Document):
+class MediaComment(Document, MediaCommentMixin):
"""
A comment on a MediaEntry.
@@ -260,8 +260,6 @@ class MediaComment(Document):
- author: user who posted this comment
- created: when the comment was created
- content: plaintext (but markdown'able) version of the comment's content.
- - content_html: the actual html-rendered version of the comment displayed.
- Run through Markdown and the HTML cleaner.
"""
__collection__ = 'media_comments'
@@ -272,7 +270,7 @@ class MediaComment(Document):
'author': ObjectId,
'created': datetime.datetime,
'content': unicode,
- 'content_html': unicode}
+ }
required_fields = [
'media_entry', 'author', 'created', 'content']
diff --git a/mediagoblin/db/sql/convert.py b/mediagoblin/db/sql/convert.py
index 9d276866..a46d62ea 100644
--- a/mediagoblin/db/sql/convert.py
+++ b/mediagoblin/db/sql/convert.py
@@ -133,7 +133,7 @@ def convert_media_comments(mk_db):
new_entry = MediaComment()
copy_attrs(entry, new_entry,
('created',
- 'content', 'content_html',))
+ 'content',))
copy_reference_attr(entry, new_entry, "media_entry")
copy_reference_attr(entry, new_entry, "author")
diff --git a/mediagoblin/db/sql/models.py b/mediagoblin/db/sql/models.py
index 72591f4e..18e1dfd7 100644
--- a/mediagoblin/db/sql/models.py
+++ b/mediagoblin/db/sql/models.py
@@ -31,7 +31,7 @@ from sqlalchemy.ext.associationproxy import association_proxy
from mediagoblin.db.sql.extratypes import PathTupleWithSlashes
from mediagoblin.db.sql.base import Base, DictReadAttrProxy
-from mediagoblin.db.mixin import UserMixin, MediaEntryMixin
+from mediagoblin.db.mixin import UserMixin, MediaEntryMixin, MediaCommentMixin
class SimpleFieldAlias(object):
@@ -218,7 +218,7 @@ class MediaTag(Base):
return DictReadAttrProxy(self)
-class MediaComment(Base):
+class MediaComment(Base, MediaCommentMixin):
__tablename__ = "media_comments"
id = Column(Integer, primary_key=True)
@@ -227,7 +227,6 @@ class MediaComment(Base):
author = Column(Integer, ForeignKey('users.id'), nullable=False)
created = Column(DateTime, nullable=False, default=datetime.datetime.now)
content = Column(UnicodeText, nullable=False)
- content_html = Column(UnicodeText)
get_author = relationship(User)