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


Python System.can_edit方法代码示例

本文整理汇总了Python中bkr.server.model.System.can_edit方法的典型用法代码示例。如果您正苦于以下问题:Python System.can_edit方法的具体用法?Python System.can_edit怎么用?Python System.can_edit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bkr.server.model.System的用法示例。


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

示例1: _import_row

# 需要导入模块: from bkr.server.model import System [as 别名]
# 或者: from bkr.server.model.System import can_edit [as 别名]
 def _import_row(self, data, log):
     if data['csv_type'] in system_types and ('fqdn' in data or 'id' in data):
         if data.get('id', None):
             try:
                 system = System.query.filter(System.id == data['id']).one()
             except InvalidRequestError as e:
                 raise ValueError('Non-existent system id')
         else:
             try:
                 system = System.query.filter(System.fqdn == data['fqdn']).one()
             except InvalidRequestError:
                 # Create new system with some defaults
                 # Assume the system is broken until proven otherwise.
                 # Also assumes its a machine.  we have to pick something
                 system = System(fqdn=data['fqdn'],
                             owner=identity.current.user,
                             type=SystemType.machine,
                             status=SystemStatus.broken)
                 session.add(system)
                 # new systems are visible to everybody by default
                 system.custom_access_policy = SystemAccessPolicy()
                 system.custom_access_policy.add_rule(
                         SystemPermission.view, everybody=True)
         if not system.can_edit(identity.current.user):
             raise ValueError('You are not the owner of %s' % system.fqdn)
         # we change the FQDN only when a valid system id is supplied
         if not data.get('id', None):
             data.pop('fqdn')
         self.from_csv(system, data, log)
     elif data['csv_type'] == 'user_group' and 'user' in data:
         user = User.by_user_name(data['user'])
         if user is None:
             raise ValueError('%s is not a valid user' % data['user'])
         CSV_GroupUser.from_csv(user, data, log)
     else:
         raise ValueError('Invalid csv_type %s or missing required fields'
                 % data['csv_type'])
开发者ID:ShaolongHu,项目名称:beaker,代码行数:39,代码来源:CSV_import_export.py

示例2: action_import

# 需要导入模块: from bkr.server.model import System [as 别名]
# 或者: from bkr.server.model.System import can_edit [as 别名]
    def action_import(self, csv_file, *args, **kw):
        """
        TurboGears method to import data from csv
        """
        log = []
        try:
            # ... process CSV file contents here ...
            missing = object()
            reader = csv.DictReader(csv_file.file, restkey=missing, restval=missing)
            for data in reader:
                if missing in data:
                    log.append('Too many fields on line %s (expecting %s)'
                            % (reader.line_num, len(reader.fieldnames)))
                    continue
                if any(value is missing for value in data.itervalues()):
                    missing_fields = [field for field, value in data.iteritems()
                            if value is missing]
                    log.append('Missing fields on line %s: %s' % (reader.line_num,
                            ', '.join(missing_fields)))
                    continue
                if 'csv_type' in data:
                    if data['csv_type'] in system_types and ('fqdn' in data or 'id' in data):
                        if data.get('id', None):
                            try:
                                system = System.query.filter(System.id == data['id']).one()
                            except InvalidRequestError as e:
                                log.append('Error importing system on line %s: Non-existent system id' %
                                           reader.line_num)
                                continue
                        else:
                            try:
                                system = System.query.filter(System.fqdn == data['fqdn']).one()
                            except InvalidRequestError:
                                # Create new system with some defaults
                                # Assume the system is broken until proven otherwise.
                                # Also assumes its a machine.  we have to pick something
                                try:
                                    system = System(fqdn=data['fqdn'],
                                                owner=identity.current.user,
                                                type=SystemType.machine,
                                                status=SystemStatus.broken)
                                    session.add(system)
                                except ValueError as e:
                                    log.append('Error importing system on line %s: %s' %
                                               (reader.line_num, str(e)))
                                    continue
                                # new systems are visible to everybody by default
                                system.custom_access_policy = SystemAccessPolicy()
                                system.custom_access_policy.add_rule(
                                        SystemPermission.view, everybody=True)

                        if system.can_edit(identity.current.user):
                            # we change the FQDN only when a valid system id is supplied
                            if not data.get('id', None):
                                data.pop('fqdn')
                            try:
                                self.from_csv(system, data, log)
                            except ValueError as e:
                                log.append('Error importing system on line %s: %s' %
                                           (reader.line_num, str(e)))
                                if system.id:
                                    # System already existed but some or all of the
                                    #  import data was invalid.
                                    session.expire(system)
                                else:
                                    # System didn't exist before import but some
                                    # or all of the import data was invalid.
                                    session.expunge(system)
                                    del(system)
                            else:
                                session.add(system)
                                session.flush()
                        else:
                            log.append("You are not the owner of %s" % system.fqdn)
                    elif data['csv_type'] == 'user_group' and \
                      'user' in data:
                        user = User.by_user_name(data['user'])
                        if user:
                            CSV_GroupUser.from_csv(user, data, log)
                        else:
                            log.append('%s is not a valid user' % data['user'])
                    else:
                        log.append("Invalid csv_type %s or missing required fields" % data['csv_type'])
                else:
                    log.append("Missing csv_type from record")
        except csv.Error, e:
            session.rollback()
            log.append('Error parsing CSV file: %s' % e)
开发者ID:ustbgaofan,项目名称:beaker,代码行数:90,代码来源:CSV_import_export.py


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