Beispiel #1
0
def add_contest_message_view(request):
    is_admin = is_contest_admin(request)
    if request.method == 'POST':
        form = AddContestMessageForm(request, request.POST)
        if form.is_valid():
            instance = form.save(commit=False)
            instance.author = request.user
            if is_admin:
                instance.kind = 'PUBLIC'
            else:
                instance.kind = 'QUESTION'
                instance.pub_date = None
            instance.date = request.timestamp
            instance.save()
            if instance.kind == 'QUESTION':
                new_question_signal.send(sender=Message, request=request,
                                         instance=instance)
            log_addition(request, instance)
            return redirect('contest_messages', contest_id=request.contest.id)

    else:
        initial = {}
        for field in ('category', 'topic', 'content'):
            if field in request.GET:
                initial[field] = request.GET[field]
        form = AddContestMessageForm(request, initial=initial)

    if is_admin:
        title = _("Add news")
    else:
        title = _("Ask question")

    return TemplateResponse(request, 'questions/add.html',
            {'form': form, 'title': title, 'is_news': is_admin})
Beispiel #2
0
def add_contest_message_view(request):
    is_admin = is_contest_basicadmin(request)
    if request.method == 'POST':
        form = AddContestMessageForm(request, request.POST)
        if form.is_valid():
            instance = form.save(commit=False)
            instance.author = request.user
            if is_admin:
                instance.kind = 'PUBLIC'
            else:
                instance.kind = 'QUESTION'
                instance.pub_date = None
            instance.date = request.timestamp
            instance.save()
            if instance.kind == 'QUESTION':
                new_question_signal.send(sender=Message,
                                         request=request,
                                         instance=instance)
            log_addition(request, instance)
            return redirect('contest_messages', contest_id=request.contest.id)

    else:
        initial = {}
        for field in ('category', 'topic', 'content'):
            if field in request.GET:
                initial[field] = request.GET[field]
        form = AddContestMessageForm(request, initial=initial)

    if is_admin:
        title = _("Add news")
    else:
        title = _("Ask question")

    return TemplateResponse(
        request,
        'questions/add.html',
        {
            'form': form,
            'title': title,
            'is_news': is_admin
        },
    )