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


Python Pool.object_name_list方法代码示例

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


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

示例1: get

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import object_name_list [as 别名]
    def get(self, ids, model, name, values=None):
        """
        Replace removed reference id by False.

        :param ids: a list of ids
        :param model: a string with the name of the model
        :param name: a string with the name of the field
        :param values: a dictionary with the read values
        :return: a dictionary with ids as key and values as value
        """
        pool = Pool()
        if values is None:
            values = {}
        res = {}
        for i in values:
            res[i["id"]] = i[name]
        ref_to_check = {}
        for i in ids:
            if not (i in res):
                res[i] = None
                continue
            if not res[i]:
                continue
            ref_model, ref_id = res[i].split(",", 1)
            if not ref_model:
                continue
            try:
                ref_id = int(ref_id)
            except Exception:
                continue
            if ref_id < 0:
                continue
            res[i] = ref_model + "," + str(ref_id)
            ref_to_check.setdefault(ref_model, (set(), []))
            ref_to_check[ref_model][0].add(ref_id)
            ref_to_check[ref_model][1].append(i)

        # Check if reference ids still exist
        with contextlib.nested(Transaction().set_context(active_test=False), Transaction().set_user(0)):
            for ref_model, (ref_ids, ids) in ref_to_check.iteritems():
                if ref_model not in pool.object_name_list():
                    res.update(dict((i, False) for i in ids))
                    continue
                ref_obj = pool.get(ref_model)
                ref_ids = ref_obj.search([("id", "in", list(ref_ids))], order=[])
                refs = [ref_model + "," + str(ref_id) for ref_id in ref_ids]
                for i in ids:
                    if res[i] not in refs:
                        res[i] = False
        return res
开发者ID:mediafactory,项目名称:tryton_core_daemon,代码行数:52,代码来源:reference.py

示例2: _inherits_reload

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import object_name_list [as 别名]
 def _inherits_reload(self):
     """
     Reconstruct _inherit_fields
     """
     res = {}
     pool = Pool()
     for model in self._inherits:
         res.update(pool.get(model)._inherit_fields)
         for field_name in pool.get(model)._columns.keys():
             res[field_name] = (model, self._inherits[model],
                     pool.get(model)._columns[field_name])
         for field_name in pool.get(model)._inherit_fields.keys():
             res[field_name] = (model, self._inherits[model],
                     pool.get(model)._inherit_fields[field_name][2])
     self._inherit_fields = res
     self._reset_columns()
     self._update_rpc()
     # Update objects that uses this one to update their _inherits fields
     for obj_name in pool.object_name_list():
         obj = pool.get(obj_name)
         if self._name in obj._inherits:
             obj._inherits_reload()
开发者ID:mediafactory,项目名称:tryton_core_daemon,代码行数:24,代码来源:model.py

示例3: run

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import object_name_list [as 别名]

#.........这里部分代码省略.........
        for db_name in CONFIG["db_name"]:
            init[db_name] = False
            database = Database(db_name).connect()
            cursor = database.cursor()

            try:
                if CONFIG['init']:
                    if not cursor.test():
                        self.logger.info("init db")
                        Database.init(cursor)
                        init[db_name] = True
                    cursor.commit()
                elif not cursor.test():
                    raise Exception("'%s' is not a Tryton database!" % db_name)
            finally:
                cursor.close()

        for db_name in CONFIG["db_name"]:
            if update:
                cursor = Database(db_name).connect().cursor()
                try:
                    if not cursor.test():
                        raise Exception("'%s' is not a Tryton database!"
                            % db_name)
                    cursor.execute('SELECT code FROM ir_lang ' \
                            'WHERE translatable')
                    lang = [x[0] for x in cursor.fetchall()]
                finally:
                    cursor.close()
            else:
                lang = None
            Pool(db_name).init(update=update, lang=lang)

        for kind in ('init', 'update'):
            CONFIG[kind] = {}

        for db_name in CONFIG['db_name']:
            if init[db_name]:
                while True:
                    password = getpass('Admin Password for %s: ' % db_name)
                    password2 = getpass('Admin Password Confirmation: ')
                    if password != password2:
                        sys.stderr.write('Admin Password Confirmation ' \
                                'doesn\'t match Admin Password!\n')
                        continue
                    if not password:
                        sys.stderr.write('Admin Password is required!\n')
                        continue
                    break

                database = Database(db_name).connect()
                cursor = database.cursor()
                try:
                    salt = ''.join(random.sample(
                        string.letters + string.digits, 8))
                    password += salt
                    if hashlib:
                        password = hashlib.sha1(password).hexdigest()
                    else:
                        password = sha.new(password).hexdigest()
                    cursor.execute('UPDATE res_user ' \
                            'SET password = %s, salt = %s ' \
                            'WHERE login = \'admin\'', (password, salt))
                    cursor.commit()
                finally:
                    cursor.close()

        if update:
            self.logger.info('Update/Init succeed!')
            logging.shutdown()
            sys.exit(0)

        threads = {}
        while True:
            if CONFIG['cron']:
                for dbname in Pool.database_list():
                    thread = threads.get(dbname)
                    if thread and thread.is_alive():
                        continue
                    pool = Pool(dbname)
                    if not pool.lock.acquire(0):
                        continue
                    try:
                        if 'ir.cron' not in pool.object_name_list():
                            continue
                        cron_obj = pool.get('ir.cron')
                    finally:
                        pool.lock.release()
                    thread = threading.Thread(
                            target=cron_obj.run,
                            args=(dbname,), kwargs={})
                    thread.start()
                    threads[dbname] = thread
            if CONFIG['auto_reload']:
                for _ in range(60):
                    if monitor():
                        self.restart()
                    time.sleep(1)
            else:
                time.sleep(60)
开发者ID:mediafactory,项目名称:tryton_core_daemon,代码行数:104,代码来源:server.py

示例4: _validate

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import object_name_list [as 别名]
    def _validate(self, ids):
        pool = Pool()
        if (Transaction().user == 0
                and Transaction().context.get('user')):
            with Transaction().set_user(Transaction().context.get('user')):
                return self._validate(ids)

        for field in self._constraints:
            if not getattr(self, field[0])(ids):
                self.raise_user_error(field[1])

        if not 'res.user' in pool.object_name_list() \
                or Transaction().user == 0:
            ctx_pref = {
            }
        else:
            user_obj = pool.get('res.user')
            ctx_pref = user_obj.get_preferences(context_only=True)

        def is_pyson(test):
            if isinstance(test, PYSON):
                return True
            if isinstance(test, (list, tuple)):
                for i in test:
                    if isinstance(i, PYSON):
                        return True
                    if isinstance(i, (list, tuple)):
                        if is_pyson(i):
                            return True
            return False

        with Transaction().set_context(ctx_pref):
            records = self.browse(ids)
            for field_name, field in self._columns.iteritems():
                if isinstance(field, fields.Function) and \
                        not field.setter:
                    continue
                # validate domain
                if (field._type in
                        ('many2one', 'many2many', 'one2many', 'one2one')
                    and field.domain):
                    if field._type in ('many2one', 'one2many'):
                        relation_obj = pool.get(field.model_name)
                    else:
                        relation_obj = field.get_target()
                    if is_pyson(field.domain):
                        pyson_domain = PYSONEncoder().encode(field.domain)
                        for record in records:
                            env = EvalEnvironment(record, self)
                            env.update(Transaction().context)
                            env['current_date'] = datetime.datetime.today()
                            env['time'] = time
                            env['context'] = Transaction().context
                            env['active_id'] = record.id
                            domain = PYSONDecoder(env).decode(pyson_domain)
                            relation_ids = []
                            if record[field_name]:
                                if field._type in ('many2one',):
                                    relation_ids.append(record[field_name].id)
                                else:
                                    relation_ids.extend(
                                            [x.id for x in record[field_name]])
                            if relation_ids and not relation_obj.search([
                                        'AND',
                                        [('id', 'in', relation_ids)],
                                        domain,
                                        ]):
                                self.raise_user_error(
                                        'domain_validation_record',
                                        error_args=self._get_error_args(
                                            field_name))
                    else:
                        relation_ids = []
                        for record in records:
                            if record[field_name]:
                                if field._type in ('many2one',):
                                    relation_ids.append(record[field_name].id)
                                else:
                                    relation_ids.extend(
                                            [x.id for x in record[field_name]])
                        if relation_ids:
                            find_ids = relation_obj.search([
                                'AND',
                                [('id', 'in', relation_ids)],
                                field.domain,
                                ])
                            if not set(relation_ids) == set(find_ids):
                                self.raise_user_error(
                                        'domain_validation_record',
                                        error_args=self._get_error_args(
                                            field_name))
                # validate states required
                if field.states and 'required' in field.states:
                    if is_pyson(field.states['required']):
                        pyson_required = PYSONEncoder().encode(
                                field.states['required'])
                        for record in records:
                            env = EvalEnvironment(record, self)
                            env.update(Transaction().context)
                            env['current_date'] = datetime.datetime.today()
#.........这里部分代码省略.........
开发者ID:mediafactory,项目名称:tryton_core_daemon,代码行数:103,代码来源:modelstorage.py

示例5: BrowseRecord

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import object_name_list [as 别名]

#.........这里部分代码省略.........
        # add datetime_field
        for field in ffields.values():
            if hasattr(field, 'datetime_field') and field.datetime_field:
                if field.datetime_field in self._model._columns:
                    datetime_field = self._model._columns[field.datetime_field]
                else:
                    datetime_field = self._model._inherit_fields[
                            field.datetime_field][2]
                ffields[field.datetime_field] = datetime_field

        def filter_(id_):
            if (id_ in self._local_data
                    and name in self._local_data[id_]):
                return False
            if id_ in self._data and name in self._data[id_]:
                return False
            return True
        index = self._ids.index(self.id)
        ids = chain(islice(self._ids, index, None),
            islice(self._ids, 0, max(index - 1, 0)))
        ids = list(islice(ifilter(filter_, ids), self._cursor.IN_MAX))
        model2ids = {}
        model2cache = {}
        # read the data
        with contextlib.nested(Transaction().set_cursor(self._cursor),
                Transaction().set_user(self._user),
                Transaction().set_context(self._context)):
            # create browse records for 'remote' models
            for data in self._model.read(ids, ffields.keys()):
                for i, j in ffields.iteritems():
                    model = None
                    if (hasattr(j, 'model_name') and
                            j.model_name in
                            self._pool.object_name_list()):
                        model = self._pool.get(j.model_name)
                    elif hasattr(j, 'get_target'):
                        model = j.get_target()
                    if model and j._type in ('many2one', 'one2one'):
                        if (not data[i]
                                and not (isinstance(data[i], (int, long))
                                    and not isinstance(data[i],
                                        type(False)))):
                            data[i] = BrowseRecordNull()
                        else:
                            _datetime = None
                            if (hasattr(j, 'datetime_field')
                                    and j.datetime_field):
                                _datetime = data[j.datetime_field]
                            with Transaction().set_context(
                                    _datetime=_datetime):
                                ids = model2ids.setdefault(model, [])
                                ids.append(data[i])
                                local_cache = model2cache.setdefault(model,
                                    LRUDict(RECORD_CACHE_SIZE))
                                data[i] = BrowseRecord(data[i], model,
                                    ids, local_cache)
                    elif (model and j._type in ('one2many', 'many2many')):
                        _datetime = None
                        if hasattr(j, 'datetime_field') and j.datetime_field:
                            _datetime = data[j.datetime_field]
                        with Transaction().set_context(
                                _datetime=_datetime):
                            ids = model2ids.setdefault(model, [])
                            ids.extend(data[i])
                            local_cache = model2cache.setdefault(model,
                                LRUDict(RECORD_CACHE_SIZE))
开发者ID:mediafactory,项目名称:tryton_core_daemon,代码行数:70,代码来源:browse.py

示例6: Pool

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import object_name_list [as 别名]
            self.logger.info('Update/Init succeed!')
            logging.shutdown()
            sys.exit(0)

        threads = {}
        while True:
            if CONFIG['cron']:
                for dbname in Pool.database_list():
                    thread = threads.get(dbname)
                    if thread and thread.is_alive():
                        continue
                    pool = Pool(dbname)
                    if not pool.lock.acquire(0):
                        continue
                    try:
                        if 'ir.cron' not in pool.object_name_list():
                            continue
                        Cron = pool.get('ir.cron')
                    finally:
                        pool.lock.release()
                    thread = threading.Thread(
                            target=Cron.run,
                            args=(dbname,), kwargs={})
                    thread.start()
                    threads[dbname] = thread
            if CONFIG['auto_reload']:
                for _ in range(60):
                    if monitor():
                        self.restart()
                    time.sleep(1)
            else:
开发者ID:Sisouvan,项目名称:ogh,代码行数:33,代码来源:server.py


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