我试图找出谁是最后一次更改文档的用户.最好,我想基于这个信息制作收藏...我能找到的只是修改日期......
使用此链接中的脚本,我似乎找不到元数据中最后一个用户的信息.
这是正确的(没有修改用户信息...),如果是这样,可以这样做吗?
正如@MikkoOhtamaa所写,Plone默认情况下不会在对象上保存最后一个修饰符.但Plone确实默认启用了 Pages,News Items,Events和Link(通过CMFEditions)版本控制,版本元数据具有最新修饰符的信息.
如果可以从版本元数据中读取信息并仅限制版本控制的内容类型的功能,我认为,您需要
注册一个新索引(catalog.xml在你的附加组件的Generic Setup -profile中使用;你可能还想注册一个元数据列以获得在结果中返回的索引数据):
<?xml version="1.0"?>
<object name="portal_catalog" meta_type="Plone Catalog Tool">
<index name="last_modifier" meta_type="FieldIndex">
<indexed_attr value="last_modifier"/>
</index>
<column value="last_modifier"/>
</object>
Run Code Online (Sandbox Code Playgroud)注册要在Topic-collections中使用的自定义搜索条件(portal_atct.xml在加载项的Generic Setup -profile中使用)和元数据列,以获取其表格视图中列出的信息:
<?xml version="1.0"?>
<atcttool>
<topic_indexes>
<index name="last_modifier"
description="The last user, who has modified the object"
friendlyName="Last Modifier"
enabled="True">
<criteria>ATCurrentAuthorCriterion</criteria>
<criteria>ATListCriterion</criteria>
<criteria>ATSimpleStringCriterion</criteria>
</index>
</topic_indexes>
<topic_metadata>
<metadata name="last_modifier"
description="The last user, who has modified the object"
friendlyName="Last Modifier"
enabled="True"/>
</topic_metadata>
</atcttool>
Run Code Online (Sandbox Code Playgroud)编写自定义索引器,从版本元数据中查找最后一个修饰符并对其编制索引:
# -*- coding: utf-8 -*-
"""Last modifier indexer"""
from zope.component import getUtility
from plone.indexer import indexer
from Products.CMFCore.interfaces import ISiteRoot, IContentish
from Products.CMFCore.utils import getToolByName
@indexer(IContentish)
def indexLastModifier(context):
try:
creator = context.Creators()[0] # fallback value
except AttributeError:
creator = None
except IndexError:
creator = None
site = getUtility(ISiteRoot)
rt = getToolByName(site, "portal_repository")
if rt is None or not rt.isVersionable(context):
# not versionable; fallback to the creator
return creator
history = rt.getHistoryMetadata(context)
if not history:
# empty history; fallback to the creator
return creator
if not rt.isUpToDate(context):
# history not up-to-date; fallback to the authenticated user
mtool = getToolByName(site, "portal_membership")
if mtool.isAnonymousUser():
# no authenticated user found; fallback to the creator
return creator
else:
return mtool.getAuthenticatedMember().getId()
length = history.getLength(countPurged=False)
last = history.retrieve(length - 1)
if not last or type(last) != dict:
# unexpected version metadata; fallback to the creator
return creator
metadata = last.get("metadata")
if not metadata or type(metadata) != dict:
# unexpected version metadata; fallback to the creator
return creator
sys_metadata = metadata.get("sys_metadata")
if not sys_metadata or type(sys_metadata) != dict:
# unexpected version metadata; fallback to the creator
return creator
principal = sys_metadata.get("principal")
if not principal or type(principal) != str:
# unexpected version metadata; fallback to the creator
return creator
return principal
Run Code Online (Sandbox Code Playgroud)并在您的加载项中注册索引器configure.zcml:
<adapter name="last_modifier"
factory=".indexers.indexLastModifier" />
Run Code Online (Sandbox Code Playgroud)但请注意,由于版本控制机制是由与目录索引器相同的事件触发的,因此我们可能无法确定在调用索引它时是否存在最新版本的元数据.上面,我应用虚拟启发式,当存储库说明与待索引的对象相比时版本历史元数据已过时时,我会改为索引当前用户的用户名(并期望用户只是编辑文档).
| 归档时间: |
|
| 查看次数: |
950 次 |
| 最近记录: |