[1593] | 1 | ## Script (Python) "hall_delete" |
---|
[639] | 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
| 7 | ##parameters=ids=[], REQUEST=None |
---|
| 8 | ##title= |
---|
| 9 | ## |
---|
[805] | 10 | # $Id: hall_delete.py 1593 2007-03-19 18:57:54Z uli $ |
---|
[639] | 11 | """ |
---|
| 12 | FIXME: add docstring. |
---|
| 13 | """ |
---|
| 14 | |
---|
[1593] | 15 | import logging |
---|
| 16 | logger = logging.getLogger('Skins.hall_delete') |
---|
| 17 | member_id = str(context.portal_membership.getAuthenticatedMember()) |
---|
| 18 | |
---|
[639] | 19 | from Products.CMFCore.utils import getToolByName |
---|
| 20 | here = context |
---|
| 21 | if context.portal_type == "University": |
---|
| 22 | here = context.academics |
---|
| 23 | |
---|
| 24 | ti = getToolByName(here, 'portal_types').getTypeInfo(here.portal_type) |
---|
| 25 | meth_id = ti.queryMethodID('view', 'folder_contents') |
---|
| 26 | ret_url = here.absolute_url() + '/' + meth_id |
---|
| 27 | pa = context.portal_accommodation |
---|
| 28 | |
---|
| 29 | if ids: |
---|
| 30 | halls = [] |
---|
| 31 | for id in ids: |
---|
| 32 | # XXX has to be called from here since the workflow doesn't handle the |
---|
| 33 | # deletion yet |
---|
| 34 | halls.append(id) |
---|
| 35 | ob = getattr(here, id) |
---|
| 36 | from Products.CPSCore.EventServiceTool import getPublicEventService |
---|
| 37 | evtool = getPublicEventService(here) |
---|
| 38 | evtool.notifyEvent('workflow_delete', ob, {}) |
---|
| 39 | beds = pa(hall=id) |
---|
| 40 | urls = [] |
---|
| 41 | for bed in beds: |
---|
| 42 | urls.append(bed.bed) |
---|
| 43 | for url in urls: |
---|
| 44 | pa.deleteRecord(url) |
---|
| 45 | here.manage_delObjects(ids) |
---|
| 46 | message = 'portal_status_message=hall(s) %s with %s beds deleted' % (" ".join(halls),len(urls)) |
---|
[1593] | 47 | logger.info('%s deletes hall(s) %s with %s beds' % (member_id," ".join(halls),len(urls))) |
---|
[639] | 48 | else: |
---|
| 49 | message = 'portal_status_message=psm_select_at_least_one_document' |
---|
| 50 | |
---|
| 51 | if REQUEST is not None: |
---|
| 52 | return REQUEST.RESPONSE.redirect(ret_url + '?' + message) |
---|