本文整理汇总了Python中hackathon.hmongo.models.UserHackathon.save方法的典型用法代码示例。如果您正苦于以下问题:Python UserHackathon.save方法的具体用法?Python UserHackathon.save怎么用?Python UserHackathon.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hackathon.hmongo.models.UserHackathon
的用法示例。
在下文中一共展示了UserHackathon.save方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __create_hackathon
# 需要导入模块: from hackathon.hmongo.models import UserHackathon [as 别名]
# 或者: from hackathon.hmongo.models.UserHackathon 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
示例2: like_hackathon
# 需要导入模块: from hackathon.hmongo.models import UserHackathon [as 别名]
# 或者: from hackathon.hmongo.models.UserHackathon import save [as 别名]
def like_hackathon(self, user, hackathon):
user_hackathon = UserHackathon.objects(hackathon=hackathon, user=user).first()
if not user_hackathon:
user_hackathon = UserHackathon(hackathon=hackathon,
user=user,
role=HACK_USER_TYPE.VISITOR,
status=HACK_USER_STATUS.UNAUDIT,
like=True,
remark="")
user_hackathon.save()
if not user_hackathon.like:
user_hackathon.like = True
user_hackathon.save()
# increase the count of users that like this hackathon
self.increase_hackathon_stat(hackathon, HACKATHON_STAT.LIKE, 1)
return ok()
示例3: add_admin
# 需要导入模块: from hackathon.hmongo.models import UserHackathon [as 别名]
# 或者: from hackathon.hmongo.models.UserHackathon import save [as 别名]
def add_admin(self, args):
"""Add a new administrator on a hackathon
:type args: dict
:param args: http request body in json format
:return hackathon response 'ok' if successfully added.
'not_found' if email is invalid or user not found.
'internal_server_error' if any other unexpected exception caught
"""
user = self.user_manager.get_user_by_id(args.get("id"))
if user is None:
return not_found("user not found")
if self.register_manager.is_user_registered(user.id, g.hackathon):
return precondition_failed("Cannot add a registered user as admin",
friendly_message="该用户已报名参赛,不能再被选为裁判或管理员。请先取消其报名")
try:
user_hackathon = UserHackathon.objects(user=user.id, hackathon=g.hackathon.id).first()
if user_hackathon is None:
uhl = UserHackathon(
user=user,
hackathon=g.hackathon,
role=args.get("role"),
status=HACK_USER_STATUS.AUTO_PASSED,
remark=args.get("remark")
)
uhl.save()
else:
user_hackathon.role = args.get("role")
user_hackathon.remark = args.get("remark")
user_hackathon.save()
return ok()
except Exception as e:
self.log.error(e)
return internal_server_error("create admin failed")