Commit efbf04ba authored by Antoine Lima's avatar Antoine Lima

Replaced pic_path by login in db

parent e4d68ae3
...@@ -75,7 +75,7 @@ class Database(): ...@@ -75,7 +75,7 @@ class Database():
self._connection.commit() self._connection.commit()
def delete_playerpic(self, playerID): def delete_playerpic(self, playerID):
self._cursor.execute('UPDATE Players SET pic=null WHERE id==?', (playerID,)) self._cursor.execute('UPDATE Players SET login=null WHERE id==?', (playerID,))
self._connection.commit() self._connection.commit()
def make_player_private(self, playerID): def make_player_private(self, playerID):
......
...@@ -57,19 +57,23 @@ class ConsentDialog(QDialog): ...@@ -57,19 +57,23 @@ class ConsentDialog(QDialog):
self.reject() self.reject()
class Player(QObject): class Player(QObject):
__query_infos = 'SELECT id, fname, lname, pic FROM Players WHERE rfid==?' __query_infos = 'SELECT id, login, fname, lname FROM Players WHERE rfid==?'
__query_time_goals_games = 'SELECT SUM(Matchs.duration) AS timePlayed, SUM(Teams.nGoals) AS goalsScored, COUNT(*) AS gamesPlayed FROM Teams INNER JOIN Matchs ON (Teams.id==Matchs.winningTeam OR Teams.id==Matchs.losingTeam) WHERE (Teams.player1==? OR player2==?)' __query_time_goals_games = 'SELECT SUM(Matchs.duration) AS timePlayed, SUM(Teams.nGoals) AS goalsScored, COUNT(*) AS gamesPlayed FROM Teams INNER JOIN Matchs ON (Teams.id==Matchs.winningTeam OR Teams.id==Matchs.losingTeam) WHERE (Teams.player1==? OR player2==?)'
__query_victories = 'SELECT COUNT(*) AS victories FROM Players INNER JOIN Teams ON (Players.id==Teams.player1 OR Players.id==Teams.player2) INNER JOIN Matchs ON (Teams.id==Matchs.winningTeam) WHERE Players.id==?' __query_victories = 'SELECT COUNT(*) AS victories FROM Players INNER JOIN Teams ON (Players.id==Teams.player1 OR Players.id==Teams.player2) INNER JOIN Matchs ON (Teams.id==Matchs.winningTeam) WHERE Players.id==?'
_placeholder_pic_path = ':ui/img/placeholder_head.jpg' _placeholder_pic_path = ':ui/img/placeholder_head.jpg'
def __init__(self, id, rfid, fname, lname, pic_path, stats): def __init__(self, id, rfid, login, fname, lname, stats=None):
def __init__(self, id, rfid, fname, lname, pic_path, stats=None): QObject.__init__(self)
self.id = id self.id = id
self.rfid = rfid self.rfid = rfid
self.login = login
self.fname = fname self.fname = fname
self.lname = lname self.lname = lname
self.pic_path = pic_path if pic_path else Player._placeholder_pic_path # Default pic if None
self.pic_path = Player._placeholder_pic_path
if self.login:
self.pic_path = Player._utcPictureURL.format(self.login)
if stats==None: if stats==None:
self.stats = { 'time_played': 0, 'goals_scored': 0, 'games_played': 0, 'victories': 0 } self.stats = { 'time_played': 0, 'goals_scored': 0, 'games_played': 0, 'victories': 0 }
...@@ -89,7 +93,7 @@ class Player(QObject): ...@@ -89,7 +93,7 @@ class Player(QObject):
if consentDialog.result()==QDialog.Accepted: if consentDialog.result()==QDialog.Accepted:
player = Player._loadFromAPI(rfid) player = Player._loadFromAPI(rfid)
else: else:
logging.debug('Consent refused when retrieving a player, returning Guest') logging.info('Consent refused when retrieving a player, returning Guest')
player = PlayerGuest player = PlayerGuest
return player return player
...@@ -100,7 +104,7 @@ class Player(QObject): ...@@ -100,7 +104,7 @@ class Player(QObject):
db = Database.instance() db = Database.instance()
try: try:
# Retrieve generic informations # Retrieve generic informations
id, fname, lname, pic = db.select_one(Player.__query_infos, rfid) id, login, fname, lname = db.select_one(Player.__query_infos, rfid)
# Retrieve stats # Retrieve stats
stats = {} stats = {}
...@@ -111,7 +115,7 @@ class Player(QObject): ...@@ -111,7 +115,7 @@ class Player(QObject):
if val==None: if val==None:
stats[key] = 0 stats[key] = 0
return Player(id, rfid, fname, lname, pic, stats) return Player(id, rfid, login, fname, lname, stats)
except DatabaseError as e: except DatabaseError as e:
logging.warn('DB Error: {}'.format(e)) logging.warn('DB Error: {}'.format(e))
...@@ -128,7 +132,7 @@ class Player(QObject): ...@@ -128,7 +132,7 @@ class Player(QObject):
return PlayerGuest return PlayerGuest
else: else:
infos = json.loads(response) infos = json.loads(response)
Database.instance().insert_player(infos['rfid'], infos['nom'], infos['prenom']) Database.instance().insert_player(infos['rfid'], infos['login'], infos['nom'], infos['prenom'])
return Player._loadFromDB(rfid) return Player._loadFromDB(rfid)
...@@ -153,6 +157,7 @@ class Player(QObject): ...@@ -153,6 +157,7 @@ class Player(QObject):
def forgetPicture(self): def forgetPicture(self):
self.pic_path = Player._placeholder_pic_path self.pic_path = Player._placeholder_pic_path
self.login = None
Database.instance().delete_playerpic(self.id) Database.instance().delete_playerpic(self.id)
def make_private(self): def make_private(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment