check is id

This commit is contained in:
virusdefender 2019-03-26 09:33:05 +08:00
parent 7e4132bed1
commit 6f8e68846c
2 changed files with 9 additions and 2 deletions

View File

@ -8,7 +8,7 @@ from django.core.cache import cache
from problem.models import Problem
from utils.api import APIView, validate_serializer
from utils.constants import CacheKey
from utils.shortcuts import datetime2str
from utils.shortcuts import datetime2str, check_is_id
from account.models import AdminType
from account.decorators import login_required, check_contest_permission
@ -35,7 +35,7 @@ class ContestAnnouncementListAPI(APIView):
class ContestAPI(APIView):
def get(self, request):
id = request.GET.get("id")
if not id:
if not id or not check_is_id(id):
return self.error("Invalid parameter, id is required")
try:
contest = Contest.objects.get(id=id, visible=True)

View File

@ -85,3 +85,10 @@ def get_env(name, default=""):
def DRAMATIQ_WORKER_ARGS(time_limit=3600_000, max_retries=0, max_age=7200_000):
return {"max_retries": max_retries, "time_limit": time_limit, "max_age": max_age}
def check_is_id(value):
try:
return int(value) > 0
except Exception as e:
return False