[5787] | 1 | ## Script (Python) "remove_all_accommodation_objects"
|
---|
| 2 | ##bind container=container
|
---|
| 3 | ##bind context=context
|
---|
| 4 | ##bind namespace=
|
---|
| 5 | ##bind script=script
|
---|
| 6 | ##bind subpath=traverse_subpath
|
---|
| 7 | ##parameters=
|
---|
| 8 | ##title=
|
---|
| 9 | ##
|
---|
| 10 | # $Id: remove_all_accommodation_objects.py 5787 2011-03-02 11:30:23Z henrik $
|
---|
| 11 | """
|
---|
| 12 | """
|
---|
| 13 | try:
|
---|
| 14 | from Products.zdb import set_trace
|
---|
| 15 | except:
|
---|
| 16 | def set_trace():
|
---|
| 17 | pass
|
---|
| 18 |
|
---|
| 19 | mtool = context.portal_membership
|
---|
| 20 | member = mtool.getAuthenticatedMember()
|
---|
| 21 | if str(member) not in ('admin'):
|
---|
| 22 | return
|
---|
| 23 |
|
---|
| 24 | import logging
|
---|
| 25 | import DateTime
|
---|
| 26 | logger = logging.getLogger('Skins.remove_all_accommodation_objects')
|
---|
| 27 | from Products.AdvancedQuery import Eq, Between, Le,In
|
---|
| 28 | aq_portal = context.portal_catalog_real.evalAdvancedQuery
|
---|
| 29 | wf = context.portal_workflow
|
---|
| 30 |
|
---|
| 31 | logger.info('start')
|
---|
| 32 | accommodation_brains = context.portal_catalog.search({'meta_type': "StudentAccommodation"})
|
---|
| 33 | num_objects = len(accommodation_brains)
|
---|
| 34 | logger.info("found %d StudentAccommodation objects" % num_objects)
|
---|
| 35 | students_folder = context.portal_url.getPortalObject().campus.students
|
---|
| 36 |
|
---|
| 37 | for i in xrange(num_objects):
|
---|
| 38 | #set_trace()
|
---|
| 39 | data = {}
|
---|
| 40 | a_brain = accommodation_brains[i]
|
---|
| 41 | pl = a_brain.getPath().split('/')
|
---|
| 42 | student_id = pl[-2]
|
---|
| 43 | student_folder = getattr(students_folder,student_id)
|
---|
| 44 | student_folder.manage_delObjects(a_brain.id)
|
---|
| 45 | logger.info("%s/%s removed" % (pl[-2],pl[-1]))
|
---|
| 46 |
|
---|
| 47 | logger.info("finished")
|
---|