Plone技术资料

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2122|回复: 0

Plone核心包:plone.app.content解读

[复制链接]
发表于 2019-8-8 12:55:24 | 显示全部楼层 |阅读模式
plone.app.content 包含了各种Plone的内置核心视图,如folder_contents、plonejsi18n、getVocabulary等等。包结构如下:
路径:plone.app.content

最重要的文件是setup.py,这里定义了包结构,包的依存部件,测试依存件等。

路径:plone.app.content/plone/app/content

这里testing.py定义测试环境,interfaces.py定义了event、Adapter等接口。

路径:plone.app.content/plone/app/content/browser


路径:plone.app.content/plone/app/content/browser/content

folder_content视图定义在这里的configure.zcml中。

主要视图定义在browser/configure.zcml和browser/content/configure.zcml两处,看下述代码:
  1. <configure
  2.     xmlns="http://namespaces.zope.org/zope"
  3.     xmlns:browser="http://namespaces.zope.org/browser"
  4.     xmlns:five="http://namespaces.zope.org/five">

  5.     <!-- Adding view -->
  6.     <browser:view
  7.         for="Products.CMFCore.interfaces.IFolderish"
  8.         name="+"
  9.         class=".adding.CMFAdding"
  10.         permission="cmf.AddPortalContent"
  11.         />

  12.     <!-- Folder contents -->
  13.     <include package=".contents" />

  14.     <!-- Review list -->
  15.     <browser:page
  16.         for="*"
  17.         class=".reviewlist.FullReviewListView"
  18.         name="full_review_list"
  19.         template="full_review_list.pt"
  20.         permission="cmf.ReviewPortalContent" />

  21.     <browser:page
  22.          for="*"
  23.          class=".reviewlist.ReviewListBrowserView"
  24.          attribute="update_table"
  25.          name="reviewlist_get_table"
  26.          permission="cmf.ReviewPortalContent" />

  27.     <!-- Content status history -->
  28.     <browser:page
  29.         for="*"
  30.         name="content_status_history"
  31.         class=".content_status_history.ContentStatusHistoryView"
  32.         permission="cmf.ModifyPortalContent"
  33.         />

  34.     <!-- Folder factories -->
  35.     <browser:page
  36.         for="*"
  37.         name="folder_factories"
  38.         class=".folderfactories.FolderFactoriesView"
  39.         template="folderfactories.pt"
  40.         permission="cmf.AddPortalContent"
  41.         />

  42.     <!-- Constrain container allowed content types -->
  43.     <permission
  44.         id="plone.ModifyConstrainTypes"
  45.         title="Modify constrain types"
  46.         />
  47.     <browser:page
  48.         name="folder_constraintypes_form"
  49.         for="Products.CMFCore.interfaces.IFolderish"
  50.         permission="plone.ModifyConstrainTypes"
  51.         class=".constraintypes.ConstrainsFormView"
  52.         />
  53.     <utility
  54.         component=".constraintypes.ValidTypesFactory"
  55.         name="plone.app.content.ValidAddableTypes"
  56.         />

  57.     <!-- Required for cmf.ModifyViewTemplate -->
  58.     <include package="Products.CMFDynamicViewFTI" />

  59.     <!-- Select default view -->
  60.     <browser:page
  61.         for="*"
  62.         name="select_default_view"
  63.         class=".selection.DefaultViewSelectionView"
  64.         template="templates/select_default_view.pt"
  65.         permission="cmf.ModifyViewTemplate"
  66.         />

  67.     <browser:page
  68.         for="*"
  69.         name="selectViewTemplate"
  70.         class=".selection.DefaultViewSelectionView"
  71.         attribute="selectViewTemplate"
  72.         permission="cmf.ModifyViewTemplate"
  73.         />

  74.     <!-- Select default page view -->
  75.     <browser:page
  76.         for="*"
  77.         name="select_default_page"
  78.         class=".selection.DefaultPageSelectionView"
  79.         template="templates/select_default_page.pt"
  80.         permission="cmf.ModifyViewTemplate"
  81.         />

  82.     <!-- Actions -->
  83.     <browser:page
  84.         for="*"
  85.         name="delete_confirmation"
  86.         class=".actions.DeleteConfirmationForm"
  87.         permission="zope2.DeleteObjects"
  88.         />

  89.     <browser:page
  90.         for="*"
  91.         name="folder_rename"
  92.         class=".actions.RenameForm"
  93.         permission="cmf.ModifyPortalContent"
  94.         />

  95.     <browser:page
  96.         for="*"
  97.         name="object_rename"
  98.         class=".actions.RenameForm"
  99.         permission="cmf.ModifyPortalContent"
  100.         />

  101.     <adapter factory=".actions.default_new_id" name="default" />
  102.     <adapter factory=".actions.default_new_title" name="default" />

  103.     <browser:page
  104.         for="*"
  105.         name="object_cut"
  106.         class=".actions.ObjectCutView"
  107.         permission="zope2.DeleteObjects"
  108.         />

  109.     <browser:page
  110.         for="*"
  111.         name="object_copy"
  112.         class=".actions.ObjectCopyView"
  113.         permission="zope2.CopyOrMove"
  114.         />

  115.     <browser:page
  116.         for="*"
  117.         name="object_paste"
  118.         class=".actions.ObjectPasteView"
  119.         permission="cmf.AddPortalContent"
  120.         />

  121.     <browser:page
  122.         for="*"
  123.         name="object_delete"
  124.         class=".actions.ObjectDeleteView"
  125.         permission="zope2.DeleteObjects"
  126.         />


  127.     <browser:page
  128.         name="getVocabulary"
  129.         for="*"
  130.         class=".vocabulary.VocabularyView"
  131.         permission="zope2.View"
  132.         />

  133.     <browser:page
  134.         name="getSource"
  135.         for="z3c.form.interfaces.IWidget"
  136.         class=".vocabulary.SourceView"
  137.         permission="zope.Public"
  138.         />

  139.     <browser:page
  140.         name="fileUpload"
  141.         for="Products.CMFCore.interfaces._content.IFolderish"
  142.         class=".file.FileUploadView"
  143.         permission="zope2.View"
  144.         />

  145.     <browser:page
  146.         name="qsOptions"
  147.         for="plone.app.layout.navigation.interfaces.INavigationRoot"
  148.         class=".query.QueryStringIndexOptions"
  149.         permission="zope2.View"
  150.         />

  151.     <browser:view
  152.         for="plone.app.layout.navigation.interfaces.INavigationRoot"
  153.         name="plonejsi18n"
  154.         class=".i18n.i18njs"
  155.         permission="zope2.View"
  156.         />

  157.     <browser:page
  158.         for="*"
  159.         name="allow_upload"
  160.         class=".file.AllowUploadView"
  161.         permission="cmf.AddPortalContent"
  162.         />

  163. </configure>
复制代码
上述文件路径为:plone.app.content/plone/app/content/browser/configure.zcml
  1. <configure
  2.     xmlns="http://namespaces.zope.org/zope"
  3.     xmlns:browser="http://namespaces.zope.org/browser"
  4.     xmlns:plone="http://namespaces.plone.org/plone"
  5.     xmlns:i18n="http://namespaces.zope.org/i18n">

  6.   <browser:page
  7.     for="Products.CMFCore.interfaces._content.IFolderish"
  8.     class=".FolderContentsView"
  9.     name="folder_contents"
  10.     template="templates/folder_contents.pt"
  11.     permission="cmf.ListFolderContents"
  12.     />

  13.   <browser:page
  14.     for="Products.CMFCore.interfaces._content.IFolderish"
  15.     name="fc-contextInfo"
  16.     class=".ContextInfo"
  17.     permission="cmf.ListFolderContents"
  18.     />

  19.   <browser:page
  20.     for="Products.CMFCore.interfaces._content.IFolderish"
  21.     name="fc-setDefaultPage"
  22.     class=".defaultpage.SetDefaultPageActionView"
  23.     permission="cmf.ModifyPortalContent"
  24.     />

  25.   <browser:page
  26.     for="Products.CMFCore.interfaces._content.IFolderish"
  27.     name="fc-itemOrder"
  28.     class=".rearrange.ItemOrderActionView"
  29.     permission="cmf.ModifyPortalContent"
  30.     />

  31.   <browser:page
  32.     for="Products.CMFCore.interfaces._content.IFolderish"
  33.     name="fc-rearrange"
  34.     class=".rearrange.RearrangeActionView"
  35.     permission="cmf.ModifyPortalContent"
  36.     />

  37.   <!-- buttons -->
  38.   <browser:page
  39.     for="Products.CMFCore.interfaces._content.IFolderish"
  40.     name="fc-rename"
  41.     class=".rename.RenameActionView"
  42.     permission="cmf.ListFolderContents"
  43.     />
  44.   <utility component=".rename.RenameAction"
  45.            provides="plone.app.content.interfaces.IStructureAction"
  46.            name="rename" />

  47.   <browser:page
  48.     for="Products.CMFCore.interfaces._content.IFolderish"
  49.     name="fc-tags"
  50.     class=".tags.TagsActionView"
  51.     permission="cmf.ListFolderContents"
  52.     />
  53.   <utility component=".tags.TagsAction"
  54.            provides="plone.app.content.interfaces.IStructureAction"
  55.            name="tags" />

  56.   <browser:page
  57.     for="Products.CMFCore.interfaces._content.IFolderish"
  58.     name="fc-delete"
  59.     class=".delete.DeleteActionView"
  60.     permission="cmf.ListFolderContents"
  61.     />
  62.   <utility component=".delete.DeleteAction"
  63.            provides="plone.app.content.interfaces.IStructureAction"
  64.            name="delete" />

  65.   <browser:page
  66.     for="Products.CMFCore.interfaces._content.IFolderish"
  67.     name="fc-workflow"
  68.     class=".workflow.WorkflowActionView"
  69.     permission="cmf.ListFolderContents"
  70.     />
  71.   <utility component=".workflow.WorkflowAction"
  72.            provides="plone.app.content.interfaces.IStructureAction"
  73.            name="workflow" />

  74.   <browser:page
  75.     for="Products.CMFCore.interfaces._content.IFolderish"
  76.     name="fc-properties"
  77.     class=".properties.PropertiesActionView"
  78.     permission="cmf.ListFolderContents"
  79.     />
  80.   <utility component=".properties.PropertiesAction"
  81.            provides="plone.app.content.interfaces.IStructureAction"
  82.            name="properties" />

  83.   <browser:page
  84.     for="Products.CMFCore.interfaces._content.IFolderish"
  85.     name="fc-copy"
  86.     class=".copy.CopyActionView"
  87.     permission="cmf.ListFolderContents"
  88.     />
  89.   <utility component=".copy.CopyAction"
  90.            provides="plone.app.content.interfaces.IStructureAction"
  91.            name="copy" />

  92.   <browser:page
  93.     for="Products.CMFCore.interfaces._content.IFolderish"
  94.     name="fc-cut"
  95.     class=".cut.CutActionView"
  96.     permission="cmf.ListFolderContents"
  97.     />
  98.   <utility component=".cut.CutAction"
  99.            provides="plone.app.content.interfaces.IStructureAction"
  100.            name="cut" />

  101.   <browser:page
  102.     for="Products.CMFCore.interfaces._content.IFolderish"
  103.     name="fc-paste"
  104.     class=".paste.PasteActionView"
  105.     permission="cmf.ListFolderContents"
  106.     />
  107.   <utility component=".paste.PasteAction"
  108.            provides="plone.app.content.interfaces.IStructureAction"
  109.            name="paste" />
  110. </configure>
复制代码

上述文件路径为:plone.app.content/plone/app/content/browser/contents/configure.zcml

本文以folder_contents视图为例,解释设计思路和实现方式:folder_contents视图是一个较为复杂的视图,设计思想:
  • 视图页面通过templates/folder_contents.pt文件给出呈现入口点
    1. <metal:content-core fill-slot="content-core">
    2.     <metal:content-core define-macro="content-core">
    3.         <span tal:replace="structure context/@@authenticator/authenticator"/>
    4.         <div class="pat-structure"
    5.           tal:attributes="data-pat-structure view/options" />
    6.     </metal:content-core>
    7. </metal:content-core>
    复制代码
    上述文件路径:plone.app.content/plone/app/content/browser/contents/templates/folder_contents.pt

  • folder_contents.pt调用视图类FolderContentsView的get_options方法 构建 所指向html部件的data-pat-structure属性值
    1.    def get_options(self):
    2.         site = get_top_site_from_url(self.context, self.request)
    3.         base_url = site.absolute_url()
    4.         base_vocabulary = '%s/@@getVocabulary?name=' % base_url
    5.         site_path = site.getPhysicalPath()
    6.         context_path = self.context.getPhysicalPath()
    7.         columns = self.get_columns()
    8.         options = {
    9.             'vocabularyUrl': '%splone.app.vocabularies.Catalog' % (
    10.                 base_vocabulary),
    11.             'urlStructure': {
    12.                 'base': base_url,
    13.                 'appended': '/folder_contents'
    14.             },
    15.             'moveUrl': '%s{path}/fc-itemOrder' % base_url,
    16.             'indexOptionsUrl': '%s/@@qsOptions' % base_url,
    17.             'contextInfoUrl': '%s{path}/@@fc-contextInfo' % base_url,
    18.             'setDefaultPageUrl': '%s{path}/@@fc-setDefaultPage' % base_url,
    19.             'availableColumns': columns,
    20.             'attributes': ['Title', 'path', 'getURL', 'getIcon', 'getMimeIcon', 'portal_type'] + list(columns.keys()),  # noqa
    21.             'buttons': self.get_actions(),
    22.             'rearrange': {
    23.                 'properties': self.get_indexes(),
    24.                 'url': '%s{path}/@@fc-rearrange' % base_url
    25.             },
    26.             'basePath': '/' + '/'.join(context_path[len(site_path):]),
    27.             'upload': {
    28.                 'relativePath': 'fileUpload',
    29.                 'baseUrl': base_url,
    30.                 'initialFolder': IUUID(self.context, None),
    31.                 'useTus': TUS_ENABLED
    32.             },
    33.             'thumb_scale': self.get_thumb_scale(),
    34.         }
    35.         return options

    36.     def __call__(self):
    37.         self.options = json_dumps(self.get_options())
    38.         return super(FolderContentsView, self).__call__()
    复制代码
    上述文件路径为:plone.app.content/plone/app/content/browser/contents/__init__py

  • 通过mockup包功能由提供的data-pat-structure属性构建动态页面(这一部分,完全由前端js操作,发出多个AJAX调用,构建动态页面)
    1. /* Structure pattern.
    2. *
    3. * Options:
    4. *    vocabularyUrl(string): Url to return query results (null)
    5. *    indexOptionsUrl(string): Url to configure querystring widget with (null)
    6. *    upload(string): upload configuration settings(null)
    7. *    moveUrl(string): For supporting drag drop reordering (null)
    8. *    contextInfoUrl(string): For supporting add menu (null)
    9. *
    10. * Documentation:
    11. *    # Example
    12. *
    13. *    {{ example-1 }}
    14. *
    15. * Example: example-1
    16. *    <div class="pat-structure"
    17. *         data-pat-structure="vocabularyUrl:/relateditems-test.json;
    18. *                             uploadUrl:/upload;
    19. *                             moveUrl:/moveitem;
    20. *                             indexOptionsUrl:/tests/json/queryStringCriteria.json;
    21. *                             contextInfoUrl:{path}/context-info;"></div>
    22. */

    23. define([
    24.   'jquery',
    25.   'underscore',
    26.   'pat-base',
    27.   'mockup-patterns-structure-url/js/views/app'
    28. ], function($, _, Base, AppView) {
    29.   'use strict';

    30.   var Structure = Base.extend({
    31.     name: 'structure',
    32.     trigger: '.pat-structure',
    33.     parser: 'mockup',
    34.     defaults: {
    35.       // for implementing history changes
    36.       // Example: {base: 'http://mysite.com', appended: '/folder_contents'}
    37.       urlStructure: null,
    38.       vocabularyUrl: null,
    39.       indexOptionsUrl: null, // for querystring widget
    40.       contextInfoUrl: null, // for add new dropdown and other info
    41.       setDefaultPageUrl: null,
    42.       menuOptions: null, // default action menu options per item.
    43.       menuGenerator: 'mockup-patterns-structure-url/js/actionmenu',  // default menu generator
    44.       backdropSelector: '.plone-modal', // Element upon which to apply backdrops used for popovers

    45.       activeColumnsCookie: 'activeColumns',

    46.       /*
    47.         As the options operate on a merging basis per new attribute
    48.         (key/value pairs) on the option Object in a recursive fashion,
    49.         array items are also treated as Objects so that custom options
    50.         are replaced starting from index 0 up to the length of the
    51.         array.  In the case of buttons, custom buttons are simply
    52.         replaced starting from the first one.  The following defines the
    53.         customized attributes that should be replaced wholesale, with
    54.         the default version prefixed with `_default_`.
    55.       */

    56.       attributes: null,
    57.       _default_attributes: [
    58.         'CreationDate',
    59.         'EffectiveDate',
    60.         'ExpirationDate',
    61.         'exclude_from_nav',
    62.         'getIcon',
    63.         'getMimeIcon',
    64.         'getObjSize',
    65.         'getURL',
    66.         'id',
    67.         'is_folderish',
    68.         'last_comment_date',
    69.         'ModificationDate',
    70.         'path',
    71.         'portal_type',
    72.         'review_state',
    73.         'Subject',
    74.         'Title',
    75.         'total_comments',
    76.         'UID'
    77.       ],

    78.       activeColumns: null,
    79.       _default_activeColumns: [
    80.         'ModificationDate',
    81.         'EffectiveDate',
    82.         'review_state'
    83.       ],

    84.       availableColumns: null,
    85.       _default_availableColumns: {
    86.         'id': 'ID',
    87.         'ModificationDate': 'Last modified',
    88.         'EffectiveDate': 'Published',
    89.         'ExpirationDate': 'Expiration',
    90.         'CreationDate': 'Created',
    91.         'review_state': 'Review state',
    92.         'Subject': 'Tags',
    93.         'portal_type': 'Type',
    94.         'is_folderish': 'Folder',
    95.         'exclude_from_nav': 'Excluded from navigation',
    96.         'getObjSize': 'Object Size',
    97.         'last_comment_date': 'Last comment date',
    98.         'total_comments': 'Total comments'
    99.       },

    100.       // action triggered for the primary link for each table row.
    101.       tableRowItemAction: null,
    102.       _default_tableRowItemAction: {
    103.         folder: ['mockup-patterns-structure-url/js/navigation', 'folderClicked'],
    104.         other: []
    105.       },

    106.       typeToViewAction: null,
    107.       _default_typeToViewAction: {
    108.           'File': '/view',
    109.           'Image': '/view',
    110.           'Blob': '/view'
    111.       },

    112.       collectionConstructor:
    113.         'mockup-patterns-structure-url/js/collections/result',

    114.       momentFormat: 'L LT',
    115.       rearrange: {
    116.         properties: {
    117.           'id': 'ID',
    118.           'sortable_title': 'Title'
    119.         },
    120.         url: '/rearrange'
    121.       },
    122.       moveUrl: null,

    123.       buttons: null,
    124.       _default_buttons: [{
    125.         tooltip: 'Cut',
    126.         title: 'Cut',
    127.         url: '/cut'
    128.       },{
    129.         tooltip: 'Copy',
    130.         title: 'Copy',
    131.         url: '/copy'
    132.       },{
    133.         tooltip: 'Paste',
    134.         title: 'Paste',
    135.         url: '/paste'
    136.       },{
    137.         tooltip: 'Delete',
    138.         title: 'Delete',
    139.         url: '/delete',
    140.         context: 'danger',
    141.         icon: 'trash'
    142.       },{
    143.         tooltip: 'Workflow',
    144.         title: 'Workflow',
    145.         url: '/workflow'
    146.       },{
    147.         tooltip: 'Tags',
    148.         title: 'Tags',
    149.         url: '/tags'
    150.       },{
    151.         tooltip: 'Properties',
    152.         title: 'Properties',
    153.         url: '/properties'
    154.       },{
    155.         tooltip: 'Rename',
    156.         title: 'Rename',
    157.         url: '/rename'
    158.       }],

    159.       datatables_options: {},

    160.       upload: {
    161.         uploadMultiple: true,
    162.         showTitle: true
    163.       }

    164.     },
    165.     init: function() {
    166.       var self = this;

    167.       /*
    168.         This part replaces the undefined (null) values in the user
    169.         modifiable attributes with the default values.

    170.         May want to consider moving the _default_* values out of the
    171.         options object.
    172.       */
    173.       var replaceDefaults = ['attributes', 'activeColumns', 'availableColumns', 'buttons', 'typeToViewAction'];
    174.       _.each(replaceDefaults, function(idx) {
    175.         if (self.options[idx] === null) {
    176.           self.options[idx] = self.options['_default_' + idx];
    177.         }
    178.       });

    179.       var mergeDefaults = ['tableRowItemAction'];
    180.       _.each(mergeDefaults, function(idx) {
    181.         var old = self.options[idx];
    182.         self.options[idx] = $.extend(
    183.           false, self.options['_default_' + idx], old
    184.         );
    185.       });

    186.       self.browsing = true; // so all queries will be correct with QueryHelper
    187.       self.options.collectionUrl = self.options.vocabularyUrl;
    188.       self.options.pattern = self;

    189.       // the ``attributes`` options key is not compatible with backbone,
    190.       // but queryHelper that will be constructed by the default
    191.       // ResultCollection will expect this to be passed into it.
    192.       self.options.queryHelperAttributes = self.options.attributes;
    193.       delete self.options.attributes;

    194.       self.view = new AppView(self.options);
    195.       self.$el.append(self.view.render().$el);
    196.     }
    197.   });

    198.   return Structure;

    199. });
    复制代码
    上述文件路径:mockup/patterns/structure/pattern.js




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|Plone技术资料 ( 湘ICP备14006519号-1 )

GMT+8, 2019-10-22 09:03 , Processed in 0.047138 second(s), 15 queries , Gzip On.

Powered by Plone! X3.4

© 2001-2019 Plone.org.

快速回复 返回顶部 返回列表