Skip to content

Commit 70c31dc

Browse files
committed
Merge branch 'dashboard_changes' of github.com:stopstalk/stopstalk-deployment
2 parents faf75fc + 26ae870 commit 70c31dc

17 files changed

Lines changed: 1161 additions & 177 deletions

File tree

controllers/default.py

Lines changed: 55 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -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
# ----------------------------------------------------------------------------
148193
def 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
# ----------------------------------------------------------------------------
16491647
def faq():

controllers/user.py

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ def update_details():
290290
db(submission_query).delete()
291291

292292
session.auth.user = db.auth_user(session.user_id)
293-
redirect(URL("default", "submissions", args=[1]))
293+
current.REDIS_CLIENT.delete(CARD_CACHE_REDIS_KEYS["more_accounts_prefix"] + str(session.user_id))
294+
redirect(URL("default", "index"))
294295
elif form.errors:
295296
response.flash = T("Form has errors")
296297

@@ -693,40 +694,10 @@ def get_stopstalk_user_stats():
693694

694695
user_id = int(user_id)
695696
custom = (custom == "True")
696-
stopstalk_handle = utilities.get_stopstalk_handle(user_id, custom)
697-
redis_cache_key = "profile_page:user_stats_" + stopstalk_handle
698-
699-
# Check if data is present in REDIS
700-
data = current.REDIS_CLIENT.get(redis_cache_key)
701-
if data:
702-
result = json.loads(data)
703-
if not auth.is_logged_in():
704-
del result["rating_history"]
705-
if "problems_authored_count" not in result:
706-
result["problems_authored_count"] = 0
707-
return result
708-
709-
stable = db.submission
710-
711-
query = (stable["custom_user_id" if custom else "user_id"] == user_id)
712-
rows = db(query).select(stable.time_stamp,
713-
stable.problem_id,
714-
stable.status,
715-
stable.site,
716-
orderby=stable.time_stamp)
717-
718-
# Returns rating history, accepted & max streak (day and accepted),
719-
result = utilities.get_stopstalk_user_stats(stopstalk_handle,
720-
custom,
721-
rows.as_list())
722-
723-
if auth.is_logged_in():
724-
current.REDIS_CLIENT.set(redis_cache_key,
725-
json.dumps(result, separators=JSON_DUMP_SEPARATORS),
726-
ex=1 * 60 * 60)
727-
elif "rating_history" in result:
728-
del result["rating_history"]
729697

698+
result = utilities.get_rating_information(user_id,
699+
custom,
700+
auth.is_logged_in())
730701
return result
731702

732703
# ------------------------------------------------------------------------------
@@ -1082,7 +1053,7 @@ def custom_friend():
10821053
if form.accepted:
10831054
session.flash = T("Submissions will be added in some time")
10841055
current.create_next_retrieval_record(form.vars, custom=True)
1085-
redirect(URL("default", "submissions", args=[1]))
1056+
redirect(URL("default", "dashboard"))
10861057

10871058
return dict(form=form,
10881059
table=table,

deploy_scripts/static_files_list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ js/web2py-bootstrap3.js
99
js/appjs/google_analytics.js
1010
js/appjs/layout.js
1111
js/appjs/default/contests.js
12+
js/appjs/default/dashboard.js
1213
js/appjs/default/faq.js
1314
js/appjs/default/filters.js
1415
js/appjs/default/search.js

models/db.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,24 @@ def _count_custom_users_lambda(row):
796796
}
797797
current.REFRESH_INTERVAL = 120 * 60
798798

799+
# ----------------------------------------------------------------------------
800+
def get_static_file_version(file_path):
801+
if current.environment == "production":
802+
new_file_path = file_path
803+
static_dir = "static/minified_files"
804+
if file_path[-3:] == ".js":
805+
new_file_path = file_path[:-3] + ".min.js"
806+
elif file_path[-4:] == ".css":
807+
new_file_path = file_path[:-4] + ".min.css"
808+
else:
809+
static_dir = "static"
810+
new_file_path = file_path
811+
else:
812+
new_file_path = file_path
813+
static_dir = "static"
814+
815+
return static_dir, new_file_path, current.REDIS_CLIENT.get(new_file_path)
816+
799817
# ----------------------------------------------------------------------------
800818
def get_static_url(file_path):
801819
"""
@@ -806,25 +824,17 @@ def get_static_url(file_path):
806824
"""
807825

808826
if current.environment == "production":
809-
new_file_path = file_path
810-
if file_path[-3:] == ".js":
811-
new_file_path = file_path[:-3] + ".min.js"
812-
elif file_path[-4:] == ".css":
813-
new_file_path = file_path[:-4] + ".min.css"
814-
else:
815-
return URL("static",
816-
file_path,
817-
vars={"_rev": current.REDIS_CLIENT.get(file_path)},
818-
extension=False)
819-
return URL("static/minified_files",
820-
new_file_path,
821-
vars={"_rev": current.REDIS_CLIENT.get(new_file_path)},
827+
static_dir, file_path, revision = get_static_file_version(file_path)
828+
return URL(static_dir,
829+
file_path,
830+
vars={"_rev": revision},
822831
extension=False)
823832
else:
824833
return URL("static",
825834
file_path,
826835
extension=False)
827836

837+
current.get_static_file_version = get_static_file_version
828838
current.get_static_url = get_static_url
829839

830840
# =============================================================================

0 commit comments

Comments
 (0)