4

We're creating a database of files on a new Plone 4.3.2 website, using eea.facetednav as the main interface. In order to have multiple searchable "tags" plus additional information like publish year, article type, etc etc, we've created custom Dexterity content types for these "files". One of the fields on the Dexterity content type is to upload the actual file.

Everything was going swimmingly UNTIL I realized...

One of the basic functionalities of linking to "files" is now broken. Whereas we would expect creating an internal link to a file will prompt opening the file or downloading it when clicked, now it just takes you to the "view" for the new Dexterity content type, where there's a link to the actual file.

This is pretty cumbersome. Has anyone done this before, or found a way to have it automatically link to download the file? If we need to disable/scrap the Dexterity content type view in favor of the direct link, that's probably fine, but bonus points if you can think of a way to make this work both ways (i.e. have a linking method that takes it to the file and a linking method that takes it to the view).

This is the page I mean by "view", in case it's unclear: enter image description here

... Off the top of my head, I can think of a weird Diazo solution of making a custom template that parses this view and automatically redirects to the file link, but that seems wrong/weird. Other thoughts?

4

2 回答 2

4

我会去加分,虽然我还没有完全测试过这个......

首先,您必须将文件字段指定为内容类型的“主要”字段。不幸的是,此选项不会显示在 UI 中,因此您必须编辑架构的 XML 版本(在最近版本的敏捷控制面板中有一个按钮)。xmlns:marshal="http://namespaces.plone.org/supermodel/marshal"在顶部添加为命名空间,并添加marshal:primary="true"到相关field标签中。

然后,在 portal_types 中找到您的类型并将“默认视图方法”更改为@@download. (它通常以view敏捷内容类型开始。)这应该使项目的 URL 下载文件而不是显示正常视图。它知道要使用哪个字段,因为您将其指定为主要字段。

您仍然可以通过添加/view到项目 URL 的末尾来访问普通视图。如果您希望 Plone 在从导航和文件夹内容链接到类型时执行此操作(就像它对内置图像和文件所做的那样),请转到 portal_properties/site_properties 并将类型的 id 添加到typesUseViewActionInListings列表中。

于 2014-09-20T07:01:13.867 回答
4

如果我必须解决这个问题,我会以plone.app.contenttypes 中的“链接”内容类型视图作为模型。

当有人要求查看链接内容类型对象时,视图会查看请求者是否具有Modify portal content链接对象的权限。如果他们这样做了,他们就会看到常规视图,从而有机会进行编辑。如果他们不这样做,则视图将重定向到目标 URL。

你的代码会更简单。检查权限后,您只需要附加@@download/field_name即可获取重定向 URL。

于 2014-09-19T16:46:50.673 回答