本文整理匯總了Python中Contest.models.Contest.getByStudent方法的典型用法代碼示例。如果您正苦於以下問題:Python Contest.getByStudent方法的具體用法?Python Contest.getByStudent怎麽用?Python Contest.getByStudent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Contest.models.Contest
的用法示例。
在下文中一共展示了Contest.getByStudent方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: listContestByUser
# 需要導入模塊: from Contest.models import Contest [as 別名]
# 或者: from Contest.models.Contest import getByStudent [as 別名]
def listContestByUser(request, pageId='1'):
"""
view used to list all contest a user can participate
"""
logger.info(str(request).replace("\n","\t"))
tpl = {'nav_act':'contest'}
try:
u = User.getSessionUser(request.session)
if not u:
messages.info(request, u'請先登錄')
contestList = None
else:
now = datetime.now()
if u.priv == 'student':
contestList = Contest.getByStudent(u)
else:
contestList = Contest.getByAdmin(u)
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)
if contestList and contestList.count>0:
return render(request, 'newtpl/contest/contestListByUser.html', {
'contest_list': paginator.page(pageId), 'tpl':tpl})
else:
return render(request, 'newtpl/contest/contestListByUser.html', {
'tpl':tpl, 'err_msg_list': [
u'您暫時沒有可以參加的測驗。',
u'不如走出教室,呼吸一下新鮮空氣,給家人打個電話,陪陪妹子?'
]})
except Exception as e:
return render(request, Const.ERROR_PAGE, {'errmsg': unicode(e), })