本文整理匯總了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)