Drop pre-rendered html: MediaEntry.description_html
After a bit of discussion, we decided to drop the pre-rendered html from the database and render it on the fly. In another step, we will use some proper caching method to cache this stuff. This commit affects the MediaEntry.description_html part.
This commit is contained in:
@@ -46,6 +46,14 @@ class UserMixin(object):
|
||||
|
||||
|
||||
class MediaEntryMixin(object):
|
||||
@property
|
||||
def description_html(self):
|
||||
"""
|
||||
Rendered version of the description, run through
|
||||
Markdown and cleaned with our cleaning tool.
|
||||
"""
|
||||
return cleaned_markdown_conversion(self.description)
|
||||
|
||||
def get_display_media(self, media_map,
|
||||
fetch_order=common.DISPLAY_IMAGE_FETCHING_ORDER):
|
||||
"""
|
||||
|
||||
@@ -29,6 +29,16 @@ def add_table_field(db, table_name, field_name, default_value):
|
||||
multi=True)
|
||||
|
||||
|
||||
def drop_table_field(db, table_name, field_name):
|
||||
"""
|
||||
Drop an old field from a table/collection
|
||||
"""
|
||||
db[table_name].update(
|
||||
{field_name: {'$exists': True}},
|
||||
{'$unset': {field_name: 1}},
|
||||
multi=True)
|
||||
|
||||
|
||||
# Please see mediagoblin/tests/test_migrations.py for some examples of
|
||||
# basic migrations.
|
||||
|
||||
@@ -118,11 +128,9 @@ def mediaentry_add_license(database):
|
||||
|
||||
|
||||
@RegisterMigration(9)
|
||||
def user_remove_bio_html(database):
|
||||
def remove_calculated_html(database):
|
||||
"""
|
||||
Drop bio_html again and calculate things on the fly (and cache)
|
||||
Drop bio_html, description_html again and calculate things on the fly (and cache)
|
||||
"""
|
||||
database['users'].update(
|
||||
{'bio_html': {'$exists': True}},
|
||||
{'$unset': {'bio_html': 1}},
|
||||
multi=True)
|
||||
drop_table_field(database, 'users', 'bio_html')
|
||||
drop_table_field(database, 'media_entries', 'description_html')
|
||||
|
||||
@@ -110,9 +110,6 @@ class MediaEntry(Document, MediaEntryMixin):
|
||||
up with MarkDown for slight fanciness (links, boldness, italics,
|
||||
paragraphs...)
|
||||
|
||||
- description_html: Rendered version of the description, run through
|
||||
Markdown and cleaned with our cleaning tool.
|
||||
|
||||
- media_type: What type of media is this? Currently we only support
|
||||
'image' ;)
|
||||
|
||||
@@ -177,7 +174,6 @@ class MediaEntry(Document, MediaEntryMixin):
|
||||
'slug': unicode,
|
||||
'created': datetime.datetime,
|
||||
'description': unicode, # May contain markdown/up
|
||||
'description_html': unicode, # May contain plaintext, or HTML
|
||||
'media_type': unicode,
|
||||
'media_data': dict, # extra data relevant to this media_type
|
||||
'plugin_data': dict, # plugins can dump stuff here.
|
||||
|
||||
@@ -77,7 +77,7 @@ def convert_media_entries(mk_db):
|
||||
new_entry = MediaEntry()
|
||||
copy_attrs(entry, new_entry,
|
||||
('title', 'slug', 'created',
|
||||
'description', 'description_html',
|
||||
'description',
|
||||
'media_type', 'state', 'license',
|
||||
'fail_error',
|
||||
'queued_task_id',))
|
||||
|
||||
@@ -85,7 +85,6 @@ class MediaEntry(Base, MediaEntryMixin):
|
||||
slug = Column(Unicode)
|
||||
created = Column(DateTime, nullable=False, default=datetime.datetime.now)
|
||||
description = Column(UnicodeText) # ??
|
||||
description_html = Column(UnicodeText) # ??
|
||||
media_type = Column(Unicode, nullable=False)
|
||||
state = Column(Unicode, default=u'unprocessed', nullable=False)
|
||||
# or use sqlalchemy.types.Enum?
|
||||
|
||||
Reference in New Issue
Block a user