From 9018db1a702e4f5e6f52f26580091974389fc977 Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Mon, 24 Jun 2013 17:44:08 -0400 Subject: [PATCH] Show a cake for player cake days! --- xonstat/static/images/icons/24x24/cake.png | Bin 0 -> 674 bytes xonstat/templates/player_info.mako | 11 +++++-- xonstat/util.py | 34 +++++++++++++++++++++ xonstat/views/player.py | 8 +++-- 4 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 xonstat/static/images/icons/24x24/cake.png diff --git a/xonstat/static/images/icons/24x24/cake.png b/xonstat/static/images/icons/24x24/cake.png new file mode 100644 index 0000000000000000000000000000000000000000..6e490a5907b68cb1bfd655b6085e3b2aa5c57649 GIT binary patch literal 674 zcmV;T0$u%yP)9|FtBflJuq-_X=UZJe{Rlgv)eCy&t`2#u^3Ee zGMRPPh{)!~$cRr`TEuK^m1{jcw{P_JHf?5|vK~1W+eLG86xdgDC(FxighJi4w+ll< z&o?;dFLJpkK3@T-Fo?(9Kypi0wtjTs^`>AaR8iT$ZvO-3S(0C#@q3o(>=HPu$b{)?)gbx3>=OwsgYIW0MiRvy@vWPzK60jWG9>2B7kL z2Z1Y7!yTsqCPGe!pzb0POx`)w2rwN!aYo>>qp9&aK+NyAX~?iLP?m0~4-#RgTPc#j z7a$9qT;-S`aZoPGP51-UM-VSqVkzJNa7ctM&!d?X)c%W(ROK3|^Htb>kaJa-yN1?| zYP9WYphSd3ME7dKSyQQl|3Xv~`DQBKc^=Nj%indKV*9_rZ={nUXiVzp0ssI207*qo IM6N<$f+M#n0{{R3 literal 0 HcmV?d00001 diff --git a/xonstat/templates/player_info.mako b/xonstat/templates/player_info.mako index 3a838f7..570eb0c 100644 --- a/xonstat/templates/player_info.mako +++ b/xonstat/templates/player_info.mako @@ -193,8 +193,15 @@ Player Information % else:
-

${player.nick_html_colors()|n}

-

Joined ${player.joined_pretty_date()} (player #${player.player_id})

+

+ ${player.nick_html_colors()|n} +

+

+ Joined ${player.joined_pretty_date()} (player #${player.player_id}) + % if cake_day: + + % endif +

diff --git a/xonstat/util.py b/xonstat/util.py index b400d2a..8af24ef 100644 --- a/xonstat/util.py +++ b/xonstat/util.py @@ -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 diff --git a/xonstat/views/player.py b/xonstat/views/player.py index 96d007e..8bdc257 100644 --- a/xonstat/views/player.py +++ b/xonstat/views/player.py @@ -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, } -- 2.39.2