本文整理汇总了Python中mediacore.model.meta.DBSession.expunge方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.expunge方法的具体用法?Python DBSession.expunge怎么用?Python DBSession.expunge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mediacore.model.meta.DBSession
的用法示例。
在下文中一共展示了DBSession.expunge方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save
# 需要导入模块: from mediacore.model.meta import DBSession [as 别名]
# 或者: from mediacore.model.meta.DBSession import expunge [as 别名]
def save(self, id, slug, title, author_name, author_email,
description, notes, details, podcast, tags, categories,
delete=None, **kwargs):
"""Save changes or create a new :class:`~mediacore.model.media.Media` instance.
Form handler the :meth:`edit` action and the
:class:`~mediacore.forms.admin.media.MediaForm`.
Redirects back to :meth:`edit` after successful editing
and :meth:`index` after successful deletion.
"""
media = fetch_row(Media, id)
if delete:
file_paths = helpers.thumb_paths(media)
for f in media.files:
file_paths.append(f.file_path)
# Remove the file from the session so that SQLAlchemy doesn't
# try to issue an UPDATE to set the MediaFile.media_id to None.
# The database ON DELETE CASCADE handles everything for us.
DBSession.expunge(f)
DBSession.delete(media)
transaction.commit()
helpers.delete_files(file_paths, 'media')
redirect(action='index', id=None)
media.slug = get_available_slug(Media, slug, media)
media.title = title
media.author = Author(author_name, author_email)
media.description = description
media.notes = notes
media.duration = details['duration'] # validator converts hh:mm:ss to secs
media.podcast_id = podcast
media.set_tags(tags)
media.set_categories(categories)
media.update_status()
DBSession.add(media)
DBSession.flush()
if id == 'new':
helpers.create_default_thumbs_for(media)
redirect(action='edit', id=media.id)
示例2: save
# 需要导入模块: from mediacore.model.meta import DBSession [as 别名]
# 或者: from mediacore.model.meta.DBSession import expunge [as 别名]
def save(self, id, slug, title, author_name, author_email,
description, notes, podcast, tags, categories,
delete=None, **kwargs):
"""Save changes or create a new :class:`~mediacore.model.media.Media` instance.
Form handler the :meth:`edit` action and the
:class:`~mediacore.forms.admin.media.MediaForm`.
Redirects back to :meth:`edit` after successful editing
and :meth:`index` after successful deletion.
"""
media = fetch_row(Media, id)
if delete:
file_paths = thumb_paths(media).values()
for f in media.files:
file_paths.append(f.file_path)
# Remove the file from the session so that SQLAlchemy doesn't
# try to issue an UPDATE to set the MediaFile.media_id to None.
# The database ON DELETE CASCADE handles everything for us.
DBSession.expunge(f)
DBSession.delete(media)
DBSession.commit()
helpers.delete_files(file_paths, Media._thumb_dir)
redirect(action='index', id=None)
if not slug:
slug = title
elif slug.startswith('_stub_'):
slug = slug[len('_stub_'):]
if slug != media.slug:
media.slug = get_available_slug(Media, slug, media)
media.title = title
media.author = Author(author_name, author_email)
media.description = description
media.notes = notes
media.podcast_id = podcast
media.set_tags(tags)
media.set_categories(categories)
media.update_status()
DBSession.add(media)
DBSession.flush()
if id == 'new':
create_default_thumbs_for(media)
if request.is_xhr:
status_form_xhtml = unicode(update_status_form.display(
action=url_for(action='update_status', id=media.id),
media=media))
return dict(
media_id = media.id,
values = {'slug': slug},
link = url_for(action='edit', id=media.id),
status_form = status_form_xhtml,
)
else:
redirect(action='edit', id=media.id)