使用 PloneFormGen 在 Plone 中以编程方式添加文件对象

发布于 2024-11-09 03:48:26 字数 651 浏览 5 评论 0原文

我正在编写一个 PloneFormGen 自定义操作适配器,以便将文件对象从表单中的文件字段添加到文件夹中。脚本如下:

target = context.filefolder   
form = request.form    
uid = str(DateTime().millis())

target.invokeFactory("File", id=uid, file=form['arquivo-do-cv_file'])

obj = target[uid]

“filefolder”是 PFG FormFolder 的父文件夹内的文件夹名称。该脚本配置为以管理员代理角色运行。

问题是,当我查看以这种方式创建的文件对象时,它们不会显示“单击此处下载文件”链接。不过,如果我抑制 URL 末尾的“/view”部分,则可以下载这些文件。调用 invokeFactory 创建 File 对象时我缺少什么?

更新:我的意思是我没有得到文件名 - 文件类型以KB为单位的大小大小以字节为单位”文档链接,位于署名下方。当我使用普通的 Plone UI 创建 File 对象时,它确实会显示。

I'm writing a PloneFormGen custom action adapter in order to add a File object to a folder from the File Field in the form. Here is the script:

target = context.filefolder   
form = request.form    
uid = str(DateTime().millis())

target.invokeFactory("File", id=uid, file=form['arquivo-do-cv_file'])

obj = target[uid]

"filefolder" is the name of a folder inside the parent folder for the PFG FormFolder. This script is configured to run with a Manager proxy role.

Problem is that the File objects created this way won't show the "Click here to download the file" link when I view them. The files can be downloaded though, if I suppress the "/view" part from the end of the URL. What am I missing when calling invokeFactory to create the File object?

UPDATE: What I meant is that I don't get the "filename - filetype, size in KBs (size in bytes)" link for the document, below the byline. When I create a File object using the normal Plone UI, it does show up.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绿萝 2024-11-16 03:48:26

我什么也不怀疑;我认为这是 Plone 4 中的默认行为。

我刚刚添加了一个文件,但没有看到任何“单击此处下载文件”。

在此处输入图像描述

快速搜索不会显示字符串“单击此处下载”:

aclark@Alex-Clarks-MacBook-Pro:~/Developer/test-4.1/ > grep -ir "Click here to download" parts/omelette
parts/omelette/plone/app/jquerytools/browser/jquery.tools.plugins.js:                   (root.tagName == 'A' ? "<p>Click here to download latest version</p>" : 
parts/omelette/plone/app/jquerytools/browser/jquery.tools.plugins.min.js:" or greater is required</h2><h3>"+(g[0]>0?"Your version is "+g:"You have no flash plugin installed")+"</h3>"+(a.tagName=="A"?"<p>Click here to download latest version</p>":"<p>Download latest version from <a href='"+k+"'>here</a></p>");if(a.tagName=="A")a.onclick=function(){location.href=k}}if(b.onFail){var d=b.onFail.call(this);if(typeof d=="string")a.innerHTML=d}}if(i)window[b.id]=document.getElementById(b.id);f(this,{getRoot:function(){return a},getOptions:function(){return b},getConf:function(){return c},

I suspect nothing; I think that is the default behavior in Plone 4.

I just added a File and I don't see any "Click here to download the file".

enter image description here

And a quick search does not reveal the string "click here to download":

aclark@Alex-Clarks-MacBook-Pro:~/Developer/test-4.1/ > grep -ir "Click here to download" parts/omelette
parts/omelette/plone/app/jquerytools/browser/jquery.tools.plugins.js:                   (root.tagName == 'A' ? "<p>Click here to download latest version</p>" : 
parts/omelette/plone/app/jquerytools/browser/jquery.tools.plugins.min.js:" or greater is required</h2><h3>"+(g[0]>0?"Your version is "+g:"You have no flash plugin installed")+"</h3>"+(a.tagName=="A"?"<p>Click here to download latest version</p>":"<p>Download latest version from <a href='"+k+"'>here</a></p>");if(a.tagName=="A")a.onclick=function(){location.href=k}}if(b.onFail){var d=b.onFail.call(this);if(typeof d=="string")a.innerHTML=d}}if(i)window[b.id]=document.getElementById(b.id);f(this,{getRoot:function(){return a},getOptions:function(){return b},getConf:function(){return c},
旧时浪漫 2024-11-16 03:48:26

我没有 Plone 实例来测试它,但尝试在 invokeFactory 之后调用 processForm()。它将:

  • 取消标记创建标志;
  • 根据标题重命名对象;
  • 重新索引对象;
  • 调用 after_creation 脚本并触发 ObjectInitialized 事件。

这些操作的详细信息请参见对象构造生命周期< /a>.也许需要其中一些操作来创建您想要的知识库信息(我希望它是索引)。

I don't have a Plone instance to test it, but try to call processForm() after invokeFactory. It will:

  • unmark creation flag;
  • rename object according to title;
  • reindex the object;
  • invoke the after_creation script and fire the ObjectInitialized event.

These actions are detailed on Object Construction Lifecycle. Maybe some of these actions are needed to create the KB information you're after (I'm hoping it's the index).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文