Exemplo n.º 1
0
def column(site,request,menuid):
    viewmap={}
    if menuid:
        menuid=int(menuid)
        viewmap['menu']=Menu.objects.get(pk=menuid)
        viewmap['titlename']=viewmap['menu'].name
    offset=request.GET.get('offset','0')
    offset=int(offset)
    offsetN=offset+PAPER_LIST_LIMIT
    offsetP=(offset>=PAPER_LIST_LIMIT and [offset-PAPER_LIST_LIMIT] or [0])[0]

    paperquery=Title.objects.filter(site=site.get('id',0)).filter(menu=int(menuid)).filter(isPub=True).order_by('-updateDate')
    totalpaper=paperquery.count()
    if totalpaper<offsetN:
        offsetN-=PAPER_LIST_LIMIT
    viewmap['paperlist']=paperquery[offset:offset+PAPER_LIST_LIMIT]
    viewmap['offset']=offset
    viewmap['offsetN']=offsetN
    viewmap['offsetP']=offsetP

    pagelist=[]
    pp=offset-(PAPER_LIST_LIMIT*4)
    nn=offset+(PAPER_LIST_LIMIT*4)
    for p in range(0,completePage(totalpaper,PAPER_LIST_LIMIT)):
        if p*PAPER_LIST_LIMIT> pp and p*PAPER_LIST_LIMIT<nn:
            pagelist.append({'page':p+1,'offset':p*PAPER_LIST_LIMIT})
    viewmap['lastpage']=p*PAPER_LIST_LIMIT
    viewmap['pagelist']=pagelist

    #### 设置左侧数据
    left(site,viewmap)
    #### 设置 menu 数据
    menu(site,viewmap)

    return viewmap
Exemplo n.º 2
0
def albumlist(site,request,albumid=None):
    viewmap={}
    albummenu=None
    if albumid:
        albumid=int(albumid)
        albummenu=Menu.objects.get(pk=albumid)
    if not albummenu:
        albummenu=Menu.objects.filter(site=site.get('id')).filter(type='album')[:1]
        if len(albummenu)==0:
            albummenu=Menu()
            albummenu.name='相册'
            albummenu.index=0
            albummenu.type='album'
            albummenu.site=WebSiteInfo.objects.get(pk=site.get('id'))
            albummenu.save()
        else:
            albummenu=albummenu[0]
    viewmap['album']=albummenu
    titlequery=Title.objects.filter(menu=albummenu)

    offset=request.GET.get('offset','0')
    offset=int(offset)
    offsetN=offset+ALBUM_LIST_LIMIT
    offsetP=(offset>=ALBUM_LIST_LIMIT and [offset-ALBUM_LIST_LIMIT] or [0])[0]
    totalpaper=titlequery.count()
    if totalpaper<offsetN:
        offsetN-=ALBUM_LIST_LIMIT
    viewmap['albumlist']=titlequery[offset:offset+ALBUM_LIST_LIMIT]
    viewmap['offset']=offset
    viewmap['offsetN']=offsetN
    viewmap['offsetP']=offsetP
    pagelist=[]
    pp=offset-(ALBUM_LIST_LIMIT*4)
    nn=offset+(ALBUM_LIST_LIMIT*4)
    for p in range(0,completePage(totalpaper,ALBUM_LIST_LIMIT)):
        if p*ALBUM_LIST_LIMIT> pp and p*ALBUM_LIST_LIMIT<nn:
            pagelist.append({'page':p+1,'offset':p*ALBUM_LIST_LIMIT})
    viewmap['lastpage']=p*ALBUM_LIST_LIMIT

    albumlist=[]
    for album in viewmap['albumlist']:
        firstImageList=PaperImage.objects.filter(title=album).order_by('index')[:1]
        if 0==len(firstImageList):
            album.firstImage=None
        else:
            album.firstImage=firstImageList[0]
            album.firstImage.imgsmal=album.firstImage.getImgUrlsmall(site.get('id'))
        albumlist.append(album)

    viewmap['albumlist']=albumlist
     ####################
    #### 设置左侧数据
    left(site,viewmap)
    #### 设置 menu 数据
    menu(site,viewmap)
    return viewmap
Exemplo n.º 3
0
def managePaper_list(site,request):
    viewmap={}
    msgid=request.GET.get('msgid')
    if msgid:
        viewmap['msg']=cache.get(msgid)
        cache.delete(msgid)
    menuid=request.GET.get('menuid')
    if menuid:
        viewmap['menu']=Menu.objects.get(pk=request.REQUEST.get('menuid'))
    paperid=request.GET.get('paperid')
    if paperid:
        try:
            delpaper=Title.objects.get(pk=paperid)
        except :
            msg=u'文章已不存在。'
        else:
            msg=u'删除文章《'+delpaper.title+u'》成功.'
            delpaper.delete()
        viewmap['msg']=msg

    offset=request.GET.get('offset','0')
    offset=int(offset)
    offsetN=offset+PAPER_LIST_LIMIT
    offsetP=(offset>=PAPER_LIST_LIMIT and [offset-PAPER_LIST_LIMIT] or [0])[0]

    paperquery=Title.objects.filter(site=site.get('id',0)).filter(menu=int(menuid)).filter(isPub=True).order_by('-updateDate')
    totalpaper=paperquery.count()
    if totalpaper<offsetN:
        offsetN-=PAPER_LIST_LIMIT
    viewmap['paperlist']=paperquery[offset:offset+PAPER_LIST_LIMIT]
    viewmap['offset']=offset
    viewmap['offsetN']=offsetN
    viewmap['offsetP']=offsetP

    pagelist=[]
    pp=offset-(PAPER_LIST_LIMIT*4)
    nn=offset+(PAPER_LIST_LIMIT*4)
    for p in range(0,completePage(totalpaper,PAPER_LIST_LIMIT)):
        if p*PAPER_LIST_LIMIT> pp and p*PAPER_LIST_LIMIT<nn:
            pagelist.append({'page':p+1,'offset':p*PAPER_LIST_LIMIT})
    viewmap['lastpage']=p*PAPER_LIST_LIMIT
    viewmap['pagelist']=pagelist

     ####################
    #### 设置左侧数据
    left(site,viewmap)
    #### 设置 menu 数据
    menu(site,viewmap)
    return viewmap