예제 #1
0
def manageAlbum_save(site,request):
    viewmap={}
    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['albummenu']=albummenu
    if 'POST'==request.method.upper():
        albumname=request.POST.get('albumName',u'未命名')
        albumid=request.POST.get('albumId',None)
        if albumid:
            album=Title.objects.get(pk=albumid)
        else:
            album=Title()
        album.title=albumname
        album.menu=albummenu
        album.type='album'
        album.author=request.user
        album.site=WebSiteInfo.objects.get(pk=site.get('id'))
        album.isPub=True
        album.save()
        viewmap['album']=album
        msg=u'保存成功'
        viewmap['msg']=msg
    else:
        albumid=request.GET.get('albumId',None)
        if albumid:
            album=Title.objects.get(pk=albumid)
            viewmap['album']=album
     ####################
    #### 设置左侧数据
    left(site,viewmap)
    #### 设置 menu 数据
    menu(site,viewmap)
    return viewmap
예제 #2
0
def managePaperImage_save(site,request):
    viewmap={}
    if request.REQUEST.get('menuid'):
        viewmap['menu']=Menu.objects.get(pk=request.REQUEST.get('menuid'))
    else:
        viewmap['menu']=None
    if 'POST'==request.method.upper():
        title=request.POST.get('title','')
        menuid=request.POST.get('menuid')
        keyword=request.POST.get('keyword')
        desc=request.POST.get('desc')
        id=request.POST.get('titleid')
        if id:
            titlepaperquery=Title.objects.filter(site=site.get('id')).filter(pk=id)[:1]
            if 1== len(titlepaperquery):
                titlepaper=titlepaperquery[0]
            else:
                titlepaper=Title()

        else:
            titlepaper=Title()

        titlepaper.title=title.strip()
        titlepaper.menu=viewmap['menu']

        titlepaper.desc=desc.strip()
        titlepaper.type='image'
        titlepaper.author=request.user
        titlepaper.site=WebSiteInfo.objects.get(pk=site.get('id'))
        titlepaper.isPub=True
        titlepaper.save()
        titlepaper.keywords.clear()
        if keyword:
            website=WebSiteInfo.objects.get(pk=site.get('id'))
            keywordset=set(keyword.strip().split())
            for key in Keyword.objects.filter(site=site.get('id')).filter(name__in=list(keywordset)):
                keywordset.remove(key.name)
                titlepaper.keywords.add(key)
            for newkeyname in keywordset:
                newkey=Keyword()
                newkey.name=newkeyname
                newkey.site=website
                newkey.save()
                titlepaper.keywords.add(newkey)
            titlepaper.save()
        result={'result':True,'id':titlepaper.id}
        return HttpResponse(json.dumps(result))


    else:
        paperid=request.GET.get('paperid')
        if paperid:
            titlepaper=Title.objects.get(pk=paperid)
            viewmap['paper']=titlepaper
            if hasattr(request,'environ'):
                viewmap['fromurl']=request.environ.get('HTTP_REFERER','')
            if hasattr(request,'META'):
                viewmap['fromurl']=request.META.get('HTTP_REFERER','')
        ####################
    #### 设置左侧数据
    left(site,viewmap)
    #### 设置 menu 数据
    menu(site,viewmap)
    return viewmap
예제 #3
0
def managePaper_save(site,request):
    viewmap={}
    if request.REQUEST.get('menuid'):
        viewmap['menu']=Menu.objects.get(pk=request.REQUEST.get('menuid'))
    else:
        viewmap['menu']=None
    if 'POST'==request.method.upper():
        editorValue=request.POST.get('papercontent','')
        title=request.POST.get('title','')
        menuid=request.POST.get('menuid')
        keyword=request.POST.get('keyword')
        desc=request.POST.get('desc')
        id=request.POST.get('id')
        if id:
            titlepaper=Title.objects.get(pk=id)
            if not titlepaper:
                titlepaper=Title()
            else:
                paperquery=Paper.objects.filter(title=titlepaper)[:1]
                if 0== len(paperquery):
                    paper=Paper()
                else:
                    paper=paperquery[0]
        else:
            titlepaper=Title()
            paper=Paper()

        titlepaper.title=title.strip()
        titlepaper.menu=viewmap['menu']

        titlepaper.desc=desc.strip()
        titlepaper.type='paper'
        titlepaper.author=request.user
        titlepaper.site=WebSiteInfo.objects.get(pk=site.get('id'))
        titlepaper.isPub=True
        titlepaper.save()
        titlepaper.keywords.clear()
        if keyword:
            website=WebSiteInfo.objects.get(pk=site.get('id'))
            keywordset=set(keyword.strip().split())
            keymap={}
            for k in keywordset:
                keymap[k.upper()]=k
            for key in Keyword.objects.filter(site=site.get('id')).filter(name__in=list(keywordset)):
                del keymap[key.name.upper()]
                titlepaper.keywords.add(key)
            for newkeyname in keymap.values():
                newkey=Keyword()
                newkey.name=newkeyname
                newkey.site=website
                newkey.save()
                titlepaper.keywords.add(newkey)
            titlepaper.save()
        paper.title=titlepaper
        paper.content=editorValue.strip()
        paper.contentnotag=strip_tags(editorValue)
        paper.save()

        msg=u'保存成功'
        viewmap['msg']=msg
#        titlepaper.papercontent='dsasfad'
#        titlepaper.keyword=keyword
        viewmap['paper']=titlepaper
        fromurl=request.POST.get('fromurl')
        if fromurl:
            msgid=str(uuid.uuid4())
            cache.set(msgid,u'修改文章《%s》成功。'%(titlepaper.title,),60)
#            response.set_cookie("msg",msgid,30)
            if fromurl.find('?')!=-1:
                fromurl+='&msgid='+msgid
            else:
                fromurl+='?msgid='+msgid
            return HttpResponseRedirect(fromurl)
#        viewmap['editorValue']=editorValue


    else:
        paperid=request.GET.get('paperid')
        if paperid:
            titlepaper=Title.objects.get(pk=paperid)
            viewmap['paper']=titlepaper
            if hasattr(request,'environ'):
                viewmap['fromurl']=request.environ.get('HTTP_REFERER','')
            if hasattr(request,'META'):
                viewmap['fromurl']=request.META.get('HTTP_REFERER','')
    ####################
    #### 设置左侧数据
    left(site,viewmap)
    #### 设置 menu 数据
    menu(site,viewmap)
    return viewmap