def add_reply_view(request, contest_id, message_id): question = get_object_or_404(Message, id=message_id, contest_id=contest_id, kind="QUESTION") if request.method == "POST": form = AddReplyForm(request, request.POST) if form.is_valid(): instance = form.save(commit=False) instance.top_reference = question instance.author = request.user instance.save() return redirect("contest_messages", contest_id=contest_id) else: form = AddReplyForm( request, initial={"topic": _("Re: ") + question.topic, "content": quote_for_reply(question.content)} ) return TemplateResponse(request, "questions/add.html", {"form": form, "title": _("Reply"), "is_reply": True})
def message_view(request, message_id): message = get_object_or_404(Message, id=message_id, contest_id=request.contest.id) vmessages = visible_messages(request) if not vmessages.filter(id=message_id): raise PermissionDenied if message.top_reference_id is None: replies = list(vmessages.filter(top_reference=message) .order_by('date')) else: replies = [] if is_contest_admin(request) and message.kind == 'QUESTION' and \ message.can_have_replies: if request.method == 'POST': form = AddReplyForm(request, request.POST) if request.POST.get('just_reload') != 'yes' and form.is_valid(): instance = form.save(commit=False) instance.top_reference = message instance.author = request.user instance.date = request.timestamp instance.save() log_addition(request, instance) return redirect('contest_messages', contest_id=request.contest.id) elif request.POST.get('just_reload') == 'yes': form.is_bound = False else: form = AddReplyForm(request, initial={ 'topic': _("Re: ") + message.topic, }) else: form = None if request.user.is_authenticated(): for m in [message] + replies: try: MessageView.objects.get_or_create(message=m, user=request.user) except IntegrityError: # get_or_create does not guarantee race-free execution, so we # silently ignore the IntegrityError from the unique index pass return TemplateResponse(request, 'questions/message.html', {'message': message, 'replies': replies, 'form': form, 'reply_to_id': message.top_reference_id or message.id, 'timestamp': request_time_seconds(request)})
def message_view(request, message_id): message = get_object_or_404(Message, id=message_id, contest_id=request.contest.id) vmessages = visible_messages(request) if not vmessages.filter(id=message_id): raise PermissionDenied if message.top_reference_id is None: replies = list(vmessages.filter(top_reference=message)) replies.sort(key=Message.get_user_date) else: replies = [] if is_contest_admin(request) and message.kind == 'QUESTION' and \ message.can_have_replies: if request.method == 'POST': form = AddReplyForm(request, request.POST) if request.POST.get('just_reload') != 'yes' and form.is_valid(): instance = form.save(commit=False) instance.top_reference = message instance.author = request.user instance.date = request.timestamp instance.save() log_addition(request, instance) return redirect('contest_messages', contest_id=request.contest.id) elif request.POST.get('just_reload') == 'yes': form.is_bound = False else: form = AddReplyForm(request, initial={ 'topic': _("Re: ") + message.topic, }) else: form = None if request.user.is_authenticated: mark_messages_read(request.user, [message] + replies) return TemplateResponse(request, 'questions/message.html', {'message': message, 'replies': replies, 'form': form, 'reply_to_id': message.top_reference_id or message.id, 'timestamp': request_time_seconds(request)})
def add_reply_view(request, contest_id, message_id): question = get_object_or_404(Message, id=message_id, contest_id=contest_id, kind='QUESTION') if request.method == 'POST': form = AddReplyForm(request, request.POST) if form.is_valid(): instance = form.save(commit=False) instance.top_reference = question instance.author = request.user instance.date = request.timestamp instance.save() log_addition(request, instance) return redirect('contest_messages', contest_id=contest_id) else: form = AddReplyForm(request, initial={ 'topic': _("Re: ") + question.topic, 'content': quote_for_reply(question.content), }) return TemplateResponse(request, 'questions/add.html', { 'form': form, 'title': _("Reply"), 'is_reply': True, 'question': question })
def message_view(request, message_id): message = get_object_or_404(Message, id=message_id, contest_id=request.contest.id) vmessages = visible_messages(request) if not vmessages.filter(id=message_id): raise PermissionDenied if message.top_reference_id is None: replies = list(vmessages.filter(top_reference=message)) replies.sort(key=Message.get_user_date) else: replies = [] if ( is_contest_basicadmin(request) and message.kind == 'QUESTION' and message.can_have_replies ): if request.method == 'POST': form = AddReplyForm(request, request.POST) if request.POST.get('just_reload') != 'yes' and form.is_valid(): instance = form.save(commit=False) instance.top_reference = message instance.author = request.user instance.date = request.timestamp instance.save() log_addition(request, instance) return redirect('contest_messages', contest_id=request.contest.id) elif request.POST.get('just_reload') == 'yes': form.is_bound = False else: form = AddReplyForm( request, initial={ 'topic': _("Re: ") + message.topic, }, ) else: form = None if request.user.is_authenticated: mark_messages_read(request.user, [message] + replies) return TemplateResponse( request, 'questions/message.html', { 'message': message, 'replies': replies, 'form': form, 'reply_to_id': message.top_reference_id or message.id, 'timestamp': request_time_seconds(request), }, )
def message_view(request, contest_id, message_id): message = get_object_or_404(Message, id=message_id, contest_id=contest_id) vmessages = visible_messages(request) if not vmessages.filter(id=message_id): raise PermissionDenied if message.top_reference_id is None: replies = list( vmessages.filter(top_reference=message).order_by('date')) else: replies = [] if is_contest_admin(request) and message.kind == 'QUESTION' and \ message.can_have_replies: if request.method == 'POST': form = AddReplyForm(request, request.POST) if request.POST.get('just_reload') != 'yes' and form.is_valid(): instance = form.save(commit=False) instance.top_reference = message instance.author = request.user instance.date = request.timestamp instance.save() log_addition(request, instance) return redirect('contest_messages', contest_id=contest_id) else: form = AddReplyForm(request, initial={ 'topic': _("Re: ") + message.topic, }) else: form = None if request.user.is_authenticated(): for m in [message] + replies: try: MessageView.objects.get_or_create(message=m, user=request.user) except IntegrityError: # get_or_create does not guarantee race-free execution, so we # silently ignore the IntegrityError from the unique index pass return TemplateResponse( request, 'questions/message.html', { 'message': message, 'replies': replies, 'form': form, 'reply_to_id': message.top_reference_id or message.id, 'timestamp': request_time_seconds(request) })