Esempio n. 1
0
def api_note_add(request):
    """
    summary:
        api interface post message
    params:
        GET['uname'] Tmitter user's username
        GET['pwd'] user's password not encoding
        GET['msg'] message want to post
        GET['from'] your web site name
    author:
        Jason Lee
    """
    # get querystring params
    _username = request.GET['uname']
    _password = function.md5_encode(request.GET['pwd'])
    _message = request.GET['msg']
    _from = request.GET['from']

    # Get user info and check user
    try:
        _user = User.objects.get(username=_username, password=_password)
    except:
        return HttpResponse("-2")

    # Get category info ,If it not exist create new
    (_cate, _is_added_cate) = Category.objects.get_or_create(name=_from)

    try:
        _note = Note(message=_message, user=_user, category=_cate)
        _note.save()
        return HttpResponse("1")
    except:
        return HttpResponse("-1")
Esempio n. 2
0
def api_note_add(request):
    """
    summary:
        api interface post message
    params:
        GET['uname'] Tmitter user's username
        GET['pwd'] user's password not encoding
        GET['msg'] message want to post
        GET['from'] your web site name
    author:
        Jason Lee
    """
    # get querystring params
    _username = request.GET['uname']    
    _password = function.md5_encode(request.GET['pwd'])
    _message = request.GET['msg']
    _from = request.GET['from']
    
    # Get user info and check user
    try:
        _user = User.objects.get(username=_username,password=_password)        
    except:
        return HttpResponse("-2")
    
    # Get category info ,If it not exist create new
    (_cate,_is_added_cate) = Category.objects.get_or_create(name=_from)
    
    try:
        _note = Note(message=_message,user=_user,category=_cate)
        _note.save()
        return HttpResponse("1")
    except:
        return HttpResponse("-1")
Esempio n. 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)
Esempio n. 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)