本文整理汇总了Python中User.models.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: viewAllClarifications
def viewAllClarifications(request, cid):
logger.info(str(request).replace("\n","\t"))
try:
u = User.getSessionUser(request.session)
if not u:
raise Exception(Const.NOT_LOGGED_IN)
c = Contest.getById(cid)
if not c:
raise Exception(Const.CONTEST_NOT_EXIST)
cs = Clarification.getByContestId(cid)
try:
c.canEnterContest(u)
can_add_clar = True
except:
can_add_clar = False
try:
c.canBeManaged(u)
can_update_clar = True
except:
can_update_clar = False
return render(request, 'newtpl/contest/viewAllClars.html', {'clars': cs, 'contest': c, 'can_add_clar': can_add_clar, 'can_update_clar': can_update_clar})
except Exception as e:
logger.error(unicode(e).replace('\n', '\t'))
return render(request, Err.ERROR_PAGE, {'errmsg': unicode(e)})
示例2: answerClarification
def answerClarification(request, clar_id):
logger.info(str(request).replace("\n","\t"))
try:
u = User.getSessionUser(request.session)
if not u:
raise Exception(Const.NOT_LOGGED_IN)
clar = Clarification.getById(clar_id)
if not clar:
raise Exception('No such Clarification!')
c = clar.contest
if not c:
raise Exception(Const.CONTEST_NOT_EXIST)
try:
c.canBeManaged(u)
except:
raise Exception('No Privilege!')
if request.method != 'POST':
return render(request, 'newtpl/contest/answerClar.html', {'clar': clar})
form = AnswerClarificationForm(request.POST)
try:
if form.is_valid():
answer = form.cleaned_data['answer']
clar.updateAnswer(answer, u)
return redirect('Contest:view_all_clars', c.cid)
else:
raise Exception('Invalid Answer!')
except Exception as e:
raise e
except Exception as e:
logger.error(unicode(e).replace('\n', '\t'))
return render(request, Err.ERROR_PAGE, {'errmsg': unicode(e)})
示例3: login
def login(request):
if User.userAuth(request, tokkening=True):
return redirect('/users/')
if request.method == 'POST':
print 'loging..'
username = request.POST['username']
password = request.POST['password']
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
msg = 'Error. User not found.'
print msg
return render_to_response('login.html', {'msg': msg}, context_instance=RequestContext(request))
except User.MultipleObjectsReturned:
msg = 'Error. Multiple user. Please contact with administrator.'
return render_to_response('login.html', {'msg': msg}, context_instance=RequestContext(request))
if user.passwordCompare(password):
user.login(request)
msg = 'Login successfully'
print msg
return redirect('/users/')
else:
msg = 'Error. Wrong password.'
return render_to_response('login.html', {'msg': msg}, context_instance=RequestContext(request))
else:
return render_to_response('login.html', context_instance=RequestContext(request))
示例4: previewTestData
def previewTestData(request, problem_id, case_id, mode): # mode = 0: view input mode = 1: view output
logger.info(str(request).replace("\n","\t"))
try:
u = User.getSessionUser(request.session)
if not u:
raise Err(request, 'not login')
if not problem_id:
raise Err(request, 'problem illegal')
try:
p = Problem.getById(int(problem_id))
except:
raise Err(request, 'problem illegal')
if not p.canManageProblem(u):
raise Err(request, 'no priv')
case_id = int(case_id)
if case_id >= p.data_count: # [0, data_count)
raise Err(request, 'testdata illegal')
mode = int(mode)
if mode != 0 and mode != 1:
raise Err(request, 'testdata mode illegal')
data_preview = p.generateTestDataPreview(case_id, mode)
return render(request, 'newtpl/problem/previewTestData.html', {'data_preview': data_preview})
except Exception as e:
logger.error(str(e).replace('\n','\t'))
return render(request, Err.ERROR_PAGE)
示例5: rejudgeSubmission
def rejudgeSubmission( request, sid):
logger.info(str(request).replace("\n\r","\t"))
"""
rejudge the very submission with the specific sid
"""
try:
sid = int( sid)
u = User.getSessionUser( request.session)
if not u:
raise Err( request, err='not login')
try:
s = Submission.getById( sid)
except:
raise Err( request, err='no submission',
log_format=( '{0}'.format( sid), ''),
user_format=( u'{0}'.format( sid), u'不要搞笑!!'),
)
if not s.problem_index.contest.course_class.canBeManaged( u):
raise Err( request, err = 'no priv')
Submission.rejudgeSubmission( s)
return redirect( 'Submission:contest_status', contest_id=s.problem_index.contest.cid)
except Exception as e:
logger.error(str(e).replace("\n\r","\t"))
return render( request, Const.NEW_ERROR_PAGE, { 'errmsg': unicode(e), }, )
示例6: rejudgeGeneralSubmission
def rejudgeGeneralSubmission( request, gsid):
"""
rejudge the very general submission with the specific id
"""
try:
gsid = int( gsid)
u = User.getSessionUser( request.session)
if not u:
raise Err( request, err='not login')
try:
g_s = GeneralSubmission.getById( gsid)
except:
raise Err( request, err='no generalsubmission',
log_format=( '{0}'.format( gsid), ''),
user_format=( u'{0}'.format( gsid), u'别扯了!!'),
)
# fake
if u.priv == 'student':
raise Err( request, err = 'no priv')
GeneralSubmission.rejudgeGeneralSubmission( g_s)
return redirect( 'Submission:status')
except Exception as e:
return render( request, Const.NEW_ERROR_PAGE, { 'errmsg': unicode(e), }, )
示例7: addRecord
def addRecord(request, cid):
try:
u = User.getSessionUser(request.session)
if not u:
raise Err(request, err='not login')
c = Contest.getById(cid)
try:
c.canBeManaged(u)
except:
raise Err(request, err='no priv')
cp = c.getContestProblem()
if request.method == 'POST':
form = ChooseProbForm(cp, request.POST)
if form.is_valid():
Cheat.addRecord(cp_set=form.cleaned_data['contest_problem'])
Cheat.antiCheat()
return redirect('Cheat:show_cheat_result', cid=c.cid)
else:
raise Err(request, err='unknown err')
else:
form = ChooseProbForm(cp)
return render(request, 'newtpl/cheat/addRecord.html', {'tpl':{'sp':True,}, 'contest':c, 'form':form,})
except Exception as e:
return render(request, Err.ERROR_PAGE)
示例8: listContestByAuthor
def listContestByAuthor(request, pageId='1'):
"""
view used to list all contest created by the specific user
"""
try:
u = User.getSessionUser(request.session)
if not u:
messages.info(request, u'请先登录')
return render(request, 'newtpl/contest/contestListByAuthor.html')
contestList = Contest.getByAuthor(u)
now = datetime.now()
for c in contestList:
c.course_class_name = unicode(c.course_class.getFullName())
c.title = unicode(c.contest_title)
if c.start_time+timedelta(minutes=c.length)<now:
c.status = 'ended'
elif c.start_time > now:
c.status = 'scheduled'
else:
c.status = 'running'
paginator = Paginator(contestList, Const.CONTEST_PER_PAGE)
pageId = min(max(int(pageId), 1), paginator.num_pages)
return render(request, 'newtpl/contest/contestListByAuthor.html', {
'contest_list': paginator.page(pageId), 'tpl':{'has_priv': True, 'nav_act':'contest',}})
except Exception as e:
return render(request, Const.ERROR_PAGE, {'errmsg': unicode(e), })
示例9: listContestByPriv
def listContestByPriv(request, ccId, pageId='1'):
"""
view used to list all contest a user can manage, course_class restricted
"""
try:
u = User.getSessionUser(request.session)
if not u:
messages.info(request, u'请先登录')
return render(request, 'newtpl/contest/contestListByPriv.html')
cc = CourseClass.getById(ccId)
if not Contest.hasPriv(cc, u):
raise Exception(Const.NOT_PVLG)
contestList = Contest.getByCourseClass(cc)
now = datetime.now()
for c in contestList:
c.course_class_name = unicode(c.course_class.getFullName())
c.title = unicode(c.contest_title)
if c.start_time+timedelta(minutes=c.length)<now:
c.status = 'ended'
elif c.start_time > now:
c.status = 'scheduled'
else:
c.status = 'running'
paginator = Paginator(contestList, Const.CONTEST_PER_PAGE)
pageId = min(max(int(pageId), 1), paginator.num_pages)
return render(request, 'newtpl/contest/contestListByPriv.html',
{'contest_list': paginator.page(pageId), 'course_class': cc,
'tpl':{'has_priv': True, 'nav_act':'contest',}})
except Exception as e:
return render(request, Const.ERROR_PAGE, {'errmsg': unicode(e), })
示例10: updateContestNotice
def updateContestNotice(request, cId, cnId):
try:
u = User.getSessionUser(request.session)
if not u:
raise Exception(Const.NOT_LOGGED_IN)
c = Contest.getById(cId)
cn = ContestNotice.getById(cnId)
c.canBeManaged(u)
if request.method == 'POST':
form = contestNoticeForm(request.POST)
if form.is_valid():
cnTitle = form.cleaned_data['title']
cnContent = form.cleaned_data['content']
cn.updateNotice(cnTitle, cnContent)
return redirect('Contest:show_contest_notice', cId, cn.id)
else:
return render(request, 'newtpl/contest/updateContestNotice.html',
{'form': form, 'cid': cId, 'cnid': cnId,
'tpl':{'has_priv': True, 'sp': True, 'nav_act':'contest',}})
else:
form = contestNoticeForm(
initial={
'title': cn.notice_title,
'content': cn.notice_content,
}
)
return render(request, 'newtpl/contest/updateContestNotice.html',
{'form': form, 'cid': cId, 'cnid': cnId,
'tpl':{'has_priv': True, 'sp': True, 'nav_act':'contest',}})
except Exception as e:
return render(request, Const.ERROR_PAGE, {'errmsg': unicode(e), })
示例11: logout
def logout(request):
if User.userAuth(request, tokkening=True):
user = User.objects.get(id=request.session['id'])
user.logout(request)
return redirect('/')
else:
return redirect('/')
示例12: listProblem
def listProblem(request, pageId="1"): # modified
logger.info(str(request).replace("\n","\t"))
try:
pageId = int(pageId)
u = User.getSessionUser(request.session)
if not u:
raise Err(request, 'not login')
tres = Problem.problemList(u)
if (pageId-1)*Const.PROBLEM_PER_PAGE>=len(tres):
raise Err(request, 'unknown err')
res = tres[(pageId-1)*Const.PROBLEM_PER_PAGE:pageId*Const.PROBLEM_PER_PAGE]
res = tres
probs = []
for p in res:
all_submits = GeneralSubmission.objects.filter(problem = p)
all_accepts = all_submits.filter(status = 'Accepted')
submits = all_submits.count()
accepts = all_accepts.count()
ratio = 0 if submits == 0 else 100 * accepts / submits
probs.append({'accepts': accepts, 'submits': submits, 'ratio': ratio, 'prob': p})
paginator = Paginator(probs, Const.PROBLEM_PER_PAGE)
pageId = min(max(int(pageId), 1), paginator.num_pages)
#return render(request,"newtpl/problem/problemList.html",{'tpl':{'sp':False}, 'problems': probs})
return render(request,"newtpl/problem/problemList.html",{'tpl':{'sp':False}, 'problems': paginator.page(pageId)})
except Exception as e:
logger.error(str(e).replace("\n","\t"))
return render(request, Err.ERROR_PAGE)
示例13: save
def save(self):
user = User()
user.username = self.username
user.set_password(self.password)
user.email = self.email
if self.signature:
user.signature = self.signature
user.save()
return user
示例14: userDetail
def userDetail(request, uid):
try:
u = User.getById(uid)
except:
return HttpResponse(status=404)
if request.method == 'GET':
serializer = UserSerializer(u)
return JSONResponse(serializer.data)
示例15: generalSubmissionList
def generalSubmissionList(request, page_id='1'):
"""
@view: list general submission
"""
try:
page_id = int(page_id)
u = User.getSessionUser(request.session)
if not u:
raise Err( request, err='not login')
# fake
if u.priv == 'university':
has_priv = True
else:
has_priv = False
user = u if not has_priv else None
lang_list = [('gcc','GNU C'), ('g++','GNU C++'), ('java','java')]
form = generalListForm( lang_list, request.GET)
if form.is_valid():
if form.cleaned_data['problem_id']:
try:
p = Problem.getById( form.cleaned_data['problem_id'])
except:
raise Err( request, err='request err',
log_format=( 'form invalid', 'problem_id error'),
user_format=( u'输入的内容不合法', u'没有这道题!')
)
else:
p = None
else:
raise Err( request, err='example err',
log_format=( 'form invalid', ''),
user_format=( u'输入的内容不合法', '')
)
g_subs = GeneralSubmission.generalSubmissionList( u=user, p=p, uname=form.cleaned_data['username'], language=form.cleaned_data['language'], status_selected=form.cleaned_data['status'], university=u.university)
if 'rejudge' in request.GET:
if has_priv:
map( lambda x: GeneralSubmission.rejudgeGeneralSubmission( x), g_subs)
else:
raise Err( request, err = 'no priv')
paginator = Paginator( g_subs, Const.STATUS_PER_PAGE)
page_id = min(max(int(page_id), 1), paginator.num_pages)
g_s = paginator.page(page_id)
for g_s_index in g_s:
g_s_index.status_color = Const.STATUS_COLOR[g_s_index.status] if g_s_index.status in Const.STATUS_COLOR else ''
g_s_index.status_cn = Const.STATUS_CN[ g_s_index.status]
return render(request, 'newtpl/submission/general/status.html', {'general_list': g_s, 'form':form, 'tpl':{'can_manage': True if has_priv else False}})
except Exception as e:
return render(request, Err.ERROR_PAGE, { 'errmsg': unicode(e) } )