예제 #1
0
def articleListView(req):
    userid = req.session.get('userid')
    password = req.session.get('password')
    nickname = getNickname(userid, password)

    page_size =20
    result2 = actions.getlist(userid, password, page=1, page_size=page_size)
    resultDic2 = json.loads(result2) #str转成json
    if resultDic2.get('done') == True:
        count = resultDic2.get('count')
        articleList = resultDic2.get('articles') #返回的文章列表
        # page_size = 100
        # '''
        # 对查询出的文章别表分页
        # '''
        # try:
        #     page = int(req.GET.get("page", 1))
        #     if page < 1:
        #         page = 1
        # except ValueError:
        #     page = 1
        # paginator = Paginator(articleList, page_size)
        # try:
        #     article = paginator.page(page)
        # except(EmptyPage, InvalidPage, PageNotAnInteger):
        #     article = paginator.page(1)
        import math
        if count%20 == 0:
                count = count / 20
        else:
                count = int(count/20) +1
    return render_to_response("article_list.html", {"nickname": nickname, "count":count, "articleList": articleList})
예제 #2
0
def getPageList(req):
    page = int(req.GET.get("page", 1))
    userid = req.session.get('userid')
    password = req.session.get('password')
    result = actions.getlist(userid, password, page, page_size=20)
    articleList = json.loads(result).get('articles')
    count = json.loads(result).get('count')
    import math
    if count%20 == 0:
        count = count/20
    else:
        count = int(count/20) +1
    print count
    return render_to_response("article_list.html", {"articleList": articleList, "count": count})
예제 #3
0
def login(request):
    if request.session.get('userid') is not None:
        userid = request.session.get('userid')
        password = request.session.get('password')
    else:
        userid = request.POST.get('user_number')
        password = request.POST.get('password')
    print userid, password
    result = actions.login(userid, password)
    #nickname传递给前端
    resultJson = json.loads(result)
    if resultJson.get('done') == True:
        request.session['userid'] = userid
        request.session['password'] = password
        nickname = resultJson.get('nickname')
        '''
        将列表数据传给前端
        '''
        page_size = 20
        result2 = actions.getlist(userid, password, page=1, page_size=page_size)
        resultDic2 = json.loads(result2) #str转成json
        if resultDic2.get('done') == True:
            count = resultDic2.get('count') #文章总数
            articleList = resultDic2.get('articles') #返回的文章列表

            # '''
            # 对查询出的文章别表分页
            # '''
            # try:
            #     page = int(request.GET.get("page", 1))
            #     if page < 1:
            #         page = 1
            # except ValueError:
            #     page = 1
            # paginator = Paginator(articleList, page_size)
            # try:
            #     article = paginator.page(page)
            # except(EmptyPage, InvalidPage, PageNotAnInteger):
            #     article = paginator.page(1)
            import math
            if count%20 == 0:
                count = count/20
            else:
                count = int(count/20) +1
            return render_to_response("article_list.html", {'nickname': nickname, "count": count,
                                                            "articleList": articleList})
    else:
        return render_to_response("index.html")