Drop pre-rendered html: User.bio_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 User.bio_html part.
This commit is contained in:
parent
38816c6607
commit
e61ab0998b
@ -29,6 +29,7 @@ real objects.
|
|||||||
|
|
||||||
from mediagoblin.auth import lib as auth_lib
|
from mediagoblin.auth import lib as auth_lib
|
||||||
from mediagoblin.tools import common, licenses
|
from mediagoblin.tools import common, licenses
|
||||||
|
from mediagoblin.tools.text import cleaned_markdown_conversion
|
||||||
|
|
||||||
|
|
||||||
class UserMixin(object):
|
class UserMixin(object):
|
||||||
@ -39,6 +40,10 @@ class UserMixin(object):
|
|||||||
return auth_lib.bcrypt_check_password(
|
return auth_lib.bcrypt_check_password(
|
||||||
password, self.pw_hash)
|
password, self.pw_hash)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def bio_html(self):
|
||||||
|
return cleaned_markdown_conversion(self.bio)
|
||||||
|
|
||||||
|
|
||||||
class MediaEntryMixin(object):
|
class MediaEntryMixin(object):
|
||||||
def get_display_media(self, media_map,
|
def get_display_media(self, media_map,
|
||||||
|
@ -115,3 +115,14 @@ def mediaentry_add_license(database):
|
|||||||
Add the 'license' field for entries that don't have it.
|
Add the 'license' field for entries that don't have it.
|
||||||
"""
|
"""
|
||||||
add_table_field(database, 'media_entries', 'license', None)
|
add_table_field(database, 'media_entries', 'license', None)
|
||||||
|
|
||||||
|
|
||||||
|
@RegisterMigration(9)
|
||||||
|
def user_remove_bio_html(database):
|
||||||
|
"""
|
||||||
|
Drop bio_html again and calculate things on the fly (and cache)
|
||||||
|
"""
|
||||||
|
database['users'].update(
|
||||||
|
{'bio_html': {'$exists': True}},
|
||||||
|
{'$unset': {'bio_html': 1}},
|
||||||
|
multi=True)
|
||||||
|
@ -59,7 +59,6 @@ class User(Document, UserMixin):
|
|||||||
- is_admin: Whether or not this user is an administrator or not.
|
- is_admin: Whether or not this user is an administrator or not.
|
||||||
- url: this user's personal webpage/website, if appropriate.
|
- url: this user's personal webpage/website, if appropriate.
|
||||||
- bio: biography of this user (plaintext, in markdown)
|
- bio: biography of this user (plaintext, in markdown)
|
||||||
- bio_html: biography of the user converted to proper HTML.
|
|
||||||
"""
|
"""
|
||||||
__collection__ = 'users'
|
__collection__ = 'users'
|
||||||
use_dot_notation = True
|
use_dot_notation = True
|
||||||
@ -76,7 +75,6 @@ class User(Document, UserMixin):
|
|||||||
'is_admin': bool,
|
'is_admin': bool,
|
||||||
'url': unicode,
|
'url': unicode,
|
||||||
'bio': unicode, # May contain markdown
|
'bio': unicode, # May contain markdown
|
||||||
'bio_html': unicode, # May contain plaintext, or HTML
|
|
||||||
'fp_verification_key': unicode, # forgotten password verification key
|
'fp_verification_key': unicode, # forgotten password verification key
|
||||||
'fp_token_expire': datetime.datetime,
|
'fp_token_expire': datetime.datetime,
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ def convert_users(mk_db):
|
|||||||
copy_attrs(entry, new_entry,
|
copy_attrs(entry, new_entry,
|
||||||
('username', 'email', 'created', 'pw_hash', 'email_verified',
|
('username', 'email', 'created', 'pw_hash', 'email_verified',
|
||||||
'status', 'verification_key', 'is_admin', 'url',
|
'status', 'verification_key', 'is_admin', 'url',
|
||||||
'bio', 'bio_html',
|
'bio',
|
||||||
'fp_verification_key', 'fp_token_expire',))
|
'fp_verification_key', 'fp_token_expire',))
|
||||||
# new_entry.fp_verification_expire = entry.fp_token_expire
|
# new_entry.fp_verification_expire = entry.fp_token_expire
|
||||||
|
|
||||||
|
@ -64,7 +64,6 @@ class User(Base, UserMixin):
|
|||||||
is_admin = Column(Boolean, default=False, nullable=False)
|
is_admin = Column(Boolean, default=False, nullable=False)
|
||||||
url = Column(Unicode)
|
url = Column(Unicode)
|
||||||
bio = Column(UnicodeText) # ??
|
bio = Column(UnicodeText) # ??
|
||||||
bio_html = Column(UnicodeText) # ??
|
|
||||||
fp_verification_key = Column(Unicode)
|
fp_verification_key = Column(Unicode)
|
||||||
fp_token_expire = Column(DateTime)
|
fp_token_expire = Column(DateTime)
|
||||||
|
|
||||||
|
@ -171,8 +171,6 @@ def edit_profile(request):
|
|||||||
user.url = unicode(request.POST['url'])
|
user.url = unicode(request.POST['url'])
|
||||||
user.bio = unicode(request.POST['bio'])
|
user.bio = unicode(request.POST['bio'])
|
||||||
|
|
||||||
user.bio_html = cleaned_markdown_conversion(user.bio)
|
|
||||||
|
|
||||||
user.save()
|
user.save()
|
||||||
|
|
||||||
messages.add_message(request,
|
messages.add_message(request,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user