コード例 #1
0
ファイル: chat.py プロジェクト: mozillazg/code
def delete_room(request):
    room_name = request.get_form_var('room_name', '')
    if Room.delete(room_name):
        get_room_message(room_name).delete_by_key()
        return {'r': 1, 'msg': '删除成功'}

    return {'r': 0, 'msg': '删除失败, 可能该room已被删除'}
コード例 #2
0
def _q_index(request):
    user = request.user
    if not user:
        return request.redirect("/")
    all_rooms = Room.get_all_rooms()
    messages = get_room_message('lobby').get_messages()
    return st("chat.html", **locals())
コード例 #3
0
def delete_room(request):
    room_name = request.get_form_var('room_name', '')
    if Room.delete(room_name):
        get_room_message(room_name).delete_by_key()
        return {'r': 1, 'msg': '删除成功'}

    return {'r': 0, 'msg': '删除失败, 可能该room已被删除'}
コード例 #4
0
ファイル: chat.py プロジェクト: 000fan000/code
def _q_index(request):
    user = request.user
    if not user:
        return request.redirect("/")
    all_rooms = Room.get_all_rooms()
    messages = get_room_message('lobby').get_messages()
    return st("chat.html", **locals())
コード例 #5
0
def add_room(request):
    user = request.user
    if not user:
        return request.redirect("/")

    name = request.get_form_var('name', '')
    owner = user.username

    error = ""
    if request.method == "POST":
        rooms = Room.get_all_rooms()
        name_pattern = re.compile(r'[a-zA-Z0-9\_]*')
        if not name:
            error = "name_not_exists"
        elif name != re.findall(name_pattern, name)[0]:
            error = "invilid_name"
        elif len(name) > 10:
            error = "too_long_name"
        elif name in ([room.name for room in rooms] + ['lobby', 'Lobby']):
            error = "name_existed"
        else:
            room = Room.add(name, owner)
            return request.redirect("/hub/chat")
    return st('add_room.html', **locals())
コード例 #6
0
ファイル: chat.py プロジェクト: 000fan000/code
def add_room(request):
    user = request.user
    if not user:
        return request.redirect("/")

    name = request.get_form_var('name', '')
    owner = user.username

    error = ""
    if request.method == "POST":
        rooms = Room.get_all_rooms()
        name_pattern = re.compile(r'[a-zA-Z0-9\_]*')
        if not name:
            error = "name_not_exists"
        elif name != re.findall(name_pattern, name)[0]:
            error = "invilid_name"
        elif len(name) > 10:
            error = "too_long_name"
        elif name in ([room.name for room in rooms]+['lobby', 'Lobby']):
            error = "name_existed"
        else:
            room = Room.add(name, owner)
            return request.redirect("/hub/chat")
    return st('add_room.html', **locals())
コード例 #7
0
def _q_lookup(request, room_name):
    if request.method == "POST":
        content = request.get_form_var('message')
        author = request.user.username
        date = datetime.now()
        message_data = {"content": content, "author": author, "date": date}
        room_message = get_room_message(room_name)
        room_message.add_message(message_data)
        return {'r': 1}
    if request.method == "GET":
        if room_name != 'lobby' and not Room.exists(room_name):
            return {'r': 0, 'msg': 'room not exists'}
        room_message = get_room_message(room_name)
        messages = room_message.get_messages()
        render_messages = [render_message(m) for m in messages]
        return {'r': 1, 'msg': render_messages}
コード例 #8
0
ファイル: chat.py プロジェクト: mozillazg/code
def _q_lookup(request, room_name):
    if request.method == "POST":
        content = request.get_form_var('message')
        author = request.user.username
        date = datetime.now()
        message_data = {
            "content": content,
            "author": author,
            "date": date
        }
        room_message = get_room_message(room_name)
        room_message.add_message(message_data)
        return {'r': 1}
    if request.method == "GET":
        if room_name != 'lobby' and not Room.exists(room_name):
            return {'r': 0, 'msg': 'room not exists'}
        room_message = get_room_message(room_name)
        messages = room_message.get_messages()
        render_messages = [render_message(m) for m in messages]
        return {'r': 1, 'msg': render_messages}