Ejemplo n.º 1
0
def message_send(request, username):

    userModel = get_user_model()

    try:
        user = userModel.objects.get(username=username)

    except userModel.DoesNotExist:
        raise Http404('Invalid username.')

    if request.method == 'POST':
        form = PrivateMessageForm(request.POST)

        if form.is_valid():

            title = form.cleaned_data['title']
            content = form.cleaned_data['content']
            message = PrivateMessage(receiver=user,
                                     sender=request.user,
                                     title=title,
                                     content=content)
            message.save()

            utilities.set_message(request,
                                  'Message sent to {}!'.format(user.username))

            return HttpResponseRedirect(user.get_url())

    else:
        form = PrivateMessageForm()

    context = {'form': form, 'username': username}

    return render(request, 'accounts/send_message.html', context)
Ejemplo n.º 2
0
def disable_user(request, username):

    userModel = get_user_model()

    try:
        user = userModel.objects.get(username=username)

    except userModel.DoesNotExist:
        raise Http404("User doesn't exist.")

    else:
        value = not user.is_active

        # only other staff users can enable/disable staff users
        if user.is_staff:
            if request.user.is_staff:
                user.is_active = value
                user.save()

            else:
                return HttpResponseForbidden("Can't disable a staff member.")

        else:
            user.is_active = value
            user.save()

        if value:
            message = "'{}' account is now active.".format(user.username)

        else:
            message = "'{}' account is now disabled.".format(user.username)

        utilities.set_message(request, message)

        return HttpResponseRedirect(user.get_url())
Ejemplo n.º 3
0
def message_remove(request, messageId):

    try:
        message = request.user.privatemessage_set.get(id=messageId)

    except PrivateMessage.DoesNotExist:
        raise Http404("Message doesn't exist.")

    message.delete()
    utilities.set_message(request, 'Message removed!')

    return HttpResponseRedirect(reverse('accounts:message_all'))
Ejemplo n.º 4
0
def remove_category(request, categorySlug):

    try:
        category = Category.objects.get(slug=categorySlug)

    except Category.DoesNotExist:
        raise Http404("Category doesn't exist.")

    utilities.set_message(request,
                          "'{}' category removed!".format(category.name))
    category.delete()

    return HttpResponseRedirect(reverse('index'))
Ejemplo n.º 5
0
def remove_sub_forum(request, forumSlug):

    try:
        forum = SubForum.objects.get(slug=forumSlug)

    except SubForum.DoesNotExist:
        raise Http404("Sub-forum doesn't exist.")

    utilities.set_message(request,
                          "'{}' sub-forum removed!".format(forum.name))
    forum.delete()

    return HttpResponseRedirect(reverse('index'))
Ejemplo n.º 6
0
def remove_post(request, postId):

    try:
        post = Post.objects.get(id=postId)

    except Post.DoesNotExist:
        raise Http404("Post doesn't exist.")

    utilities.set_message(request, "Post removed!")
    theThread = post.thread
    post.delete()

    return HttpResponseRedirect(theThread.get_url())
Ejemplo n.º 7
0
def remove_thread(request, threadSlug):

    try:
        thread = Thread.objects.get(slug=threadSlug)

    except Thread.DoesNotExist:
        raise Http404("Thread doesn't exist.")

    utilities.set_message(request, "'{}' thread removed!".format(thread.title))
    url = thread.sub_forum.get_url()

    thread.delete()

    return HttpResponseRedirect(url)
Ejemplo n.º 8
0
def remove_user(request, username):

    userModel = get_user_model()

    try:
        user = userModel.objects.get(username=username)

    except userModel.DoesNotExist:
        raise Http404("User doesn't exist.")

    else:
        utilities.set_message(request,
                              "'{}' user removed!".format(user.username))
        user.delete()

        return HttpResponseRedirect(reverse('index'))
Ejemplo n.º 9
0
def new_account(request):

    if request.method == 'POST':

        form = MyUserCreationForm(request.POST)

        if form.is_valid():

            form.save()
            utilities.set_message(
                request,
                "User '{}' created!".format(form.cleaned_data['username']))

            return HttpResponseRedirect(reverse('accounts:login'))

    else:
        form = MyUserCreationForm()

    context = {'form': form}

    return render(request, 'accounts/new_account.html', context)
Ejemplo n.º 10
0
def set_moderator(request, username):

    userModel = get_user_model()

    try:
        user = userModel.objects.get(username=username)

    except userModel.DoesNotExist:
        raise Http404("User doesn't exist.")

    user.is_moderator = not user.is_moderator
    user.save()

    if user.is_moderator:
        message = "'{}' is now a moderator.".format(user.username)

    else:
        message = "'{}' is not a moderator anymore.".format(user.username)

    utilities.set_message(request, message)

    return HttpResponseRedirect(user.get_url())
Ejemplo n.º 11
0
def lock_thread(request, threadSlug):
    """
        Locks/unlocks the thread
    """

    try:
        thread = Thread.objects.get(slug=threadSlug)

    except Thread.DoesNotExist:
        raise Http404("Thread doesn't exist.")

    thread.is_locked = not thread.is_locked
    thread.save()

    if thread.is_locked:
        message = 'Thread locked!'

    else:
        message = 'Thread unlocked!'

    utilities.set_message(request, message)

    return HttpResponseRedirect(thread.get_url())
Ejemplo n.º 12
0
def password_changed(request):

    utilities.set_message(request, 'Password changed!')

    return HttpResponseRedirect(reverse('home'))