File size: 1,494 Bytes
75df934
46d747a
 
 
 
 
 
 
75df934
46d747a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75df934
 
 
4b81092
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# chat/views.py
from django.shortcuts import render,redirect
from django.http import HttpResponse
from django.contrib.auth.decorators import login_required
from .database_manage import DataManage
import uuid
import json
@login_required
def index(request):
    roomid = request.GET.get('id')
    data = DataManage()
    rooms = data.LoadRooms(username=request.user.username)
    if roomid:
        # try:
            roomdata = data.LoadRoomDetail(roomid=roomid)
            if roomdata==None:
                raise("Room not found")
            context = {
                'rooms': rooms,
                'roomdata': json.dumps(roomdata),
            }
            return render(request, 'index.html',context=context)
        # except Exception as e:
        #     print(e)
        #     return HttpResponse("Room not found", status=404)
    else:
        roomdata = {'messages':[]}
        return render(request, "index.html",{"rooms":rooms,'roomdata':roomdata})

@login_required
def newchat(request):
    data = DataManage()
    user = request.user.username
    ques = request.GET.get('ques')
    room = data.InsertRoom(user,ques[:23])
    return redirect(f'/chat?id={room}&ques={ques}')


def room(request, room_name):
    return render(request, "chat/room.html", {"room_name": room_name})
@login_required
def deletechat(request):
    data = DataManage()
    roomid = request.GET.get('id')
    data.DeleteRoom(roomid)
    return redirect('/chat')