我想这应该很简单。我有一个包含文件夹式 TTW 灵 active 项目(提案)的文件夹式 TTW 灵 active 内容项(下拉框)。每个提案都包含 TTW 灵 active 评论,其中包含我想要总结的字段。
只要对文件夹 ListView 进行简单修改,我就可以轻松创建一个 View ,为任何提案生成如下所示的表格:
[review1 link] [criterion_1 value] [criterion-2 value]...
[review2 link] [criterion_1 value] [criterion-2 value]...
.
.
我还可以通过修改文件夹 ListView 为下拉框生成工作 TableView :
[proposal1 link] [column I would like to insert the above table in for this proposal]
[proposal2 link] [column I would like to insert the above table in for this proposal]
.
.
我的问题是我不知道如何将第一个表格插入到第二个表格第二列的单元格中。我试过两件事:
- 在 dropbox 列表的 View 模板中,我尝试复制 listingmacro 的 repeat 宏,给它和它的所有变量新的名称,让它在每个提案上迭代。这很容易访问每个评论的所有都柏林核心模式,但我无法访问灵巧字段。我尝试过的一切(生成第一个表时有效的东西)都会产生 LocationError 和 AttributeError 警告。不知何故,当我下降一个级别时,我会丢失一些 View 模板找到所有内容所需的信息。有什么建议吗?
- 我还尝试访问提案的列表宏,调用类似
<metal use-macro="item/first_table_template_name/listing"/>
.这甚至是部分正确的方法吗?它没有给出任何错误,但也没有在我的页面中插入任何内容。
谢谢。
最佳答案
此解决方案大致基于 kuel 提供的示例:https://github.com/plone/Products.CMFPlone/blob/854be6e30d1905a7bb0f20c66fbc1ba1f628eb1b/Products/CMFPlone/skins/plone_content/folder_full_view.pt和 https://github.com/plone/Products.CMFPlone/blob/b94584e2b1231c44aa34dc2beb1ed9b0c9b9e5da/Products/CMFPlone/skins/plone_content/folder_full_view_item.pt . --谢谢。
我发现最容易创建和调试的方法是:
从 plone 标准模板 folder_listing.pt 创建一个极简模板,该模板仅制作单个提案的汇总审查数据表。该模板仅用于表格,没有标题信息或任何其他插槽。这是一个精简版,但在第一个语句之上没有任何内容。允许访问字段的关键语句采用以下形式:
python: item.getObject().restrictedTraverse('criterion_1')
表格模板:
<table class="review_summary listing">
<tbody><tr class="column_labels"><th>Review</th><th>Scholarly Merit</th><th>Benefits to Student</th><th>Clarity</th><th>Sum</th></tr>
<metal:listingmacro define-macro="listing">
<tal:foldercontents define="contentFilter contentFilter|request/contentFilter|nothing;
contentFilter python:contentFilter and dict(contentFilter) or {};
I kept all the standard definitions from the original template.
I have just removed them for brevity.
plone_view context/@@plone;">
The following tal:sum is where I did some math on my data. If you are
not manipulating the data this would not be needed. Note that I am only
looking at the first character of the choice field.
<tal:sum define="c1_list python:[int(temp.getObject().restrictedTraverse('criterion_1')[0])
for temp in batch if temp.portal_type=='ug_small_grants_review'];
c1_length python: test(len(c1_list)<1,-1,len(c1_list));
c2_list python:[int(temp.getObject().restrictedTraverse('criterion_2')[0])
for temp in batch if temp.portal_type=='ug_small_grants_review'];
c2_length python: test(len(c2_list)<1,-1,len(c2_list));
c1_avg python: round(float(sum(c1_list))/c1_length,2);
c2_avg python: round(float(sum(c2_list))/c2_length,2);
avg_sum python: c1_avg+c2_avg;
">
<tal:listing condition="batch">
<dl metal:define-slot="entries">
<tal:entry tal:repeat="item batch" metal:define-macro="entries">
<tal:block tal:define="item_url item/getURL|item/absolute_url;
item_id item/getId|item/id;
Again, this is the standard define from the folder_listing.pt
but I've left out most of it to save space here.
item_samedate python: (item_end - item_start < 1) if item_type == 'Event' else False;">
<metal:block define-slot="entry"
The following condition is key if you can have things
other than reviews within a proposal. Make sure the
item_type is proper for your review/item.
tal:condition="python: item_type=='ug_small_grants_review'">
<tr class="review_entry"><td class="entry_info">
<dt metal:define-macro="listitem"
tal:attributes="class python:test(item_type == 'Event', 'vevent', '')">
I kept all the standard stuff from folder_listing.pt here.
</dt>
<dd tal:condition="item_description">
</dd>
</td>
The following tal:comp block is used to calculate values
across the rows because we do not know the index of the
item the way the batch is iterated.
<tal:comp define = "crit_1 python: item.getObject().restrictedTraverse('criterion_1')[0];
crit_2 python: item.getObject().restrictedTraverse('criterion_2')[0];
">
<td tal:content="structure crit_1"># here</td>
<td tal:content="structure crit_2"># here</td>
<td tal:content="structure python: int(crit_1)+int(crit_2)"># here</td>
</tal:comp>
</tr>
</metal:block>
</tal:block>
</tal:entry>
</dl>
<tr>
<th>Average</th>
<td tal:content="structure c1_avg"># here</td>
<td tal:content="structure c2_avg"># here</td>
<td tal:content="structure avg_sum"># here</td>
</tr>
</tal:listing>
</tal:sum>
<metal:empty metal:define-slot="no_items_in_listing">
<p class="discreet"
tal:condition="not: folderContents"
i18n:translate="description_no_items_in_folder">
There are currently no items in this folder.
</p>
</metal:empty>
</tal:foldercontents>
</metal:listingmacro>
</tbody></table>
创建另一个列表模板,调用这个模板来填充适当的表格单元格。同样,我使用了对 folder_listing.pt 的修改。基本上在重复 block 中,我将以下语句放在表的第二列中:
这属于正常项目列表结束的 标签之后。
请注意,“ug_small_grant_review_summary_table”是我为上面更详细显示的模板指定的名称。
关于templates - 如何制作插入其他较小内容项 View 的平面 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24394556/