当前位置: 首页>>代码示例>>Python>>正文


Python Session.delete方法代码示例

本文整理汇总了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}
开发者ID:ablanco,项目名称:yith-library-server,代码行数:35,代码来源:views.py

示例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)
开发者ID:brendan-rius,项目名称:honeygen_pyramid,代码行数:9,代码来源:base_view.py

示例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()
开发者ID:ablanco,项目名称:yith-library-server,代码行数:28,代码来源:clean_access_codes.py

示例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
开发者ID:numb3r3,项目名称:nefertari-sqla,代码行数:32,代码来源:documents.py

示例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}
开发者ID:ablanco,项目名称:yith-library-server,代码行数:30,代码来源:views.py

示例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()
开发者ID:marplatense,项目名称:multitenant_rls,代码行数:9,代码来源:default.py

示例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)
开发者ID:ablanco,项目名称:yith-library-server,代码行数:11,代码来源:validator.py

示例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
开发者ID:lorenzogil,项目名称:yith-library-server,代码行数:56,代码来源:views.py

示例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}}
开发者ID:lorenzogil,项目名称:yith-library-server,代码行数:15,代码来源:views.py

示例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)
开发者ID:ablanco,项目名称:yith-library-server,代码行数:24,代码来源:accounts.py

示例11: hg_delete

# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import delete [as 别名]
 def hg_delete(self):
     Session.delete(self)
开发者ID:brendan-rius,项目名称:honeygen_pyramid,代码行数:4,代码来源:base_model.py

示例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'))
开发者ID:IYism,项目名称:lectures.www,代码行数:7,代码来源:views.py

示例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()
开发者ID:howaryoo,项目名称:nefertari-sqla,代码行数:7,代码来源:documents.py


注:本文中的pyramid_sqlalchemy.Session.delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。