本文整理汇总了Python中pyramid_sqlalchemy.Session.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Session.delete方法的具体用法?Python Session.delete怎么用?Python Session.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid_sqlalchemy.Session
的用法示例。
在下文中一共展示了Session.delete方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: revoke_application
# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import delete [as 别名]
def revoke_application(request):
app_id = request.matchdict['app']
try:
uuid.UUID(app_id)
except ValueError:
return HTTPBadRequest()
try:
app = Session.query(Application).filter(Application.id == app_id).one()
except NoResultFound:
return HTTPNotFound()
assert_authenticated_user_is_registered(request)
if 'submit' in request.POST:
authorized_apps = Session.query(AuthorizedApplication).filter(
AuthorizedApplication.application == app,
AuthorizedApplication.user == request.user
).all()
for authorized_app in authorized_apps:
Session.delete(authorized_app)
request.session.flash(
_('The access to application ${app} has been revoked',
mapping={'app': app.name}),
'success',
)
return HTTPFound(
location=request.route_path('oauth2_authorized_applications'))
return {'app': app}
示例2: delete
# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import delete [as 别名]
def delete(self):
"""
Delete an item from a collection; typically occurs with requests like DELETE /users/1
"""
Session.delete(self.context.entity)
Session.flush()
return Response(status=204)
示例3: clean_access_codes
# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import delete [as 别名]
def clean_access_codes():
result = setup_simple_command(
"clean_access_codes",
"Deletes expired access codes"
)
if isinstance(result, int):
return result
else:
settings, closer, env, args = result
try:
now = datetime.datetime.utcnow()
with transaction.manager:
counter = 0
for access_code in Session.query(AccessCode).filter(
AccessCode.expiration < now
):
Session.delete(access_code)
counter += 1
if counter > 0:
safe_print('%d access codes were cleaned' % counter)
finally:
closer()
示例4: _delete_many
# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import delete [as 别名]
def _delete_many(cls, items, request=None,
synchronize_session=False):
""" Delete :items: queryset or objects list.
When queryset passed, Query.delete() is used to delete it but
first queryset is re-queried to clean it from explicit
limit/offset/etc.
If some of the methods listed above were called, or :items: is not
a Query instance, one-by-one items update is performed.
`on_bulk_delete` function is called to delete objects from index
and to reindex relationships. This is done explicitly because it is
impossible to get access to deleted objects in signal handler for
'after_bulk_delete' ORM event.
"""
if isinstance(items, Query):
del_queryset = cls._clean_queryset(items)
del_items = del_queryset.all()
del_count = del_queryset.delete(
synchronize_session=synchronize_session)
on_bulk_delete(cls, del_items, request)
return del_count
items_count = len(items)
session = Session()
for item in items:
item._request = request
session.delete(item)
session.flush()
return items_count
示例5: developer_application_delete
# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import delete [as 别名]
def developer_application_delete(request):
app_id = request.matchdict['app']
try:
uuid.UUID(app_id)
except ValueError:
return HTTPBadRequest()
try:
app = Session.query(Application).filter(Application.id == app_id).one()
except NoResultFound:
return HTTPNotFound()
assert_authenticated_user_is_registered(request)
if app.user != request.user:
return HTTPUnauthorized()
if 'submit' in request.POST:
Session.delete(app)
request.session.flash(
_('The application ${app} was deleted successfully',
mapping={'app': app.name}),
'success',
)
return HTTPFound(
location=request.route_path('oauth2_developer_applications'))
return {'app': app}
示例6: delete
# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import delete [as 别名]
def delete(self):
set_config(self.request.user)
result = Session.query(self.model).get(int(self.request.matchdict['id']))
if result and not result.is_readonly:
Session.delete(result)
return result
raise HTTPNotFound()
示例7: invalidate_authorization_code
# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import delete [as 别名]
def invalidate_authorization_code(self, client_id, code, request, *args, **kwargs):
"""Authorization codes are use once, invalidate it when a Bearer token
has been acquired.
"""
authorization_code = Session.query(AuthorizationCode).filter(
AuthorizationCode.code == code,
AuthorizationCode.application == request.client,
).one()
Session.delete(authorization_code)
示例8: destroy
# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import delete [as 别名]
def destroy(request):
schema = AccountDestroySchema()
button1 = Button('submit', _('Yes, I am sure. Destroy my account'))
button1.css_class = 'btn-danger'
button2 = Button('cancel', _('Cancel'))
button2.css_class = 'btn-default'
form = Form(schema, buttons=(button1, button2))
user = request.user
can_destroy = len(user.applications) == 0
context = {
'passwords': len(user.passwords),
'can_destroy': can_destroy,
}
if 'submit' in request.POST:
if not can_destroy:
request.session.flash(
_('You must remove your applications before destroying your account'),
'error',
)
return HTTPFound(location=request.route_path('oauth2_developer_applications'))
controls = request.POST.items()
try:
appstruct = form.validate(controls)
except ValidationFailure as e:
context['form'] = e.render()
return context
reason = appstruct['reason']
notify_admins_of_account_removal(request, user, reason)
Session.delete(user)
request.session.flash(
_('Your account has been removed. Have a nice day!'),
'success',
)
return logout(request)
elif 'cancel' in request.POST:
request.session.flash(
_('Thanks for reconsidering removing your account!'),
'info',
)
return HTTPFound(location=request.route_path('user_information'))
context['form'] = form.render()
return context
示例9: delete
# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import delete [as 别名]
def delete(self):
try:
uuid.UUID(self.password_id)
except ValueError:
return invalid_password_id()
password = self._get_password()
if password is None:
return password_not_found()
else:
Session.delete(password)
return {'password': {'id': self.password_id}}
示例10: merge_users
# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import delete [as 别名]
def merge_users(user1, user2):
values = {'user_id': user1.id}
for Model in (Password, Application, AuthorizationCode, AccessCode,
ExternalIdentity):
Session.query(Model).filter(Model.user == user2).update(values, False)
# Because the previous updates break the Unit of Work pattern we need
# to refresh the current objects in the session
Session.expire_all()
for auth_app in Session.query(AuthorizedApplication).filter(
AuthorizedApplication.user == user2):
try:
Session.query(AuthorizedApplication).filter(
AuthorizedApplication.user == user1,
AuthorizedApplication.application == auth_app.application,
).one()
except NoResultFound:
auth_app.user = user1
Session.add(auth_app)
Session.delete(user2)
示例11: hg_delete
# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import delete [as 别名]
def hg_delete(self):
Session.delete(self)
示例12: blog_delete
# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import delete [as 别名]
def blog_delete(request):
article = Session.query(Article)\
.filter_by(id=request.matchdict['id']).one()
Session.delete(article)
return HTTPFound(location=request.route_url('blog'))
示例13: _delete_many
# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import delete [as 别名]
def _delete_many(cls, items):
session = Session()
for item in items:
session.delete(item)
session.flush()