]> de.git.xonotic.org Git - xonotic/xonstat.git/blob - xonstat/models/mixins.py
Remove more refs to sqlahelper.
[xonotic/xonstat.git] / xonstat / models / mixins.py
1 """
2 Mixins for methods used by several model classes.
3 """
4 from calendar import timegm
5 from xonstat.util import pretty_date, html_colors
6
7
8 class FuzzyDateMixin(object):
9     """Provides a class with a "create_dt" attribute the ability to return a fuzzy date."""
10
11     def fuzzy_date(self):
12         return pretty_date(self.create_dt)
13
14
15 class EpochMixin(object):
16     """Provides a class with a "create_dt" attribute the ability to return the epoch time."""
17
18     def epoch(self):
19         return timegm(self.create_dt.timetuple())
20
21
22 class NickColorsMixin(object):
23     """Provides a class with a "nick" attribute the ability to return the nick's HTML colors."""
24
25     def nick_html_colors(self, limit=None):
26         if self.nick is None:
27             return "Anonymous Player"
28         else:
29             return html_colors(self.nick, limit)