本文整理汇总了Python中mediacore.model.meta.DBSession.rollback方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.rollback方法的具体用法?Python DBSession.rollback怎么用?Python DBSession.rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mediacore.model.meta.DBSession
的用法示例。
在下文中一共展示了DBSession.rollback方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_file
# 需要导入模块: from mediacore.model.meta import DBSession [as 别名]
# 或者: from mediacore.model.meta.DBSession import rollback [as 别名]
def add_file(self, id, file=None, url=None, **kwargs):
"""Save action for the :class:`~mediacore.forms.admin.media.AddFileForm`.
Creates a new :class:`~mediacore.model.media.MediaFile` from the
uploaded file or the local or remote URL.
:param id: Media ID. If ``"new"`` a new Media stub is created.
:type id: :class:`int` or ``"new"``
:param file: The uploaded file
:type file: :class:`cgi.FieldStorage` or ``None``
:param url: A URL to a recognizable audio or video file
:type url: :class:`unicode` or ``None``
:rtype: JSON dict
:returns:
success
bool
message
Error message, if unsuccessful
media_id
The :attr:`~mediacore.model.media.Media.id` which is
important if new media has just been created.
file_id
The :attr:`~mediacore.model.media.MediaFile.id` for the newly
created file.
edit_form
The rendered XHTML :class:`~mediacore.forms.admin.media.EditFileForm`
for this file.
status_form
The rendered XHTML :class:`~mediacore.forms.admin.media.UpdateStatusForm`
"""
if id == 'new':
media = Media()
user = request.environ['repoze.who.identity']['user']
media.author = Author(user.display_name, user.email_address)
# Create a temp stub until we can set it to something meaningful
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
media.title = u'Temporary stub %s' % timestamp
media.slug = get_available_slug(Media, '_stub_' + timestamp)
DBSession.add(media)
DBSession.flush()
else:
media = fetch_row(Media, id)
try:
media_file = add_new_media_file(media, file, url)
except Invalid, e:
DBSession.rollback()
data = dict(
success = False,
message = e.message,
)
示例2: __call__
# 需要导入模块: from mediacore.model.meta import DBSession [as 别名]
# 或者: from mediacore.model.meta.DBSession import rollback [as 别名]
def __call__(self, environ, start_response):
"""Commit or rollback the DBSession for every request.
Your controller may override this method and have it call
:meth:`BareBonesController.__call__` directly to avoid
this transaction management.
"""
try:
app_iter = BareBonesController.__call__(self, environ,
start_response)
except:
# An unexpected error has occurred that the WebError will catch
DBSession.rollback()
raise
else:
# webob.exc.HTTPException's are caught and turned into a regular
# responses in WSGIController._inspect_call. Veto error responses:
if 200 <= response.status_int < 400:
DBSession.commit()
else:
DBSession.rollback()
return app_iter
示例3: save_engine_params
# 需要导入模块: from mediacore.model.meta import DBSession [as 别名]
# 或者: from mediacore.model.meta.DBSession import rollback [as 别名]
def save_engine_params(self, engine, panda, s3, cloudfront, profiles, **kwargs):
"""Map validated field values to engine data.
Since form widgets may be nested or named differently than the keys
in the :attr:`mediacore.lib.storage.StorageEngine._data` dict, it is
necessary to manually map field values to the data dictionary.
:type engine: :class:`mediacore.lib.storage.StorageEngine` subclass
:param engine: An instance of the storage engine implementation.
:param \*\*kwargs: Validated and filtered form values.
:raises formencode.Invalid: If some post-validation error is detected
in the user input. This will trigger the same error handling
behaviour as with the @validate decorator.
"""
# The panda client library expects strings.
for key in panda:
if panda[key] is None:
panda[key] = u''
StorageForm.save_engine_params(self, engine, **kwargs)
engine._data[PANDA_CLOUD_ID] = panda['cloud_id']
engine._data[PANDA_ACCESS_KEY] = panda['access_key']
engine._data[PANDA_SECRET_KEY] = panda['secret_key']
engine._data[PANDA_API_HOST] = panda['api_host']
engine._data[PANDA_PROFILES] = profiles
engine._data[S3_BUCKET_NAME] = s3['bucket_name']
engine._data[CLOUDFRONT_STREAMING_URI] = cloudfront['streaming_uri']
engine._data[CLOUDFRONT_DOWNLOAD_URI] = cloudfront['download_uri']
engine.panda_helper.cache.clear()
try:
engine.panda_helper().client.get_cloud()
except PandaException, e:
DBSession.rollback()
# TODO: Display this error to the user.
raise Invalid(str(e), None, None)
示例4: _autocommit_rollback
# 需要导入模块: from mediacore.model.meta import DBSession [as 别名]
# 或者: from mediacore.model.meta.DBSession import rollback [as 别名]
def _autocommit_rollback(req):
from mediacore.model.meta import DBSession
DBSession.rollback()
_autocommit_fire_callbacks(req, req.rollback_callbacks)
示例5: _autocommit_rollback
# 需要导入模块: from mediacore.model.meta import DBSession [as 别名]
# 或者: from mediacore.model.meta.DBSession import rollback [as 别名]
def _autocommit_rollback(req):
DBSession.rollback()
_autocommit_fire_callbacks(req, req.rollback_callbacks)