本文整理汇总了Python中hackathon.hmongo.models.Hackathon.save方法的典型用法代码示例。如果您正苦于以下问题:Python Hackathon.save方法的具体用法?Python Hackathon.save怎么用?Python Hackathon.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hackathon.hmongo.models.Hackathon
的用法示例。
在下文中一共展示了Hackathon.save方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __create_hackathon
# 需要导入模块: from hackathon.hmongo.models import Hackathon [as 别名]
# 或者: from hackathon.hmongo.models.Hackathon import save [as 别名]
def __create_hackathon(self, creator, context):
"""Insert hackathon and creator(admin of course) to database
We enforce that default config are used during the creation
:type context: Context
:param context: context of the args to create a new hackathon
:rtype: Hackathon
:return hackathon instance
"""
new_hack = Hackathon(
name=context.name,
display_name=context.display_name,
ribbon=context.get("ribbon"),
description=context.get("description"),
short_description=context.get("short_description"),
location=context.get("location"),
banners=context.get("banners", []),
status=HACK_STATUS.INIT,
creator=creator,
type=context.get("type", HACK_TYPE.HACKATHON),
config=context.get("config", Context()).to_dict(),
tags=context.get("tags", []),
event_start_time=context.get("event_start_time"),
event_end_time=context.get("event_end_time"),
registration_start_time=context.get("registration_start_time"),
registration_end_time=context.get("registration_end_time"),
judge_start_time=context.get("judge_start_time"),
judge_end_time=context.get("judge_end_time")
)
# basic xss prevention
if new_hack.description: # case None type
new_hack.description = self.cleaner.clean_html(new_hack.description)
# insert into table hackathon
new_hack.save()
# add the current login user as admin and creator
try:
admin = UserHackathon(user=creator,
hackathon=new_hack,
role=HACK_USER_TYPE.ADMIN,
status=HACK_USER_STATUS.AUTO_PASSED,
remark='creator')
admin.save()
except Exception as ex:
# TODO: send out a email to remind administrator to deal with this problems
self.log.error(ex)
raise InternalServerError("fail to create the default administrator")
return new_hack