示例#1
0
def askAdmin(request):
    user = request.user
    if user.is_authenticated:
        if request.method == "POST":
            form = SendMessageForm(request.POST)
            if form.is_valid():
                admin = Student.objects.filter(username='******').first()
                veileder = Student.objects.filter(username='******').first()
                chat = Chat.objects.create()
                chat.participents.set([admin, veileder, user])
                pk = chat.id
                send = form.save(commit=False)
                send.from_user = user
                send.to_chat = chat
                send.message = form.cleaned_data['message']
                send.save()
                updateChats()
            return redirect('advisorChat', pk)
        form = SendMessageForm(request.POST)
        context = {
            'form': form,
        }
        send_fargetema(request, context)
        return render(request, "chat/askAdmin.html", context)
    return redirect('home')
示例#2
0
def sendFeedback(request):
    if request.method == "POST":
        form = SendMessageForm(request.POST)
        if form.is_valid():
            user = request.user
            if not user.is_authenticated:
                user = Student.objects.filter(username='******').first()
            admin = Student.objects.filter(username='******').first()
            chat = Chat.objects.create()
            chat.participents.set([admin, user])
            chat.is_feedback = True
            chat.save()
            send = form.save(commit=False)
            send.from_user = user
            send.to_chat = chat
            send.message = form.cleaned_data['message']
            send.save()
            updateChats()
        return redirect('home')
    form = SendMessageForm(request.POST)
    context = {
        'form': form,
    }
    send_fargetema(request, context)
    return render(request, "chat/sendFeedback.html", context)
示例#3
0
def getAdvisorChats(request):
    user = request.user
    if user.is_staff or user.groups.all().filter(name='veileder').exists():
        chats = Chat.objects.filter(
            participents=user).order_by('-last_message__sent_at')
        admin = Student.objects.filter(username='******').first()
        veileder = Student.objects.filter(username='******').first()
        veilederChats = Chat.objects.filter(participents=veileder).exclude(
            participents=admin)
        yourAssigned = veilederChats.filter(
            participents__username=user.username)
        chatsWithAdmin = Chat.objects.filter(participents=admin)
        chatsWithAdmin = chatsWithAdmin.filter(participents=veileder)
        chatsWithAdmin = chatsWithAdmin.filter(participents=user)

        context = {
            'user': user,
            'chats': chats,
            'veileder': veileder,
            'veilederChats': veilederChats,
            'yourAssigned': yourAssigned,
            'chatsWithAdmin': chatsWithAdmin,
            'chat': None,
        }
        send_fargetema(request, context)
        return context
    return redirect('chats')
示例#4
0
def getAdminChats(request):
    user = request.user
    if user.is_staff:
        chats = Chat.objects.all()
        admin = Student.objects.filter(username='******').first()
        veileder = Student.objects.filter(username='******').first()
        veilederChats = Chat.objects.filter(participents=veileder).exclude(
            participents=admin)
        yourAssigned = veilederChats.filter(
            participents__username=user.username)
        chatsWithAdmin = Chat.objects.filter(participents=admin)
        chatsWithAdmin = chatsWithAdmin.filter(participents=veileder)
        chatsWithAdmin = chatsWithAdmin.filter(participents=user)

        context = {
            'user': user,
            'chats': chats,
            'admin': admin,
            'veileder': veileder,
            'veilederChats': veilederChats,
            'yourAssigned': yourAssigned,
            'chatsWithAdmin': chatsWithAdmin,
            'chat': None,
        }
        send_fargetema(request, context)
        return context
    return redirect('chats')
示例#5
0
def messageAll(request):
    user = request.user
    if user.is_authenticated:
        if request.method == "POST":
            form = SendMessageForm(request.POST)
            if form.is_valid():
                alle = Student.objects.filter(username='******').first()
                admin = Student.objects.filter(username='******').first()
                chat = Chat.objects.create()
                chat.participents.set([alle])
                chat.is_closed = True
                chat.save()
                pk = chat.id
                send = form.save(commit=False)
                send.from_user = admin
                send.to_chat = chat
                send.message = form.cleaned_data['message']
                send.save()
                updateChats()
            return redirect('adminChat', pk)
        form = SendMessageForm(request.POST)
        context = {
            'form': form,
        }
        send_fargetema(request, context)
        return render(request, "chat/messageAll.html", context)
    return redirect('home')
示例#6
0
def messageAll(request):
    user = request.user
    # Checks if user is admin or else redirects to the front page
    if user.is_staff:
        # If the send button is pushed a new chat is created with all users and sent from Admin
        if request.method == "POST":
            form = SendMessageForm(request.POST)
            if form.is_valid():
                alle = Student.objects.filter(username='******').first()
                admin = Student.objects.filter(username='******').first()
                chat = Chat.objects.create()
                chat.participants.set([alle])
                chat.is_closed = True
                chat.save()
                pk = chat.id
                send = form.save(commit=False)
                send.from_user = admin
                send.to_chat = chat
                send.message = form.cleaned_data['message']
                send.save()
                updateChats()
            return redirect('adminChat', pk)
        # Else it gets and loads the form to message all page
        form = SendMessageForm(request.POST)
        context = {
            'form': form,
        }
        send_fargetema(request, context)
        return render(request, "chat/messageAll.html", context)
    return redirect('home')
示例#7
0
def askAdvisor(request):
    user = request.user
    # Makes sure the user is signed in or else redirects to the front page
    if user.is_authenticated:
        # If the send button is pushed a new chat is created with the user and all the advisors
        if request.method == "POST":
            form = SendMessageForm(request.POST)
            if form.is_valid():
                veileder = Student.objects.filter(username='******').first()
                chat = Chat.objects.create()
                chat.participants.set([veileder, user])
                pk = chat.id
                send = form.save(commit=False)
                send.from_user = user
                send.to_chat = chat
                send.message = form.cleaned_data['message']
                send.save()
                updateChats()
            return redirect('chat', pk)
        # Else it gets and loads the form to ask advisors
        form = SendMessageForm(request.POST)
        context = {
            'form': form,
        }
        send_fargetema(request, context)
        return render(request, "chat/askAdvisor.html", context)
    return redirect('home')
示例#8
0
def sendFeedback(request):
    # If the send button is pushed
    if request.method == "POST":
        form = SendMessageForm(request.POST)
        if form.is_valid():
            user = request.user
            # If the user isn't signed in the feedback is sent anonymously
            if not user.is_authenticated:
                user = Student.objects.filter(username='******').first()
            admin = Student.objects.filter(
                username='******').first()  # Universal Admin user
            # Creates a new chat, sets the participants to be the user/anonymous and admin and sends the message
            chat = Chat.objects.create()
            chat.participants.set([admin, user])
            chat.is_feedback = True
            chat.save()
            send = form.save(commit=False)
            send.from_user = user
            send.to_chat = chat
            send.message = form.cleaned_data['message']
            send.save()
            updateChats()
        return redirect(
            'home')  # Redirects to the front page after the message is sent
    # Else it gets and loads the form to send feedback
    form = SendMessageForm(request.POST)
    context = {
        'form': form,
    }
    send_fargetema(request, context)
    return render(request, "chat/sendFeedback.html", context)
示例#9
0
def getChats(request):
    user = request.user
    chats = Chat.objects.filter(
        participents=user).order_by('-last_message__sent_at')
    Alle = Student.objects.filter(username='******')
    allChat = Chat.objects.filter(participents__in=Alle)
    veilederChats = None

    context = {
        'user': user,
        'chats': chats,
        'allChat': allChat,
        'chat': None,
    }
    send_fargetema(request, context)
    return context
示例#10
0
def getAdminChats(request):
    user = request.user
    # Checks if the user is admin
    if user.is_staff:
        chats = Chat.objects.all()
        admin = Student.objects.filter(username='******').first()
        veileder = Student.objects.filter(username='******').first()
        chatsWithAdmin = Chat.objects.filter(participants=admin)
        chatsWithAdmin = chatsWithAdmin.filter(participants=veileder)
        # Not also filtering on the user, because all the admins can see these messages
        context = {
            'user': user,
            'chats': chats,
            'admin': admin,
            'chatsWithAdmin': chatsWithAdmin,
            'chat': None,
        }
        send_fargetema(request, context)
        return context
    return redirect('chats')
示例#11
0
def getChats(request):
    user = request.user
    chats = Chat.objects.filter(
        participants=user).order_by('-last_message__sent_at')
    Alle = Student.objects.filter(
        username='******'
    )  # User used instead of having all users in a chat you just have
    # this universal user
    allChat = Chat.objects.filter(participants__in=Alle)

    context = {
        'user': user,
        'chats': chats,
        'allChat': allChat,
        'chat': None,
    }
    send_fargetema(
        request, context
    )  # Makes sure either the global or personal color theme is used for the site
    return context