Beispiel #1
0
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), })
Beispiel #2
0
 def getByAdmin(cls, user):
     cList = []
     ccList = CourseClass.getAllManagedClasses(user)
     map(cList.extend, [Contest.getByCourseClass(cc) for cc in ccList])
     cList = list(set(cList))
     return sorted(cList,
                   key=lambda contest: contest.start_time,
                   reverse=True)
Beispiel #3
0
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)
Beispiel #4
0
 def getByStudent(cls, user):
     cList = []
     map(cList.extend, [
         Contest.getByCourseClass(cc)
         for cc in CourseClass.getByStudent(user)
     ])
     cList = list(set(cList))
     return sorted(cList,
                   key=lambda contest: contest.start_time,
                   reverse=True)
Beispiel #5
0
 def canAddCourseProblem(cls, cs, u):
     if cs.canBeManaged(u):
         return True
     try:
         for css in CourseClass.getByCourse(cs):
             if css.canBeManaged(u):
                 return True
         return False
     except Exception as e:
         raise e
Beispiel #6
0
 def canAddCourseProblem(cls, cs, u):
     if cs.canBeManaged(u):
         return True
     try:
         for css in CourseClass.getByCourse(cs):
             if css.canBeManaged(u):
                 return True
         return False
     except Exception as e:
         raise e
Beispiel #7
0
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)
Beispiel #8
0
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)
Beispiel #9
0
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),
        })
Beispiel #10
0
 def getByStudent(cls, user):
     cList = []
     map(cList.extend, [Contest.getByCourseClass(cc) for cc in CourseClass.getByStudent(user)])
     cList = list(set(cList))
     return sorted(cList, key=lambda contest: contest.start_time, reverse=True)
Beispiel #11
0
 def getByAdmin(cls, user):
     cList = []
     ccList = CourseClass.getAllManagedClasses(user)
     map(cList.extend, [Contest.getByCourseClass(cc) for cc in ccList])
     cList = list(set(cList))
     return sorted(cList, key=lambda contest: contest.start_time, reverse=True)
Beispiel #12
0
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')
            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.canManageProblem(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:
        return render(request, Err.ERROR_PAGE)