本文整理汇总了Python中models.media.Media.save_new_media方法的典型用法代码示例。如果您正苦于以下问题:Python Media.save_new_media方法的具体用法?Python Media.save_new_media怎么用?Python Media.save_new_media使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.media.Media
的用法示例。
在下文中一共展示了Media.save_new_media方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_photo
# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import save_new_media [as 别名]
def save_photo(memorial_url=None):
from lib import uploader
from models.memorial import Memorial
from models.media import Media
photo = request.files.get('photo') or ''
new_file = uploader.process_media( photo ) if photo else ''
if photo and new_file:
if g.user.is_anonymous():
status = 'ok'
message = jinjer.static( new_file, 'tmp' )
# replace current photo in user's session with new one
if sessions.save_photo('has'):
uploader.remove_memorial_photo( sessions.save_photo('get') )
sessions.save_photo('set', new_file)
else:
memorial = Memorial.get_memorial( url=memorial_url, user_id=g.user.id, create_if_none=False )
if memorial:
status = 'ok'
# is this a new memorial?
if memorial.status == 1:
message = jinjer.static( new_file, 'tmp' )
else:
uploader.move_file( new_file, app.config['MEDIA_FOLDER'] )
message = jinjer.static( new_file, 'memorial' )
media = Media.query.filter_by(memorial_id=memorial.id).first()
if media:
uploader.remove_memorial_photo(media.filename) # remove current file stored on disk
media.update_filename(new_file)
else:
media = Media(memorial.id, Media.media_types['photo'], new_file)
media.save_new_media()
else:
status = 'invalid'
message = ''
else:
status = 'unknown'
message = ''
return render(ajax=True, status=status, message=message)