Exemplo n.º 1
0
  def post(self):
    tournament_name  = self.request.get("tournament_name")
    if Tournament.get_by_key_name(tournament_name):
      # TODO error: already exists
      return

    max_enrollment   = int(self.request.get("max_enrollment"))
    assert not (max_enrollment < 4 or max_enrollment > 64)

    background       = self.request.get("background")
    seed_by          = self.request.get("seed_by")
    coach            = Coach.get_by_key_name(self.request.get("coach_key_name"))
    min_tv           = self.request.get("min_tv")
    max_tv           = self.request.get("max_tv")
    min_ma           = self.request.get("min_ma")
    max_ma           = self.request.get("max_ma")

    # compute race restrictions
    race_restriction = self.request.get("race_restriction")
    if race_restriction:
      races_allowed = self.request.get_all("races_allowed")
      races_allowed = [
          db.Key.from_path("Race", race_name) for race_name in races_allowed]
    else:
      races_allowed = []

    tournament = Tournament(
        key_name       = tournament_name,
        owner          = coach,
        background     = background,
        max_enrollment = max_enrollment,
        seed_by        = seed_by,
        races_allowed  = races_allowed)

    def format_tv(tv):
      tv = (tv / 10) * 10
      return max(0, min(3500, tv))

    if min_tv:
      tournament.min_tv = int(min_tv)
    if max_tv:
      tournament.max_tv = int(max_tv)

    if min_ma:
      tournament.min_ma = int(min_ma)
    if max_ma:
      tournament.max_ma = int(max_ma)

    trophy_pic = self.request.get("trophy_pic")
    if trophy_pic:
      pic = TournamentPicture.create_from_img(tournament_name, trophy_pic)
      pic.put()
      tournament.pic = pic

    tournament.put()
    views.Tournaments.clear()

    # I need to give a response or I get an error. Nobody on the internet seems
    # to know why.  See https://github.com/malsup/form/issues#issue/22.
    self.response.out.write("OK") 
Exemplo n.º 2
0
    def get(self):

        # check for a cached version
        #--------------------------------------------------------------------#

        tournament = Tournament.get_by_key_name(
            self.request.get("tournament_key_name"))

        if tournament.started:
            if self.emit(self.response.out, tournament.key()):
                return

        # not cached or evicted from cache; regenerate
        #--------------------------------------------------------------------#

        teams = [
            m.team for m in TournamentMembership.all().ancestor(tournament)
        ]

        races_allowed = []
        for race_key in tournament.races_allowed:
            races_allowed.append(Race.get(race_key))

        if not tournament.started:
            user = users.get_current_user()
            coach = None
            if user:
                coach = Coach.all().filter("user ="******":")]

            # pixel settings
            width_unit = 530 / round
            match_width = 200

            # compute data for each match_up
            match_up_data = []
            for match_up, child in match_ups:
                round, seed = [
                    int(x) for x in match_up.key().name().split(":")
                ]
                position_left = round * width_unit

                team_data = []
                for i, mm in enumerate(
                        match_up.tournamentmatchupmembership_set.order(
                            "__key__")):

                    data = {}
                    data["name"] = "_" * 25
                    data["seed"] = ""
                    data["score"] = ""

                    if mm.membership:
                        team = mm.membership.team
                        if team.matches:
                            data[
                                "name"] = "<a rel='tournament_teams' href='%s'>%s</a>" % (
                                    team.get_box_href(), team.key().name())
                        else:
                            data["name"] = "<b title='%s'>%s</b>" % (
                                team.coach.key().name(), team.key().name())
                        data["seed"] = mm.membership.seed + 1

                        if match_up.match:
                            team_record = match_up.match.get_team_records_query(
                            ).filter("team =", mm.membership.team.key()).get()
                            score = str(team_record.tds_for)
                            if (match_up.winner.key() == mm.membership.key()
                                    and
                                (team_record.tds_for == team_record.tds_against
                                 or match_up.match.disconnect)):
                                score += "*"

                            data["score"] = "<b>%s</b>" % score

                        elif match_up.winner:
                            # if there was a winner but no match then it was a forfeit
                            if match_up.winner.key() == mm.membership.key():
                                data["score"] = "&nbsp;"
                            else:
                                data["score"] = "<b><i>F</i></b>"

                    team_data.append(data)

                if child == 0:
                    arrow_class = "down_arrow"
                elif child == 1:
                    arrow_class = "up_arrow"
                else:
                    arrow_class = None

                match_data = match_up.match

                end_this_match = width_unit * round + match_width
                mid_next_match = width_unit * (round + 1) + match_width / 2
                arrow_width = mid_next_match - end_this_match

                match_up_data.append((round, team_data, position_left,
                                      arrow_width, arrow_class, match_data))

        # render and update
        #--------------------------------------------------------------------#

        tournament_box = misc.render('tournament_box.html', locals())
        if tournament.started:
            self.update(tournament_box, tournament.key())

        self.response.out.write(tournament_box)
Exemplo n.º 3
0
    def post(self):
        tournament_name = self.request.get("tournament_name")
        if Tournament.get_by_key_name(tournament_name):
            # TODO error: already exists
            return

        max_enrollment = int(self.request.get("max_enrollment"))
        assert not (max_enrollment < 4 or max_enrollment > 64)

        background = self.request.get("background")
        seed_by = self.request.get("seed_by")
        coach = Coach.get_by_key_name(self.request.get("coach_key_name"))
        min_tv = self.request.get("min_tv")
        max_tv = self.request.get("max_tv")
        min_ma = self.request.get("min_ma")
        max_ma = self.request.get("max_ma")

        # compute race restrictions
        race_restriction = self.request.get("race_restriction")
        if race_restriction:
            races_allowed = self.request.get_all("races_allowed")
            races_allowed = [
                db.Key.from_path("Race", race_name)
                for race_name in races_allowed
            ]
        else:
            races_allowed = []

        tournament = Tournament(key_name=tournament_name,
                                owner=coach,
                                background=background,
                                max_enrollment=max_enrollment,
                                seed_by=seed_by,
                                races_allowed=races_allowed)

        def format_tv(tv):
            tv = (tv / 10) * 10
            return max(0, min(3500, tv))

        if min_tv:
            tournament.min_tv = int(min_tv)
        if max_tv:
            tournament.max_tv = int(max_tv)

        if min_ma:
            tournament.min_ma = int(min_ma)
        if max_ma:
            tournament.max_ma = int(max_ma)

        trophy_pic = self.request.get("trophy_pic")
        if trophy_pic:
            pic = TournamentPicture.create_from_img(tournament_name,
                                                    trophy_pic)
            pic.put()
            tournament.pic = pic

        tournament.put()
        views.Tournaments.clear()

        # I need to give a response or I get an error. Nobody on the internet seems
        # to know why.  See https://github.com/malsup/form/issues#issue/22.
        self.response.out.write("OK")