Add checking of uploading

This commit is contained in:
Daochen Zha 2020-12-11 12:46:47 -06:00
parent a5ae7a9d5b
commit f61f478589
1 changed files with 5 additions and 1 deletions

View File

@ -134,8 +134,12 @@ def upload_agent(request):
f = request.FILES['model'] f = request.FILES['model']
name = request.POST['name'] name = request.POST['name']
game = request.POST['game'] 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(): 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 = UploadedAgent(name=name, game=game, f=f)
a.save() a.save()