From f61f4785892055ac2ca3177f57164c0c1acb48fd Mon Sep 17 00:00:00 2001 From: Daochen Zha Date: Fri, 11 Dec 2020 12:46:47 -0600 Subject: [PATCH] Add checking of uploading --- server/tournament/views.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/tournament/views.py b/server/tournament/views.py index 3677391..90f20ff 100644 --- a/server/tournament/views.py +++ b/server/tournament/views.py @@ -134,8 +134,12 @@ def upload_agent(request): f = request.FILES['model'] name = request.POST['name'] game = request.POST['game'] + if name == '': + return HttpResponse(json.dumps({'value': -1, 'info': 'name can not be empty'})) + if game not in ['leduc-holdem', 'doudizhu']: + return HttpResponse(json.dumps({'value': -2, 'info': 'game can only be leduc-holdem or doudizhu'})) if UploadedAgent.objects.filter(name=name).exists(): - return HttpResponse(json.dumps({'value': -1, 'info': 'name exists'})) + return HttpResponse(json.dumps({'value': -3, 'info': 'name exists'})) a = UploadedAgent(name=name, game=game, f=f) a.save()