Skip to content

Commit

Permalink
Merge pull request #202 from QingdaoU/api
Browse files Browse the repository at this point in the history
remove restriction when using open api
  • Loading branch information
zema1 committed Dec 16, 2018
2 parents 745dba8 + 03c6841 commit f2f6b48
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions account/middleware.py
Expand Up @@ -14,6 +14,7 @@ def process_request(self, request):
try:
request.user = User.objects.get(open_api_appkey=appkey, open_api=True, is_disabled=False)
request.csrf_processing_done = True
request.auth_method = "api_key"
except User.DoesNotExist:
pass

Expand Down
2 changes: 1 addition & 1 deletion contest/views/admin.py
Expand Up @@ -57,7 +57,7 @@ def put(self, request):
for ip_range in data["allowed_ip_ranges"]:
try:
ip_network(ip_range, strict=False)
except ValueError as e:
except ValueError:
return self.error(f"{ip_range} is not a valid cidr network")
if not contest.real_time_rank and data.get("real_time_rank"):
cache_key = f"{CacheKey.contest_rank_cache}:{contest.id}"
Expand Down
1 change: 0 additions & 1 deletion fps/parser.py
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
import os
import base64
import copy
import random
Expand Down
6 changes: 3 additions & 3 deletions problem/utils.py
Expand Up @@ -14,9 +14,9 @@


def parse_problem_template(template_str):
prepend = re.findall("//PREPEND BEGIN\n([\s\S]+?)//PREPEND END", template_str)
template = re.findall("//TEMPLATE BEGIN\n([\s\S]+?)//TEMPLATE END", template_str)
append = re.findall("//APPEND BEGIN\n([\s\S]+?)//APPEND END", template_str)
prepend = re.findall(r"//PREPEND BEGIN\n([\s\S]+?)//PREPEND END", template_str)
template = re.findall(r"//TEMPLATE BEGIN\n([\s\S]+?)//TEMPLATE END", template_str)
append = re.findall(r"//APPEND BEGIN\n([\s\S]+?)//APPEND END", template_str)
return {"prepend": prepend[0] if prepend else "",
"template": template[0] if template else "",
"append": append[0] if append else ""}
Expand Down
4 changes: 4 additions & 0 deletions submission/views/oj.py
Expand Up @@ -18,6 +18,10 @@

class SubmissionAPI(APIView):
def throttling(self, request):
# 使用 open_api 的请求暂不做限制
auth_method = getattr(request, "auth_method", "")
if auth_method == "api_key":
return
user_bucket = TokenBucket(key=str(request.user.id),
redis_conn=cache, **SysOptions.throttling["user"])
can_consume, wait = user_bucket.consume()
Expand Down

0 comments on commit f2f6b48

Please sign in to comment.