本文整理汇总了Python中multiproduct.model.Product类的典型用法代码示例。如果您正苦于以下问题:Python Product类的具体用法?Python Product怎么用?Python Product使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Product类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_delete
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))
示例2: test_get_tickets
def test_get_tickets(self):
for pdata in (
{'prefix': 'p2', 'name':'product, too', 'description': ''},
{'prefix': 'p3', 'name':'strike three', 'description': ''},
):
num_tickets = 5
product = Product(self.global_env)
product._data.update(pdata)
product.insert()
self.env = ProductEnvironment(self.global_env, product)
for i in range(num_tickets):
ticket = Ticket(self.env)
ticket['summary'] = 'hello ticket #%s-%d' % (product.prefix, i)
ticket['reporter'] = 'admin'
tid = ticket.insert()
# retrieve tickets using both global and product scope
tickets_from_global = [(t['product'], t['id']) for t in
Product.get_tickets(self.global_env, product.prefix)]
self.assertEqual(len(tickets_from_global), num_tickets)
tickets_from_product = [(t['product'], t['id']) for t in
Product.get_tickets(self.env)]
self.assertEqual(len(tickets_from_product), num_tickets)
# both lists should contain same elements
intersection = set(tickets_from_global) & set(tickets_from_product)
self.assertEqual(len(intersection), num_tickets)
示例3: _do_product_add
def _do_product_add(self, prefix, owner, name):
product = Product(self.env)
product._data.update({'prefix':prefix, 'name':name, 'owner':owner})
try:
product.insert()
except TracError, exc:
raise AdminCommandError(to_unicode(exc))
示例4: _do_save
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))
示例5: _load_product_from_data
def _load_product_from_data(cls, env, prefix):
r"""Ensure test product with prefix is loaded
"""
# TODO: Use fixtures implemented in #314
product_data = cls.PRODUCT_DATA[prefix]
prefix = to_unicode(prefix)
product = Product(env)
product._data.update(product_data)
product.insert()
示例6: test_creating_new_product_calls_environment_created
def test_creating_new_product_calls_environment_created(self):
self._enable_component(DummyPlugin)
self._enable_multiproduct()
self.env.upgrade()
prod = Product(self.env)
prod.update_field_dict(dict(prefix='p1'))
ProductEnvironment(self.env, prod, create=True)
with self.env.db_direct_transaction as db:
db('SELECT * FROM "p1_dummy_table"')
示例7: test_select
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))
示例8: test_insert
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))
示例9: test_update
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'])
示例10: find_ticket
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
示例11: test_set_table_field
def test_set_table_field(self):
"""tests that table.field style update works"""
test = {'prefix': 'td',
'name': 'test field access',
'description': 'product to test field setting'}
product = Product(self.env)
# attempt to set the fields from the data
product.prefix = test['prefix']
product.name = test['name']
product.description = test['description']
self.assertEqual(product._data['prefix'], test['prefix'])
self.assertEqual(product._data['name'], test['name'])
self.assertEqual(product._data['description'], test['description'])
示例12: lookup_env
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,))
示例13: test_update_key_change
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)
示例14: test_field_set
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)
示例15: _render_list
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