Ejemplo n.º 1
0
    def get(self):
        try:
            user_id = get_jwt_identity()
            user = User.objects.get(id=user_id)
            chats = Chat.objects(type='private', users__contains=user)

            all_sessions = [convert_session(session) for session in Session.objects(host=user)]
            for chat in chats:
                sessions = Session.objects(chats__contains=chat)
                for session in sessions:
                    all_sessions.append(convert_session_chat(session, chat))

            return Response(JSONEncoder().encode(all_sessions), mimetype="application/json", status=200)
        except DoesNotExist:
            raise DocumentMissing
        except Exception as e:
            raise InternalServerError
Ejemplo n.º 2
0
def get_sessions():
    all_sessions = Session.objects().to_json()
    return Response(all_sessions, mimetype="application/json", status=200)