• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python session.delete函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中turbogears.database.session.delete函数的典型用法代码示例。如果您正苦于以下问题:Python delete函数的具体用法?Python delete怎么用?Python delete使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了delete函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: remove

    def remove(self, **kw):
        u = identity.current.user
        try:
            group = Group.by_id(kw['group_id'])
        except DatabaseLookupError:
            flash(unicode('Invalid group or already removed'))
            redirect('../groups/mine')

        if not group.can_edit(u):
            flash(_(u'You are not an owner of group %s' % group))
            redirect('../groups/mine')

        if group.is_protected_group():
            flash(_(u'This group %s is predefined and cannot be deleted' % group))
            redirect('../groups/mine')

        if group.jobs:
            flash(_(u'Cannot delete a group which has associated jobs'))
            redirect('../groups/mine')

        # Record the access policy rules that will be removed
        # before deleting the group
        for rule in group.system_access_policy_rules:
            rule.record_deletion()

        # For any system pool owned by this group, unset owning_group
        # and set owning_user to the user deleting this group
        pools = SystemPool.query.filter_by(owning_group_id=group.group_id)
        for pool in pools:
            pool.change_owner(user=u, service='WEBUI')
        session.delete(group)
        activity = Activity(u, u'WEBUI', u'Removed', u'Group', group.display_name, u"")
        session.add(activity)
        flash( _(u"%s deleted") % group.display_name )
        raise redirect(".")
开发者ID:ShaolongHu,项目名称:beaker,代码行数:35,代码来源:group.py


示例2: genkey

    def genkey(self):
        
        username = turbogears.identity.current.user_name
        person = People.by_username(username)

        created = time.strftime("%Y-%m-%dT%H:%M:%S")
        hexctr = "%012x" % person.id
        publicname = hex2modhex(hexctr)
        internalname = gethexrand(12)
        aeskey = gethexrand(32)
        lockcode = gethexrand(12)

        try:
            new_ykksm = Ykksm(serialnr=person.id, publicname=publicname, created=created, internalname=internalname, aeskey=aeskey, lockcode=lockcode, creator=username)
            session.add(new_ykksm)
            session.flush() 
        except IntegrityError:
            session.rollback()
            old_ykksm = session.query(Ykksm).filter_by(serialnr=person.id).all()[0]
            session.delete(old_ykksm)
            new_ykksm = Ykksm(serialnr=person.id, publicname=publicname, created=created, internalname=internalname, aeskey=aeskey, lockcode=lockcode, creator=username)
            old_ykksm = new_ykksm
            session.flush()
        try:
            old_ykval = session.query(Ykval).filter_by(yk_publicname=publicname).all()[0]
            session.delete(old_ykval)
            session.flush()
        except IndexError:
            # No old record?  Maybe they never used their key
            pass
            
        string = "%s %s %s" % (publicname, internalname, aeskey)
        return dict(key=string)
开发者ID:chepioq,项目名称:fas,代码行数:33,代码来源:__init__.py


示例3: deleteQuery

    def deleteQuery(self, query_id, *args, **kwargs):
        '''
            Allows user to delete a query. Updates query logging.
            
            @param query_id: identifies the query
            @return: status of attempted  delete operation of the query
        '''
        
        query = session.query(Query).get_by(query_id=int(query_id))
        
        status = ""
        
        if not query:
            status = "Query not found"
        elif session.query(ChatSession).get_by(query_id=int(query_id)):
            status = "Chat already started"
        elif query.user_id != identity.current.user.user_id:
            status = "Permission denied"
        else:
            query.experts[:] = []
            query_log=QueryLog(
                query_id = int(query_id),
                user_id = query.user_id,
                user_name = session.query(User).get_by(user_id=query.user_id).user_name,
                created = datetime.now(),
                status = 'Deleted')

            session.save(query_log)
            session.flush()
            session.delete(query);
            session.flush();
            
        return dict(status=status)    
开发者ID:macagua,项目名称:SPREE,代码行数:33,代码来源:search_controller.py


示例4: remove

    def remove(self, id, *args, **kw):
        try:
            labcontroller = LabController.by_id(id)
            labcontroller.removed = datetime.utcnow()
            systems = System.query.filter_by(lab_controller_id=id).values(System.id)
            for system_id in systems:
                sys_activity = SystemActivity(identity.current.user, 'WEBUI', \
                    'Changed', 'lab_controller', labcontroller.fqdn,
                    None, system_id=system_id[0])
            system_table.update().where(system_table.c.lab_controller_id == id).\
                values(lab_controller_id=None).execute()
            watchdogs = Watchdog.by_status(labcontroller=labcontroller, 
                status='active')
            for w in watchdogs:
                w.recipe.recipeset.job.cancel(msg='LabController %s has been deleted' % labcontroller.fqdn)
            for lca in labcontroller._distro_trees:
                lca.distro_tree.activity.append(DistroTreeActivity(
                        user=identity.current.user, service=u'WEBUI',
                        action=u'Removed', field_name=u'lab_controller_assocs',
                        old_value=u'%s %s' % (lca.lab_controller, lca.url),
                        new_value=None))
                session.delete(lca)
            labcontroller.disabled = True
            LabControllerActivity(identity.current.user, 'WEBUI', 
                'Changed', 'Disabled', unicode(False), unicode(True), 
                lab_controller_id=id)
            LabControllerActivity(identity.current.user, 'WEBUI', 
                'Changed', 'Removed', unicode(False), unicode(True), 
                lab_controller_id=id)
            session.commit()
        finally:
            session.close()

        flash( _(u"%s removed") % labcontroller.fqdn )
        raise redirect(".")
开发者ID:sibiaoluo,项目名称:beaker,代码行数:35,代码来源:labcontroller.py


示例5: delete_system_access_policy_rules

def delete_system_access_policy_rules(fqdn):
    system = _get_system_by_FQDN(fqdn)
    if not system.can_edit_policy(identity.current.user):
        raise Forbidden403('Cannot edit system policy')
    if system.custom_access_policy:
        policy = system.custom_access_policy
    else:
        policy = system.custom_access_policy = SystemAccessPolicy()
    # We expect some query string args specifying which rules should be 
    # deleted. If those are not present, it's "Method Not Allowed".
    query = SystemAccessPolicyRule.query.filter(SystemAccessPolicyRule.policy == policy)
    if 'permission' in request.args:
        query = query.filter(SystemAccessPolicyRule.permission.in_(
                request.args.getlist('permission', type=SystemPermission.from_string)))
    else:
        raise MethodNotAllowed405
    if 'user' in request.args:
        query = query.join(SystemAccessPolicyRule.user)\
                .filter(User.user_name.in_(request.args.getlist('user')))
    elif 'group' in request.args:
        query = query.join(SystemAccessPolicyRule.group)\
                .filter(Group.group_name.in_(request.args.getlist('group')))
    elif 'everybody' in request.args:
        query = query.filter(SystemAccessPolicyRule.everybody)
    else:
        raise MethodNotAllowed405
    for rule in query:
        rule.record_deletion(service=u'HTTP')
        session.delete(rule)
    return '', 204
开发者ID:sujithshankar,项目名称:beaker,代码行数:30,代码来源:systems.py


示例6: save

    def save(self, targetname, bugzilla_email):
        person = People.by_username(turbogears.identity.current.user_name)
        target = People.by_username(targetname)

        if not can_edit_user(person, target):
            turbogears.flash(_("You do not have permission to edit '%s'") % target.username)
            turbogears.redirect('/bugzilla')
            return dict()

        new_configs = {'bugzilla_email': bugzilla_email}
        cur_configs = Configs.query.filter_by(person_id=target.id, application='bugzilla').all()

        if bugzilla_email == None:
          session.delete(cur_configs[0])
          turbogears.flash(_("Bugzilla specific email removed!  This means your bugzilla email must be set to: %s" % target.email))
          turbogears.redirect('/bugzilla/')
        for config in cur_configs:
            for new_config in new_configs.keys():
                if config.attribute == new_config:
                    config.value = new_configs[new_config]
                    del(new_configs[new_config])
        for config in new_configs:
            c = Configs(application='bugzilla', attribute=config, value=new_configs[config])
            target.configs.append(c)

        turbogears.flash(_("Changes saved.  Please allow up to 1 hour for changes to be realized."))
        turbogears.redirect('/bugzilla/')
        return dict()
开发者ID:0-T-0,项目名称:fas,代码行数:28,代码来源:__init__.py


示例7: _from_csv

    def _from_csv(cls,system,data,csv_type,log):
        """
        Import data from CSV file into System Objects
        """
        try:
            arch = Arch.by_name(data['arch'])
        except ValueError:
            log.append("%s: Invalid Arch %s" % (system.fqdn, data['arch']))
            return False

        if data['update'] and data['family']:
            try:
                osversion = OSVersion.by_name(OSMajor.by_name(unicode(data['family'])),
                                                            unicode(data['update']))
            except InvalidRequestError:
                log.append("%s: Invalid Family %s Update %s" % (system.fqdn,
                                                        data['family'],
                                                        data['update']))
                return False
            if osversion not in [oldosversion.osversion for oldosversion in system.excluded_osversion_byarch(arch)]:
                if data['excluded'] == 'True':
                    exclude_osversion = ExcludeOSVersion(osversion=osversion,
                                                         arch=arch)
                    system.excluded_osversion.append(exclude_osversion)
                    system.record_activity(user=identity.current.user, service=u'CSV',
                            action=u'Added', field=u'Excluded_families',
                            old=u'', new=u'%s/%s' % (osversion, arch))
            else:
                if data['excluded'] == 'False':
                    for old_osversion in system.excluded_osversion_byarch(arch):
                        if old_osversion.osversion == osversion:
                            system.record_activity(user=identity.current.user,
                                    service=u'CSV', action=u'Removed',
                                    field=u'Excluded_families',
                                    old=u'%s/%s' % (old_osversion.osversion, arch),
                                    new=u'')
                            session.delete(old_osversion)
        if not data['update'] and data['family']:
            try:
                osmajor = OSMajor.by_name(data['family'])
            except InvalidRequestError:
                log.append("%s: Invalid family %s " % (system.fqdn,
                                                       data['family']))
                return False
            if osmajor not in [oldosmajor.osmajor for oldosmajor in system.excluded_osmajor_byarch(arch)]:
                if data['excluded'].lower() == 'true':
                    exclude_osmajor = ExcludeOSMajor(osmajor=osmajor, arch=arch)
                    system.excluded_osmajor.append(exclude_osmajor)
                    system.record_activity(user=identity.current.user, service=u'CSV',
                            action=u'Added', field=u'Excluded_families',
                            old=u'', new=u'%s/%s' % (osmajor, arch))
            else:
                if data['excluded'].lower() == 'false':
                    for old_osmajor in system.excluded_osmajor_byarch(arch):
                        if old_osmajor.osmajor == osmajor:
                            system.record_activity(user=identity.current.user, service=u'CSV',
                                    action=u'Removed', field=u'Excluded_families',
                                    old=u'%s/%s' % (old_osmajor.osmajor, arch), new=u'')
                            session.delete(old_osmajor)
        return True
开发者ID:ShaolongHu,项目名称:beaker,代码行数:60,代码来源:CSV_import_export.py


示例8: logout

 def logout(self):
     '''Remove the link between this identity and the visit.'''
     visit = self.visit_link
     if visit:
         session.delete(visit)
         session.flush()
     # Clear the current identity
     identity.set_current_identity(SaFasIdentity())
开发者ID:Affix,项目名称:fas,代码行数:8,代码来源:safasprovider.py


示例9: delete

 def delete(self, id):
     tag = Tag.by_id(id)
     if not tag.can_delete(): # Trying to be funny...
         flash(u'%s is not applicable for deletion' % tag.tag)
         redirect('/retentiontag/admin')
     session.delete(tag)
     flash(u'Successfully deleted %s' % tag.tag)
     redirect('/retentiontag/admin')
开发者ID:omps,项目名称:beaker,代码行数:8,代码来源:retention_tags.py


示例10: destroy_self

 def destroy_self(self):
     '''
         Destroys self
     '''
     
     session.delete(self)
     session.flush()
     del(self)
开发者ID:macagua,项目名称:SPREE,代码行数:8,代码来源:register_model.py


示例11: logout

 def logout(self):
     """Remove the link between this identity and the visit."""
     visit = self.visit_link
     if visit:
         session.delete(visit)
         session.flush()
     # Clear the current identity
     identity.set_current_identity(SqlAlchemyIdentity())
开发者ID:marqui678,项目名称:finalchance.Panopta,代码行数:8,代码来源:saprovider.py


示例12: update_reservation_request

def update_reservation_request(id):
    """
    Updates the reservation request of a recipe. The request must be 
    :mimetype:`application/json`.

    :param id: Recipe's id.
    :jsonparam boolean reserve: Whether the system will be reserved at the end
      of the recipe. If true, the system will be reserved. If false, the system
      will not be reserved.
    :jsonparam int duration: Number of seconds to reserve the system.
    :jsonparam string when: Circumstances under which the system will be 
      reserved. Valid values are:

      onabort
        If the recipe status is Aborted.
      onfail
        If the recipe status is Aborted, or the result is Fail.
      onwarn
        If the recipe status is Aborted, or the result is Fail or Warn.
      always
        Unconditionally.
    """

    recipe = _get_recipe_by_id(id)
    if not recipe.can_update_reservation_request(identity.current.user):
        raise Forbidden403('Cannot update the reservation request of recipe %s'
                % recipe.id)
    data = read_json_request(request)
    if 'reserve' not in data:
        raise BadRequest400('No reserve specified')
    with convert_internal_errors():
        if data['reserve']:
            if not recipe.reservation_request:
                recipe.reservation_request = RecipeReservationRequest()
            if 'duration' in data:
                duration = int(data['duration'])
                if duration > MAX_SECONDS_PROVISION:
                    raise BadRequest400('Reservation time exceeds maximum time of %s hours'
                            % MAX_HOURS_PROVISION)
                old_duration = recipe.reservation_request.duration
                recipe.reservation_request.duration = duration
                _record_activity(recipe, u'Reservation Request', old_duration,
                        duration)
            if 'when' in data:
                old_condition = recipe.reservation_request.when
                new_condition = RecipeReservationCondition.from_string(data['when'])
                recipe.reservation_request.when = new_condition
                _record_activity(recipe, u'Reservation Condition',
                        old_condition, new_condition)
            session.flush() # to ensure the id is populated
            return jsonify(recipe.reservation_request.__json__())
        else:
            if recipe.reservation_request:
                session.delete(recipe.reservation_request)
                _record_activity(recipe, u'Reservation Request',
                        recipe.reservation_request.duration, None)
            return jsonify(RecipeReservationRequest.empty_json())
开发者ID:beaker-project,项目名称:beaker,代码行数:57,代码来源:recipes.py


示例13: destroy

    def destroy(self):

        for city in self.cities:
            city.destroy()

        groups = self.groups
        for group in list(groups):
            groups.remove(group)

        session.delete(self)
开发者ID:DaveInKentucky,项目名称:micropolis,代码行数:10,代码来源:model.py


示例14: delete

 def delete(self, **kw):
     item = ConfigItem.by_id(kw['item'])
     val = item.value_class.by_id(kw['id'])
     if val.valid_from <= datetime.utcnow():
         flash(_(u"Cannot remove past value of %s") % item.name)
         raise redirect("/configuration/edit?id=%d" % item.id)
     session.delete(val)
     session.flush()
     flash(_(u"Future value of %s cleared") % item.name)
     raise redirect(".")
开发者ID:beaker-project,项目名称:beaker,代码行数:10,代码来源:configuration.py


示例15: delete

 def delete(self, uuid):
     # TODO also search and clean batch queue?
     try:
         host = session.query(Host).filter_by(uuid=uuid).one()
     except:
         raise ValueError("Critical: UUID does not exist %s " % uuid)
     try:
         session.delete(host)
         session.flush()
     except:
         raise ValueError("Critical: Could not delete UUID - Please contact the smolt development team")
     raise ValueError('Success: UUID Removed')
开发者ID:MythTV,项目名称:smolt,代码行数:12,代码来源:client_impl.py


示例16: test_02_abort_dead_recipes

 def test_02_abort_dead_recipes(self):
     beakerd.process_new_recipes()
     beakerd.update_dirty_jobs()
     beakerd.queue_processed_recipesets()
     beakerd.update_dirty_jobs()
     with session.begin():
         self.assertEqual(Job.by_id(self.job2.id).status, TaskStatus.queued)
         # Remove distro_tree2 from lab1, should cause remaining recipe to abort.
         for lca in self.distro_tree2.lab_controller_assocs[:]:
             session.delete(lca)
     beakerd.abort_dead_recipes()
     beakerd.update_dirty_jobs()
     with session.begin():
         self.assertEqual(Job.by_id(self.job2.id).status, TaskStatus.aborted)
开发者ID:sujithshankar,项目名称:beaker,代码行数:14,代码来源:test_deadrecipes.py


示例17: delete_ssh_public_key

def delete_ssh_public_key(username, id):
    """
    Deletes a public SSH public key belonging to the given user account.

    :param username: The user's username.
    :param id: Database id of the SSH public key to be deleted.
    """
    user = _get_user(username)
    if not user.can_edit(identity.current.user):
        raise Forbidden403('Cannot edit user %s' % user)
    matching_keys = [k for k in user.sshpubkeys if k.id == id]
    if not matching_keys:
        raise NotFound404('SSH public key id %s does not belong to user %s' % (id, user))
    key = matching_keys[0]
    session.delete(key)
    return '', 204
开发者ID:beaker-project,项目名称:beaker,代码行数:16,代码来源:user.py


示例18: deleteBlogEntry

    def deleteBlogEntry(self, blogentry_id, **kwargs): 
        '''
            Deletes note and it's count.
            
            @param blogentry_id: needed to identify note
        '''
        
        entry = session.query(BlogEntry).get_by(blogentry_id=int(blogentry_id))
        entry.relatedQueries = []
        user=session.query(User).get_by(user_id = entry.user_id)

        if user.user_stats.no_of_blogs>1:
            user.user_stats.no_of_blogs-=1

        session.delete(entry);
        session.flush()
        return dict()
开发者ID:macagua,项目名称:SPREE,代码行数:17,代码来源:blog_controller.py


示例19: ssh_key_remove

    def ssh_key_remove(self, *args, **kw):
        user = identity.current.user
        keyid = kw.get('id', None)

        try:
            key = SSHPubKey.by_id(keyid)
        except InvalidRequestError:
            flash(_(u"SSH key not found"))
            redirect('.')

        if user != key.user:
            flash(_(u"May not remove another user's keys"))
            redirect('.')

        session.delete(key)
        flash(_(u"SSH public key removed"))
        redirect('.')
开发者ID:ShaolongHu,项目名称:beaker,代码行数:17,代码来源:preferences.py


示例20: remove

    def remove(self, **kw):
        group = Group.by_id(kw['group_id'])

        if not group.can_edit(identity.current.user):
            flash(_(u'You are not an owner of group %s' % group))
            redirect('../groups/mine')

        if group.jobs:
            flash(_(u'Cannot delete a group which has associated jobs'))
            redirect('../groups/mine')

        session.delete(group)
        activity = Activity(identity.current.user, u'WEBUI', u'Removed', u'Group', group.display_name, u"")
        session.add(activity)
        for system in group.systems:
            SystemActivity(identity.current.user, u'WEBUI', u'Removed', u'Group', group.display_name, u"", object=system)
        flash( _(u"%s deleted") % group.display_name )
        raise redirect(".")
开发者ID:sibiaoluo,项目名称:beaker,代码行数:18,代码来源:group.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python session.expire_all函数代码示例发布时间:2022-05-27
下一篇:
Python session.begin函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap