Example #1
0
 def editTeam(self, leagueID, teamID):
     # Return a rendered template
     #return render('/manage.mako')
     # or, return a string
     user = User()
     if user:
         RUser = user[0]
         if RUser.level <= 3:
             RTeam = db.Session.query(
                 db.Teams).filter(db.Teams.id == teamID).first()
             if (RTeam):
                 RTeam.name = request.params["name"]
                 RTeam.country = request.params["country"]
                 RTeam.league = leagueID,
                 RTeam.leagueID = request.params["leagueID"]
                 db.Session.commit()
                 success = True
                 message = "Changed selected league."
             else:
                 success = False
                 message = "<strong>Oh snap!</strong> Couldn't edit this team."
         else:
             success = False
             message = "You don't have sufficent priviledges to access this page."
     else:
         success = False
         message = "You don't have sufficent priviledges to access this page."
     array = {"success": success, "message": message}
     return json.dumps(array)
Example #2
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/')
Example #3
0
    def removeTeam(self, leagueID, teamID):
        # Return a rendered template
        #return render('/manage.mako')
        # or, return a string
        user = User()
        if user:
            RUser = user[0]
            if RUser.level <= 3:
                RTeam = db.Session.query(
                    db.Teams).filter(db.Teams.id == teamID).first()
                if RTeam:
                    RMatch = db.Session.query(db.Matches).filter(
                        db.or_(db.Matches.team1 == teamID,
                               db.Matches.team2 == teamID)).first()
                    if RMatch:
                        success = False
                        message = "<strong>Oh snap!</strong> I can't remove a team with matches."
                    else:
                        db.Session.delete(RTeam)
                        db.Session.commit()
                        success = True
                        message = "Removed selected team."
                else:
                    success = False
                    message = "<strong>Oh snap!</strong> Couldn't remove this team."
            else:
                success = False
                message = "You don't have sufficent priviledges to access this page."
        else:
            success = False
            message = "You don't have sufficent priviledges to access this page."

        array = {"success": success, "message": message}
        return json.dumps(array)
Example #4
0
 def editLeague(self, id):
     # Return a rendered template
     #return render('/manage.mako')
     # or, return a string
     user = User()
     if user:
         RUser = user[0]
         if RUser.level <= 3:
             RLeague = db.Session.query(
                 db.Leagues).filter(db.Leagues.id == id).first()
             print request.params
             if RLeague:
                 RLeague.name = request.params["name"]
                 RLeague.type = request.params["type"]
                 RLeague.region = request.params["region"]
                 RLeague.colour = request.params["accentColour"]
                 db.Session.commit()
                 success = True
                 message = "Changed selected league."
             else:
                 success = False
                 message = "<strong>Oh snap!</strong> Couldn't change this league."
     else:
         success = False
         message = "You don't have sufficent priviledges to access this page."
     array = {"success": success, "message": message}
     return json.dumps(array)
Example #5
0
    def addTeam(self, leagueID):
        # Return a rendered template
        #return render('/manage.mako')
        # or, return a string
        user = User()
        if user:
            RUser = user[0]
            if RUser.level <= 3:
                RTeam = db.Teams(name=request.params["name"],
                                 country=request.params["country"],
                                 league=leagueID,
                                 leagueID=request.params["leagueID"])
                db.Session.add(RTeam)
                db.Session.commit()

                avatar = request.params["avatar"].file
                avatar_path = os.path.join('website/public/images/teams',
                                           str(RTeam.id) + '.jpg')
                print avatar_path
                temp_path = avatar_path + '~'
                output_file = open(temp_path, 'wb')
                avatar.seek(0)
                while True:
                    data = avatar.read(2 << 16)
                    if not data:
                        break
                    output_file.write(data)
                output_file.close()
                os.rename(temp_path, avatar_path)
                return redirect("/manage/teams/" + leagueID)
            else:
                return redirect("/")
        else:
            return redirect("/")
Example #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/')
Example #7
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')
Example #8
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/')
Example #9
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/')
Example #10
0
    def addLeague(self):
        # Return a rendered template
        #return render('/manage.mako')
        # or, return a string
        user = User()
        if user:
            RUser = user[0]
            if RUser.level <= 3:
                params = ["name", "type", "region", "avatar", "accentColour"]
                if all(item in request.params for item in params):
                    if request.params["avatar"].filename[-4:] != ".png":
                        success = False
                        message = "Wrong file type."
                    else:
                        RLeague = db.Leagues(
                            name=request.params["name"],
                            type=request.params["type"],
                            region=request.params["region"],
                            colour=request.params["accentColour"])
                        db.Session.add(RLeague)
                        db.Session.commit()
                        os.makedirs("website/public/images/leagues/" +
                                    str(RLeague.id))

                        avatar = request.params["avatar"].file
                        avatar_path = os.path.join(
                            'website/public/images/leagues', str(RLeague.id),
                            'logo.png')
                        print avatar_path
                        temp_path = avatar_path + '~'
                        output_file = open(temp_path, 'wb')
                        avatar.seek(0)
                        while True:
                            data = avatar.read(2 << 16)
                            if not data:
                                break
                            output_file.write(data)
                        output_file.close()
                        os.rename(temp_path, avatar_path)
                        return redirect("/manage/leagues")
                else:
                    return redirect("/manage/leagues")
            else:
                return redirect("/")
        else:
            return redirect("/")
Example #11
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/')
Example #12
0
 def removeLeague(self, id):
     # Return a rendered template
     #return render('/manage.mako')
     # or, return a string
     user = User()
     if user:
         RUser = user[0]
         if RUser.level <= 3:
             RLeague = db.Session.query(
                 db.Leagues).filter(db.Leagues.id == id).first()
             if RLeague:
                 db.Session.delete(RLeague)
                 db.Session.commit()
                 success = True
                 message = "Removed selected league."
             else:
                 success = False
                 message = "<strong>Oh snap!</strong> Couldn't remove this league."
     else:
         success = False
         message = "You don't have sufficent priviledges to access this page."
     array = {"success": success, "message": message}
     return json.dumps(array)