本文整理汇总了Python中hackathon.hmongo.models.HackathonNotice.save方法的典型用法代码示例。如果您正苦于以下问题:Python HackathonNotice.save方法的具体用法?Python HackathonNotice.save怎么用?Python HackathonNotice.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hackathon.hmongo.models.HackathonNotice
的用法示例。
在下文中一共展示了HackathonNotice.save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_hackathon_notice
# 需要导入模块: from hackathon.hmongo.models import HackathonNotice [as 别名]
# 或者: from hackathon.hmongo.models.HackathonNotice import save [as 别名]
def create_hackathon_notice(self, hackathon_id, notice_event, notice_category, body={}):
"""
create hackathon notice with hackathon_id, notice_event, notice_category.
notice 'content' and 'link' can be included in body (optional)
:type hackathon_id: int
:param hackathon_id: id of hackathon that the notice belongs to (-1 if the notice doesn't belong to a specfic hackathon)
:type notice_event: Class HACK_NOTICE_EVENT
:param notice_event: event that the notice is triggered by, used for notice filtering (see get_hackathon_notice_list())
more specfic than notice_category, new events can be added without disturbing front-end code
:type notice_category: Class HACK_NOTICE_CATEGORY
:param notice_category: category that the notice belongs to, used for notice filtering and notice properties display
at front-end (e.g. icons/descriptions, see oh.manage.notice.js & oh.site.hackathon.js),
more general than notice_event, if you want to add a new category in HACK_NOTICE_CATEGORY,
remember to update front-end js code as well.
:type body: dict/Context, default value: {}
:param body: other necessary information, e.g.: 'content'(notice's content), 'link'(notice's link), other keys for specfic uses
:return: hackathon_notice in dict
::Example:
:create_hackathon_notice(2, HACK_NOTICE_EVENT.xx, HACK_NOTICE_CATEGORY.yy, {'content': 'zz'})
a new notice for a hackathon with id 2 is created for the propose of HACK_NOTICE_EVENT.xx. The notice's front-end icon
and description is determined by HACK_NOTICE_CATEGORY.yy, while its content is 'zz' and its link url is ''
:create_hackathon_notice(-1, HACK_NOTICE_EVENT.xx, HACK_NOTICE_CATEGORY.yy)
a new notice not belongs to any hackathon is created for the propose of HACK_NOTICE_EVENT.xx. The notice's front-end icon
and description is determined by HACK_NOTICE_CATEGORY.yy, while its content and link url is ''
"""
hackathon_notice = HackathonNotice(content='',
link='',
event=notice_event,
category=notice_category)
hackathon = self.get_hackathon_by_id(hackathon_id)
if hackathon:
hackathon_notice.hackathon = hackathon
# notice creation logic for different notice_events
if hackathon:
if notice_event == HACK_NOTICE_EVENT.HACK_CREATE:
hackathon_notice.content = u"%s即将火爆来袭,敬请期待!" % (hackathon.display_name)
# elif notice_event == HACK_NOTICE_EVENT.HACK_EDIT and hackathon:
# hackathon_notice.content = u"%s更新啦,快去看看!" % (hackathon.display_name)
elif notice_event == HACK_NOTICE_EVENT.HACK_ONLINE:
hackathon_notice.content = u"%s开始啦,点击报名!" % (hackathon.display_name)
hackathon_notice.link = "/site/%s" % hackathon.name
elif notice_event == HACK_NOTICE_EVENT.HACK_OFFLINE:
hackathon_notice.content = u"%s圆满结束,点击查看详情!" % (hackathon.display_name)
hackathon_notice.link = "/site/%s" % hackathon.name
elif notice_event == HACK_NOTICE_EVENT.HACK_PLAN and body.get('receiver', None):
user = body.get('receiver')
old_hackathon_notice = HackathonNotice.objects(receiver=user, event=HACK_NOTICE_EVENT.HACK_PLAN,
hackathon=hackathon).first()
if old_hackathon_notice: # duplicate
return old_hackathon_notice.dic()
hackathon_notice.content = u"您有未完成的任务,请提交开发说明书"
hackathon_notice.receiver = user
hackathon_notice.link = u"/site/%s/team" % (hackathon.name)
elif notice_event == HACK_NOTICE_EVENT.HACK_REGISTER_AZURE and body.get('receiver', None):
user = body.get('receiver')
old_hackathon_notice = HackathonNotice.objects(receiver=user,
event=HACK_NOTICE_EVENT.HACK_REGISTER_AZURE,
hackathon=hackathon).first()
if old_hackathon_notice: # duplicate
return old_hackathon_notice.dic()
hackathon_notice.content = u"请完成实名认证"
hackathon_notice.receiver = user
hackathon_notice.link = u"https://www.azure.cn/pricing/1rmb-trial-full/?form-type=waitinglist"
else:
pass
if notice_event == HACK_NOTICE_EVENT.EXPR_JOIN and body.get('user_id'):
user_id = body.get('user_id')
user = self.user_manager.get_user_by_id(user_id)
hackathon_notice.content = u"用户 %s 开始编程" % (user.nickname)
else:
pass
# use assigned value if content or link is assigned in body
hackathon_notice.content = body.get('content', hackathon_notice.content)
hackathon_notice.link = body.get('link', hackathon_notice.link)
hackathon_notice.save(validate=False)
self.log.debug("a new notice is created: hackathon: %s, event: %d, category: %d" % (
hackathon.name, notice_event, notice_category))
return hackathon_notice.dic()
示例2: create_hackathon_notice
# 需要导入模块: from hackathon.hmongo.models import HackathonNotice [as 别名]
# 或者: from hackathon.hmongo.models.HackathonNotice import save [as 别名]
def create_hackathon_notice(self, hackathon_id, notice_event, notice_category, body={}):
"""
create hackathon notice with hackathon_id, notice_event, notice_category.
notice 'content' and 'link' can be included in body (optional)
:type hackathon_id: int
:param hackathon_id: id of hackathon that the notice belongs to (-1 if the notice doesn't belong to a specfic hackathon)
:type notice_event: Class HACK_NOTICE_EVENT
:param notice_event: event that the notice is triggered by, used for notice filtering (see get_hackathon_notice_list())
more specfic than notice_category, new events can be added without disturbing front-end code
:type notice_category: Class HACK_NOTICE_CATEGORY
:param notice_category: category that the notice belongs to, used for notice filtering and notice properties display
at front-end (e.g. icons/descriptions, see oh.manage.notice.js & oh.site.hackathon.js),
more general than notice_event, if you want to add a new category in HACK_NOTICE_CATEGORY,
remember to update front-end js code as well.
:type body: dict/Context, default value: {}
:param body: other necessary information, e.g.: 'content'(notice's content), 'link'(notice's link), other keys for specfic uses
:return: hackathon_notice in dict
::Example:
:create_hackathon_notice(2, HACK_NOTICE_EVENT.xx, HACK_NOTICE_CATEGORY.yy, {'content': 'zz'})
a new notice for a hackathon with id 2 is created for the propose of HACK_NOTICE_EVENT.xx. The notice's front-end icon
and description is determined by HACK_NOTICE_CATEGORY.yy, while its content is 'zz' and its link url is ''
:create_hackathon_notice(-1, HACK_NOTICE_EVENT.xx, HACK_NOTICE_CATEGORY.yy)
a new notice not belongs to any hackathon is created for the propose of HACK_NOTICE_EVENT.xx. The notice's front-end icon
and description is determined by HACK_NOTICE_CATEGORY.yy, while its content and link url is ''
"""
hackathon_notice = HackathonNotice(content='',
link='',
event=notice_event,
category=notice_category)
hackathon = self.get_hackathon_by_id(hackathon_id)
if hackathon:
hackathon_notice.hackathon = hackathon
# notice creation logic for different notice_events
if hackathon:
if notice_event == HACK_NOTICE_EVENT.HACK_CREATE:
hackathon_notice.content = u"Hachathon: %s 创建成功" % (hackathon.name)
elif notice_event == HACK_NOTICE_EVENT.HACK_EDIT and hackathon:
hackathon_notice.content = u"Hachathon: %s 信息变更" % (hackathon.name)
elif notice_event == HACK_NOTICE_EVENT.HACK_ONLINE and hackathon:
hackathon_notice.content = u"Hachathon: %s 正式上线" % (hackathon.name)
elif notice_event == HACK_NOTICE_EVENT.HACK_OFFLINE and hackathon:
hackathon_notice.content = u"Hachathon: %s 下线" % (hackathon.name)
else:
pass
if notice_event == HACK_NOTICE_EVENT.EXPR_JOIN and body.get('user_id'):
user_id = body.get('user_id')
user = self.user_manager.get_user_by_id(user_id)
hackathon_notice.content = u"用户 %s 开始编程" % (user.nickname)
else:
pass
# use assigned value if content or link is assigned in body
hackathon_notice.content = body.get('content', hackathon_notice.content)
hackathon_notice.link = body.get('link', hackathon_notice.link)
hackathon_notice.save(validate=False)
self.log.debug("a new notice is created: hackathon: %s, event: %d, category: %d" % (
hackathon.name, notice_event, notice_category))
return hackathon_notice.dic()