本文整理汇总了Python中models.Group.create方法的典型用法代码示例。如果您正苦于以下问题:Python Group.create方法的具体用法?Python Group.create怎么用?Python Group.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Group
的用法示例。
在下文中一共展示了Group.create方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: populate_with_defaults
# 需要导入模块: from models import Group [as 别名]
# 或者: from models.Group import create [as 别名]
def populate_with_defaults():
'''Create user admin and grant him all permission
If the admin user already exists the function will simply return
'''
logging.getLogger(__name__).debug("Populating with default users")
if not User.select().where(User.name == 'admin').exists():
admin = User.create(name='admin', password='admin')
admins = Group.create(name='admins')
starCap = Capability.create(domain='.+',
action=(Action.CREATE |
Action.READ |
Action.UPDATE |
Action.DELETE))
admins.capabilities.add(starCap)
admin.groups.add(admins)
admin.save()
if not User.select().where(User.name == 'anonymous').exists():
anon = User.create(name='anonymous', password='')
anons = Group.create(name='anonymous')
readCap = Capability.create(domain=Capability.simToReg('/volumes/*'),
action=Action.READ)
anons.capabilities.add(readCap)
anon.groups.add(anons)
anon.save()
示例2: init
# 需要导入模块: from models import Group [as 别名]
# 或者: from models.Group import create [as 别名]
def init():
''' Initialize the database '''
print('Initializing')
barrel.db.init(app)
Role.create(name='admin')
Role.create(name='mod')
Role.create(name='user')
Group.create(
abbr=u'ACME',
name=u'Administration, Control and Management Environment')
add_user('admin', 'nidma', 'admin', group=Group.get_admin_group())
return 'Database initialized successfully'
示例3: get_group
# 需要导入模块: from models import Group [as 别名]
# 或者: from models.Group import create [as 别名]
def get_group(self, title):
db.connect()
try:
g = Group.get(Group.title == title)
except Group.DoesNotExist:
g = Group.create(title = title)
db.close()
return g
示例4: get
# 需要导入模块: from models import Group [as 别名]
# 或者: from models.Group import create [as 别名]
def get(self):
# Check if the list name is provided
user_key = self.request.get('user_key')
name = self.request.get('name')
try:
# Add the new list to the database
new_content = Group.create(user_key, name)
# Respond with the list key
self.response.set_status(201)
self.response.write(new_content)
except Exception as e:
# Respond with the error
self.response.set_status(406)
self.response.write(str(e))
示例5: register
# 需要导入模块: from models import Group [as 别名]
# 或者: from models.Group import create [as 别名]
def register():
group_name = request.form['group'].strip()
player_name = request.form['player'].strip()
try:
# Perform case-insensitive search.
group = Group.get(fn.Lower(Group.name) == group_name.lower())
except:
group = Group.create(name=group_name)
try:
# Perform case-insensitive search.
player = Player.get(fn.lower(Player.name) == player_name.lower(), group=group)
except Player.DoesNotExist:
player = Player.create(
group=group, name=player_name, order=group.players.count())
return str(player.id)
示例6: get_group
# 需要导入模块: from models import Group [as 别名]
# 或者: from models.Group import create [as 别名]
def get_group(self, title):
try:
g = Group.get(Group.title == title)
except Group.DoesNotExist:
g = Group.create(title = title)
return g