Esempio n. 1
0
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)})    
Esempio n. 2
0
File: views.py Progetto: YLAsce/oj
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)})
Esempio n. 3
0
def deleteClarification(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!')
        
        clar.deleteClarification()
        return redirect('Contest:view_all_clars', c.pk)
    except Exception as e:
        logger.error(unicode(e).replace('\n', '\t')) 
        return render(request, Err.ERROR_PAGE, {'errmsg': unicode(e)})    
Esempio n. 4
0
File: views.py Progetto: YLAsce/oj
def deleteClarification(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!')

        clar.deleteClarification()
        return redirect('Contest:view_all_clars', c.pk)
    except Exception as e:
        logger.error(unicode(e).replace('\n', '\t'))
        return render(request, Err.ERROR_PAGE, {'errmsg': unicode(e)})