本文整理汇总了Python中models.Corporation.by_name方法的典型用法代码示例。如果您正苦于以下问题:Python Corporation.by_name方法的具体用法?Python Corporation.by_name怎么用?Python Corporation.by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Corporation
的用法示例。
在下文中一共展示了Corporation.by_name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_corporation
# 需要导入模块: from models import Corporation [as 别名]
# 或者: from models.Corporation import by_name [as 别名]
def create_corporation(name, description="No description"):
if Corporation.by_name(name) is not None:
logging.info("Corporation with name '%s' already exists, skipping" % (name))
return Corporation.by_name(name)
logging.info("Create Corporation: %s" % name)
corp = Corporation(
name=unicode(name[:32]),
description=unicode(description[:1024]),
)
dbsession.add(corp)
dbsession.flush()
return corp
示例2: create_corporation
# 需要导入模块: from models import Corporation [as 别名]
# 或者: from models.Corporation import by_name [as 别名]
def create_corporation(self):
''' Add a new corporation to the database '''
form = Form(
corporation_name="Enter a corporation name",
description="Please enter a description",
)
if form.validate(self.request.arguments):
corp_name = self.get_argument('corporation_name')
if Corporation.by_name(corp_name) is not None:
self.render("admin/create/corporation.html",
errors=["Name already exists"]
)
else:
corporation = Corporation(
name=unicode(corp_name),
description=unicode(self.get_argument('description')),
)
dbsession.add(corporation)
dbsession.flush()
self.redirect('/admin/view/game_objects')
else:
self.render("admin/create/corporation.html", errors=form.errors)