2222
2323import json
2424import utilities
25+ import datetime
2526from stopstalk_constants import *
2627
2728from gluon import current , IMG , DIV , TABLE , THEAD , HR , H5 , B , \
@@ -35,6 +36,7 @@ def __init__(self, user_id):
3536 self .genre = self .__class__ .__name__
3637 self .user_id = user_id
3738 self .cache_serializer = "json"
39+ self .sunset_card_date = None
3840
3941 # --------------------------------------------------------------------------
4042 def get_html (self , ** args ):
@@ -86,6 +88,16 @@ def set_to_cache(self, value):
8688 result ,
8789 ex = ONE_HOUR )
8890
91+ # --------------------------------------------------------------------------
92+ @staticmethod
93+ def enabled_check (func ):
94+ def wrapper (* args ):
95+ self_obj = args [0 ]
96+ return (self_obj .sunset_card_date is None or \
97+ (self_obj .sunset_card_date - datetime .datetime .now ()).days > 0 ) and \
98+ func (* args )
99+ return wrapper
100+
89101# ==============================================================================
90102class StreakCard (BaseCard ):
91103 # --------------------------------------------------------------------------
@@ -135,6 +147,7 @@ def get_data(self):
135147 return self .stats [self .key_name ]
136148
137149 # --------------------------------------------------------------------------
150+ @BaseCard .enabled_check
138151 def should_show (self ):
139152 cache_value = self .get_from_cache ()
140153 if cache_value :
@@ -191,6 +204,7 @@ def get_data(self):
191204 return
192205
193206 # --------------------------------------------------------------------------
207+ @BaseCard .enabled_check
194208 def should_show (self ):
195209 return True
196210
@@ -263,6 +277,7 @@ def get_data(self):
263277 return data
264278
265279 # --------------------------------------------------------------------------
280+ @BaseCard .enabled_check
266281 def should_show (self ):
267282 return True
268283
@@ -329,6 +344,7 @@ def get_data(self):
329344 return self .final_data if self .final_data else "FAILURE"
330345
331346 # --------------------------------------------------------------------------
347+ @BaseCard .enabled_check
332348 def should_show (self ):
333349 final_data = self .get_from_cache ()
334350 if final_data :
@@ -416,6 +432,7 @@ def get_data(self):
416432 return result
417433
418434 # --------------------------------------------------------------------------
435+ @BaseCard .enabled_check
419436 def should_show (self ):
420437 db = current .db
421438 self .friend_count = db (db .following .follower_id == self .user_id ).count ()
@@ -453,6 +470,7 @@ def get_html(self):
453470 def get_data (self ):
454471 pass
455472 # --------------------------------------------------------------------------
473+ @BaseCard .enabled_check
456474 def should_show (self ):
457475 db = current .db
458476 query = (db .resume_data .user_id == self .user_id )
@@ -493,6 +511,7 @@ def get_data(self):
493511 return self .handle_count
494512
495513 # --------------------------------------------------------------------------
514+ @BaseCard .enabled_check
496515 def should_show (self ):
497516 cache_value = self .get_from_cache ()
498517 if cache_value :
@@ -564,6 +583,7 @@ def get_data(self):
564583 return self .problem_details
565584
566585 # --------------------------------------------------------------------------
586+ @BaseCard .enabled_check
567587 def should_show (self ):
568588 cache_value = self .get_from_cache ()
569589
@@ -644,6 +664,7 @@ def get_data(self):
644664 return self .trending_problems
645665
646666 # --------------------------------------------------------------------------
667+ @BaseCard .enabled_check
647668 def should_show (self ):
648669 cache_value = self .get_from_cache ()
649670 if cache_value :
@@ -696,7 +717,50 @@ def get_data(self):
696717 return
697718
698719 # --------------------------------------------------------------------------
720+ @BaseCard .enabled_check
699721 def should_show (self ):
700722 return True
701723
724+ # ==============================================================================
725+ class AtCoderHandleCard (BaseCard ):
726+ # --------------------------------------------------------------------------
727+ def __init__ (self , user_id ):
728+ self .user_id = user_id
729+ self .final_pid = None
730+ self .card_title = "Link AtCoder now!"
731+
732+ self .ctas = [
733+ dict (btn_url = URL ("user" ,
734+ "update_details" ),
735+ btn_text = "Update Now" ,
736+ btn_class = "atcoder-handle-card-update-now" )
737+ ]
738+ BaseCard .__init__ (self , user_id )
739+ self .sunset_card_date = datetime .datetime .now () + \
740+ datetime .timedelta (days = 90 )
741+
742+ # --------------------------------------------------------------------------
743+ def get_html (self ):
744+ card_content = P ("AtCoder has come up in our surveys multiple times and here we are. We now support AtCoder profiles :)" )
745+
746+ card_html = BaseCard .get_html (self , ** dict (
747+ card_title = self .card_title ,
748+ card_content = card_content ,
749+ cta_links = self .get_cta_html (),
750+ card_color_class = "white" ,
751+ card_text_color_class = "black-text"
752+ ))
753+ return card_html
754+
755+ # --------------------------------------------------------------------------
756+ def get_data (self ):
757+ return
758+
759+ # --------------------------------------------------------------------------
760+ @BaseCard .enabled_check
761+ def should_show (self ):
762+ db = current .db
763+ user_record = utilities .get_user_records ([self .user_id ], "id" , "id" , True )
764+ return user_record ["atcoder_handle" ] == ""
765+
702766# ==============================================================================
0 commit comments