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

    _page_title = _('Everyone')

    _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()

            # 使自己排在第一位
            # _users = User.objects.order_by('-addtime').exclude(id=__user_id(request))
            _users = User.objects.order_by('-addtime')
        except:
            _login_user = None

    else:
        _users = User.objects.order_by('-addtime')

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

    # 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')

    _one_page_num = len(_users)
    if _one_page_num < 4:
        _one_page_num_list = [i for i in range(4 - _one_page_num)]
    else:
        _one_page_num_list = ''

    _context = {
        'page_title': _page_title,
        'users': _users,
        'userself': _login_user,
        'login_user_friend_list': _login_user_friend_list,
        'islogin': _islogin,
        'userid': __user_id(request),
        'page_bar': _page_bar,
        'one_page_num': _one_page_num,
        'one_page_num_list': _one_page_num_list,
    }

    _output = _template.render(_context)

    return HttpResponse(_output)
Example #2
0
def users_list(request, _page_index=1):
    _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 = formatter.pagebar(_users, _page_index, '',
                                  'control/userslist_pagebar.html')

    _offset_index = (int(_page_index) - 1) * PAGE_SIZE
    _last_item_index = PAGE_SIZE * int(_page_index)

    _users = _users[_offset_index:_last_item_index]

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

    return render(request, 'users_list.html', _context)
Example #3
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 #4
0
def loadfollowuser(request,pageindex=1):
    if request.session:
        userinfo=User.objects.get(id=request.session['userid'])
        friendlist=userinfo.friend.all()
        pagebar=formatter.pagebar(friendlist,pageindex,'find','microblog/pagebar.html')
        offsetindex=(int(pageindex)-1)*PAGE_SIZE
        lastindex=PAGE_SIZE*int(pageindex)
        friendlist=friendlist[offsetindex:lastindex]
        return render_to_response('microblog/followuser.html',{
            'session':request.session,
            'userinfo':userinfo,
            'friendlist':friendlist,
            'pagebar':pagebar,}
        )
    else:
        return HttpResponseRedirect('/')
Example #5
0
def loadsquare(request,pageindex=1):
    if request.session:
        userinfo=User.objects.get(id=request.session['userid'])
        friendlist=userinfo.friend.all()
        otherlist=Shuoshuo.objects.all().order_by('-id')
        pagebar=formatter.pagebar(otherlist,pageindex,'square','microblog/pagebar.html')
        offsetindex=(int(pageindex)-1)*PAGE_SIZE
        lastindex=PAGE_SIZE*int(pageindex)
        otherlist=otherlist[offsetindex:lastindex]
        return render_to_response('microblog/square.html',{
            'session':request.session,
            'userinfo':userinfo,'list':otherlist,
            'friendlist':friendlist,
            'pagebar':pagebar,}
        )
    else:
        return HttpResponseRedirect('/')
Example #6
0
def loadfollowuser(request, pageindex=1):
    if request.session:
        userinfo = User.objects.get(id=request.session['userid'])
        friendlist = userinfo.friend.all()
        pagebar = formatter.pagebar(friendlist, pageindex, 'find',
                                    'microblog/pagebar.html')
        offsetindex = (int(pageindex) - 1) * PAGE_SIZE
        lastindex = PAGE_SIZE * int(pageindex)
        friendlist = friendlist[offsetindex:lastindex]
        return render_to_response(
            'microblog/followuser.html', {
                'session': request.session,
                'userinfo': userinfo,
                'friendlist': friendlist,
                'pagebar': pagebar,
            })
    else:
        return HttpResponseRedirect('/')
Example #7
0
def loadusershuoshuo(request,username,pageindex=1):
    if request.session:
        userinfo=User.objects.get(id=request.session['userid'])
        friendlist=userinfo.friend.all()
        selectuser=get_object_or_404(User,username=username)
        shuoshuolist=Shuoshuo.objects.filter(user=selectuser).order_by('-id')
        pagebar=formatter.pagebar(shuoshuolist,pageindex,'user/'+username,'microblog/pagebar.html')
        offsetindex=int(int(pageindex)-1)*PAGE_SIZE
        lastindex=PAGE_SIZE*int(pageindex)
        shuoshuolist=shuoshuolist[offsetindex:lastindex]
        return  render_to_response('microblog/square.html',{
            'session':request.session,
            'userinfo':userinfo,
            'list':shuoshuolist,
            'friendlist':friendlist,
            'pagebar':pagebar,}
        )
    else:
        return HttpResponseRedirect('/')
Example #8
0
def loadsquare(request, pageindex=1):
    if request.session:
        userinfo = User.objects.get(id=request.session['userid'])
        friendlist = userinfo.friend.all()
        otherlist = Shuoshuo.objects.all().order_by('-id')
        pagebar = formatter.pagebar(otherlist, pageindex, 'square',
                                    'microblog/pagebar.html')
        offsetindex = (int(pageindex) - 1) * PAGE_SIZE
        lastindex = PAGE_SIZE * int(pageindex)
        otherlist = otherlist[offsetindex:lastindex]
        return render_to_response(
            'microblog/square.html', {
                'session': request.session,
                'userinfo': userinfo,
                'list': otherlist,
                'friendlist': friendlist,
                'pagebar': pagebar,
            })
    else:
        return HttpResponseRedirect('/')
Example #9
0
def loadhome(request,pageindex=1):
    #for i in request.session.keys():
    #    print request.session[i]
    if request.session:
        count=noreadcount(request.session['userid'])
        userinfo=User.objects.get(id=request.session['userid'])
        friendlist=userinfo.friend.all()
        mylist=Shuoshuo.objects.filter(user=userinfo).order_by('-id')
        pagebar=formatter.pagebar(mylist,pageindex,'home','microblog/pagebar.html')
        offsetindex=int(int(pageindex)-1)*PAGE_SIZE
        lastindex=PAGE_SIZE*int(pageindex)
        mylist=mylist[offsetindex:lastindex]
        return  render_to_response('microblog/home.html',{
            'count':count,
            'session':request.session,
            'userinfo':userinfo,
            'list':mylist,
            'friendlist':friendlist,
            'pagebar':pagebar,}
        )
    else:
        return HttpResponseRedirect('/')
Example #10
0
def loadusershuoshuo(request, username, pageindex=1):
    if request.session:
        userinfo = User.objects.get(id=request.session['userid'])
        friendlist = userinfo.friend.all()
        selectuser = get_object_or_404(User, username=username)
        shuoshuolist = Shuoshuo.objects.filter(user=selectuser).order_by('-id')
        pagebar = formatter.pagebar(shuoshuolist, pageindex,
                                    'user/' + username,
                                    'microblog/pagebar.html')
        offsetindex = int(int(pageindex) - 1) * PAGE_SIZE
        lastindex = PAGE_SIZE * int(pageindex)
        shuoshuolist = shuoshuolist[offsetindex:lastindex]
        return render_to_response(
            'microblog/square.html', {
                'session': request.session,
                'userinfo': userinfo,
                'list': shuoshuolist,
                'friendlist': friendlist,
                'pagebar': pagebar,
            })
    else:
        return HttpResponseRedirect('/')
Example #11
0
def loadhome(request, pageindex=1):
    #for i in request.session.keys():
    #    print request.session[i]
    if request.session:
        count = noreadcount(request.session['userid'])
        userinfo = User.objects.get(id=request.session['userid'])
        friendlist = userinfo.friend.all()
        mylist = Shuoshuo.objects.filter(user=userinfo).order_by('-id')
        pagebar = formatter.pagebar(mylist, pageindex, 'home',
                                    'microblog/pagebar.html')
        offsetindex = int(int(pageindex) - 1) * PAGE_SIZE
        lastindex = PAGE_SIZE * int(pageindex)
        mylist = mylist[offsetindex:lastindex]
        return render_to_response(
            'microblog/home.html', {
                'count': count,
                'session': request.session,
                'userinfo': userinfo,
                'list': mylist,
                'friendlist': friendlist,
                'pagebar': pagebar,
            })
    else:
        return HttpResponseRedirect('/')
Example #12
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]
        _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 #13
0
def index_user_page(request, _username, _page_index):
    # get user login status
    _islogin = __is_login(request)
    _page_title = _('Home')

    _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]
        _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:
        _notes = Note.objects.all().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')

    _one_page_num = len(_notes)
    if _one_page_num < 4:
        _one_page_num_list = [i for i in range(4 - _one_page_num)]
    else:
        _one_page_num_list = ''

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

    _output = _template.render(_context)

    return HttpResponse(_output)