Example #1
0
 def update_team(self, team_id, data):
     data = util.clean_query_input(data, "Teams", set_nulls=False)
     for key in data:
         self.db.query('''update Teams set
             {} = {}
             where team_id = {}'''.format(
             key, data[key], team_id))
Example #2
0
    def set_pool(self, data):
        pool_id = None  # keeping this variable in case we need it later
        data = util.clean_query_input(data, "Pools")

        if pool_id is None:
            query = '''insert into Pools(
                league_id,
                day,
                pool_time,
                max_size)
                values (
                {}, \"{}\", \"{}\", {})'''.format(data['league_id'],
                                                  data['day'],
                                                  data['pool_time'],
                                                  data['max_size'])
            self.db.query(query)
        else:
            self.db.query('''update Pools set
                league_id = {},
                day = {},
                pool_time = {},
                max_size = {}
                where pool_id = {}'''.format(data['league_id'],
                                             data['pool_time'],
                                             data['max_size'], pool_id))

        self.db.query('select last_insert_id()')
        r = self.db.store_result()
        return util.get_dict_from_query(r.fetch_row(how=1))['last_insert_id()']
Example #3
0
 def update_user(self, user_id, data):
     data = util.clean_query_input(data, "Users", set_nulls=False)
     for key in data:
         query = '''update Users set
             {} = {}
             where user_id = {}'''.format(key, data[key], user_id)
         self.db.query(query)
Example #4
0
    def set_user(self, data):
        user_id = None  # keeping this variable in case we need it later
        pass_hash = hashlib.sha256()
        pass_hash.update(data['pass_hash'].encode(encoding='ascii'))
        pass_hash = pass_hash.digest().hex()
        data['pass_hash'] = pass_hash
        data = util.clean_query_input(data, "Users")

        if user_id is None:
            self.db.query('''insert into Users(
                pass_hash,
                netid,
                email,
                first_name,
                last_name,
                is_undergrad,
                is_admin,
                gender,
                residence_hall,
                wins,
                losses,
                ties) values (
                {},{},{},{},{},{},{},{},{},{},{},{})'''.format(
                data['pass_hash'], data['netid'], data['email'],
                data['first_name'], data['last_name'], data['is_undergrad'],
                data['is_admin'], data['gender'], data['residence_hall'],
                data['wins'], data['losses'], data['ties']))
        #else:
        #    self.db.query('''update Users set
        #        pass_hash = {},
        #        netid = {},
        #        email = {},
        #        first_name = {},
        #        last_name = {},
        #        is_undergrad = {},
        #        is_admin = {},
        #        gender = {},
        #        residence_hall = {},
        #        wins = {},
        #        losses = {},
        #        ties = {}
        #        where user_id = {}'''.format(
        #        data['pass_hash'],
        #        data['netid'],
        #        data['email'],
        #        data['first_name'],
        #        data['last_name'],
        #        data['is_undergrad'],
        #        data['is_admin'],
        #        data['gender'],
        #        data['residence_hall'],
        #        data['wins'],
        #        data['losses'],
        #        data['ties'],
        #        user_id))

        self.db.query('select last_insert_id()')
        r = self.db.store_result()
        return util.get_dict_from_query(r.fetch_row(how=1))['last_insert_id()']
Example #5
0
    def set_sport(self, data):
        sport_id = None  # keeping this variable in case we need it later
        data = util.clean_query_input(data, "Sports")

        if sport_id is None:
            self.db.query('''insert into Sports(
				name) values (
				{})'''.format(data['name']))
        else:
            self.db.query('''update Sports set
				name = {}
				where sport_id = {}'''.format(data['name'], sport_id))

        self.db.query('select last_insert_id()')
        r = self.db.store_result()
        return util.get_dict_from_query(r.fetch_row(how=1))['last_insert_id()']
Example #6
0
    def set_team(self, data):
        team_id = None # keeping this variable in case we need it later
        data = util.clean_query_input(data, "Teams")

        if team_id is None:
            self.db.query('''insert into Teams(
                league_id,
                pool_id,
                name,
                wins,
                losses,
                ties,
                max_members) values (
                {},{},{},{},{},{},{})'''.format(
                data['league_id'],
                data['pool_id'],
                data['name'],
                data['wins'],
                data['losses'],
                data['ties'],
                data['max_members']))
        else:
            self.db.query('''update Teams set
                league_id = {},
                pool_id = {},
                name = {},
                wins = {},
                losses = {},
                ties = {},
                max_members = {}
                where team_id = {}'''.format(
                data['league_id'],
                data['pool_id'],
                data['name'],
                data['wins'],
                data['losses'],
                data['ties'],
                data['max_members'],
                team_id))

        self.db.query('select last_insert_id()')
        r = self.db.store_result()
        return util.get_dict_from_query(r.fetch_row(how=1))['last_insert_id()']
Example #7
0
    def set_league(self, data):
        league_id = None  # keeping this variable in case we need it later
        data = util.clean_query_input(data, "Leagues")

        # TODO: update sport id to grab from page rather than hard-coding in 1
        if league_id is None:
            self.db.query('''insert into Leagues(
                sport_id,
                name,
                start_time,
                end_time,
                team_size) 
                values (
                {},\"{}\",\"{}\",\"{}\",{})'''.format(
                #data['sport_id'],
                1,
                data['leagueName'],
                data['startDate'],
                data['endDate'],
                #data['team_size']))
                10))
        else:
            self.db.query('''update Leagues set 
                sport_id = {},
                name = {},
                start_time = {},
                end_time = {},
                team_size = {}
                where league_id = {}'''.format(data['sport_id'], data['name'],
                                               data['start_time'],
                                               data['end_time'],
                                               data['team_size'], league_id))

        self.db.query('select last_insert_id()')
        r = self.db.store_result()
        return util.get_dict_from_query(r.fetch_row(how=1))['last_insert_id()']
Example #8
0
 def update_league(self, league_id, data):
     data = util.clean_query_input(data, "Leagues", set_nulls=False)
     for key in data:
         self.db.query('''update Leagues set
             {} = {}
             where league_id = {}'''.format(key, data[key], league_id))
Example #9
0
 def update_pool(self, pool_id, data):
     data = util.clean_query_input(data, "Pools", set_nulls=False)
     for key in data:
         self.db.query('''update Pools set
             {} = {}
             where pool_id = {}'''.format(key, data[key], pool_id))
Example #10
0
    def update_sport(self, sport_id, data):
        data = util.clean_query_input(data, "Sports", set_nulls=False)
        for key in data:
            self.db.query('''update Sports set
				{} = {}
				where sport_id = {}'''.format(key, data[key], sport_id))