首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何制作插入其他较小的内容项视图的plone视图?

如何制作插入其他较小的内容项视图的plone视图?
EN

Stack Overflow用户
提问于 2014-06-24 19:17:50
回答 1查看 267关注 0票数 3

我觉得这应该很简单。我有一个折叠式TTW灵巧的内容项目(一个投篮),其中包含折叠式TTW灵巧项目(提案)。每个提案都包含了TTW灵巧的评论,我想总结一下。

我可以很容易地为任何提案生成一个表,如下所示,并对folderlisting视图进行简单的修改:

代码语言:javascript
复制
[review1 link]   [criterion_1 value] [criterion-2 value]... 
[review2 link]  [criterion_1 value] [criterion-2 value]... 
.
.

我还可以通过修改折叠列表视图来生成一个放置框的工作表视图:

代码语言:javascript
复制
[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]
.
.

我的问题是,我不知道如何将第一个表插入到第二个表第二列的单元格中。我试过两件事:

  1. 在dropbox清单的视图模板中,我尝试复制listing宏的重复宏,给它及其所有变量新的名称,让它在每个建议中迭代。这很容易访问每个评审的所有都柏林核心模式,但我无法访问灵巧字段。我尝试过的所有东西(生成第一个表时都能工作)都会产生LocationError和AttributeError警告。不知何故,当我下降一个级别时,我会丢失视图模板查找所有内容所需的一些信息。有什么建议吗?
  2. 我还尝试访问这个提议的清单宏,调用类似于<metal use-macro="item/first_table_template_name/listing"/>。这甚至部分是正确的方法吗?它不会出现错误,但也不会在我的页面中插入任何内容。

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-27 01:52:34

这个解决方案是基于kuel:view.ptitem.pt提供的示例松散的。--谢谢

我认为最容易创建和调试的方法是:

  1. 从plone标准模板folder_listing.pt中创建一个极简的模板,该模板只为单个提案提供汇总评审数据的表格。模板只是一个表,没有头信息或任何其他插槽。这是一个精简的版本,但没有什么比第一个语句更重要。允许访问字段的关键语句的形式如下: python: item.getObject().restrictedTraverse('criterion_1')

表格模板:

代码语言:javascript
复制
    <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 &lt; 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>
  1. 创建另一个清单模板,该模板调用此模板来填充适当的表单元格。再次,我使用了对folder_listing.pt的修改。基本上,在重复块中,我将以下语句放在表的第二列中: 这是在标记结束普通项目列表之后立即出现的。

请注意,"ug_small_grant_review_summary_table“是我给模板指定的名称,更详细地显示在上面。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24394556

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档