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


Python Pool.check方法代码示例

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


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

示例1: raise_user_warning

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import check [as 别名]
    def raise_user_warning(cls, warning_name, warning,
            warning_args=None, warning_description='',
            warning_description_args=None):
        '''
        Raise an exception that will be displayed as a warning message
        in the client, if the user has not yet bypassed it.

        :param warning_name: the unique warning name
        :param warning: the key of the dictionary _error_messages used
            for warning message
        :param warning_args: the arguments that will be used for
            "%"-based substitution
        :param warning_description: the key of the dictionary
            _error_messages used for warning description
        :param warning_description_args: the arguments that will be used
            for "%"-based substitution
        '''
        Warning_ = Pool().get('res.user.warning')
        if Warning_.check(warning_name):
            if warning_description:
                warning, warning_description = cls.raise_user_error(warning,
                        error_args=warning_args,
                        error_description=warning_description,
                        error_description_args=warning_description_args,
                        raise_exception=False)
                raise UserWarning(warning_name, warning, warning_description)
            else:
                warning = cls.raise_user_error(warning,
                        error_args=warning_args, raise_exception=False)
                raise UserWarning(warning_name, warning)
开发者ID:coopengo,项目名称:trytond,代码行数:32,代码来源:error.py

示例2: delete

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import check [as 别名]
    def delete(self, ids):
        '''
        Delete records.

        :param ids: a list of ids or an id
        :return: True if succeed
        '''
        model_access_obj = Pool().get('ir.model.access')

        model_access_obj.check(self._name, 'delete')
        if not self.check_xml_record(ids, None):
            self.raise_user_error('delete_xml_record',
                    error_description='xml_record_desc')

        # Clean cursor cache
        for cache in Transaction().cursor.cache.values():
            for cache in (cache, cache.get('_language_cache', {}).values()):
                if self._name in cache:
                    if isinstance(ids, (int, long)):
                        ids = [ids]
                    for i in ids:
                        if i in cache[self._name]:
                            del cache[self._name][i]
        return False
开发者ID:mediafactory,项目名称:tryton_core_daemon,代码行数:26,代码来源:modelstorage.py

示例3: WfsRequest

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import check [as 别名]
class WfsRequest(object):
    def __init__(self):
        self.tmpl_loader = TemplateLoader(
            os.path.join(os.path.dirname(__file__), 'templates'),
            auto_reload=True,
            default_class=MarkupTemplate,
        )
        WfsConf = Pool().get('wfs.conf')
        conf = WfsConf.search([])

        if len(conf) == 0:
            self.show_non_geo = False
            self.default_geo = False
        else:
            self.show_non_geo = conf[0].show_non_geo
            self.default_geo = conf[0].default_geo

        self.url = WfsConf.get_url()
        self.model_access = Pool().get('ir.model.access')
        self.field_access = Pool().get('ir.model.field.access')

    def access_check(self, model, field=None, mode='read', raise_exception=True):
        allowed = True
        try:
            allowed &= self.model_access.check(model, mode, raise_exception=False)
            if field is not None:
                allowed &= self.field_access.check(model, [field], mode, raise_exception=False)
        except:
            allowed = False

        if not allowed and raise_exception:
            raise Exception('Permission denied')
        return allowed

    def _parse_args(self, **kw):
        _kw = {}
        for arg, val in kw.iteritems():
            if isinstance(val, str):
                _kw[arg.lower()] = unquote(val)

        if 'acceptversions' in _kw:
            version = _kw.pop('acceptversions')
            if WFS_VERSION not in version.split(','):
                raise Exception('Unsupported version, server version %s, client version %s' % (WFS_VERSION, version))

        if 'version' in _kw:
            self.version = _kw.pop('version')
            if self.version.split('.') > WFS_VERSION.split('.'):
                logger.warning('Wfs version of client is superior than our version (1.0.0)')
        else:
            self.version = ''

        service = _kw.pop('service', 'wfs').lower()
        if service != 'wfs':
            raise Exception('Invalid service %s, expected WFS' % service)

        if 'srsname' in _kw:
            _kw['srsname'] = int(_kw['srsname'].split(':')[1])
        return _kw

    def handle(self, **kw):
        _kw = self._parse_args(**kw)
        request = _kw.pop('request').lower()

        if request in WFS_REQUESTS and hasattr(self, request):
            return getattr(self, request)(**_kw)
        return self.getcapabilities()

    def getcapabilities(self, bbox=[], srsname=0, **kw):
        Field = Pool().get('ir.model.field')
        features = []
        models = []
        if bbox != []:
            bbox = [float(nbr) for nbr in bbox.split(',')]

        domain = ['OR'] + [[('ttype', '=', geo_type)] for geo_type in GEO_TYPES]
        fields = Field.search(domain)
        for field in fields:
            model = field.model.model
            if not self.access_check(model, raise_exception=False):
                continue
            Model = Pool().get(model)
            records = Model.search([], limit=1)

            # Check the table contains records in the bbox
            models.append(model)
            cursor = Transaction().cursor
            table = model.replace('.', '_')
            if Model.table_query() : table = '('+Model.table_query()[0]%tuple(Model.table_query()[1])+') AS mytable'
            col = field.name
            if bbox != [] and srsname != 0:
                sql = 'SELECT ST_Extent(Box2D(%(col)s)) FROM %(table)s WHERE\
                    ST_Intersects(\
                        ST_SetSRID(\
                            ST_MakeBox2D(\
                                ST_MakePoint(%(xmin)s, %(ymin)s),\
                                ST_MakePoint(%(xmax)s, %(ymax)s)\
                            ), %(srsname)s\
                        ), %(col)s )' % {
                        'col': col,
#.........这里部分代码省略.........
开发者ID:silpol,项目名称:tryton-bef,代码行数:103,代码来源:wfs.py


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