本文整理汇总了Python中multiproduct.model.Product.update_field_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Product.update_field_dict方法的具体用法?Python Product.update_field_dict怎么用?Python Product.update_field_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiproduct.model.Product
的用法示例。
在下文中一共展示了Product.update_field_dict方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _do_save
# 需要导入模块: from multiproduct.model import Product [as 别名]
# 或者: from multiproduct.model.Product import update_field_dict [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))
示例2: test_creating_new_product_calls_environment_created
# 需要导入模块: from multiproduct.model import Product [as 别名]
# 或者: from multiproduct.model.Product import update_field_dict [as 别名]
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"')
示例3: _render_admin_panel
# 需要导入模块: from multiproduct.model import Product [as 别名]
# 或者: from multiproduct.model.Product import update_field_dict [as 别名]
def _render_admin_panel(self, req, cat, page, product):
req.perm.require('PRODUCT_VIEW')
name = req.args.get('name')
description = req.args.get('description','')
prefix = req.args.get('prefix') if product is None else product
owner = req.args.get('owner')
keys = {'prefix':prefix}
field_data = {'name':name,
'description':description,
'owner':owner,
}
data = {}
# Detail view?
if product:
prod = Product(self.env, keys)
if req.method == 'POST':
if req.args.get('save'):
req.perm.require('PRODUCT_MODIFY')
prod.update_field_dict(field_data)
prod.update(req.authname)
add_notice(req, _('Your changes have been saved.'))
req.redirect(req.href.admin(cat, page))
elif req.args.get('cancel'):
req.redirect(req.href.admin(cat, page))
Chrome(self.env).add_wiki_toolbars(req)
data = {'view': 'detail', 'product': prod}
else:
default = self.config.get('ticket', 'default_product')
if req.method == 'POST':
# Add Product
if req.args.get('add'):
req.perm.require('PRODUCT_CREATE')
if not (prefix and name and owner):
if not prefix:
add_warning(req, _("You must provide a prefix "
"for the product."))
if not name:
add_warning(req, _("You must provide a name "
"for the product."))
if not owner:
add_warning(req, _("You must provide an owner "
"for the product."))
data['prefix'] = prefix
data['name'] = name
data['owner'] = owner
else:
try:
prod = Product(self.env, keys)
except ResourceNotFound:
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))
req.redirect(req.href.admin(cat, page))
else:
if prod.prefix is None:
raise TracError(_('Invalid product id.'))
raise TracError(_("Product %(id)s already exists.",
id=prefix))
# Remove product
elif req.args.get('remove'):
raise TracError(_('Product removal is not allowed!'))
# Set default product
elif req.args.get('apply'):
prefix = req.args.get('default')
if prefix and prefix != default:
self.log.info("Setting default product to %s",
prefix)
self.config.set('ticket', 'default_product',
prefix)
_save_config(self.config, req, self.log)
req.redirect(req.href.admin(cat, page))
# Clear default product
elif req.args.get('clear'):
self.log.info("Clearing default product")
self.config.set('ticket', 'default_product', '')
_save_config(self.config, req, self.log)
req.redirect(req.href.admin(cat, page))
data['view'] = 'list'
data['products'] = Product.select(self.env)
data['default'] = default
if self.config.getbool('ticket', 'restrict_owner'):
perm = PermissionSystem(self.env)
def valid_owner(username):
return perm.get_user_permissions(username).get('TICKET_MODIFY')
data['owners'] = [username for username, name, email
in self.env.get_known_users()
if valid_owner(username)]
data['owners'].insert(0, '')
data['owners'].sort()
else:
#.........这里部分代码省略.........