Spaces:
Sleeping
Sleeping
# 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 | |
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}) | |
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}) | |
def deletechat(request): | |
data = DataManage() | |
roomid = request.GET.get('id') | |
data.DeleteRoom(roomid) | |
return redirect('/chat') |