示例#1
0
    def post(self, request, team, user, description=''):
        """向用户发出加入团队邀请

        :param description: 附带消息
        """
        if request.user != team.owner:
            abort(403, '只有队长可以操作')

        if user == team.owner:
            abort(403, '对方是本团队队长')

        if team.members.filter(user=user).exists():
            abort(403, '对方已经是团队成员')

        if team.invitations.filter(user=user).exists():
            abort(200)

        if team.member_requests.filter(user=user).exists():
            abort(403, '对方已经发送过申请')

        for need in team.needs.all():
            if need.member_requests.filter(sender=request.user).exists():
                abort(403, '对方已经发送过申请')

        team.invitations.create(user=user, description=description)
        notify_user(user, json.dumps({'type': 'invitation'}))
        abort(200)
示例#2
0
def send_undertake_need(team, need):
    """记录团队发布承接需求事件"""

    team.actions.create(action='send',
                        object_type='undertake_need',
                        object_id=need.id)
    for t in team.followers.all():
        notify_user(
            t.follower,
            json.dumps({
                'type': 'team_action',
                'content': team.name + '发布了需求' + need.title
            }))
示例#3
0
def send_forum(user, forum):
    """记录创建论坛事件"""

    user.actions.create(action='create',
                        object_type='forum',
                        object_id=forum.id)
    for u in user.followers.all():
        notify_user(
            u.follower,
            json.dumps({
                'type': 'user_action',
                'content': user.name + '创建了论坛' + forum.name
            }))
示例#4
0
    def post(self, request, user, description=''):
        """向目标用户发出好友申请

        :param description: 附带消息
        """
        if user == request.user:
            return self.fail(1, '不能给自己发送好友申请')

        if user.friends.filter(other_user=request.user).exists():
            return self.fail(2, '已经是好友了')

        if user.friend_requests.filter(other_user=request.user).exists():
            return self.success()

        user.friend_requests.create(other_user=request.user,
                                    description=description)

        notify_user(user, json.dumps({'type': 'friend_request'}))
        return self.success()
示例#5
0
def leave_team(user, team):
    """记录退出团队事件"""

    user.actions.create(action='leave', object_type='team', object_id=team.id)
    team.actions.create(action='leave', object_type='user', object_id=user.id)
    for u in user.followers.all():
        notify_user(
            u.follower,
            json.dumps({
                'type': 'user_action',
                'content': user.name + '退出了团队' + team.name
            }))
    for t in team.followers.all():
        notify_user(
            t.follower,
            json.dumps({
                'type': 'team_action',
                'content': user.name + '退出了团队' + team.name
            }))
示例#6
0
def finish_external_task(team, task):
    """记录团队完成外包及外包团队完成支付事件"""

    team.actions.create(action='finish',
                        object_type='external_task',
                        object_id=task.id,
                        related_object_type='team',
                        related_object_id=task.team.id)
    task.team.actions.create(action='pay',
                             object_type='team',
                             object_id=team.id,
                             related_object_type='external_task',
                             related_object_id=task.id)
    for t in team.followers.all():
        notify_user(
            t.follower,
            json.dumps({
                'type': 'team_action',
                'content': team.name + '完成了任务' + task.title
            }))