Esempio n. 1
0
def add_topic(request, forum_id):
    """
    create a new topic, with or without poll
    """
    forum = get_object_or_404(Forum, pk=forum_id)
    if not forum.category.has_access(request.user):
        raise PermissionDenied

    ip = request.META.get('REMOTE_ADDR', None)
    post_form_kwargs = {
        "forum": forum,
        "user": request.user,
        "ip": ip,
    }

    poll_form = None
    if request.method == 'POST':
        form = AddPostForm(request.POST, request.FILES, **post_form_kwargs)
        if form.is_valid():
            all_valid = True
        else:
            all_valid = False

        if forum_settings.ENABLE_POLLS:
            poll_form = PollForm(request.POST)
            if not poll_form.has_data():
                # All poll fields are empty: User didn't want to create a poll
                # Don't run validation and remove all form error messages
                poll_form = PollForm()  # create clean form without form errors
            elif not poll_form.is_valid():
                all_valid = False

        if all_valid:
            post = form.save()
            if poll_form and poll_form.has_data():
                poll_form.save(post)
                messages.success(request, _("Topic with poll saved."))
            else:
                messages.success(request, _("Topic saved."))
            return HttpResponseRedirect(post.get_absolute_url())
    else:
        form = AddPostForm(initial={
            'markup':
            request.user.forum_profile.markup,
            'subscribe':
            request.user.forum_profile.auto_subscribe,
        },
                           **post_form_kwargs)
        if forum_settings.ENABLE_POLLS and forum_id:  # Create a new topic
            poll_form = PollForm()

    context = {
        'forum': forum,
        'create_poll_form': poll_form,
        'form': form,
        'form_url': request.path,
        'back_url': forum.get_absolute_url(),
        'forum_settings': forum_settings,
    }
    return render(request, 'djangobb_forum/add_topic.html', context)
Esempio n. 2
0
def add_topic(request, forum_id, full=True):
    """
    create a new topic, with or without poll
    """
    forum = get_object_or_404(Forum, pk=forum_id)
    if not forum.category.has_access(request.user) or (forum.moderator_only and not (request.user.is_superuser or request.user in forum.moderators.all())):
        return HttpResponseForbidden()

    ip = request.META.get('REMOTE_ADDR', None)
    post_form_kwargs = {"forum":forum, "user":request.user, "ip":ip, }

    if request.method == 'POST':
        form = AddPostForm(request.POST, request.FILES, **post_form_kwargs)
        if form.is_valid():
            all_valid = True
        else:
            all_valid = False

        poll_form = PollForm(request.POST)
        create_poll = poll_form.create_poll()
        if not create_poll:
            # All poll fields are empty: User didn't want to create a poll
            # Don't run validation and remove all form error messages
            poll_form = PollForm() # create clean form without form errors
        elif not poll_form.is_valid():
            all_valid = False

        if all_valid:
            post = form.save()
            if create_poll:
                poll_form.save(post)
                messages.success(request, _("Topic with poll saved."))
            else:
                messages.success(request, _("Topic saved."))
            return HttpResponseRedirect(post.get_absolute_url() if full else post.get_mobile_url())
    else:
        form = AddPostForm(
            initial={
                'markup': request.user.forum_profile.markup,
                'subscribe': request.user.forum_profile.auto_subscribe,
            },
            **post_form_kwargs
        )

    # if creating a new topic and allowed
    create_poll_form = forum_id and forum_settings.ALLOW_POLLS

    poll_form = PollForm()

    context = {
        'forum': forum,
        'create_poll_form': create_poll_form,
        'poll_form': poll_form,
        'form': form,
        'form_url': request.path,
        'back_url': forum.get_absolute_url(),
    }
    return render(request, 'djangobb_forum/add_topic.html' if full else 'djangobb_forum/mobile/add_topic.html', context)
Esempio n. 3
0
def add_topic(request, forum_id):
    """
    create a new topic, with or without poll
    """
    forum = get_object_or_404(Forum, pk=forum_id)
    if not forum.category.has_access(request.user):
        raise PermissionDenied

    ip = request.META.get('REMOTE_ADDR', None)
    post_form_kwargs = {"forum":forum, "user":request.user, "ip":ip, }

    poll_form = None
    if request.method == 'POST':
        form = AddPostForm(request.POST, request.FILES, **post_form_kwargs)
        if form.is_valid():
            all_valid = True
        else:
            all_valid = False

        if forum_settings.ENABLE_POLLS:
            poll_form = PollForm(request.POST)
            if not poll_form.has_data():
                # All poll fields are empty: User didn't want to create a poll
                # Don't run validation and remove all form error messages
                poll_form = PollForm() # create clean form without form errors
            elif not poll_form.is_valid():
                all_valid = False

        if all_valid:
            post = form.save()
            if poll_form and poll_form.has_data():
                poll_form.save(post)
                messages.success(request, _("Topic with poll saved."))
            else:
                messages.success(request, _("Topic saved."))
            return HttpResponseRedirect(post.get_absolute_url())
    else:
        form = AddPostForm(
            initial={
                'markup': request.user.forum_profile.markup,
                'subscribe': request.user.forum_profile.auto_subscribe,
            },
            **post_form_kwargs
        )
        if forum_settings.ENABLE_POLLS and forum_id: # Create a new topic
            poll_form = PollForm()

    context = {
        'forum': forum,
        'create_poll_form': poll_form,
        'form': form,
        'form_url': request.path,
        'back_url': forum.get_absolute_url(),
    }
    return render(request, 'djangobb_forum/add_topic.html', context)
Esempio n. 4
0
def add_topic(request, forum_id):
    """
    create a new topic, with or without poll
    """
    forum = get_object_or_404(Forum, pk=forum_id)
    if not forum.category.has_access(request.user):
        return HttpResponseForbidden()

    ip = request.META.get("REMOTE_ADDR", None)
    post_form_kwargs = {"forum": forum, "user": request.user, "ip": ip}

    if request.method == "POST":
        form = AddPostForm(request.POST, request.FILES, **post_form_kwargs)
        if form.is_valid():
            all_valid = True
        else:
            all_valid = False

        poll_form = PollForm(request.POST)
        if not poll_form.has_data():
            # All poll fields are empty: User didn't want to create a poll
            # Don't run validation and remove all form error messages
            poll_form = PollForm()  # create clean form without form errors
        elif not poll_form.is_valid():
            all_valid = False

        if all_valid:
            post = form.save()
            if poll_form.has_data():
                poll_form.save(post)
                messages.success(request, _("Topic with poll saved."))
            else:
                messages.success(request, _("Topic saved."))
            return HttpResponseRedirect(post.get_absolute_url())
    else:
        form = AddPostForm(
            initial={
                "markup": request.user.forum_profile.markup,
                "subscribe": request.user.forum_profile.auto_subscribe,
            },
            **post_form_kwargs
        )
        if forum_id:  # Create a new topic
            poll_form = PollForm()

    context = {
        "forum": forum,
        "create_poll_form": poll_form,
        "form": form,
        "form_url": request.path,
        "back_url": forum.get_absolute_url(),
    }
    return render(request, "djangobb_forum/add_topic.html", context)
Esempio n. 5
0
def add_topic(request, forum_id, full=True):
    """
    create a new topic, with or without poll
    """
    forum = get_object_or_404(Forum, pk=forum_id)
    if not forum.category.has_access(request.user) or (
            forum.moderator_only
            and not (request.user.is_superuser
                     or request.user in forum.moderators.all())):
        return HttpResponseForbidden()

    ip = get_client_ip(request)
    post_form_kwargs = {
        "forum": forum,
        "user": request.user,
        "ip": ip,
        "is_ip_banned": request.is_ip_banned,
        "request_data": request.META
    }

    if request.method == 'POST':
        form = AddPostForm(request.POST, request.FILES, **post_form_kwargs)
        if form.is_valid():
            all_valid = True
        else:
            all_valid = False

        poll_form = PollForm(request.POST)
        create_poll = poll_form.create_poll()
        if not create_poll:
            # All poll fields are empty: User didn't want to create a poll
            # Don't run validation and remove all form error messages
            poll_form = PollForm()  # create clean form without form errors
        elif not poll_form.is_valid():
            all_valid = False

        if all_valid:
            post = form.save()
            if create_poll:
                poll_form.save(post)
                messages.success(request, _("Topic with poll saved."))
            else:
                messages.success(request, _("Topic saved."))
            return HttpResponseRedirect(
                post.get_absolute_url() if full else post.get_mobile_url())
    else:
        form = AddPostForm(initial={
            'markup': request.user.forum_profile.markup,
            'subscribe': True,
        },
                           **post_form_kwargs)

    # if creating a new topic and allowed
    create_poll_form = forum_id and forum_settings.ALLOW_POLLS

    poll_form = PollForm()

    context = {
        'forum': forum,
        'create_poll_form': create_poll_form,
        'poll_form': poll_form,
        'form': form,
        'form_url': request.path,
        'back_url': forum.get_absolute_url(),
        'simple_user_agent': simple_user_agent(request),
    }
    return render(
        request, 'djangobb_forum/add_topic.html'
        if full else 'djangobb_forum/mobile/add_topic.html', context)
Esempio n. 6
0
def add_topic(request, forum_id):
    """
    create a new topic, with or without poll
    """
    forum = get_object_or_404(Forum, pk=forum_id)
    if not forum.category.has_access(request.user):
        raise PermissionDenied

    ip = request.META.get('REMOTE_ADDR', None)

    contest = True if 'contest' in request.GET else False
    id = request.GET.get('id')
    if contest and id != '':
        try:
            ban = bans.Ban.objects.get(bid=request.GET.get('id'))
        except bans.Ban.DoesNotExist:
            ban = False
            messages.error(request, "No ban with this ID found.")
    else:
        ban = False
    post_form_kwargs = {
        "forum": forum,
        "user": request.user,
        "ip": ip,
        'contest': contest
    }

    poll_form = None
    if request.method == 'POST':
        form = AddPostForm(request.POST, request.FILES, **post_form_kwargs)
        if form.is_valid():
            all_valid = True
        else:
            all_valid = False

        if forum_settings.ENABLE_POLLS:
            poll_form = PollForm(request.POST)
            if not poll_form.has_data():
                # All poll fields are empty: User didn't want to create a poll
                # Don't run validation and remove all form error messages
                poll_form = PollForm()  # create clean form without form errors
            elif not poll_form.is_valid():
                all_valid = False

        if all_valid:
            post = form.save()
            if poll_form and poll_form.has_data():
                poll_form.save(post)
                messages.success(request, _("Topic with poll saved."))
            else:
                messages.success(request, _("Topic saved."))
            return HttpResponseRedirect(post.get_absolute_url())
    else:
        form = AddPostForm(initial={
            'contest':
            True if 'contest' in request.GET else False,
            'markup':
            request.user.forum_profile.markup,
            'subscribe':
            request.user.forum_profile.auto_subscribe,
        },
                           **post_form_kwargs)
        if forum_settings.ENABLE_POLLS and forum_id:  # Create a new topic
            poll_form = PollForm()

    context = {
        'contest': True if 'contest' in request.GET else False,
        'forum': forum,
        'create_poll_form': poll_form,
        'form': form,
        'form_url': request.path,
        'back_url': forum.get_absolute_url(),
        'ban': ban,
    }
    if contest:
        messages.warning(
            request,
            "Please complete the template below to submit your ban appeal to the forums.\n\
         Any alteration of the template will get your request denied and locked. You may attach your proof to the post \
        or link to Youtube for video proof. Links to other external sites will get your appeal denied and locked."
        )
    return render(request, 'djangobb_forum/add_topic.html', context)