本文整理汇总了Python中Contest.models.Contest.addContest方法的典型用法代码示例。如果您正苦于以下问题:Python Contest.addContest方法的具体用法?Python Contest.addContest怎么用?Python Contest.addContest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Contest.models.Contest
的用法示例。
在下文中一共展示了Contest.addContest方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addContest
# 需要导入模块: from Contest.models import Contest [as 别名]
# 或者: from Contest.models.Contest import addContest [as 别名]
def addContest(request, ccId):
try:
u = User.getSessionUser(request.session)
if not u:
raise Err(request, 'not login')
try:
cc = CourseClass.getById(ccId)
except:
raise Err(request, 'no resource')
try:
Contest.canAddContest(cc, u)
except:
raise Err(request, 'no priv')
recentProblem = Problem.problemListByAuthor(u)
if request.method == 'POST':
form = contestForm(request.POST)
pIdList = request.POST.getlist('problem_id')
#pIdList = Problem.problemList(u)
pTitleList = request.POST.getlist('problem_title_custom')
pCnt = len(pIdList)
if form.is_valid():
for i in xrange(pCnt):
p = Problem.getById(pIdList[i])
if not p.canViewProblem(u):
raise Err(request, 'no problem priv')
pInfos = [(pIdList[i], pTitleList[i], chr(65+i)) for i in xrange(pCnt)]
cTitle = form.cleaned_data['title']
cDesc = form.cleaned_data['desc']
cStartDate = form.cleaned_data['start_date']
cStartTime = form.cleaned_data['start_time']
cLength = form.cleaned_data['length']
cBoardStop = form.cleaned_data['board_stop']
cType = form.cleaned_data['contest_type']
cBoardType = form.cleaned_data['board_type']
permitLang = reduce(add, [Const.LANG_MASK[lang] for lang in form.cleaned_data['lang_limit']])
c = Contest.addContest(u, cc, cTitle, pInfos, datetime.combine(cStartDate, cStartTime),
cDesc, cLength, cBoardStop, cType, cBoardType, permitLang)
return redirect('Contest:show_contest', c.cid)
else:
problemList = [{'pid': pIdList[x], 'title': pTitleList[x], 'origTitle':Problem.getById(pIdList[x]).prob_title} for x in xrange(pCnt)]
return render(request, 'newtpl/contest/addContest.html', {'cc':cc,
'form': form, 'recent_problem': recentProblem,
'problem_list': problemList, 'tpl':{'has_priv': True, 'sp': True, }})
else:
form = contestForm()
return render(request, 'newtpl/contest/addContest.html', {'cc':cc,
'form': form, 'recent_problem': recentProblem,
'tpl':{'has_priv': True, 'sp': True, }})
except Exception as e:
messages.info(request, unicode(e))
return render(request, Err.ERROR_PAGE)