Ejemplo n.º 1
0
    def get(self, match_id):
        match = Match.get_or_404(id=match_id)

        query = MatchMember.select(MatchMember, MatchGroup).join(
            MatchGroup,
            join_type=JOIN_LEFT_OUTER,
            on=(MatchMember.group_id == MatchGroup.id).alias("group")).where(
                MatchMember.match_id == match.id).order_by(
                    MatchMember.id.desc())

        group_query = MatchGroup.select() \
            .where(MatchGroup.match_id == match_id)
        self.logger.debug(group_query.sql())
        groups = []
        for group in group_query:
            groups.append({"name": group.name})

        group_name = self.get_argument("group_name", "")
        if group_name:
            query = query.where(MatchGroup.name == group_name)

        members = self.paginate_query(query)

        sum_fee = MatchMember.select(
            fn.SUM(MatchMember.total_fee).alias("sum")).where(
                MatchMember.match_id == match_id).scalar()

        self.render("match/match_members_list.html",
                    sum_fee=sum_fee,
                    groups=groups,
                    match=match,
                    members=members,
                    pagination=members.pagination)
Ejemplo n.º 2
0
    def get(self, round_id):

        match_round = MatchRound.get_or_404(id=round_id)
        match = Match.get_or_404(id=match_round.match_id)

        query = MatchMember.select().where(
            MatchMember.match_id == match.id,
            MatchMember.state == MatchMember.MatchMemberState.normal)

        members = []
        for member in query:
            members.append({"id": member.id, "name": member.name})

        query = MatchAgainst.select().where(
            MatchAgainst.round_id == match_round.id).order_by(
                MatchAgainst.id.asc())

        againsts = []
        for against in query:
            againsts.append(against.info)

        match_options = MatchOption.select().where(
            MatchOption.match_id == match.id)

        self.render("match/round_againsts.html",
                    match=match,
                    match_round=match_round,
                    members=members,
                    againsts=againsts,
                    match_options=match_options)
Ejemplo n.º 3
0
    def get(self, match_id):
        keyword = self.get_argument("kw", "")
        match = Match.get_or_404(id=match_id)
        query = MatchMember.query_all_members(match_id)

        group_query = MatchGroup.select() \
            .where(MatchGroup.match_id == match_id)
        self.logger.debug(group_query.sql())
        groups = []
        for group in group_query:
            groups.append({"name": group.name})

        group_name = self.get_argument("group_name", "")
        if group_name:
            query = query.where(MatchGroup.name == group_name)

        if keyword:
            if is_mobile(keyword):
                query = query.where(MatchMember.mobile == keyword)
            else:
                query = query.where(MatchMember.name.contains(keyword))

        members = self.paginate_query(query)

        sum_fee = MatchMember.select(
            fn.SUM(MatchMember.total_fee).alias("sum")).where(
                MatchMember.match_id == match_id).scalar()

        self.render("match/match_members_list.html",
                    sum_fee=sum_fee,
                    match=match,
                    groups=groups,
                    members=members,
                    pagination=members.pagination)
Ejemplo n.º 4
0
 def members(cls, match: Match, state: Union[None, MatchMemberState]=None)\
         -> SelectQuery:
     """
     获取赛事参赛成员
     :param match: Match, 赛事
     :param state: MatchMember.MatchMemberState, 过滤参赛成员状态
     :return: SelectQuery
     """
     query = MatchMember.select().where(MatchMember.match_id == match.id)
     if state:
         query = query.where(MatchMember.state == state.value)
     return query
Ejemplo n.º 5
0
    def get(self, match_id):
        members = MatchMember.select(MatchMember, MatchGroup).join(
            MatchGroup,
            join_type=JOIN_LEFT_OUTER,
            on=(MatchMember.group_id == MatchGroup.id).alias("group")).where(
                MatchMember.match_id == match_id).order_by(
                    MatchMember.id.desc())

        # display_fields = ("name")
        #
        # with Workbook("temp.xls") as workbook:
        #     worksheet = workbook.add_worksheet()
        #     worksheet.write_row(0, 0, )
        #     for member in members:
        #
        #
        # self.write()
        self.write_success()
Ejemplo n.º 6
0
 def has_joined(self, match: Match, user_id: int):
     """
     用户是否已经加入过赛事
     :param match:
     :param user_id:
     :return:
     """
     try:
         member = MatchMember.select()\
             .where(MatchMember.user_id == user_id,
                    MatchMember.match_id == match.id)\
             .get()
     except MatchMember.DoesNotExist:
         return True
     else:
         if member.state == MatchMember.MatchMemberState.leave.value:
             msg = "你的退赛申请正在处理中, 退赛完成后再尝试"
             raise ApiException(422, msg, log_message=msg)
         raise ApiException(422, "您已参赛, 无须重复参加")
Ejemplo n.º 7
0
    def cancel(cls, match: Match, user: User):
        """
        主办方取消赛事
        :param match:
        :param user:
        :return:
        """
        from yiyun.tasks.match import batch_refund_worker
        if not match.can_cancel():
            raise MatchStateError("当前赛事状态无法取消: {0}".format(match.state))

        with cls.database.transaction():
            Match.update(state=Match.MatchState.cancelled.value)\
                .where(Match.id == match.id).execute()

            members = MatchMember.select()\
                .where(MatchMember.match_id == match.id,
                       MatchMember.state >= MatchMember.MatchMemberState.wait_pay.value,
                       MatchMember.state <= MatchMember.MatchMemberState.normal.value)
            for member in members:
                batch_refund_worker.delay(member_id=member.id)