Пример #1
0
    def create_default_team(self, hackathon, user):
        """Create a default new team for user after registration.

        Use user name as team name by default. Append user id in case user name is duplicate
        """
        user_team_rel = self.__get_valid_team_by_user(user.id, hackathon.id)
        if user_team_rel:
            self.log.debug("fail to create team since user is already in some team.")
            return precondition_failed("you must leave the current team first")

        team_name = self.__generate_team_name(hackathon, user)
        team = Team(name=team_name,
                    leader_id=user.id,
                    logo=user.avatar_url,
                    hackathon_id=hackathon.id)
        self.db.add_object(team)

        user_team_rel = UserTeamRel(join_time=self.util.get_now(),
                                    status=TeamMemberStatus.Approved,
                                    hackathon_id=hackathon.id,
                                    user_id=user.id,
                                    team_id=team.id)
        self.db.add_object(user_team_rel)

        return team.dic()
Пример #2
0
    def create_team(self, kwargs):
        """Create new team by given args.

        user only allow to join or create 1 team. So if user joined or created team before, will be get failed
        when creating new team.

        :type kwargs: dict
        :param kwargs: a dict of required information to create new team

        :rtype: dict
        :return: created team information
        """
        user_team_rel = self.__get_team_by_user(g.user.id, g.hackathon.id)
        if user_team_rel:
            self.log.debug(
                "fail to create team since user is already in some team.")
            return precondition_failed("you must leave the current team first")

        if "team_name" not in kwargs:
            return bad_request("Please provide a team name")

        # check team name to avoid duplicate name
        team_name = kwargs["team_name"]
        if self.__get_team_by_name(g.hackathon.id, team_name):
            return precondition_failed(
                "The team name is existed, please provide a new name")

        team = Team(name=team_name,
                    description=kwargs.get("description"),
                    git_project=kwargs.get("git_project"),
                    logo=kwargs.get("logo"),
                    create_time=self.util.get_now(),
                    update_time=self.util.get_now(),
                    leader_id=g.user.id,
                    hackathon_id=g.hackathon.id)
        self.db.add_object(team)

        user_team_rel = UserTeamRel(join_time=self.util.get_now(),
                                    update_time=self.util.get_now(),
                                    status=TeamMemberStatus.Approved,
                                    hackathon_id=g.hackathon.id,
                                    user_id=g.user.id,
                                    team_id=team.id)
        self.db.add_object(user_team_rel)

        return team.dic()
Пример #3
0
    def create_team(self, kwargs):
        """Create new team by given args.

        user only allow to join or create 1 team. So if user joined or created team before, will be get failed
        when creating new team.

        :type kwargs: dict
        :param kwargs: a dict of required information to create new team

        :rtype: dict
        :return: created team information
        """
        user_team_rel = self.__get_team_by_user(g.user.id, g.hackathon.id)
        if user_team_rel:
            self.log.debug("fail to create team since user is already in some team.")
            return precondition_failed("you must leave the current team first")

        if "team_name" not in kwargs:
            return bad_request("Please provide a team name")

        # check team name to avoid duplicate name
        team_name = kwargs["team_name"]
        if self.__get_team_by_name(g.hackathon.id, team_name):
            return precondition_failed("The team name is existed, please provide a new name")

        team = Team(name=team_name,
                    description=kwargs.get("description"),
                    git_project=kwargs.get("git_project"),
                    logo=kwargs.get("logo"),
                    create_time=self.util.get_now(),
                    update_time=self.util.get_now(),
                    leader_id=g.user.id,
                    hackathon_id=g.hackathon.id)
        self.db.add_object(team)

        user_team_rel = UserTeamRel(join_time=self.util.get_now(),
                                    update_time=self.util.get_now(),
                                    status=TeamMemberStatus.Approved,
                                    hackathon_id=g.hackathon.id,
                                    user_id=g.user.id,
                                    team_id=team.id)
        self.db.add_object(user_team_rel)

        return team.dic()