当前位置: 首页>>代码示例>>Python>>正文


Python User.getSessionUser方法代码示例

本文整理汇总了Python中User.models.User.getSessionUser方法的典型用法代码示例。如果您正苦于以下问题:Python User.getSessionUser方法的具体用法?Python User.getSessionUser怎么用?Python User.getSessionUser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在User.models.User的用法示例。


在下文中一共展示了User.getSessionUser方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: answerClarification

# 需要导入模块: from User.models import User [as 别名]
# 或者: from User.models.User import getSessionUser [as 别名]
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)})    
开发者ID:Mr-Phoebe,项目名称:BOJ-V2,代码行数:35,代码来源:views.py

示例2: rejudgeSubmission

# 需要导入模块: from User.models import User [as 别名]
# 或者: from User.models.User import getSessionUser [as 别名]
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), }, )
开发者ID:YLAsce,项目名称:oj,代码行数:31,代码来源:views.py

示例3: updateContestNotice

# 需要导入模块: from User.models import User [as 别名]
# 或者: from User.models.User import getSessionUser [as 别名]
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), })
开发者ID:Mr-Phoebe,项目名称:BOJ-V2,代码行数:35,代码来源:views.py

示例4: rejudgeGeneralSubmission

# 需要导入模块: from User.models import User [as 别名]
# 或者: from User.models.User import getSessionUser [as 别名]
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), }, )
开发者ID:Mr-Phoebe,项目名称:BOJ-V2,代码行数:30,代码来源:general_views.py

示例5: viewAllClarifications

# 需要导入模块: from User.models import User [as 别名]
# 或者: from User.models.User import getSessionUser [as 别名]
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)})    
开发者ID:YLAsce,项目名称:oj,代码行数:29,代码来源:views.py

示例6: listProblem

# 需要导入模块: from User.models import User [as 别名]
# 或者: from User.models.User import getSessionUser [as 别名]
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)
开发者ID:Mr-Phoebe,项目名称:BOJ-V2,代码行数:30,代码来源:views.py

示例7: previewTestData

# 需要导入模块: from User.models import User [as 别名]
# 或者: from User.models.User import getSessionUser [as 别名]
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)
开发者ID:YLAsce,项目名称:oj,代码行数:33,代码来源:views.py

示例8: listContestByAuthor

# 需要导入模块: from User.models import User [as 别名]
# 或者: from User.models.User import getSessionUser [as 别名]
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), })
开发者ID:Mr-Phoebe,项目名称:BOJ-V2,代码行数:30,代码来源:views.py

示例9: listContestByPriv

# 需要导入模块: from User.models import User [as 别名]
# 或者: from User.models.User import getSessionUser [as 别名]
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), })
开发者ID:Mr-Phoebe,项目名称:BOJ-V2,代码行数:36,代码来源:views.py

示例10: addRecord

# 需要导入模块: from User.models import User [as 别名]
# 或者: from User.models.User import getSessionUser [as 别名]
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)
开发者ID:Mr-Phoebe,项目名称:BOJ-V2,代码行数:29,代码来源:views.py

示例11: generalSubmissionList

# 需要导入模块: from User.models import User [as 别名]
# 或者: from User.models.User import getSessionUser [as 别名]
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) } )
开发者ID:Mr-Phoebe,项目名称:BOJ-V2,代码行数:60,代码来源:general_views.py

示例12: addContest

# 需要导入模块: from User.models import User [as 别名]
# 或者: from User.models.User import getSessionUser [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)
开发者ID:Mr-Phoebe,项目名称:BOJ-V2,代码行数:59,代码来源:views.py

示例13: chooseCourseClass

# 需要导入模块: from User.models import User [as 别名]
# 或者: from User.models.User import getSessionUser [as 别名]
def chooseCourseClass(request):
    try:
        u = User.getSessionUser(request.session)
        if not u:
            raise Err(request, 'not login')
        if u.isStudent():
            raise Err(request, 'no priv')
        cc_list = CourseClass.getAllManagedClasses(u)

        return render(request,'newtpl/contest/chooseCourseClass.html',{'list': cc_list, 'tpl':{'sp':True}})
    except Exception as e:
        return render(request, Err.ERROR_PAGE)
开发者ID:Mr-Phoebe,项目名称:BOJ-V2,代码行数:14,代码来源:views.py

示例14: showResult

# 需要导入模块: from User.models import User [as 别名]
# 或者: from User.models.User import getSessionUser [as 别名]
def showResult(request, cid, page='1'):
    try:
        u = User.getSessionUser(request.session)
        if not u:
            raise Err(request, err='not login')

        c = Contest.getById(int(cid))
        try:
            c.canBeManaged(u)
        except:
            raise Err(request, err='no priv')

        if ('threshold' in request.GET) and request.GET['threshold']:
            threshold = float(request.GET['threshold'])
        else:
            threshold = Const.CHEAT_DEFAULT_THRESHOLD

        cheatList = Cheat.getCheatList(contest=c, threshold=threshold)
        paginator = Paginator(cheatList, Const.CHEAT_PER_PAGE)
        page = min(max(int(page), 1), paginator.num_pages)

        cl = paginator.page(page)
        ipa = []
        ipb = []
        for idx, element in enumerate(cl):
            info_a = eval(element.sub1.other_info)
            info_b = eval(element.sub2.other_info)
            #cl[idx] = {'c': element, 'ip_a': info_a['submit_ip'], 'ip_b': info_b['submit_ip']}
            ipa.append(info_a['submit_ip'])
            ipb.append(info_b['submit_ip'])
        
        return render(request, 'newtpl/cheat/showResult.html', {'tpl':{'sp':True,}, 'contest':c, 'cheat_list':cl, 'ipa':ipa,'ipb':ipb })
    except Exception as e:
        return render(request, Err.ERROR_PAGE)

# def codeDiff(request, ctid):
#     try:
#         u = User.getSessionUser(request.session)
#         if not u:
#             raise Err(request, err='not login')
#         ct = Cheat.objects.select_related('sub1__user', 'sub2__user').get(ctid=ctid)
# 
#         try:
#             ct.contest.canBeManaged(u)
#         except:
#             raise Err(request, err='no priv')
# 
#         return render(request, 'newtpl/cheat/codeDiff.html', {'tpl':{'sp':True,}, 'sub1':ct.sub1, 'sub2':ct.sub2})
# 
# 
#     except Exception as e:
#         return render(request, Err.ERROR_PAGE)
    """
开发者ID:YLAsce,项目名称:oj,代码行数:55,代码来源:views.py

示例15: chooseCourse

# 需要导入模块: from User.models import User [as 别名]
# 或者: from User.models.User import getSessionUser [as 别名]
def chooseCourse(request):
    logger.info(str(request).replace("\n","\t"))
    try:
        u = User.getSessionUser(request.session)
        if not u:
            raise Err(request, 'not login')
        if u.isStudent():
            raise Err(request, 'no priv')
        cs_list = Course.getAllManagedCourses(u)

        return render(request,'newtpl/problem/chooseCourse.html',{'list': cs_list, 'tpl':{'sp':True}})
    except Exception as e:
        logger.error(str(e).replace("\n","\t"))
        return render(request, Err.ERROR_PAGE)
开发者ID:YLAsce,项目名称:oj,代码行数:16,代码来源:views.py


注:本文中的User.models.User.getSessionUser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。