实现了在contest中的clarification功能以及对于已经存在的问题进行了修改:
部分核心代码:
<script type="text/javascript">
function post_clar(){
var clar = $("#clar_content").val()
if(clar == ""){
alert("New Clarification is null!")
}else{
$.ajax({
type : "post",
url : "/contest/"+{{contest.id}}+"/clarification/",
data : {"clar":clar},
success : function(responseData){
$('#panel-clar').html(responseData)
scrollTo(0,0)
}
})
}
}
</script>
def contest_clarification(req,cid):
#pid=req.GET.get("proid")
#pro = Problem.objects.get(proid=proid)
contest = Contest.objects.get(id = cid)
isAuthor = req.user == contest.uid
print('OUT POST clar', req.POST.get('clar'))
print('OUT GET clar', req.GET.get('clar'))
if not req.POST.get('clar') :
#print('GET count', Contest_clarification.objects.filter(contest=contest).count())
return render(req,'contest/contest_clar.html',{'contest':contest,'list': Contest_clarification.objects.filter(contest=contest).order_by('-time'), 'isAuthor':isAuthor})
else :
#print('POST count', Contest_clarification.objects.filter(contest=contest).count())
#print('POST clar', req.POST.get('clar'))
if isAuthor:
contest_clarification = Contest_clarification(contest = contest, clarification = req.POST.get('clar'),
time = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())))
contest_clarification.save()
return render(req,'contest/contest_clar.html',{'contest':contest, 'list': Contest_clarification.objects.filter(contest=contest).order_by('-time'), 'isAuthor':isAuthor })
def dateToInt(date, field):
if field == 0:
return date.days * 24 * 60 + date.seconds // 60
else:
return date.days * 24 * 60 *60 + date.seconds