本文整理汇总了Python中multiproduct.model.Product.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Product.delete方法的具体用法?Python Product.delete怎么用?Python Product.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiproduct.model.Product
的用法示例。
在下文中一共展示了Product.delete方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ProductTestCase
# 需要导入模块: from multiproduct.model import Product [as 别名]
# 或者: from multiproduct.model.Product import delete [as 别名]
#.........这里部分代码省略.........
self.assertEqual('updated', comp_product._data['name'])
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)
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))
def test_insert_duplicate_key(self):
"""test attempted saving of Product with existing key fails"""
dupe_key_data = {'prefix':'tp',
'name':'dupe',
'description':'dupe primary key'}
product2 = Product(self.env)
product2._data.update(dupe_key_data)
self.assertRaises(TracError, product2.insert)
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))
def test_delete_twice(self):
"""test that we error when deleting twice on the same key"""
product = list(Product.select(self.env, where={'prefix':'tp'}))[0]
product.delete()
self.assertRaises(TracError, product.delete)
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)
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)
示例2: process_request
# 需要导入模块: from multiproduct.model import Product [as 别名]
# 或者: from multiproduct.model.Product import delete [as 别名]
def process_request(self, req):
"""process request handler"""
req.perm.require('PRODUCT_VIEW')
pid = req.args.get('productid', None)
if pid:
req.perm('product', pid).require('PRODUCT_VIEW')
action = req.args.get('action', 'view')
products = [p for p in Product.select(self.env)
if 'PRODUCT_VIEW' in req.perm(p.resource)]
if pid is not None:
add_link(req, 'up', req.href.products(), _('Products'))
try:
product = Product(self.env, {'prefix': pid})
except ResourceNotFound:
product = Product(self.env)
data = {'product': product,
'context': web_context(req, product.resource)}
if req.method == 'POST':
if req.args.has_key('cancel'):
req.redirect(req.href.products(product.prefix))
elif action == 'edit':
return self._do_save(req, product)
elif action == 'delete':
req.perm(product.resource).require('PRODUCT_DELETE')
retarget_to = req.args.get('retarget', None)
name = product.name
product.delete(resources_to=retarget_to)
add_notice(req, _('The product "%(n)s" has been deleted.',
n = name))
req.redirect(req.href.products())
elif action in ('new', 'edit'):
return self._render_editor(req, product)
elif action == 'delete':
req.perm(product.resource).require('PRODUCT_DELETE')
return 'product_delete.html', data, None
if pid is None:
data = {'products': products,
'context': web_context(req, Resource('products', None))}
return 'product_list.html', data, None
def add_product_link(rel, product):
href = req.href.products(product.prefix)
add_link(req, rel, href, _('Product "%(name)s"',
name=product.name))
idx = [i for i, p in enumerate(products) if p.name == product.name]
if idx:
idx = idx[0]
if idx > 0:
add_product_link('first', products[0])
add_product_link('prev', products[idx - 1])
if idx < len(products) - 1:
add_product_link('next', products[idx + 1])
add_product_link('last', products[-1])
prevnext_nav(req, _('Previous Product'), _('Next Product'),
_('Back to Product List'))
return 'product_view.html', data, None