def delete(self): key = self.request.cookies['roomlist'] roomlist = db.get(key) #roomId = simplejson.loads(self.request.body)['id'] roomId = self.request.get("roomId") room = Rooms.get_by_id(int(roomId)) if room.roomlist.key() == roomlist.key(): #tmp = room.toDict() room.delete() else: self.error(403)
def room(roomId): if 'loggedin' in session: if(session['loggedin']==True): room = Rooms.get_by_id(roomId) if (room == None): return render_template('message.html', vars={'title': 'eRRoR:', 'msg':'No Room by that Id.', 'link': '/', 'linkStr': 'home'}) vars = room.to_dict() vars['id'] = room.key.id() vars['username'] = session['username'] return render_template('room.html', vars=vars) return render_template('message.html', vars={'title': 'eRRoR:', 'msg':'Not Signed In.', 'link': '/', 'linkStr': 'home'})
def roomCreate(): if 'loggedin' in session: if(session['loggedin']==True): roomId = '' while True: roomId = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(8)) room = Rooms.get_by_id(roomId) if (room == None): break roomKey = Rooms(id = roomId, url = roomId, canvas = '{"objects":[],"background":""}', canvasVersion = 0, chatHistory = ['{"username": "******", "date": "'+datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S")+'", "chatMessage": "Hello and welcome to Brainstorm. You can start drawing in the pane to the left and share it with the people who are here, or message them directly by typing a message below."}']).put() return redirect('/room/' + roomId) return render_template('message.html', vars={'title': 'eRRoR:', 'msg':'Not Signed In.', 'link': '/', 'linkStr': 'home'})
def put(self): key = self.request.cookies['roomlist'] roomlist = db.get(key) roomId = simplejson.loads(self.request.body)['id'] room = Rooms.get_by_id(int(roomId)) #room = Rooms.get_by_id(int(2)) if room.roomlist.key() == roomlist.key(): inputData = simplejson.loads(self.request.body) # room.content = inputData['content'] # room.done = inputData['done'] # room.put() # room = simplejson.dumps(room.toDict()) temp = room.updateRoom(inputData) room = simplejson.dumps(temp) self.response.out.write(room) else: self.error(403)
def roomPoll(): inData = request.form room = Rooms.get_by_id(inData['id']) if (room == None): return json.dumps({'code': -1, 'reason': 'eRRoR: No room by that id'}) hereData = room.to_dict() inMessages = json.loads(inData['messages']) newMessages = [] for msgPlace in xrange(int(inData['chatHistoryLength']) - len(inMessages), len(hereData['chatHistory'])): newMessages.append(hereData['chatHistory'][msgPlace]) for msg in inMessages: msgWithName = {} msgWithName['chatMessage'] = msg msgWithName['username'] = session['username'] msgWithName['date'] = datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S") room.chatHistory.append(json.dumps(msgWithName)) room.put() #codes: -1: error - 0: no changes - 1: changes on server - 2: changes on client - 3: changes on server and client if (inData['canvasChanged'] == 'false'): if (int(inData['canvasVersion']) == hereData['canvasVersion']): return json.dumps({'code': 0, 'messages': newMessages}) else: hereData['code'] = 1 hereData['messages'] = newMessages return json.dumps(hereData) else: if (int(inData['canvasVersion']) == hereData['canvasVersion']): room.canvas = inData['canvas'] room.canvasVersion = int(inData['canvasVersion']) + 1 room.put() return json.dumps({'code': 2, 'canvasVersion': int(inData['canvasVersion']) + 1, 'messages': newMessages}) else: # todo - diff hereData['code'] = 3 hereData['messages'] = newMessages return json.dumps(hereData)