@@ -144,6 +144,51 @@ def _get_failure_message(ticket):
144144
145145 return dict (error_message = error_message , similar_users = similar_users )
146146
147+ # ----------------------------------------------------------------------------
148+ @auth .requires_login ()
149+ def get_card_html ():
150+ init_arguments = request .vars ["init_arguments[]" ]
151+
152+ if not isinstance (init_arguments , list ):
153+ init_arguments = [init_arguments ]
154+
155+ if int (init_arguments [0 ]) != session .user_id :
156+ return ""
157+
158+ import dashboard_cards
159+ card_class = getattr (dashboard_cards ,
160+ request .vars ["class_name" ])(* init_arguments )
161+
162+ return card_class .get_html () if card_class .should_show () else ""
163+
164+ # ----------------------------------------------------------------------------
165+ @auth .requires_login ()
166+ def dashboard ():
167+ session .welcome_shown = True
168+ ratable = db .recent_announcements
169+ rarecord = db (ratable .user_id == session .user_id ).select ().first ()
170+ if rarecord is None :
171+ ratable .insert (user_id = session .user_id )
172+ rarecord = db (ratable .user_id == session .user_id ).select ().first ()
173+
174+ user = session .auth .user
175+ db .sessions_today .insert (message = "%s %s %d %s" % (user .first_name ,
176+ user .last_name ,
177+ user .id ,
178+ datetime .datetime .now ()))
179+
180+ return dict (recent_announcements = json .loads (rarecord .data ))
181+
182+ # ----------------------------------------------------------------------------
183+ @auth .requires_login ()
184+ def cta_handler ():
185+ problem_id = utilities .pick_a_problem (
186+ session .user_id ,
187+ False ,
188+ ** request .vars
189+ )
190+ redirect (URL ("problems" , "index" , vars = dict (problem_id = problem_id )))
191+
147192# ----------------------------------------------------------------------------
148193def user_editorials ():
149194
@@ -282,7 +327,7 @@ def index():
282327 session .flash = T ("Welcome StopStalker!!" )
283328 elif response .flash is not None :
284329 session .flash = response .flash
285- redirect (URL ("default" , "submissions" , args = [ 1 ] ))
330+ redirect (URL ("default" , "dashboard" ))
286331
287332 return dict ()
288333
@@ -332,7 +377,7 @@ def _get_ids(ids):
332377 TD (IMG (_src = get_static_url ("images/" + \
333378 utilities .urltosite (row .link ) + \
334379 "_small.png" ),
335- _style = "height: 30px; weight: 30px; " )),
380+ _class = "parent-site-icon-small " )),
336381 TD (row .total_submissions ),
337382 TD (len (uids ) + len (cuids )),
338383 TD (I (_class = "red-text text-accent-4 fa fa-times remove-from-todo" ,
@@ -449,6 +494,7 @@ def _upload_resume():
449494 else :
450495 rdtable .insert (** update_params )
451496 resume_data_record = db (rdtable .user_id == session .user_id ).select ().first ()
497+ current .REDIS_CLIENT .delete (CARD_CACHE_REDIS_KEYS ["job_profile_prefix" ] + str (session .user_id ))
452498
453499 response .flash = "Successfully saved your details!"
454500 return _get_response_from_record (resume_data_record )
@@ -675,30 +721,14 @@ def contests():
675721 Show the upcoming contests
676722 """
677723
678- today = datetime . datetime . today ()
679- today = datetime . datetime . strptime ( str ( today )[: - 7 ],
680- "%Y-%m-%d %H:%M:%S" )
724+ ongoing , upcoming = utilities . get_contests ()
725+ if None in [ ongoing , upcoming ]:
726+ return dict ( retrieved = False )
681727
682- start_date = today .date ()
683- end_date = start_date + datetime .timedelta (90 )
684728 site_mapping = {"CODECHEF" : "CodeChef" ,
685729 "CODEFORCES" : "Codeforces" ,
686730 "HACKERRANK" : "HackerRank" ,
687731 "HACKEREARTH" : "HackerEarth" }
688- url = "https://contesttrackerapi.herokuapp.com/"
689-
690- from urllib3 import disable_warnings
691- disable_warnings ()
692-
693- response = requests .get (url , verify = False )
694- if response .status_code == 200 :
695- response = response .json ()["result" ]
696- else :
697- return dict (retrieved = False )
698-
699- ongoing = response ["ongoing" ]
700- upcoming = response ["upcoming" ]
701- contests = []
702732 cal = pdt .Calendar ()
703733
704734 table = TABLE (_class = "centered bordered" , _id = "contests-table" )
@@ -714,7 +744,6 @@ def contests():
714744 button_class = "btn-floating btn-small accent-4 tooltipped"
715745 view_link_class = button_class + " green view-contest"
716746 reminder_class = button_class + " orange set-reminder"
717- icon_style = "height: 30px; width: 30px;"
718747 left_tooltip_attrs = {"position" : "left" , "delay" : "50" }
719748
720749 for i in ongoing :
@@ -743,7 +772,7 @@ def contests():
743772 str (i ["Platform" ]).lower () + \
744773 "_small.png" ),
745774 _title = site_mapping [i ["Platform" ]],
746- _style = icon_style )))
775+ _class = "parent-site-icon-small" )))
747776
748777 append (TD ("-" ))
749778 append (TD (str (endtime ).replace ("-" , "/" ),
@@ -1228,6 +1257,7 @@ def mark_friend():
12281257 # Insert a tuple of users' id into the following table
12291258 ftable .insert (user_id = friend_id , follower_id = session .user_id )
12301259
1260+ current .REDIS_CLIENT .delete (CARD_CACHE_REDIS_KEYS ["add_more_friends_prefix" ] + str (session .user_id ))
12311261 trtable = db .todays_requests
12321262 query = (trtable .user_id == friend_id ) & \
12331263 (trtable .follower_id == session .user_id )
@@ -1534,6 +1564,7 @@ def _invalid_url():
15341564 return _invalid_url ()
15351565
15361566 db (query ).delete ()
1567+ current .REDIS_CLIENT .delete (CARD_CACHE_REDIS_KEYS ["add_more_friends_prefix" ] + str (session .user_id ))
15371568
15381569 trtable = db .todays_requests
15391570 query = (trtable .user_id == friend_id ) & \
@@ -1569,13 +1600,11 @@ def submissions():
15691600 # The pagination page number is not integer
15701601 raise HTTP (404 )
15711602 return
1572- session .welcome_shown = True
15731603
15741604 cftable = db .custom_friend
15751605 stable = db .submission
15761606 atable = db .auth_user
15771607 ptable = db .problem
1578- ratable = db .recent_announcements
15791608
15801609 # Get all the friends/custom friends of the logged-in user
15811610 friends , cusfriends = utilities .get_friends (session .user_id )
@@ -1602,48 +1631,17 @@ def submissions():
16021631 return dict (count = count ,
16031632 total_rows = 1 )
16041633
1605- rarecord = db (ratable .user_id == session .user_id ).select ().first ()
1606- if rarecord is None :
1607- ratable .insert (user_id = session .user_id )
1608- rarecord = db (ratable .user_id == session .user_id ).select ().first ()
1609-
1610- user = session .auth .user
1611- db .sessions_today .insert (message = "%s %s %d %s" % (user .first_name ,
1612- user .last_name ,
1613- user .id ,
1614- datetime .datetime .now ()))
1615-
16161634 offset = PER_PAGE * (active - 1 )
16171635 # Retrieve only some number of submissions from the offset
16181636 rows = db (query ).select (orderby = ~ db .submission .time_stamp ,
16191637 limitby = (offset , offset + PER_PAGE ))
16201638
16211639 table = utilities .render_table (rows , cusfriends , session .user_id )
16221640
1623- country_value = session .auth .user .get ("country" )
1624- country = country_value if country_value else "not-available"
1625-
1626- country_form = None
1627- if country == "not-available" :
1628- country_form = SQLFORM (db .auth_user ,
1629- session .auth .user ,
1630- fields = ["country" ],
1631- showid = False )
1632- if country_form .process (onvalidation = current .sanitize_fields ).accepted :
1633- session .auth .user = db .auth_user (session .user_id )
1634- session .flash = T ("Country updated!" )
1635- redirect (URL ("default" , "submissions" , args = 1 ))
1636- elif country_form .errors :
1637- response .flash = T ("Form has errors" )
1638-
16391641 return dict (table = table ,
16401642 friends = friends ,
16411643 cusfriends = cusfriends ,
1642- total_rows = len (rows ),
1643- country = country ,
1644- country_form = country_form ,
1645- utilities = utilities ,
1646- recent_announcements = json .loads (rarecord .data ))
1644+ total_rows = len (rows ))
16471645
16481646# ----------------------------------------------------------------------------
16491647def faq ():
0 commit comments