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)})
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)})
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)})
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)})
def addClarification(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) has_priv = False try: c.canBeManaged(u) has_priv = True except: pass try: c.canEnterContest(u) has_priv = True except: pass if not has_priv: raise Exception('No Privilege!') if request.method != 'POST': return render(request, 'newtpl/contest/addClar.html', {'contest': c}) form = ClarificationForm(request.POST) try: if form.is_valid(): question = form.cleaned_data['question'] Clarification.addClarification(question, u, c) return redirect('Contest:view_all_clars', cid) else: raise except: raise Exception('Invalid Question') except Exception as e: logger.error(unicode(e).replace('\n', '\t')) return render(request, Err.ERROR_PAGE, {'errmsg': unicode(e)})
def addClarification(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) has_priv = False try: c.canBeManaged(u) has_priv = True except: pass try: c.canEnterContest(u) has_priv = True except: pass if not has_priv: raise Exception('No Privilege!') if request.method != 'POST': return render(request, 'newtpl/contest/addClar.html', {'contest': c}) form = ClarificationForm(request.POST) try: if form.is_valid(): question = form.cleaned_data['question'] Clarification.addClarification(question, u, c) return redirect('Contest:view_all_clars', cid) else: raise except: raise Exception('Invalid Question') except Exception as e: logger.error(unicode(e).replace('\n', '\t')) return render(request, Err.ERROR_PAGE, {'errmsg': unicode(e)})
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)})
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)})