コード例 #1
0
ファイル: views.py プロジェクト: pimiento/naval-battle
def update_data_main_page():
    """return json with information about:

    - users who wait second player
    - games which does now

    the structure of dictionary is:
    { 'users':{ 'id1':'username1',
                'id2':'username2'},

      'games': { 'id':[user1, user2],
                 'id':[user1, user2]}}
    """
    if request.method == 'POST':
        current_user = "******"
        if request.cookies.has_key('session_id'):
            cookie_session = request.cookies.get('session_id')
            update_user(**{ 'session_id': cookie_session, 'time': True })
            user_status = get_user_status(cookie_session)
            if user_status == 1:
                return jsonify(user_status=user_status)
            if user_status == 0:
                user = get_user_by_session(cookie_session)
                if user:
                    current_user = user.user_name
        users = get_wait_users()
        list_username = {}
        for user in users:
            list_username[str(user.id)] = user.user_name
        games = get_begin_games()
        user_server = get_user_id(cookie_session)
        return jsonify(users=list_username, 
                       games=games, 
                       current_user=current_user, 
                       user_server=user_server)
コード例 #2
0
ファイル: views.py プロジェクト: le087/naval-battle
def main_page():
    """main page, install cookie for new users
    """
    current_page = u'Главная страница'
    users_wait = get_wait_users()
    if not request.cookies.has_key('session_id'):
        cookie_session = randstring()
        response = make_response(render_template('main_page.html', 
                                                 current_page=current_page,
                                                 users_wait=users_wait))
        response.set_cookie('session_id', cookie_session)
        return response
    else:
        return make_response(render_template('main_page.html', 
                                             current_page=current_page,
                                             users_wait=users_wait))
コード例 #3
0
ファイル: tests.py プロジェクト: le087/naval-battle
 def test_update_main_page(self):
     print get_wait_users()
     print str(get_begin_games())