當前位置: 首頁>>代碼示例>>Python>>正文


Python HackathonNotice.link方法代碼示例

本文整理匯總了Python中hackathon.hmongo.models.HackathonNotice.link方法的典型用法代碼示例。如果您正苦於以下問題:Python HackathonNotice.link方法的具體用法?Python HackathonNotice.link怎麽用?Python HackathonNotice.link使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在hackathon.hmongo.models.HackathonNotice的用法示例。


在下文中一共展示了HackathonNotice.link方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create_hackathon_notice

# 需要導入模塊: from hackathon.hmongo.models import HackathonNotice [as 別名]
# 或者: from hackathon.hmongo.models.HackathonNotice import link [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()
開發者ID:yongxu74,項目名稱:open-hackathon,代碼行數:96,代碼來源:hackathon_manager.py

示例2: create_hackathon_notice

# 需要導入模塊: from hackathon.hmongo.models import HackathonNotice [as 別名]
# 或者: from hackathon.hmongo.models.HackathonNotice import link [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()
開發者ID:qianliwg,項目名稱:open-hackathon,代碼行數:72,代碼來源:hackathon_manager.py


注:本文中的hackathon.hmongo.models.HackathonNotice.link方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。