5e73cb8057e679dcbd5e08a927c5413dba2a0578
1 # -*- coding: utf-8 -*-
2 from argparse
import ArgumentParser
4 from AccessControl
import getSecurityManager
5 from Testing
.makerequest
import makerequest
6 from zope
.globalrequest
import setRequest
7 from zope
.site
.hooks
import setSite
8 from ZODB
.POSException
import ConflictError
11 def main(app
, portal_path
, userid
) :
12 portal
= app
.unrestrictedTraverse(portal_path
)
13 portal
= makerequest(portal
)
14 setRequest(portal
.REQUEST
)
16 user
= portal
.acl_users
.getUser(userid
)
17 sm
= getSecurityManager()
18 sm
._context
.user
= user
19 ctool
= portal
.portal_catalog
20 brains
= ctool
.unrestrictedSearchResults(portal_type
='Photo', tiles_available
=1)
22 for i
, brain
in enumerate(brains
) :
23 photo
= brain
.getObject()
24 print photo
.absolute_url()
25 if photo
._methodResultsCache
.has_key('DateTimeOriginal') :
26 del photo
._methodResultsCache
['DateTimeOriginal']
27 photo
.reindexObject(idxs
=['DateTimeOriginal'])
28 if i
and i
% 100 == 0 :
34 if __name__
== '__main__':
35 parser
= ArgumentParser(description
="Update DateTimeOriginal index")
36 parser
.add_argument('portal_path', help='portal object path')
37 parser
.add_argument('userid', help='zope user id')
38 args
= parser
.parse_args()