Example #1
0
def users_list(request, _page_index=1):

    # check is login
    _islogin = __is_login(request)

    _page_title = _('Everyone')
    _users = User.objects.order_by('-addtime')

    _login_user = None
    _login_user_friend_list = None
    if _islogin:
        try:
            _login_user = User.objects.get(id=__user_id(request))
            _login_user_friend_list = _login_user.friend.all()
        except:
            _login_user = None

    # page bar
    _page_bar = formatter.pagebar(_users, _page_index, '',
                                  'control/userslist_pagebar.html')

    # get message list
    _offset_index = (int(_page_index) - 1) * PAGE_SIZE
    _last_item_index = PAGE_SIZE * int(_page_index)

    # get current page
    _users = _users[_offset_index:_last_item_index]

    # body content
    _template = loader.get_template('users_list.html')

    # _context = Context({
    #     'page_title' : _page_title,
    #     'users' : _users,
    #     'login_user_friend_list' : _login_user_friend_list,
    #     'islogin' : _islogin,
    #     'userid' : __user_id(request),
    #     'page_bar' : _page_bar,
    #     })

    _context = {
        'page_title': _page_title,
        'users': _users,
        'login_user_friend_list': _login_user_friend_list,
        'islogin': _islogin,
        'userid': __user_id(request),
        'page_bar': _page_bar,
    }

    _output = _template.render(_context)

    return HttpResponse(_output)
Example #2
0
def users_list(request,_page_index=1):
    
    # check is login
    _islogin = __is_login(request)

    _page_title = _('Everyone')
    _users = User.objects.order_by('-addtime')

    _login_user = None
    _login_user_friend_list = None
    if _islogin:
        try:
            _login_user = User.objects.get(id=__user_id(request))
            _login_user_friend_list = _login_user.friend.all()
        except:
            _login_user = None

    # page bar
    _page_bar = formatter.pagebar(_users,_page_index,'','control/userslist_pagebar.html')
    
    # get message list
    _offset_index = (int(_page_index) - 1) * PAGE_SIZE
    _last_item_index = PAGE_SIZE * int(_page_index)

    # get current page
    _users = _users[_offset_index:_last_item_index]
    
    # body content
    _template = loader.get_template('users_list.html')

    _context = Context({
        'page_title' : _page_title,
        'users' : _users,
        'login_user_friend_list' : _login_user_friend_list,
        'islogin' : _islogin,
        'userid' : __user_id(request),
        'page_bar' : _page_bar,
        })
    
    _output = _template.render(_context)    
    
    return HttpResponse(_output)
Example #3
0
def index_user_page(request, _username, _page_index):
    # get user login status
    _islogin = __is_login(request)
    _page_title = _('Home')

    try:
        # get post params
        _message = request.POST['message']
        _is_post = True
    except (KeyError):
        _is_post = False

    # save message
    if _is_post:
        # check login
        if not _islogin:
            return HttpResponseRedirect('/signin/')

        # save messages
        (_category, _is_added_cate) = Category.objects.get_or_create(name='网页')

        try:
            _user = User.objects.get(id=__user_id(request))
        except:
            return HttpResponseRedirect('/signin/')

        _note = Note(message=_message, category=_category, user=_user)
        _note.save()

        return HttpResponseRedirect('/user/' + _user.username)

    _userid = -1
    # get message list
    _offset_index = (int(_page_index) - 1) * PAGE_SIZE
    _last_item_index = PAGE_SIZE * int(_page_index)

    _login_user_friend_list = None
    if _islogin:
        # get friend messages if user is logined
        _login_user = User.objects.get(username=__user_name(request))
        _login_user_friend_list = _login_user.friend.all()
    else:
        _login_user = None

    _friends = None
    _self_home = False
    if _username != '':
        # there is get user's messages
        _user = get_object_or_404(User, username=_username)
        _userid = _user.id
        _notes = Note.objects.filter(user=_user).order_by('-addtime')
        _page_title = '%s' % _user.realname
        # get friend list
        #_friends = _user.friend.get_query_set().order_by("id")[0:FRIEND_LIST_MAX]
        _friends = _user.friend.order_by("id")[0:FRIEND_LIST_MAX]
        print(("................", _friends))
        if (_userid == __user_id(request)):
            _self_home = True

    else:
        # get all messages
        _user = None

        if _islogin:
            _query_users = [_login_user]
            _query_users.extend(_login_user.friend.all())
            _notes = Note.objects.filter(
                user__in=_query_users).order_by('-addtime')
        else:
            # can't get  message
            _notes = []  # Note.objects.order_by('-addtime')

    # page bar
    _page_bar = formatter.pagebar(_notes, _page_index, _username)

    # get current page
    _notes = _notes[_offset_index:_last_item_index]

    # body content
    _template = loader.get_template('index.html')

    _context = {
        'page_title': _page_title,
        'notes': _notes,
        'islogin': _islogin,
        'userid': __user_id(request),
        'self_home': _self_home,
        'user': _user,
        'page_bar': _page_bar,
        'friends': _friends,
        'login_user_friend_list': _login_user_friend_list,
    }

    _output = _template.render(_context)

    return HttpResponse(_output)
Example #4
0
def index_user_page(request,_username,_page_index):
    
    # get user login status
    _islogin = __is_login(request)
    _page_title = _('Home')
    
    try:
        # get post params
        _message = request.POST['message']        
        _is_post = True
    except (KeyError):
        _is_post = False
    
    # save message
    if _is_post:
        # check login
        if not _islogin:
            return HttpResponseRedirect('/signin/')
        
        # save messages
        (_category,_is_added_cate) = Category.objects.get_or_create(name=u'网页')

        try:
            _user = User.objects.get(id = __user_id(request))
        except:
            return HttpResponseRedirect('/signin/')
        
        _note = Note(message = _message,category = _category , user = _user)
        _note.save()
        
        return HttpResponseRedirect('/user/' + _user.username)
          
    _userid = -1
    # get message list
    _offset_index = (int(_page_index) - 1) * PAGE_SIZE
    _last_item_index = PAGE_SIZE * int(_page_index)

    _login_user_friend_list = None
    if _islogin:
         # get friend messages if user is logined
        _login_user = User.objects.get(username = __user_name(request))
        _login_user_friend_list = _login_user.friend.all()
    else:
        _login_user = None
    
    _friends = None    
    _self_home = False
    if _username != '':
        # there is get user's messages
        _user = get_object_or_404(User,username=_username)
        _userid = _user.id        
        _notes = Note.objects.filter(user = _user).order_by('-addtime')
        _page_title = u'%s' % _user.realname
        # get friend list
        _friends = _user.friend.get_query_set().order_by("id")[0:FRIEND_LIST_MAX]
        
        if(_userid == __user_id(request)):
            _self_home = True         
            
    else:
        # get all messages
        _user = None
        
        if _islogin:           
            _query_users = [_login_user]
            _query_users.extend(_login_user.friend.all())
            _notes = Note.objects.filter(user__in = _query_users).order_by('-addtime')            
        else:
            # get all user message
            _notes = Note.objects.order_by('-addtime')

    # page bar
    _page_bar = formatter.pagebar(_notes,_page_index,_username)
    
    # get current page
    _notes = _notes[_offset_index:_last_item_index]
    
    # body content
    _template = loader.get_template('index.html')

    _context = Context({
        'page_title' : _page_title,
        'notes' : _notes,
        'islogin' : _islogin,
        'userid' : __user_id(request),
        'self_home' : _self_home,
        'user' : _user,
        'page_bar' : _page_bar,
        'friends' : _friends,
        'login_user_friend_list' : _login_user_friend_list,
        })
    
    _output = _template.render(_context)
    
    return HttpResponse(_output)