Ejemplo n.º 1
0
  def bets(self, matchID, teamID, offset = 0, limit = 10):
    c.current = "match"
    c.user = False
    if "steamid" in session:
      RUser = Session.query(db.Users).filter(db.Users.steamID == session["steamid"]).first()
      if RUser:
        c.user = RUser.to_dict()

    limit = min(int(limit), 10)

    RMatch = Session.query(db.Matches).filter(db.Matches.id == matchID).first()
    c.match = RMatch.to_dict()

    conditions = [
      db.Bets.match == matchID,
      db.Bets.team == teamID,
    ]
    if c.user:
      conditions += [db.Bets.user != RUser.id]

    c.bets = []
    RBets = Session.query(db.Bets) \
      .filter(and_(*conditions)) \
      .order_by(db.Bets.value.desc()) \
      .offset(offset).limit(limit).all()

    if not RBets:
      return render('/ajax/bets.mako')

    
    betIDs = [RBet.id for RBet in RBets]

    betItems = defaultdict(list)

    RItemsBet = Session.query(db.ItemsInstances, db.ItemsBet) \
      .distinct(db.ItemsInstances.originID) \
      .filter(db.ItemsBet.bet.in_(betIDs), db.ItemsBet.itemInstance == db.ItemsInstances.id) \
      .all()

    RItemsBet = sorted(RItemsBet, key = lambda x: (x[1].origin * -1, x[0].Item.type, x[0].Item.quality, x[0].Item.value * -1))

    for RBet in RBets:
      bet = RBet.to_dict(show=["bets.User", "bets.Team"])
      if RBet.team == RMatch.team1:
        bet["Team"].update(RMatch.team1Score())
      else:
        bet["Team"].update(RMatch.team2Score())

      bet["own"] = False
      bet["items"] = []
      for RItemInstance, RItemBet in RItemsBet:
        if RItemBet.bet != RBet.id:
          continue
        item = RItemInstance.to_dict(show=["itemsinstances.Item"])
        item["origin"] = RItemBet.origin
        bet["items"].append(item)

      c.bets.append(bet)

    return render('/ajax/bets.mako')
Ejemplo n.º 2
0
  def newOffer(self, botID, userID):
    if "steamid" in session:
      RUser = Session.query(db.Users).filter(db.Users.steamID == session["steamid"]).first()
      if RUser.Permissions[0].economy:
        c.current = "manage"
        c.managePage = "bots"
        c.user = RUser.to_dict()

        RBot = Session.query(db.Bots).filter(db.Bots.id == botID).first()
        ROtherUser = Session.query(db.Users).filter(db.Users.id == userID).first()
        if RBot and ROtherUser:
          botAPI = API(RBot.steamAPI, RBot.steamID)
          c.bot = RBot.to_dict()
          c.botItems = botAPI.Friend(RBot.steamID).sortedInventory()
          c.botItemsCount = 0
          for itemsGroup in c.botItems:
            for item in itemsGroup["items"].values():
              c.botItemsCount += 1
          c.botPages = int(math.ceil(c.botItemsCount / 24.0))

          c.otherUser = ROtherUser.to_dict()
          inventory = botAPI.Friend(ROtherUser.steamID).inventory()
          c.otherUserItems = botAPI.Friend(ROtherUser.steamID).sortedInventory()
          c.otherUserItemsCount = 0
          for itemsGroup in c.botItems:
            for item in itemsGroup["items"].values():
              c.otherUserItemsCount += 1
          c.otherUserPages = int(math.ceil(c.botItemsCount / 24.0))

          return render("/manage/offers/new.mako")
    return render("/manage/bots/")
Ejemplo n.º 3
0
  def tickets(self):
    c.user = False
    if "steamid" in session:
      RUser = Session.query(db.Users).filter(db.Users.steamID == session["steamid"]).first()
      if RUser:
        if RUser.Permissions[0].bets:
          c.current = "manage"
          c.managePage = "tickets"
          c.user = RUser.to_dict()
          c.tickets = []

          RTickets = Session.query(db.Tickets).filter(db.Tickets.open == True).order_by(db.Tickets.id.desc()).all()
          for RTicket in RTickets:
            ticket = RTicket.to_dict()
            ticket["categoryName"] = RTicket.categoryName()
            
            params = {}
            params["view"] = "cm"
            params["ui"] = 2
            params["tf"] = 0
            params["fs"] = 1
            params["to"] = ticket["email"]
            params["su"] = "Saloon.tf_staging %s #%d - %s" % (ticket["categoryName"], ticket["id"], ticket["title"])
            params["body"] = "\nBest regards, %s\n\nQuoted:\n" % (RUser.name)
            for line in ticket["text"].splitlines():
              params["body"] += "> %s\n" % (line)
            ticket["url"] = "https://mail.google.com/mail/u/0/?" + urllib.urlencode(params)

            c.tickets.append(ticket)
          return render("/manage/tickets.mako")
    return redirect("https://saloon.tf/manage/")
Ejemplo n.º 4
0
  def bots(self):
    user = User()
    if user:
      RUser = user[0]
      if RUser.Permissions[0].bots:
        c.current = "manage"
        c.managePage = "bots"
        c.user = user[1]
        c.bots = []
        RBots = db.Session.query(db.Bots).order_by(db.Bots.id).limit(10).all()

        for RBot in RBots:
          bot = {}
          bot["id"] = RBot.id
          bot["name"] = RBot.name
          bot["emailAddress"] = RBot.emailAddress
          bot["steamLogin"] = RBot.steamLogin
          bot["steamID"] = RBot.steamID
          bot["steamAPI"] = RBot.steamAPI
          bot["tradeoffers"] = "http://steamcommunity.com/tradeoffer/new/?partner=%d&token=%s" % (int(RBot.steamID) - 76561197960265728, RBot.token)
          bot["slots"] = RBot.slots
          bot["slotsEmpty"] = RBot.slotsEmpty
          bot["backpackAPI"] = RBot.backpackAPI

          bot["json"] = json.dumps(bot)
          c.bots.append(bot)

        return render('/manage/bots.mako')
      else:
        return redirect("/manage/")
    else: 
      return redirect("/")
Ejemplo n.º 5
0
  def user(self, userID):
    if "steamid" in session:
      RUser = Session.query(db.Users).filter(db.Users.steamID == session["steamid"]).first()
      if RUser.Permissions[0].users:
        ROtherUser = Session.query(db.Users).filter(db.Users.id == userID).first()
        if ROtherUser:
          c.current = "manage"
          c.managePage = "users"
          c.user = RUser.to_dict()
          c.otherUser = ROtherUser.to_dict()
          c.ranks = {}
          if RUser.Permissions[0].permissions:
            RUsersRanks = Session.query(db.UsersRanks).all()
            for RUsersRank in RUsersRanks:
              c.ranks[RUsersRank.id] = RUsersRank.name

          c.teams = []
          if ROtherUser.teams:
            RTeams = Session.query(db.Teams).filter(db.Teams.id.in_(ROtherUser.teams)).all()
            for RTeam in RTeams:
              c.teams.append(RTeam.to_dict())

          return render('/manage/users/user.mako')
        return redirect("https://saloon.tf/manage/users/") 
    return redirect("https://saloon.tf/manage/")
Ejemplo n.º 6
0
 def index(self):
     # Return a rendered template
     #return render('/inventory.mako')
     # or, return a string
     user = User()
     if user:
         RUser = user[0]
         c.user = user[1]
         c.current = "inventory"
         if not c.user:
             return redirect("http://saloon.tf/home/")
         c.items = {}
         c.items["names"] = ["keys", "refs", "recs", "scraps"]
         c.hasItems = False
         c.items["quantity"] = []
         c.items["quantity"].append(RUser.Items[0].keys)
         if RUser.Items[0].keys > 0:
             c.hasItems = True
         metal = RUser.Items[0].metal
         if metal > 0:
             c.hasItems = True
         c.items["quantity"].append(metal / 9)
         metal -= c.items["quantity"][1] * 9
         c.items["quantity"].append(metal / 3)
         metal -= c.items["quantity"][2] * 3
         c.items["quantity"].append(metal)
         return render('/inventory.mako')
     else:
         return redirect('http://saloon.tf/home/')
Ejemplo n.º 7
0
  def matchesLeagues(self):
    # Returns a rendered template
    user = User()
    if user:
      RUser = user[0]
      if RUser.Permissions[0].bets:
        c.user = user[1]
        c.current = "manage"
        c.managePage = "matches"

        RLeagues = db.Session.query(db.Leagues).order_by(db.Leagues.id).limit(10).all()
        c.leagues = []
        for RLeague in RLeagues:
          league = {}
          league["id"] = RLeague.id
          league["name"] = RLeague.name
          league["type"] = RLeague.type
          league["region"] = RLeague.region
          league["colour"] = RLeague.colour
          league["json"] = json.dumps(league)
          c.leagues.append(league)

        return render('/manage/matches/index.mako')
      else:
        return redirect('/home/')
    else:
      return redirect('/home/')
Ejemplo n.º 8
0
    def matchesLeagues(self):
        # Return a rendered template
        #return render('manage/teams.mako')
        # or, return a string
        user = User()
        if user:
            RUser = user[0]
            if RUser.level <= 3:
                c.user = user[1]
                c.current = "manage"
                c.managePage = "matches"

                RLeagues = db.Session.query(db.Leagues).order_by(
                    db.Leagues.id).limit(10).all()
                c.leagues = []
                for RLeague in RLeagues:
                    league = {}
                    league["id"] = RLeague.id
                    league["name"] = RLeague.name
                    league["type"] = RLeague.type
                    league["region"] = RLeague.region
                    league["colour"] = RLeague.colour
                    league["json"] = json.dumps(league)
                    c.leagues.append(league)

                return render('/manage/matches/index.mako')
            else:
                return redirect('http://saloon.tf/home/')
        else:
            return redirect('http://saloon.tf/home/')
Ejemplo n.º 9
0
  def matchesList(self, leagueID):
    # Returns a rendered template
    if "steamid" in session:
      RUser = Session.query(db.Users).filter(db.Users.steamID == session["steamid"]).first()
      if RUser.Permissions[0].bets:
        c.current = "manage"
        c.managePage = "matches"
        c.user = RUser.to_dict()

        RLeague = Session.query(db.Leagues).filter(db.Leagues.id == leagueID).first()
        RMatches = Session.query(db.Matches, db.Writeups).join(db.Writeups).filter(and_(db.Matches.league == leagueID, db.Matches.status != 5)).order_by(db.Matches.id.desc()).all()
        RTeams = Session.query(db.Teams).filter(db.Teams.league == leagueID).order_by(db.Teams.id).all()

        c.league = RLeague.to_dict()

        c.matches = []
        c.writeups = []
        for RMatch, RWriteup in RMatches:
          match = RMatch.to_dict()
          match["naturalTime"] = RMatch.naturalTime()
          match["Team1"].update(RMatch.team1Score())
          match["Team2"].update(RMatch.team2Score())
          match["json"] = json.dumps(match, default = lambda obj: obj.strftime("%d-%m-%Y %H:%M") if isinstance(obj, datetime.datetime) else None)
          c.matches.append(match)
          writeup = RWriteup.to_dict()
          writeup["json"] = json.dumps(writeup)
          c.writeups.append(writeup)

        c.teams = []
        for RTeam in RTeams:
          team = RTeam.to_dict()
          c.teams.append(team)

        return render('/manage/matches/list.mako')
    return abort(403)
Ejemplo n.º 10
0
  def teamsList(self, leagueID):
    # Returns a rendered template
    if "steamid" in session:
      RUser = Session.query(db.Users).filter(db.Users.steamID == session["steamid"]).first()
      if RUser.Permissions[0].teams:
        c.current = "manage"
        c.managePage = "teams"
        c.user = RUser.to_dict()

        RLeague = Session.query(db.Leagues).filter(db.Leagues.id == leagueID).first()
        RTeams = Session.query(db.Teams).filter(db.Teams.league == leagueID).order_by(db.Teams.id).all()
        RCountries = Session.query(db.Countries).order_by(db.Countries.name).all()

        c.league = RLeague.to_dict()

        c.teams = []
        for RTeam in RTeams:
          team = RTeam.to_dict()
          team["json"] = json.dumps(team)
          c.teams.append(team)
        
        c.countries = []
        for RCountry in RCountries:
          country = {}
          country["id"] = RCountry.id
          country["name"] = RCountry.name
          c.countries.append(country)

        return render('/manage/teams/list.mako')
      else:
        return abort(403)
    else:
      return abort(403)
Ejemplo n.º 11
0
 def index(self):
     # Return a rendered template
     #return render('/inventory.mako')
     # or, return a string
     user = User()
     if user:
         RUser = user[0]
         c.user = user[1]
         c.current = "inventory"
         if not c.user:
           return redirect("http://saloon.tf/home/")
         c.items = {}
         c.items["names"] = ["keys","refs","recs","scraps"]
         c.hasItems = False
         c.items["quantity"] = []
         c.items["quantity"].append(RUser.Items[0].keys)
         if RUser.Items[0].keys > 0:
             c.hasItems = True
         metal = RUser.Items[0].metal
         if metal > 0:
             c.hasItems = True
         c.items["quantity"].append(metal / 9)
         metal -= c.items["quantity"][1] * 9
         c.items["quantity"].append(metal / 3)
         metal -= c.items["quantity"][2] * 3
         c.items["quantity"].append(metal)
         return render('/inventory.mako')
     else:
         return redirect('http://saloon.tf/home/')
Ejemplo n.º 12
0
    def index(self, id):
        # Return a rendered template
        #return render('/bet.mako')
        # or, return a string
        user = User()
        if user:
            c.user = user[1]
        else:
            c.user = False
        c.current = "bet"

        RMatch = db.Session.query(db.Matches).first()
        RItems = db.Session.query(db.Items).all()

        items = {}
        for RItem in RItems:
            items[RItem.assetID] = RItem

        c.match = {}
        c.match = {}
        c.match["id"] = RMatch.id
        c.match["league"] = {}
        c.match["league"]["id"] = RMatch.League.id
        c.match["league"]["name"] = RMatch.League.name
        c.match["league"]["type"] = RMatch.League.type
        c.match["league"]["region"] = RMatch.League.region
        c.match["league"]["colour"] = RMatch.League.colour

        c.match["teams"] = []
        for RTeam in [RMatch.Team1, RMatch.Team2]:
            team = {}
            team["id"] = RTeam.id
            team["name"] = RTeam.name
            team["bets"] = {}
            c.match["teams"].append(team)

        betsTotal = 0
        for team, RBetsTotal in enumerate(
            [RMatch.BetsTotal1, RMatch.BetsTotal2]):
            bets = 0
            bets += RBetsTotal.metal
            for classID in items:
                RItem = items[classID]
                if not RItem.metal:
                    bets += (getattr(RBetsTotal, RItem.name) * RItem.value)
            betsTotal += bets
            c.match["teams"][team]["bets"]["value"] = bets

        if betsTotal > 0:
            for team in c.match["teams"]:
                team["bets"]["percentage"] = int(
                    round(
                        float(team["bets"]["value"]) / float(betsTotal) * 100))
        else:
            for team in c.match["teams"]:
                team["bets"]["percentage"] = 50

        return render('/bet.mako')
Ejemplo n.º 13
0
 def offersReceived(self, botID):
   if "steamid" in session:
     RUser = Session.query(db.Users).filter(db.Users.steamID == session["steamid"]).first()
     if RUser.Permissions[0].economy:
       c.current = "manage"
       c.managePage = "bots"
       c.user = RUser.to_dict()
       RBot = Session.query(db.Bots).filter(db.Bots.id == botID).first()
       if RBot:
         c.bot = RBot.to_dict()
         c.offers = API(RBot.steamAPI, RBot.steamID).GetOffers("received", False, True, False, True)
         for offer in c.offers.values():
           RUser = Session.query(db.Users).filter(db.Users.steamID == int(offer.Partner.steamID)).first()
           offer.user = False
           if RUser:
             offer.user = RUser.to_dict()
         return render("/manage/offers/received.mako")
   return render("/manage/bots/")
Ejemplo n.º 14
0
  def index(self):
    c.current = "tos"
    c.user = False
    if "steamid" in session:
      RUser = Session.query(db.Users).filter(db.Users.steamID == session["steamid"]).first()
      if RUser:
        c.user = RUser.to_dict()

    return render("/tos.mako")
Ejemplo n.º 15
0
    def index(self):
        # Return a rendered template
        #return render('/home.mako')
        # or, return a string
        user = User()
        if user:
          c.user = user[1]
        else:
          c.user = False
        c.current = "home"

        RMatches = db.Session.query(db.Matches).limit(10).all()
        RItems = db.Session.query(db.Items).all()
        
        items = {}
        for RItem in RItems:
          items[RItem.assetID] = RItem

        c.matches = []
        for RMatch in RMatches:
          match = {}
          match["id"] = RMatch.id
          match["league"] = {}
          match["league"]["id"] = RMatch.League.id
          match["league"]["name"] = RMatch.League.name
          match["league"]["type"] = RMatch.League.type
          match["league"]["region"] = RMatch.League.region
          match["league"]["colour"] = RMatch.League.colour

          match["teams"] = []
          for RTeam in [RMatch.Team1, RMatch.Team2]:
            team = {}
            team["id"] = RTeam.id
            team["name"] = RTeam.name
            team["bets"] = {}
            match["teams"].append(team)
          c.matches.append(match)

          betsTotal = 0
          for team, RBetsTotal in enumerate([RMatch.BetsTotal1, RMatch.BetsTotal2]):
            bets = 0
            bets += RBetsTotal.metal
            for classID in items:
              RItem = items[classID]
              if not RItem.metal:
                bets += (getattr(RBetsTotal, RItem.name) * RItem.value)
            betsTotal += bets
            match["teams"][team]["bets"]["value"] = bets

          if betsTotal > 0:
            for team in match["teams"]:
              team["bets"]["percentage"] = int(round(float(team["bets"]["value"]) / float(betsTotal) * 100))
          else:
            for team in match["teams"]:
              team["bets"]["percentage"] = 50

        return render('/home.mako')
Ejemplo n.º 16
0
  def matchesList(self, leagueID):
    # Returns a rendered template
    user = User()
    if user:
      RUser = user[0]
      if RUser.Permissions[0].bets:
        c.user = user[1]
        c.current = "manage"
        c.managePage = "matches"

        RLeague = db.Session.query(db.Leagues).filter(db.Leagues.id == leagueID).first()
        RMatches = db.Session.query(db.Matches).filter(db.Matches.league == leagueID).order_by(db.Matches.id).limit(10).all()
        RTeams = db.Session.query(db.Teams).filter(db.Teams.league == leagueID).order_by(db.Teams.id).all()

        c.league = {}
        c.league["id"] = RLeague.id
        c.league["name"] = RLeague.name
        c.league["type"] = RLeague.type
        c.league["region"] = RLeague.region
        c.league["colour"] = RLeague.colour

        c.matches = []
        for RMatch in RMatches:
          match = {}
          match["id"] = RMatch.id
          match["channel"] = RMatch.Stream.channel
          match["ip"] = RMatch.Stream.ip
          match["port"] = RMatch.Stream.port
          match["logsecret"] = RMatch.Stream.logsecret

          match["team1"] = {}
          match["team1"]["id"] = RMatch.Team1.id
          match["team1"]["name"] = RMatch.Team1.name
          match["team1"]["country"] = RMatch.Team1.Country.name
          match["team1"]["countryID"] = RMatch.Team1.Country.id

          match["team2"] = {}
          match["team2"]["id"] = RMatch.Team2.id
          match["team2"]["name"] = RMatch.Team2.name
          match["team2"]["country"] = RMatch.Team2.Country.name
          match["team2"]["countryID"] = RMatch.Team2.Country.id

          match["json"] = json.dumps(match)
          c.matches.append(match)
        print c.matches
        c.teams = []
        for RTeam in RTeams:
          team = {}
          team["id"] = RTeam.id
          team["name"] = RTeam.name
          c.teams.append(team)

        return render('/manage/matches/list.mako')
      else:
        return redirect('/home/')
    else:
      return redirect('/home/')
Ejemplo n.º 17
0
 def users(self):
   # Returns rendered template
   if "steamid" in session:
     RUser = Session.query(db.Users).filter(db.Users.steamID == session["steamid"]).first()
     if RUser.Permissions[0].users:
       c.current = "manage"
       c.managePage = "users"
       c.user = RUser.to_dict()
       return render('/manage/users/index.mako')
   return redirect("https://saloon.tf/manage/")
Ejemplo n.º 18
0
  def index(self):
    # Return a rendered template
    c.current = "help"
    c.user = False
    if "steamid" in session:
      RUser = Session.query(db.Users).filter(db.Users.steamID == session["steamid"]).first()
      if RUser:
        c.user = RUser.to_dict()

    return render("/help.mako")
Ejemplo n.º 19
0
  def index(self):
    # Return a rendered template
    c.current = "code"
    c.user = False
    if "steamid" in session:
      RUser = Session.query(db.Users).filter(db.Users.steamID == session["steamid"]).first()
      if RUser:
        c.user = RUser.context()

    return render('/code.mako')
Ejemplo n.º 20
0
  def index(self):
    # Return a rendered template
    c.current = "home"
    c.user = False
    if "steamid" in session:
      RUser = Session.query(db.Users).filter(db.Users.steamID == session["steamid"]).first()
      if RUser:
        c.user = RUser.to_dict()

    RMatches = Session.query(db.Matches)\
      .filter(db.Matches.status != 5)\
      .order_by(
        sql.expression.case((
          (db.Matches.status == 1, 0),
          (db.Matches.status == 0, sql.expression.extract('epoch', db.Matches.time))
        )).asc(),
        db.Matches.time.desc(),
        db.Matches.id.desc()
      )\
      .limit(10).all()

    c.matches, c.bets, c.offers = ([],[],[])
    for RMatch in RMatches:
      match = RMatch.to_dict(show=["matches.Team1", "matches.Team2"])
      match["Team1"].update(RMatch.team1Score())
      match["Team2"].update(RMatch.team2Score())
      match["naturalTime"] = RMatch.naturalTime()
      match["json"] = json.dumps(match, default = lambda obj: obj.isoformat() if isinstance(obj, datetime.datetime) else None)
      match["Team1"]["json"] = json.dumps(match["Team1"])
      match["Team2"]["json"] = json.dumps(match["Team2"])
      c.matches.append(match)

      offer = False
      bet = False
      if c.user:
        ROffer = Session.query(db.Offers).filter(and_(db.Offers.status == 2, db.Offers.match == RMatch.id, db.Offers.user == RUser.id, db.Offers.hidden == False)).first()
        if ROffer:
          offer = ROffer.team

        bet = {
          "team": None,
          "own": False,
          "limit": RUser.Rank.slots
        }
        RBet = Session.query(db.Bets).filter(and_(db.Bets.user == RUser.id, db.Bets.match == RMatch.id)).first()
        if RBet:
          bet["team"] = RBet.team
          bet["own"] = True
          RItemsCount = Session.query(func.count(db.ItemsBet.id)).filter(db.ItemsBet.bet == RBet.id).first()
          bet["limit"] -= RItemsCount[0]

      c.bets.append(bet)
      c.offers.append(offer)

    return render('/home.mako')
Ejemplo n.º 21
0
 def index(self, id):
     # Return a rendered template
     #return render('/trade.mako')
     # or, return a string
     RBot = db.Session.query(db.Bots).filter(db.Bots.id == id).first()
     if RBot and RBot.tradeLink:
       c.current = "trade"
       c.user = False
       c.url = RBot.tradeLink
       return render('/trade.mako')
     else:
       return redirect("http://saloon.tf/home/")
Ejemplo n.º 22
0
  def user(self, userID):
    user = User()
    if user:
      RUser = user[0]
      if RUser.Permissions[0].users:
        ROtherUser = db.Session.query(db.Users).filter(db.Users.id == userID).first()
        if ROtherUser:
          if request.POST:
            if int(request.POST["steamid"]) != ROtherUser.steamID:
              url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=%s&steamids=%d" % (config["steamapi"], int(request.POST["steamid"]))
              data = json.loads(requests.get(url).text)[u"response"][u"players"][0]
              ROtherUser.avatar = data[u"avatarfull"][67:-9] + "_full.jpg"
              ROtherUser.name = data[u"personaname"]
              ROtherUser.steamID = request.POST["steamid"]
            if RUser.Permissions[0].permissions:
              for permission in ["manage", "leagues", "teams", "users", "bets", "bots"]:
                if permission not in request.POST.getall("permissions"):
                  setattr(ROtherUser.Permissions[0], permission, False)
                else:
                  setattr(ROtherUser.Permissions[0], permission, True)

            ROtherUser.bot = int(request.POST["botID"])

          c.user = user[1]
          c.otherUser = {}
          c.otherUser["id"] = ROtherUser.id
          c.otherUser["name"] = ROtherUser.name
          c.otherUser["steamid"] = ROtherUser.steamID
          c.otherUser["botID"] = ROtherUser.bot
          c.otherUser["permissions"] = ROtherUser.Permissions[0]

          c.current = "manage"
          c.managePage = "users"

          RBots = db.Session.query(db.Bots).order_by(db.Bots.id).all()
          c.bots = []
          for RBot in RBots:
            bot = {}
            bot["id"] = RBot.id
            bot["name"] = RBot.name
            c.bots.append(bot)

          if request.POST:
            db.Session.commit()

          return render('/manage/users/user.mako')
        else:
          return redirect("/manage/users/")
      else: 
        return redirect("/")
    else: 
      return redirect("/")
Ejemplo n.º 23
0
    def teamsList(self, leagueID):
        # Return a rendered template
        #return render('manage/teams.mako')
        # or, return a string
        user = User()
        if user:
            RUser = user[0]
            if RUser.level <= 3:
                c.user = user[1]
                c.current = "manage"
                c.managePage = "teams"

                RLeague = db.Session.query(
                    db.Leagues).filter(db.Leagues.id == leagueID).first()
                RTeams = db.Session.query(
                    db.Teams).filter(db.Teams.league == leagueID).order_by(
                        db.Teams.id).limit(10).all()
                RCountries = db.Session.query(db.Countries).order_by(
                    db.Countries.name).all()

                c.league = {}
                c.league["id"] = RLeague.id
                c.league["name"] = RLeague.name
                c.league["type"] = RLeague.type
                c.league["region"] = RLeague.region
                c.league["colour"] = RLeague.colour

                c.teams = []
                for RTeam in RTeams:
                    team = {}
                    team["id"] = RTeam.id
                    team["name"] = RTeam.name
                    team["leagueID"] = RTeam.leagueID
                    team["country"] = RTeam.Country.name
                    team["countryID"] = RTeam.Country.id
                    team["json"] = json.dumps(team)
                    c.teams.append(team)

                c.countries = []
                for RCountry in RCountries:
                    country = {}
                    country["id"] = RCountry.id
                    country["name"] = RCountry.name
                    c.countries.append(country)

                return render('/manage/teams/list.mako')
            else:
                return redirect('http://saloon.tf/home/')
        else:
            return redirect('http://saloon.tf/home/')
Ejemplo n.º 24
0
 def index(self):
   # Returns a rendered template
   c.user = False
   if "steamid" in session:
     RUser = Session.query(db.Users).filter(db.Users.steamID == session["steamid"]).first()
     if RUser:
       if RUser.Permissions[0].manage:
         c.current = "manage"
         c.managePage = "dashboard"
         c.user = RUser.to_dict()
         RNotification = Session.query(db.Notifications).first()
         c.notification = RNotification.to_dict()
         return render('/manage/dashboard.mako')
   return abort(403)
Ejemplo n.º 25
0
  def index(self):
    # Return a rendered template
    c.current = "settings"
    c.user = False

    if "steamid" in session:
      RUser = Session.query(db.Users).filter(db.Users.steamID == session["steamid"]).first()
      if RUser:
        c.user = RUser.context()

    if not c.user:
      return redirect("https://saloon.tf/home/")

    return render("settings.mako")
Ejemplo n.º 26
0
 def users(self):
   # Returns rendered template
   user = User()
   if user:
     RUser = user[0]
     if RUser.Permissions[0].users:
       c.user = user[1]
       c.current = "manage"
       c.managePage = "users"
       return render('/manage/users/index.mako')
     else:
       return redirect("/")
   else:
     return redirect("/")
Ejemplo n.º 27
0
 def index(self):
   # Returns a rendered template
   user = User()
   if user:
     RUser = user[0]
     if RUser.Permissions[0].manage:
       c.user = user[1]
       c.current = "manage"
       c.managePage = "dashboard"
       return render('/manage/dashboard.mako')
     else:
       return redirect('/home/')
   else:
     return redirect('/home/')
Ejemplo n.º 28
0
 def index(self):
     # Return a rendered template
     #return render('/manage.mako')
     # or, return a string
     user = User()
     if user:
         RUser = user[0]
         if RUser.level <= 3:
             c.user = user[1]
             c.current = "manage"
             c.managePage = "dashboard"
             return render('/manage/dashboard.mako')
         else:
             return redirect('http://saloon.tf/home/')
     else:
         return redirect('http://saloon.tf/home/')
Ejemplo n.º 29
0
  def matchesLeagues(self):
    # Returns a rendered template
    if "steamid" in session:
      RUser = Session.query(db.Users).filter(db.Users.steamID == session["steamid"]).first()
      if RUser.Permissions[0].bets:
        c.current = "manage"
        c.managePage = "matches"
        c.user = RUser.to_dict()

        RLeagues = Session.query(db.Leagues).order_by(db.Leagues.id).all()
        c.leagues = []
        for RLeague in RLeagues:
          league = RLeague.to_dict()
          league["json"] = json.dumps(league)
          c.leagues.append(league)
        return render('/manage/matches/index.mako')
    return abort(403)
Ejemplo n.º 30
0
  def scores(self):
    user = User()
    if user:
      RUser = user[0]
      if RUser.Permissions[0].users:
        c.current = "manage"
        c.managePage = "scores"
        c.user = user[1]
        c.matches = []
        RMatches = db.Session.query(db.Matches).order_by(db.Matches.id.desc()).limit(10).all()

        for RMatch in RMatches:
          match = {}
          match["id"] = RMatch.id
          match["channel"] = RMatch.Stream.channel
          match["status"] = RMatch.status
          match["status"] = RMatch.status
          match["ip"] = RMatch.Stream.ip
          match["port"] = RMatch.Stream.port
          match["logsecret"] = RMatch.Stream.logsecret

          match["team1"] = {}
          match["team1"]["id"] = RMatch.Team1.id
          match["team1"]["name"] = RMatch.Team1.name
          match["team1"]["short"] = RMatch.Team1.short
          match["team1"]["points"] = RMatch.points1
          match["team1"]["country"] = RMatch.Team1.Country.name
          match["team1"]["countryID"] = RMatch.Team1.Country.id

          match["team2"] = {}
          match["team2"]["id"] = RMatch.Team2.id
          match["team2"]["name"] = RMatch.Team2.name
          match["team2"]["short"] = RMatch.Team2.short
          match["team2"]["points"] = RMatch.points2
          match["team2"]["country"] = RMatch.Team2.Country.name
          match["team2"]["countryID"] = RMatch.Team2.Country.id

          match["json"] = json.dumps(match)
          c.matches.append(match)

        return render('/manage/scores.mako')
      else:
        return redirect("/manage/")
    else: 
      return redirect("/")
Ejemplo n.º 31
0
  def teamsList(self, leagueID):
    # Returns a rendered template
    user = User()
    if user:
      RUser = user[0]
      if RUser.Permissions[0].teams:
        c.user = user[1]
        c.current = "manage"
        c.managePage = "teams"

        RLeague = db.Session.query(db.Leagues).filter(db.Leagues.id == leagueID).first()
        RTeams = db.Session.query(db.Teams).filter(db.Teams.league == leagueID).order_by(db.Teams.id).limit(10).all()
        RCountries = db.Session.query(db.Countries).order_by(db.Countries.name).all()

        c.league = {}
        c.league["id"] = RLeague.id
        c.league["name"] = RLeague.name
        c.league["type"] = RLeague.type
        c.league["region"] = RLeague.region
        c.league["colour"] = RLeague.colour

        c.teams = []
        for RTeam in RTeams:
          team = {}
          team["id"] = RTeam.id
          team["name"] = RTeam.name
          team["leagueID"] = RTeam.leagueID
          team["country"] = RTeam.Country.name
          team["countryID"] = RTeam.Country.id
          team["json"] = json.dumps(team)
          c.teams.append(team)
        
        c.countries = []
        for RCountry in RCountries:
          country = {}
          country["id"] = RCountry.id
          country["name"] = RCountry.name
          c.countries.append(country)

        return render('/manage/teams/list.mako')
      else:
        return redirect('/home/')
    else:
      return redirect('/home/')
Ejemplo n.º 32
0
  def index(self, categoryID = False, topic = False):
    # Return a rendered template
    c.current = "support"
    c.success = False
    c.user = False
    if "steamid" in session:
      RUser = Session.query(db.Users).filter(db.Users.steamID == session["steamid"]).first()
      if RUser:
        c.user = RUser.to_dict()

    if not c.user:
      return abort(403)

    c.category = categoryID
    c.topic = topic
    if c.topic:
      c.topic = c.topic.replace("+", " ")

    return render("/support.mako")
Ejemplo n.º 33
0
  def bots(self):
    if "steamid" in session:
      RUser = Session.query(db.Users).filter(db.Users.steamID == session["steamid"]).first()
      if RUser.Permissions[0].bots:
        c.current = "manage"
        c.managePage = "bots"
        c.user = RUser.to_dict()
        c.bots = []
        RBots = Session.query(db.Bots).order_by(db.Bots.id).all()

        for RBot in RBots:
          bot = RBot.to_dict()
          bot["json"] = json.dumps(bot)
          c.bots.append(bot)

        return render('/manage/bots.mako')
      else:
        return redirect("https://saloon.tf/manage/")
    else: 
      return redirect("https://saloon.tf/")
Ejemplo n.º 34
0
    def leagues(self):
        # Return a rendered template
        #return render('/manage.mako')
        # or, return a string
        user = User()
        if user:
            RUser = user[0]
            if RUser.level <= 3:
                c.user = user[1]
                c.current = "manage"
                c.managePage = "leagues"

                RLeagues = db.Session.query(db.Leagues).order_by(
                    db.Leagues.id).limit(10).all()
                c.leagues = []
                for RLeague in RLeagues:
                    league = {}
                    league["id"] = RLeague.id
                    league["name"] = RLeague.name
                    league["type"] = RLeague.type
                    league["region"] = RLeague.region
                    league["colour"] = RLeague.colour
                    league["json"] = json.dumps(league)
                    c.leagues.append(league)

                if hasattr(session, "failed"):
                    c.failed = True
                    c.action = session.action
                    c.message = session.message
                    c.name = session.name
                    c.type = session.type
                    c.region = session.region
                    c.accentColour = session.accentColour

                return render('/manage/leagues.mako')
            else:
                return redirect('http://saloon.tf/home/')
        else:
            return redirect('http://saloon.tf/home/')
Ejemplo n.º 35
0
  def leagues(self):
    # Returns a rendered template
    user = User()
    if user:
      RUser = user[0]
      if RUser.Permissions[0].leagues:
        c.user = user[1]
        c.current = "manage"
        c.managePage = "leagues"

        RLeagues = db.Session.query(db.Leagues).order_by(db.Leagues.id).limit(10).all()
        c.leagues = []
        for RLeague in RLeagues:
          league = {}
          league["id"] = RLeague.id
          league["name"] = RLeague.name
          league["type"] = RLeague.type
          league["region"] = RLeague.region
          league["colour"] = RLeague.colour
          league["json"] = json.dumps(league)
          c.leagues.append(league)

        if hasattr(session, "failed"):
          c.failed = True
          c.action = session.action
          c.message = session.message
          c.name = session.name
          c.type = session.type
          c.region = session.region
          c.accentColour = session.accentColour

        return render('/manage/leagues.mako')
      else:
        return redirect('/home/')
    else:
      return redirect('/home/')
Ejemplo n.º 36
0
 def index(self):
     return render('/placeholder.mako')
Ejemplo n.º 37
0
  def index(self, matchID):
    # Return a rendered template
    c.current = "match"
    c.user = False
    if "steamid" in session:
      RUser = Session.query(db.Users).filter(db.Users.steamID == session["steamid"]).first()
      if RUser:
        c.user = RUser.to_dict()

    RMatch, RWriteup = Session.query(db.Matches, db.Writeups).join(db.Writeups).filter(db.Matches.id == matchID).first()
    c.match = RMatch.to_dict(show=["matches.Team1", "matches.Team2"])
    c.match["Team1"].update(RMatch.team1Score())
    c.match["Team2"].update(RMatch.team2Score())
    c.match["naturalTime"] = RMatch.naturalTime()
    c.match["json"] = json.dumps(c.match, default = lambda obj: obj.isoformat() if isinstance(obj, datetime.datetime) else None)
    c.match["Team1"]["json"] = json.dumps(c.match["Team1"])
    c.match["Team2"]["json"] = json.dumps(c.match["Team2"])

    c.offers = []
    c.offer = False
    c.bet = False
    if c.user:
      # ROffers = Session.query(db.Offers).filter(and_(db.Offers.user == RUser.id, db.Offers.match == matchID, db.Offers.offerID > 0, db.Offers.hidden == False)).order_by(db.Offers.id.desc()).all()
      # for ROffer in ROffers:
      #   if ROffer.status == 2:
      #     c.offer = ROffer.team
      #   offer = ROffer.to_dict()
      #   offer["typeText"] = ROffer.typeText()
      #   offer["statusText"] = ROffer.statusText()
      #   c.offers.append(offer)

      c.bet = {
        "team": None,
        "own": False,
        "limit": RUser.Rank.slots
      }

      RBet = Session.query(db.Bets).filter(and_(db.Bets.user == RUser.id, db.Bets.match == RMatch.id)).first()
      if RBet:
        c.bet = RBet.to_dict()
        if RBet.team == RMatch.team1:
          c.bet["Team"] = c.match["Team1"]
        else:
          c.bet["Team"] = c.match["Team2"]
        c.bet["User"] = c.user
        c.bet["own"] = True

        RItemsBet = Session.query(db.ItemsInstances, db.ItemsBet) \
          .distinct(db.ItemsInstances.originID) \
          .filter(db.ItemsBet.bet == RBet.id, db.ItemsBet.itemInstance == db.ItemsInstances.id) \
          .all()

        RItemsBet = sorted(RItemsBet, key = lambda x: (x[1].origin * -1, x[0].Item.type, x[0].Item.quality, x[0].Item.value * -1))

        c.bet["items"] = []
        c.bet["limit"] = RUser.Rank.slots
        for RItemInstance, RItemBet in RItemsBet:
          if RItemBet.bet != RBet.id:
            continue

          item = RItemInstance.to_dict(show=["itemsinstances.Item"])
          item["origin"] = RItemBet.origin
          c.bet["items"].append(item)
          c.bet["limit"] -= 1

    c.writeup = False
    if RWriteup.text:
      c.writeup = RWriteup.to_dict()

    return render('/match.mako')