Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contests api and removing json dependencies for api calls #453

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
15 changes: 14 additions & 1 deletion controllers/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,15 @@ def user_editorials():

table_rows = sorted(table_rows, key=lambda x: (x[0], x[1]), reverse=True)

return dict(table_rows=table_rows[:10],
res = dict(table_rows=table_rows[:10],
recent_editorials_table=table,
pending_count=pending_count)

# for api request
if utilities.is_apicall():
return response.json(res)

return res

# ----------------------------------------------------------------------------
def user_wise_editorials():
Expand Down Expand Up @@ -748,6 +754,8 @@ def contests():
reminder_class = button_class + " orange set-reminder"
left_tooltip_attrs = {"position": "left", "delay": "50"}

api_resp = []

for contest in contest_list:
if contest["site"] not in CONTESTS_SITE_MAPPING:
continue
Expand All @@ -764,6 +772,8 @@ def contests():

contest["name"] = contest["name"].encode("ascii", "ignore")

api_resp.append(contest)

append = tr.append

if contest["status"] == "CODING":
Expand Down Expand Up @@ -811,6 +821,9 @@ def contests():

tbody.append(tr)

if utilities.is_apicall():
return response.json(dict(contests=api_resp))

table.append(tbody)
return dict(table=table, retrieved=True)

Expand Down
15 changes: 13 additions & 2 deletions controllers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,8 +813,10 @@ def _get_categorized_json(problem_ids):
# ------------------------------------------------------------------------------
def get_stopstalk_user_stats():
if request.extension != "json":
raise HTTP(400)
return
# for api request
if not utilities.is_apicall():
raise HTTP(400)
return

user_id = request.vars.get("user_id", None)
custom = request.vars.get("custom", None)
Expand Down Expand Up @@ -842,6 +844,11 @@ def get_stopstalk_user_stats():
result = utilities.get_rating_information(user_id,
custom,
auth.is_logged_in())

# for api request
if utilities.is_apicall():
return response.json(result)

return result

# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -974,6 +981,10 @@ def profile():

output["cf_count"] = cf_count

# for api request
if utilities.is_apicall():
return response.json(output)

return output

# ------------------------------------------------------------------------------
Expand Down