diff options
author | MichaĆ Klichowicz <emkael@tlen.pl> | 2018-10-17 20:02:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-17 20:02:57 +0200 |
commit | 984540cd2dfba29c1dc9cbc43ab6fa4c85c7727b (patch) | |
tree | d03e49f564cec7c3eec7ce7c98fae530ec1544e0 /jfr_playoff/dto.py | |
parent | 9a5f06ee9cddd38e11f49a2f934de202d34e63e2 (diff) | |
parent | 31fc51ce22e7c5197ed367cadd14d8a258f8fd65 (diff) |
Merge pull request #28 from emkael/develv1.2.0
v1.2
Diffstat (limited to 'jfr_playoff/dto.py')
-rw-r--r-- | jfr_playoff/dto.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/jfr_playoff/dto.py b/jfr_playoff/dto.py index f5e08ef..a88cd2b 100644 --- a/jfr_playoff/dto.py +++ b/jfr_playoff/dto.py @@ -1,7 +1,22 @@ +import sys + +def coalesce(*arg): + for el in arg: + if el is not None: + return el + return None + + class Team(object): name = '' score = 0.0 + def __unicode__(self): + return u'%s (%.1f)' % (coalesce(self.name, '<None>'), self.score) + + def __repr__(self): + return unicode(self).encode(sys.stdin.encoding) + class Match(object): id = None @@ -13,6 +28,13 @@ class Match(object): winner_matches = None loser_matches = None + def __repr__(self): + return (u'#%d (%s) %s [%s]' % ( + self.id, coalesce(self.link, '<None>'), [unicode(team) for team in self.teams], + u'finished' if self.running < 0 else ( + u'%d boards' % self.running)) + ).encode(sys.stdin.encoding) + class Phase(object): title = None @@ -20,4 +42,9 @@ class Phase(object): matches = [] running = False + def __repr__(self): + return u'%s (%s) <%d matches> [%srunning]' % ( + self.title, coalesce(self.link, '<None>'), + len(self.matches), '' if self.running else 'not ') + __all__ = ('Team', 'Match', 'Phase') |