Exemplo n.º 1
0
    def post(self, match_id):

        match = Match.get_or_404(id=match_id)
        form = CreateCoverForm(self.arguments)

        if form.validate():

            cover = MatchCover(match_id=match.id)
            form.populate_obj(cover)

            if "coverfile" in self.request.files:
                to_bucket = self.settings['qiniu_avatar_bucket']
                to_key = "match:cover:%s%s" % (match_id, time.time())
                to_key = hashlib.md5(to_key.encode()).hexdigest()

                cover_key = self.upload_file(
                    "coverfile",
                    to_bucket=to_bucket,
                    to_key=to_key,
                )

                cover.cover_key = cover_key

            cover.save()

            self.redirect(self.reverse_url("admin_match_detail", match_id))
            return

        self.render("match/add_cover.html", form=form, match=match)
Exemplo n.º 2
0
    def get(self, match_id):

        match = Match.get_or_404(id=match_id)
        cover = MatchCover(match_id=match_id)

        form = CreateCoverForm(obj=cover)

        self.render("match/add_cover.html", form=form, match=match)
Exemplo n.º 3
0
    def get(self, match_id):
        match = Match.get_or_404(id=match_id)

        # 获取赛事分组信息
        groups = MatchGroup.select().where(
            MatchGroup.match_id == match.id).order_by(
                MatchGroup.sort_num.desc())

        # 获取报名表自定义选项
        custom_options = MatchOption.select().where(
            MatchOption.match_id == match.id).order_by(
                MatchOption.sort_num.desc())

        rounds = MatchRound.select(MatchRound, ).where(
            MatchRound.match_id == match.id).order_by(MatchRound.created.asc(),
                                                      MatchRound.id.asc())

        covers = MatchCover.select().where(
            MatchCover.match_id == match.id).order_by(MatchCover.id.desc())

        # 获取对阵图
        RightMember = MatchMember.alias()

        against_query = MatchAgainst.select(
            MatchAgainst, MatchMember, RightMember).join(
                MatchMember,
                on=(MatchAgainst.left_member_id == MatchMember.id
                    ).alias("left_member")).switch(MatchAgainst).join(
                        RightMember,
                        join_type=JOIN_LEFT_OUTER,
                        on=(MatchAgainst.right_member_id == RightMember.id
                            ).alias("right_member")).where(
                                MatchAgainst.match_id == match_id).order_by(
                                    MatchAgainst.start_time.asc())

        againsts = {}
        for against in against_query:
            if against.round_id not in againsts:
                againsts[against.round_id] = []

            againsts[against.round_id].append(against)

        # 如果已经结束 获取是否已经提交了结算申请
        is_application_exist =\
            SettlementApplication.is_application_exist(match_id)

        self.render("match/detail.html",
                    match=match,
                    rounds=rounds,
                    groups=groups,
                    custom_options=custom_options,
                    covers=covers,
                    againsts=againsts,
                    is_application_exist=is_application_exist)
Exemplo n.º 4
0
    def post(self, match_id):
        cover_id = self.get_argument("cover_id")
        match_cover = MatchCover.get_or_404(id=cover_id, match_id=match_id)
        bucket_name, key = match_cover.cover_key.split(":")

        with self.db.transaction():
            match_cover.delete_instance()
            ret, info = tasks.qiniu_tool.delete_file(bucket_name, key)
            if not ret:
                self.logger.debug("删除海报失败: %s" % info)
                raise ArgumentError(500, "删除失败")
        self.write_success()
Exemplo n.º 5
0
    def get(self, match_id):
        """获取赛事信息

        :match_id: 赛事ID
        :returns: 赛事信息

        """

        preview = self.get_query_argument("preview", False)
        match = self.get_object(match_id, preview)
        match.team = Team.get_or_404(id=match.team_id)

        serializer = MatchSerializer(instance=match)

        info = serializer.data

        # 获取赛事分组信息
        query = MatchGroup.select().where(
            MatchGroup.match_id == match.id, ).order_by(
                MatchGroup.sort_num.desc())

        groups = []
        for group in query:
            groups.append(group.info)

        info['groups'] = groups

        # 获取赛事海报列表
        query = MatchCover.select().where(
            MatchCover.match_id == match.id).order_by(MatchCover.id.desc())

        covers = []
        for cover in query:
            covers.append(cover.info)

        info['covers'] = covers

        if self.current_user:
            member = MatchMember.get_or_none(match_id=match_id,
                                             user_id=self.current_user.id)

            if member:
                info['my_state'] = member.mini_info

        self.write(info)