def reply(request): try: clarification = request.POST["clarification"] instance = Clarification.objects.get(pk=clarification) contest_obj = instance.contest contest = contest_obj.id except: logger.warning("Clarification: User %s can not reply Clarification!" % (request.user.username)) raise Http404("Contest does not exist, can not reply.") if can_reply(request.user, contest_obj): if request.method == "POST": form = ReplyForm(request.POST, instance=instance) if form.is_valid(): replied_clarification = form.save() replied_clarification.reply_time = datetime.now() replied_clarification.save() logger.info( "Clarification: User %s reply Clarification %s!" % (request.user.username, replied_clarification.id) ) message = "User %s successfully replied!" % (request.user.username) messages.success(request, message) else: logger.warning( "Clarification: User %s can not reply Clarification %s!" % (request.user.username, replied_clarification.id) ) message = "Some fields are wrong!" messages.error(request, message) return redirect("contest:contest", contest) message = "User %s cannot reply!" % (request.user.username) messages.error(request, message) return redirect("contest:archive")
def reply(request): try: clarification = request.POST['clarification'] instance = Clarification.objects.get(pk=clarification) contest_obj = instance.contest contest = contest_obj.id except: logger.warning('Clarification: User %s can not reply Clarification!' % (request.user.username)) raise Http404('Contest does not exist, can not reply.') if can_reply(request.user, contest_obj): if request.method == 'POST': form = ReplyForm(request.POST, instance=instance) if form.is_valid(): replied_clarification = form.save() replied_clarification.reply_time = datetime.now() replied_clarification.save() logger.info('Clarification: User %s reply Clarification %s!' % (request.user.username, replied_clarification.id)) message = 'User %s successfully replied!' % \ (request.user.username) messages.success(request, message) else: logger.warning( 'Clarification: User %s can not reply Clarification %s!' % (request.user.username, replied_clarification.id)) message = 'Some fields are wrong!' messages.error(request, message) return redirect('contest:contest', contest) message = 'User %s cannot reply!' % \ (request.user.username) messages.error(request, message) return redirect('contest:archive')
def can_reply(user, contest): return contest_info.can_reply(user, contest)