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


Python Product.select方法代码示例

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


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

示例1: test_delete

# 需要导入模块: from multiproduct.model import Product [as 别名]
# 或者: from multiproduct.model.Product import select [as 别名]
    def test_delete(self):
        """test that we are able to delete Products"""
        product = list(Product.select(self.env, where={'prefix':'tp'}))[0]
        product.delete()

        post = list(Product.select(self.env, where={'prefix':'tp'}))
        self.assertEqual(0, len(post))
开发者ID:mohsadki,项目名称:dargest,代码行数:9,代码来源:model.py

示例2: test_select

# 需要导入模块: from multiproduct.model import Product [as 别名]
# 或者: from multiproduct.model.Product import select [as 别名]
    def test_select(self):
        """tests that select can search Products by fields"""

        p2_data = {'prefix':'tp2',
                   'name':'test project 2',
                   'description':'a different test project'}
        p3_data = {'prefix':'tp3',
                   'name':'test project 3',
                   'description':'test project'}

        product2 = Product(self.env)
        product2._data.update(p2_data)
        product3 = Product(self.env)
        product3._data.update(p3_data)

        product2.insert()
        product3.insert()

        products = list(Product.select(self.env, where={'prefix':'tp'}))
        self.assertEqual(1, len(products))
        products = list(Product.select(self.env,
            where={'name':'test project'}))
        self.assertEqual(1, len(products))
        products = list(Product.select(self.env,
            where={'prefix':'tp3', 'name':'test project 3'}))
        self.assertEqual(1, len(products))
开发者ID:mohsadki,项目名称:dargest,代码行数:28,代码来源:model.py

示例3: _do_save

# 需要导入模块: from multiproduct.model import Product [as 别名]
# 或者: from multiproduct.model.Product import select [as 别名]
    def _do_save(self, req, product):
        """common processing for product save events"""
        req.perm.require('PRODUCT_VIEW')

        name = req.args.get('name')
        prefix = req.args.get('prefix')
        description = req.args.get('description', '')

        owner = req.args.get('owner') or req.authname
        keys = {'prefix': prefix}
        field_data = {'name': name,
                      'description': description,
                      'owner': owner,
                      }

        warnings = []
        def warn(msg):
            add_warning(req, msg)
            warnings.append(msg)

        if product._exists:
            if name != product.name and Product.select(self.env,
                                                       where={'name': name}):
                warn(_('A product with name "%(name)s" already exists, please '
                       'choose a different name.', name=name))
            elif not name:
                warn(_('You must provide a name for the product.'))
            else:
                req.perm.require('PRODUCT_MODIFY')
                product.update_field_dict(field_data)
                product.update(req.authname)
                add_notice(req, _('Your changes have been saved.'))
        else:
            req.perm.require('PRODUCT_CREATE')

            if not prefix:
                warn(_('You must provide a prefix for the product.'))
            elif Product.select(self.env, where={'prefix': prefix}):
                warn(_('Product "%(id)s" already exists, please choose another '
                       'prefix.', id=prefix))
            if not name:
                warn(_('You must provide a name for the product.'))
            elif Product.select(self.env, where={'name': name}):
                warn(_('A product with name "%(name)s" already exists, please '
                       'choose a different name.', name=name))

            if not warnings:
                prod = Product(self.env)
                prod.update_field_dict(keys)
                prod.update_field_dict(field_data)
                prod.insert()
                add_notice(req, _('The product "%(id)s" has been added.',
                                  id=prefix))

        if warnings:
            product.update_field_dict(keys)
            product.update_field_dict(field_data)
            return self._render_editor(req, product)
        req.redirect(req.href.products(prefix))
开发者ID:thimalk,项目名称:bloodhound,代码行数:61,代码来源:web_ui.py

示例4: test_update

# 需要导入模块: from multiproduct.model import Product [as 别名]
# 或者: from multiproduct.model.Product import select [as 别名]
    def test_update(self):
        """tests that we can use update to push data to the database"""
        product = list(Product.select(self.env, where={'prefix':'tp'}))[0]
        self.assertEqual('test project', product._data['name'])

        new_data = {'prefix':'tp',
                    'name':'updated',
                    'description':'nothing'}
        product._data.update(new_data)
        product.update()

        comp_product = list(Product.select(self.env, where={'prefix':'tp'}))[0]
        self.assertEqual('updated', comp_product._data['name'])
开发者ID:mohsadki,项目名称:dargest,代码行数:15,代码来源:model.py

示例5: lookup_env

# 需要导入模块: from multiproduct.model import Product [as 别名]
# 或者: from multiproduct.model.Product import select [as 别名]
    def lookup_env(cls, env, prefix=None, name=None):
        """Instantiate environment according to product prefix or name

        @throws LookupError if no product matches neither prefix nor name
        """
        if isinstance(env, ProductEnvironment):
            global_env = env.parent
        else:
            global_env = env

        # FIXME: Update if multiproduct.dbcursor.GLOBAL_PRODUCT != ''
        if not prefix and not name:
            return global_env
        elif isinstance(env, ProductEnvironment) and \
                env.product.prefix == prefix:
            return env
        if prefix:
            try:
                return ProductEnvironment(global_env, prefix)
            except LookupError:
                if not name:
                    raise
        if name:
            # Lookup product by name
            products = Product.select(global_env, where={'name' : name})
            if products:
                return ProductEnvironment(global_env, products[0])
            else:
                raise LookupError("Missing product '%s'" % (name,))
        else:
            raise LookupError("Mising product '%s'" % (prefix or name,))
开发者ID:mohsadki,项目名称:dargest,代码行数:33,代码来源:env.py

示例6: find_ticket

# 需要导入模块: from multiproduct.model import Product [as 别名]
# 或者: from multiproduct.model.Product import select [as 别名]
    def find_ticket(self, ticket_spec):
        ticket = None
        m = re.match(r'#?(?P<tid>\d+)', ticket_spec)
        if m:
            tid = m.group('tid')
            try:
                ticket = Ticket(self.env, tid)
            except ResourceNotFound:
                # ticket not found in current product, try all other products
                for p in Product.select(self.env):
                    if p.prefix != self.env.product.prefix:
                        # TODO: check for PRODUCT_VIEW permissions
                        penv = ProductEnvironment(self.env.parent, p.prefix)
                        try:
                            ticket = Ticket(penv, tid)
                        except ResourceNotFound:
                            pass
                        else:
                            break

        # ticket still not found, use fallback for <prefix>:ticket:<id> syntax
        if ticket is None:
            try:
                resource = ResourceIdSerializer.get_resource_by_id(ticket_spec)
                ticket = self._create_ticket_by_full_id(resource)
            except:
                raise NoSuchTicketError
        return ticket
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:30,代码来源:api.py

示例7: test_update_key_change

# 需要导入模块: from multiproduct.model import Product [as 别名]
# 或者: from multiproduct.model.Product import select [as 别名]
 def test_update_key_change(self):
     """tests that we raise an error for attempting to update key fields"""
     bad_data = {'prefix':'tp0',
                 'name':'update',
                 'description':'nothing'}
     product = list(Product.select(self.env, where={'prefix':'tp'}))[0]
     product._data.update(bad_data)
     self.assertRaises(TracError, product.update)
开发者ID:mohsadki,项目名称:dargest,代码行数:10,代码来源:model.py

示例8: test_field_set

# 需要导入模块: from multiproduct.model import Product [as 别名]
# 或者: from multiproduct.model.Product import select [as 别名]
    def test_field_set(self):
        """tests that we can use table.field = something to set field data"""
        prefix = self.default_data['prefix']
        product = list(Product.select(self.env, where={'prefix':prefix}))[0]

        new_description = 'test change of description'
        product.description = new_description
        self.assertEqual(new_description, product.description)
开发者ID:mohsadki,项目名称:dargest,代码行数:10,代码来源:model.py

示例9: _render_list

# 需要导入模块: from multiproduct.model import Product [as 别名]
# 或者: from multiproduct.model.Product import select [as 别名]
 def _render_list(self, req):
     """products list"""
     products = [p for p in Product.select(self.env)
                 if 'PRODUCT_VIEW' in req.perm(Neighborhood('product',
                                                            p.prefix))]
     data = {'products': products,
             'context': web_context(req, Resource('product', None))}
     return 'product_list.html', data, None
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:10,代码来源:web_ui.py

示例10: test_field_data_get

# 需要导入模块: from multiproduct.model import Product [as 别名]
# 或者: from multiproduct.model.Product import select [as 别名]
 def test_field_data_get(self):
     """tests that we can use table.field syntax to get to the field data"""
     prefix = self.default_data['prefix']
     name = self.default_data['name']
     description = self.default_data['description']
     product = list(Product.select(self.env, where={'prefix':prefix}))[0]
     self.assertEqual(prefix, product.prefix)
     self.assertEqual(name, product.name)
     self.assertEqual(description, product.description)
开发者ID:mohsadki,项目名称:dargest,代码行数:11,代码来源:model.py

示例11: _render_list

# 需要导入模块: from multiproduct.model import Product [as 别名]
# 或者: from multiproduct.model.Product import select [as 别名]
 def _render_list(self, req):
     """products list"""
     products = [p for p in Product.select(self.env)
                 if 'PRODUCT_VIEW' in req.perm(Neighborhood('product',
                                                            p.prefix))]
     map(lambda p: setattr(p, 'href', resolve_product_href(
         lookup_product_env(self.env, p.prefix), self.env)), products)
     data = {'products': products,
             'context': web_context(req, Resource('product', None))}
     return 'product_list.html', data, None
开发者ID:thimalk,项目名称:bloodhound,代码行数:12,代码来源:web_ui.py

示例12: test_migrating_to_multiproduct_with_custom_default_prefix

# 需要导入模块: from multiproduct.model import Product [as 别名]
# 或者: from multiproduct.model.Product import select [as 别名]
    def test_migrating_to_multiproduct_with_custom_default_prefix(self):
        ticket = self.insert_ticket('ticket')

        self.env.config.set('multiproduct', 'default_product_prefix', 'xxx')
        self._enable_multiproduct()
        self.env.upgrade()

        products = Product.select(self.env)
        self.assertEqual(len(products), 1)
        self.assertEqual(products[0].prefix, 'xxx')
开发者ID:thimalk,项目名称:bloodhound,代码行数:12,代码来源:upgrade.py

示例13: test_insert

# 需要导入模块: from multiproduct.model import Product [as 别名]
# 或者: from multiproduct.model.Product import select [as 别名]
    def test_insert(self):
        """test saving new Product"""
        data = {'prefix':'new', 'name':'new', 'description':'new'}
        product = Product(self.env)
        product._data.update(data)
        product.insert()

        check_products = list(Product.select(self.env, where={'prefix':'new'}))

        self.assertEqual(product._data['prefix'],
                         check_products[0]._data['prefix'])
        self.assertEqual(1, len(check_products))
开发者ID:mohsadki,项目名称:dargest,代码行数:14,代码来源:model.py

示例14: get_product_list

# 需要导入模块: from multiproduct.model import Product [as 别名]
# 或者: from multiproduct.model.Product import select [as 别名]
 def get_product_list(cls, env, req, href_fcn=None):
     """Returns a list of products as (prefix, name, url) tuples
     """
     if href_fcn is None:
         href_fcn = req.href.products
     product_list = []
     for product in Product.select(env):
         if 'PRODUCT_VIEW' in req.perm(Neighborhood('product',
                                                    product.prefix).
                                       child(product.resource)):
             product_list.append((product.prefix, product.name,
                                  href_fcn(product.prefix)))
     return product_list
开发者ID:thimalk,项目名称:bloodhound,代码行数:15,代码来源:web_ui.py

示例15: pre_process_request

# 需要导入模块: from multiproduct.model import Product [as 别名]
# 或者: from multiproduct.model.Product import select [as 别名]
 def pre_process_request(self, req, handler):
     """pre process request filter"""
     pid = None
     match = PRODUCT_RE.match(req.path_info)
     if match:
         dispatcher = self.env[RequestDispatcher]
         if dispatcher is None:
             raise TracError('Unable to load RequestDispatcher.')
         pid = match.group('pid')
     
     if pid:
         products = Product.select(self.env, where={'prefix': pid})
         if pid and len(products) == 1:
             req.args['productid'] = pid
             req.args['product'] = products[0].name
             if handler is self and match.group('pathinfo') not in ('', '/'):
                 # select a new handler
                 environ = req.environ.copy()
                 pathinfo = environ['PATH_INFO'].split('/')
                 pathinfo = '/'.join(pathinfo[:1] + pathinfo[3:])
                 environ['PATH_INFO'] = pathinfo
                 newreq = Request(environ, lambda *args, **kwds: None)
                 
                 new_handler = None
                 for hndlr in dispatcher.handlers:
                     if hndlr is not self and hndlr.match_request(newreq):
                         new_handler = hndlr
                         req.args.update(newreq.args)
                         break
                 if new_handler is None:
                     if req.path_info.endswith('/'):
                         target = req.path_info.rstrip('/').encode('utf-8')
                         if req.query_string:
                             target += '?' + req.query_string
                         req.redirect(req.href + target, permanent=True)
                     raise HTTPNotFound('No handler matched request to %s',
                                        req.path_info)
                 handler = new_handler
         else:
             raise ResourceNotFound(_("Product %(id)s does not exist.", 
                                      id=pid), _("Invalid product id"))
     
     return handler
开发者ID:domaemon,项目名称:bloodhound-qa,代码行数:45,代码来源:web_ui.py


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