Exemplo n.º 1
0
    def __response_get_score(self, user, scores):
        resp = {"all": [to_dic(s) for s in scores]}

        my = filter(lambda sc: sc.judge.id == user.id, scores)
        assert len(my) < 2
        if my:
            resp["my"] = to_dic(my[0])

        return resp
Exemplo n.º 2
0
    def __response_get_score(self, user, scores):
        resp = {"all": [to_dic(s) for s in scores]}

        my = [sc for sc in scores if sc.judge.id == user.id]
        assert len(my) < 2
        if my:
            resp["my"] = to_dic(my[0])

        return resp
Exemplo n.º 3
0
    def __response_get_score(self, user, scores):
        resp = {
            "all": [to_dic(s) for s in scores]}

        my = filter(lambda sc: sc.judge.id == user.id, scores)
        assert len(my) < 2
        if my:
            resp["my"] = to_dic(my[0])

        return resp
Exemplo n.º 4
0
    def join_team(self, user, team_id):
        """Join a team will create a record on user_team_rel table which status will be 0.

        :type user: User

        :rtype: dict
        :return: if user already joined team or team not exist, return bad request. Else, return a dict of joined
            details.
        """
        if Team.objects(id=team_id, members__user=user.id).count():
            return ok("You already joined this team.")

        team = self.__get_team_by_id(team_id)
        if not team:
            return not_found()

        cur_team = self.__get_valid_team_by_user(user.id, team.hackathon.id)
        if cur_team and cur_team.members.count() > 1:
            return precondition_failed(
                "Team leader cannot join another team for team member count greater than 1"
            )

        if not self.register_manager.is_user_registered(
                user.id, team.hackathon):
            return precondition_failed("user not registerd")

        mem = TeamMember(join_time=self.util.get_now(),
                         status=TEAM_MEMBER_STATUS.INIT,
                         user=user)
        team.members.append(mem)

        team.save()

        return to_dic(mem)
Exemplo n.º 5
0
    def join_team(self, user, team_id):
        """Join a team will create a record on user_team_rel table which status will be 0.

        :type user: User

        :rtype: dict
        :return: if user already joined team or team not exist, return bad request. Else, return a dict of joined
            details.
        """
        if Team.objects(id=team_id, members__user=user.id).count():
            return ok("You already joined this team.")

        team = self.__get_team_by_id(team_id)
        if not team:
            return not_found()

        cur_team = self.__get_valid_team_by_user(user.id, team.hackathon.id)
        if cur_team and cur_team.members.count() > 1:
            return precondition_failed("Team leader cannot join another team for team member count greater than 1")

        if not self.register_manager.is_user_registered(user.id, team.hackathon):
            return precondition_failed("user not registerd")

        mem = TeamMember(
            join_time=self.util.get_now(),
            status=TEAM_MEMBER_STATUS.INIT,
            user=user)
        team.members.append(mem)

        team.save()

        return to_dic(mem)
Exemplo n.º 6
0
    def __award_with_detail(self, team_award, hackathon=None):
        if not hackathon:
            hackathon = g.hackathon

        try:
            award = filter(lambda a: str(a.id) == str(team_award), hackathon.awards)[0]
        except IndexError:
            return None

        return to_dic(award)
Exemplo n.º 7
0
    def __award_with_detail(self, team_award, hackathon=None):
        if not hackathon:
            hackathon = g.hackathon

        try:
            award = [
                a for a in hackathon.awards if str(a.id) == str(team_award)
            ][0]
        except IndexError:
            return None

        return to_dic(award)
Exemplo n.º 8
0
    def add_team_show(self, user, context):
        team = self.__get_team_by_id(context.team_id)
        if not team:
            return not_found()

        self.__validate_team_permission(team.hackathon.id, team, user)
        try:
            work = TeamWork(id=uuid.uuid1(), description=context.get("note"), type=context.type, uri=context.uri)

            team.works.append(work)
            team.save()

        except ValidationError as e:
            if "uri" in e.message:
                return bad_request("`uri` field must be in uri format")
            else:
                raise e

        return to_dic(work)
Exemplo n.º 9
0
    def add_team_show(self, user, context):
        team = self.__get_team_by_id(context.team_id)
        if not team:
            return not_found()

        self.__validate_team_permission(team.hackathon.id, team, user)
        try:
            work = TeamWork(id=uuid.uuid1(),
                            description=context.get("note"),
                            type=context.type,
                            uri=context.uri)

            team.works.append(work)
            team.save()

        except ValidationError as e:
            if "uri" in e.message:
                return bad_request("`uri` field must be in uri format")
            else:
                raise e

        return to_dic(work)
Exemplo n.º 10
0
 def sub(t):
     m = to_dic(t)
     m["user"] = self.user_manager.user_display_info(t.user)
     return m
Exemplo n.º 11
0
    def get_team_show_list(self, team_id):
        team = self.__get_team_by_id(team_id)
        if not team:
            return []

        return [to_dic(s) for s in team.works]
Exemplo n.º 12
0
    def get_team_show_list(self, team_id):
        team = self.__get_team_by_id(team_id)
        if not team:
            return []

        return [to_dic(s) for s in team.works]
Exemplo n.º 13
0
 def sub(t):
     m = to_dic(t)
     m["user"] = self.user_manager.user_display_info(t.user)
     return m