예제 #1
0
    def test_read_user_notice(self, user1):
        self.login(user1)

        # init new unread msg
        hackathon_notice = HackathonNotice(
            content='',
            link='',
            event=HACK_NOTICE_EVENT.HACK_CREATE,
            category=HACK_NOTICE_CATEGORY.HACKATHON,
            receiver=user1,
            creator=user1,
        )
        hackathon_notice.save()
        assert not hackathon_notice.is_read

        # test read msg
        payload = self.client.put("/api/user/notice/read", json_data=dict(id=str(hackathon_notice.id)))
        assert payload['code'] == 200
        hackathon_notice = HackathonNotice.objects(id=str(hackathon_notice.id)).first()
        assert hackathon_notice.is_read
예제 #2
0
    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()
예제 #3
0
    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)
            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()
예제 #4
0
    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()