Skip to content

Commit

Permalink
Fixed handling of inactive users in Elo list
Browse files Browse the repository at this point in the history
  • Loading branch information
vthorsteinsson committed Apr 7, 2015
1 parent e97d58a commit 2ae8acf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
7 changes: 6 additions & 1 deletion netskrafl.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ def _rating(kind):
break
is_robot = False
usr = None
inactive = False
if uid.startswith(u"robot-"):
is_robot = True
nick = Game.autoplayer_name(int(uid[6:]))
Expand All @@ -413,13 +414,16 @@ def _rating(kind):
fairplay = False
else:
usr = User.load(uid)
if usr is None or not usr.is_displayable():
if usr is None:
# Something wrong with this one: don't bother
continue
nick = usr.nickname()
if not User.is_valid_nick(nick):
nick = u"--"
fullname = usr.full_name()
chall = uid in challenges
fairplay = usr.fairplay()
inactive = usr.is_inactive()

games = ru["games"]
if games == 0:
Expand All @@ -440,6 +444,7 @@ def _rating(kind):
"fullname": fullname,
"chall": chall,
"fairplay": fairplay,
"inactive": inactive,

"elo": ru["elo"],
"elo_yesterday": ru["elo_yesterday"],
Expand Down
4 changes: 4 additions & 0 deletions skraflgame.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ def is_valid_nick(nick):
return False
return nick[0:8] != u"https://" and nick[0:7] != u"http://"

def is_inactive(self):
""" Return True if the user is marked as inactive """
return self._inactive

def is_displayable(self):
""" Returns True if this user should appear in user lists """
if self._inactive:
Expand Down
18 changes: 9 additions & 9 deletions static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,12 @@ function populateEloList(json) {
var item = json.rating[i];
// Robot userids start with 'robot-'
var isRobot = item.userid.indexOf("robot-") === 0;
var chId = "chall" + i.toString();
var chId = "chall" + i;
var ch = "";
var nick = escapeHtml(item.nick);
var info = "";
if (item.userid != userId())
// Not the logged-in user himself: allow a challenge
if (item.userid != userId() && !item.inactive)
// Not the logged-in user himself and not inactive: allow a challenge
ch = "<span title='Skora á' class='glyphicon glyphicon-hand-right" +
(item.chall ? "'" : " grayed'") +
" id='" + chId + "'></span>";
Expand All @@ -347,7 +347,7 @@ function populateEloList(json) {
}
else {
// Create a link to access user info
info = "<span id='usr" + i.toString() + "' class='usr-info'></span>";
info = "<span id='usr" + i + "' class='usr-info'></span>";
}
// Fair play commitment
if (item.fairplay)
Expand All @@ -361,19 +361,19 @@ function populateEloList(json) {
"<span class='list-rank'>" + rankStr(item.rank_yesterday) + "</span>" +
"<span class='list-rank'>" + rankStr(item.rank_week_ago) + "</span>" +
"<span class='list-nick'>" + nick + "</span>" +
"<span class='list-elo bold'>" + item.elo.toString() + "</span>" +
"<span class='list-elo bold'>" + item.elo + "</span>" +
"<span class='list-elo'>" + rankStr(item.elo_yesterday, item.games_yesterday) + "</span>" +
"<span class='list-elo'>" + rankStr(item.elo_week_ago, item.games_week_ago) + "</span>" +
"<span class='list-elo'>" + rankStr(item.elo_month_ago, item.games_month_ago) + "</span>" +
"<span class='list-games bold'>" + item.games.toString() + "</span>" +
"<span class='list-ratio'>" + item.ratio.toString() + "%</span>" +
"<span class='list-avgpts'>" + item.avgpts.toString() + "</span>" +
"<span class='list-games bold'>" + item.games + "</span>" +
"<span class='list-ratio'>" + item.ratio + "%</span>" +
"<span class='list-avgpts'>" + item.avgpts + "</span>" +
info +
"</div>";
$("#userlist").append(str);
// Associate a click handler with the info button, if present
if (info.length)
$("#usr" + i.toString()).click(
$("#usr" + i).click(
{ userid: item.userid, nick: item.nick, fullname: item.fullname },
showUserInfo
);
Expand Down

0 comments on commit 2ae8acf

Please sign in to comment.