本文整理汇总了Python中models.media.Media.get_media方法的典型用法代码示例。如果您正苦于以下问题:Python Media.get_media方法的具体用法?Python Media.get_media怎么用?Python Media.get_media使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.media.Media
的用法示例。
在下文中一共展示了Media.get_media方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_memorial
# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import get_media [as 别名]
def get_memorial(url=None, user_id=None, create_if_none=True, init=False):
from models.media import Media
from models.comment import Comment
memorial = None
if url:
# TODO - figure out how to condense into just a single db query. Either we have to build the Memorial obj from the tuple returned from exec, or research more on case sensitive searching using SQLAlchemy
# https://bitbucket.org/mitsuhiko/flask/src/tip/examples/minitwit/minitwit.py --> db_query()
memorial = db.session.execute('SELECT id FROM memorials WHERE BINARY memorials.url = :url and memorials.status < 5 LIMIT 1', { 'url': url } ).fetchone()
if memorial:
memorial = Memorial.query.filter_by(id=memorial[0]).first()
memorial.media = Media.get_media(memorial.id, init=init, validate=False)
memorial.comments = Comment.get_comments(memorial.id)
else:
if user_id > 0:
memorial = Memorial.query.filter(Memorial.user_id == user_id, Memorial.status == 1).first()
if memorial:
memorial.media = Media.get_media(memorial.id, init=True, validate=False)
elif create_if_none:
memorial = Memorial(user_id, status=1)
memorial.save_new_memorial()
else:
from lib import sessions
memorial = Memorial(user_id, status=1)
if sessions.save_photo('has'):
memorial.media = Media(media_type=Media.media_types['photo'], filename=sessions.save_photo('get'))
if memorial:
# Need ordered to ensure validation goes through date checking in order
from collections import OrderedDict
memorial.errors = OrderedDict([ ('name', ''), ('dob', ''), ('dod', ''), ('cause', ''), ('epitaph', ''), ('funeral_type', ''), ('funeral_date', ''), ('funeral_loc', ''), ('media', '') ])
memorial.media = ( memorial.media if hasattr(memorial, 'media') and memorial.media else None ) #media = db.relationship('Media', backref = 'memorial', lazy = 'dynamic')
return memorial