]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Show a cake for player cake days!
authorAnt Zucaro <azucaro@gmail.com>
Mon, 24 Jun 2013 21:44:08 +0000 (17:44 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Mon, 24 Jun 2013 21:44:08 +0000 (17:44 -0400)
xonstat/static/images/icons/24x24/cake.png [new file with mode: 0644]
xonstat/templates/player_info.mako
xonstat/util.py
xonstat/views/player.py

diff --git a/xonstat/static/images/icons/24x24/cake.png b/xonstat/static/images/icons/24x24/cake.png
new file mode 100644 (file)
index 0000000..6e490a5
Binary files /dev/null and b/xonstat/static/images/icons/24x24/cake.png differ
index 3a838f70b480d78889de063408cf76fa8f0bc124..570eb0c791acf7fe2a26f764f0729a1290f51110 100644 (file)
@@ -193,8 +193,15 @@ Player Information
 % else:
 <div class="row">
   <div class="span12">
-    <h2>${player.nick_html_colors()|n}</h2>
-    <h4><i><span class="abstime" data-epoch="${player.epoch()}" title="${player.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">Joined ${player.joined_pretty_date()}</span> (player #${player.player_id})</i></h4>
+    <h2>
+      ${player.nick_html_colors()|n}
+    </h2>
+    <h4>
+      <i><span class="abstime" data-epoch="${player.epoch()}" title="${player.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">Joined ${player.joined_pretty_date()}</span> (player #${player.player_id})</i>
+      % if cake_day:
+      <img src="/static/images/icons/24x24/cake.png" title="Happy cake day!" />
+      % endif
+    </h4>
   </div>
 </div>
 
index b400d2aeba6d5b4c59df7fa2a19bc3982a1b26f7..8af24efc1a16ec7c75d8da08c1476c9185dfba9c 100644 (file)
@@ -203,3 +203,37 @@ def to_json(data):
             result[key] = to_json(value.to_dict())
     return result
 
+
+def is_leap_year(today_dt=None):
+    if today_dt is None:
+        today_dt = datetime.utcnow()
+
+    if today_dt.year % 400 == 0:
+       leap_year = True
+    elif today_dt.year % 100 == 0:
+       leap_year = False
+    elif today_dt.year % 4 == 0:
+       leap_year = True
+    else:
+       leap_year = False
+
+    return leap_year
+
+
+def is_cake_day(create_dt, today_dt=None):
+    cake_day = False
+
+    if today_dt is None:
+        today_dt = datetime.utcnow()
+
+    # cakes are given on the first anniversary, not the actual create date!
+    if datetime.date(today_dt) != datetime.date(create_dt):
+        if today_dt.day == create_dt.day and today_dt.month == create_dt.month:
+            cake_day = True
+
+        # leap year people get their cakes on March 1
+        if not is_leap_year(today_dt) and create_dt.month == 2 and create_dt.day == 29:
+            if today_dt.month == 3 and today_dt.day == 1:
+                cake_day = True
+
+    return cake_day
index 96d007e19439b5849e51f8ba528c43403fe5acb8..8bdc25735e4340b3199b4832f392dec74ee35d5a 100644 (file)
@@ -8,6 +8,7 @@ from collections import namedtuple
 from webhelpers.paginate import Page
 from xonstat.models import *
 from xonstat.util import page_url, to_json, pretty_date, datetime_seconds
+from xonstat.util import is_cake_day
 from xonstat.views.helpers import RecentGame, recent_games_q
 
 log = logging.getLogger(__name__)
@@ -519,6 +520,7 @@ def player_info_data(request):
         ranks          = get_ranks(player_id)
         recent_games   = get_recent_games(player_id)
         recent_weapons = get_recent_weapons(player_id)
+        cake_day       = is_cake_day(player.create_dt)
 
     except Exception as e:
         player         = None
@@ -529,8 +531,9 @@ def player_info_data(request):
         ranks          = None
         recent_games   = None
         recent_weapons = []
+        cake_day       = False
         ## do not raise exceptions here (only for debugging)
-        #raise e
+        # raise e
 
     return {'player':player,
             'games_played':games_played,
@@ -539,7 +542,8 @@ def player_info_data(request):
             'elos':elos,
             'ranks':ranks,
             'recent_games':recent_games,
-            'recent_weapons':recent_weapons
+            'recent_weapons':recent_weapons,
+            'cake_day':cake_day,
             }