• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gcivil-nyu-org / fall24-monday-team4 / 75

04 Nov 2024 11:54PM UTC coverage: 65.594% (-0.07%) from 65.663%
75

Pull #87

travis-pro

shashankdatta
Cleared Merged Conflicts
Pull Request #87: Idan/chatroom

47 of 72 new or added lines in 7 files covered. (65.28%)

265 of 404 relevant lines covered (65.59%)

0.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

29.41
/chat/views.py
1
from django.contrib.auth.decorators import login_required
1✔
2
from django.shortcuts import render, redirect
1✔
3
from .models import ChatRoom, Message
1✔
4
from .forms import ChatRoomForm, MessageForm
1✔
5

6

7
@login_required
1✔
8
def index(request):
1✔
NEW
9
    chat_rooms = ChatRoom.objects.all()
×
NEW
10
    return render(request, "chat/index.html", {"chat_rooms": chat_rooms})
×
11

12

13
@login_required
1✔
14
def chat_room(request, pk):
1✔
NEW
15
    chat_room = ChatRoom.objects.get(pk=pk)
×
NEW
16
    if request.user not in chat_room.users.all():
×
NEW
17
        return redirect(
×
18
            "index"
19
        )  # Redirect to the index page if the user doesn't have access
NEW
20
    messages = Message.objects.filter(chat_room=chat_room)
×
NEW
21
    if request.method == "POST":
×
NEW
22
        form = MessageForm(request.POST)
×
NEW
23
        if form.is_valid():
×
NEW
24
            message = form.save(commit=False)
×
NEW
25
            message.user = request.user
×
NEW
26
            message.chat_room = chat_room
×
NEW
27
            message.save()
×
NEW
28
            return redirect("chat_room", pk=chat_room.pk)
×
29
    else:
NEW
30
        form = MessageForm()
×
NEW
31
    return render(
×
32
        request,
33
        "chat/chat_room.html",
34
        {"chat_room": chat_room, "messages": messages, "form": form},
35
    )
36

37

38
@login_required
1✔
39
def create_chat_room(request):
1✔
NEW
40
    if request.method == "POST":
×
NEW
41
        form = ChatRoomForm(request.POST)
×
NEW
42
        if form.is_valid():
×
NEW
43
            chat_room = form.save()  # Save the ChatRoom instance to the database
×
NEW
44
            chat_room.users.add(
×
45
                request.user
46
            )  # Add the requesting user to the chat room
NEW
47
            return redirect("index")
×
48
    else:
NEW
49
        form = ChatRoomForm(initial={"users": [request.user.id]})
×
NEW
50
    return render(request, "chat/create_chat_room.html", {"form": form})
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc