本文整理汇总了Python中mediacore.model.meta.DBSession.refresh方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.refresh方法的具体用法?Python DBSession.refresh怎么用?Python DBSession.refresh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mediacore.model.meta.DBSession
的用法示例。
在下文中一共展示了DBSession.refresh方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_file
# 需要导入模块: from mediacore.model.meta import DBSession [as 别名]
# 或者: from mediacore.model.meta.DBSession import refresh [as 别名]
def edit_file(self, id, file_id, file_type=None, duration=None, delete=None, bitrate=None, width_height=None, **kwargs):
"""Save action for the :class:`~mediacore.forms.admin.media.EditFileForm`.
Changes or deletes a :class:`~mediacore.model.media.MediaFile`.
XXX: We do NOT use the @validate decorator due to complications with
partial validation. The JS sends only the value it wishes to
change, so we only want to validate that one value.
FancyValidator.if_missing seems to eat empty values and assign
them None, but there's an important difference to us between
None (no value from the user) and an empty value (the user
is clearing the value of a field).
:param id: Media ID
:type id: :class:`int`
:rtype: JSON dict
:returns:
success
bool
message
Error message, if unsuccessful
status_form
Rendered XHTML for the status form, updated to reflect the
changes made.
"""
media = fetch_row(Media, id)
data = dict(success=False)
file_id = int(file_id) # Just in case validation failed somewhere.
for file in media.files:
if file.id == file_id:
break
else:
file = None
fields = edit_file_form.c
try:
if file is None:
data['message'] = _('File "%s" does not exist.') % file_id
elif file_type:
file.type = fields.file_type.validate(file_type)
data['success'] = True
elif duration is not None:
media.duration = fields.duration.validate(duration)
data['success'] = True
data['duration'] = helpers.duration_from_seconds(media.duration)
elif width_height is not None:
width_height = fields.width_height.validate(width_height)
file.width, file.height = width_height or (0, 0)
data['success'] = True
elif bitrate is not None:
file.bitrate = fields.bitrate.validate(bitrate)
data['success'] = True
elif delete:
file.storage.delete(file.unique_id)
DBSession.delete(file)
DBSession.flush()
# media.files must be updated to reflect the file deletion above
DBSession.refresh(media)
data['success'] = True
else:
data['message'] = _('No action to perform.')
except Invalid, e:
data['success'] = False
data['message'] = unicode(e)