当我使用plone.api文件内容.创建在寻找结果永远是空的

2024-09-26 23:21:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用plone.api创建一个脚本,将一批PDF上传到一个文件夹中,关于我将把每个PDF放在哪个文件夹的信息来自csv。我的问题是。。你知道吗

如果for中的下一个值是同一年,那么在for的最后一个变量yearBrain中创建的变量的输出又是空的。当脚本完成后,在plone中我会有很多文件夹,标题是2015,ID是20152015-1。。。你知道吗

for i in csv:
    yearBrain = api.content.find(context=container, SearchableText=str(i[1]))
    if solidData(yearBrain):
        #solidData returns if exist infor and year have 4 digits
        print 'if true, insert a PDF into a folder'
    else:
        #If solidData false, yearBrain results empty, so create a folder
        container = api.content.create(type='Folder', title=unicode(str(i[1]), 'utf-8'), container=container)
        transaction.commit()

我想api.content.find找不到最近创建的文件夹。你知道吗

我是怎么解决这个问题的?你知道吗

[更新-工作]

        if pdf_tipodoc:
            if pdf_tipodoc == 'PROCESSO':
                valor = splitProcesso(pdf_nprocesso)
                # valor returns a list with two elements like ['234', '2016']
                container = portal[plone_site_pasta][processos]
                # Container is: <ATFolder at /intranet/ged/processos>
                print container.objectIds() #look what have inside!
                if valor[1] in container.objectIds():
                    print 'Folder already created! Commit PDF inside'
                else:
                    container = api.content.create(type='Folder', title=valor[1], container=container)
                    transaction.commit()

Tags: 文件夹apiforifpdfcontainerplonecreate
1条回答
网友
1楼 · 发布于 2024-09-26 23:21:23

不要使用api.content.find文件为此:您不需要在文件夹中搜索具有know id的项。你知道吗

如果i[1]在某种程度上是你当前的一年(我猜),就试试这样的方法:

if str(i[1]) in container.objectIds():
    # year folder already exists

相关问题 更多 >

    热门问题