]> de.git.xonotic.org Git - xonotic/xonstat.git/blobdiff - xonstat/models/player.py
Get rid of joined_pretty_date in favor of the mixin.
[xonotic/xonstat.git] / xonstat / models / player.py
index 0fb18d878634592c5e2d8e87dd3ef663b88a4c56..d9df0759d628a8d3bbb06a30dfcc9fa745e442f6 100644 (file)
@@ -4,29 +4,21 @@ Models related to players.
 
 from calendar import timegm
 
-from xonstat.util import html_colors, strip_colors, pretty_date, qfont_decode
+from xonstat.models.mixins import FuzzyDateMixin, EpochMixin, NickColorsMixin
+from xonstat.util import strip_colors, pretty_date, qfont_decode
 
 
-class Player(object):
+class Player(EpochMixin, NickColorsMixin, FuzzyDateMixin):
     """
     A player, which can represent either a human or a bot.
     """
 
-    def nick_html_colors(self, limit=None):
-        if self.nick is None:
-            return "Anonymous Player"
-        else:
-            return html_colors(self.nick, limit)
-
     def nick_strip_colors(self):
         if self.nick is None:
             return "Anonymous Player"
         else:
             return strip_colors(self.nick)
 
-    def joined_pretty_date(self):
-        return pretty_date(self.create_dt)
-
     def __repr__(self):
         return "<Player({}, {})>".format(self.player_id, self.nick.encode('utf-8'))
 
@@ -40,9 +32,6 @@ class Player(object):
             'stripped_nick': qfont_decode(self.stripped_nick),
         }
 
-    def epoch(self):
-        return timegm(self.create_dt.timetuple())
-
 
 class Achievement(object):
     """
@@ -50,7 +39,7 @@ class Achievement(object):
     """
 
     def __repr__(self):
-        return "<Achievement({}, {}, {})>".format(self.achievement_cd, self.descr, self.limit)
+        return "<Achievement({0.achievement_cd}, {0.descr}, {0.limit})>".format(self)
 
     def to_dict(self):
         return {
@@ -66,7 +55,7 @@ class PlayerAchievement(object):
     """
 
     def __repr__(self):
-        return "<PlayerAchievement({}, {})>".format(self.player_id, self.achievement_cd)
+        return "<PlayerAchievement({0.player_id}, {0.achievement_cd})>".format(self)
 
     def to_dict(self):
         return {
@@ -85,7 +74,7 @@ class Hashkey(object):
         self.hashkey = hashkey
 
     def __repr__(self):
-        return "<Hashkey({}, {})>".format(self.player_id, self.hashkey)
+        return "<Hashkey({0.player_id}, {0.hashkey})>".format(self)
 
     def to_dict(self):
         return {
@@ -100,7 +89,7 @@ class PlayerNick(object):
     """
 
     def __repr__(self):
-        return "<PlayerNick({}, {})>".format(self.player_id, qfont_decode(self.stripped_nick))
+        return "<PlayerNick({0.player_id}, {0.stripped_nick})>".format(self)
 
     def to_dict(self):
         return {
@@ -122,8 +111,8 @@ class PlayerElo(object):
         self.games = 0
 
     def __repr__(self):
-        return ("<PlayerElo(pid={}, gametype={}, elo={}, games={})>"
-                .format(self.player_id, self.game_type_cd, self.elo, self.games))
+        return ("<PlayerElo(pid={0.player_id}, gametype={0.game_type_cd}, elo={0.elo}, "
+                "games={0.games})>".format(self))
 
     def to_dict(self):
         return {
@@ -134,20 +123,14 @@ class PlayerElo(object):
         }
 
 
-class PlayerRank(object):
+class PlayerRank(NickColorsMixin):
     """
     A player's rank for a given game type.
     """
 
-    def nick_html_colors(self, limit=None):
-        if self.nick is None:
-            return "Anonymous Player"
-        else:
-            return html_colors(self.nick, limit)
-
     def __repr__(self):
-        return ("<PlayerRank(pid={}, gametype={}, rank={})>"
-                .format(self.player_id, self.game_type_cd, self.rank))
+        return ("<PlayerRank(pid={0.player_id}, gametype={0.game_type_cd}, rank={0.rank})>"
+                .format(self))
 
     def to_dict(self):
         return {
@@ -157,7 +140,7 @@ class PlayerRank(object):
         }
 
 
-class PlayerCaptime(object):
+class PlayerCaptime(FuzzyDateMixin, EpochMixin):
     """
     A flag capture time for a player on a given map.
     """
@@ -170,14 +153,7 @@ class PlayerCaptime(object):
         self.mod = mod
 
     def __repr__(self):
-        return ("<PlayerCaptime(pid={}, map_id={}, mod={})>"
-                .format(self.player_id, self.map_id, self.mod))
-
-    def fuzzy_date(self):
-        return pretty_date(self.create_dt)
-
-    def epoch(self):
-        return timegm(self.create_dt.timetuple())
+        return "<PlayerCaptime(pid={0.player_id}, map_id={0.map_id}, mod={0.mod})>".format(self)
 
 
 class PlayerGroups(object):
@@ -190,7 +166,7 @@ class PlayerGroups(object):
         self.group_name = group_name
 
     def __repr__(self):
-        return "<PlayerGroups({}, {})>".format(self.player_id, self.group_name)
+        return "<PlayerGroups({0.player_id}, {0.group_name})>".format(self)
 
 
 # TODO: determine if this is a real model (it is very similar to PlayerCaptime from above)
@@ -230,4 +206,4 @@ class PlayerMedal(object):
     """
 
     def __repr__(self):
-        return "<PlayerRank(pid={}, place={}, alt={})>".format(self.player_id, self.place, self.alt)
+        return "<PlayerMedal(pid={0.player_id}, place={0.place}, alt={0.alt})>".format(self)