Exemple #1
0
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), })
Exemple #2
0
def showContestNotice(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.canEnterContest(u)
        return render(request, 'newtpl/contest/showContestNotice.html',
                      {'cid': cId, 'contest_notice': cn,
                       'tpl': {'has_priv': Contest.hasPriv(c.course_class, u), 'sp': True, 'nav_act':'contest',}})
    except Exception as e:
        return render(request, Const.ERROR_PAGE, {'errmsg': unicode(e), })
Exemple #3
0
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),
        })
Exemple #4
0
def showContestNotice(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.canEnterContest(u)
        return render(
            request, 'newtpl/contest/showContestNotice.html', {
                'cid': cId,
                'contest_notice': cn,
                'tpl': {
                    'has_priv': Contest.hasPriv(c.course_class, u),
                    'sp': True,
                    'nav_act': 'contest',
                }
            })
    except Exception as e:
        return render(request, Const.ERROR_PAGE, {
            'errmsg': unicode(e),
        })