[2007] | 1 | ## Script (Python) "deleteResultByKey" |
---|
| 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
| 7 | ##parameters=REQUEST,key=None |
---|
| 8 | ##title= |
---|
| 9 | ## |
---|
| 10 | # $Id: deleteStudentByMatricNo.py 1567 2007-03-17 08:34:51Z henrik $ |
---|
| 11 | """ |
---|
| 12 | """ |
---|
| 13 | import logging |
---|
| 14 | logger = logging.getLogger('Skins.deleteResultByKey') |
---|
| 15 | |
---|
| 16 | request = REQUEST |
---|
| 17 | wftool = context.portal_workflow |
---|
| 18 | mtool = context.portal_membership |
---|
| 19 | member = mtool.getAuthenticatedMember() |
---|
| 20 | roles = member.getRolesInContext(context) |
---|
| 21 | stdir = context.portal_directories.students |
---|
| 22 | st_cat = context.students_catalog |
---|
| 23 | ret_imp = context.returning_import |
---|
| 24 | res_imp = context.results_import |
---|
| 25 | students = context.portal_url.getPortalObject().campus.students |
---|
[2097] | 26 | if str(member) not in ('admin','joachim','med','despej') or key is None: |
---|
[2007] | 27 | return |
---|
| 28 | |
---|
| 29 | output = [] |
---|
| 30 | |
---|
| 31 | # remove from results_import |
---|
| 32 | |
---|
| 33 | res_deleted = [] |
---|
| 34 | res_res = res_imp(key=key) |
---|
| 35 | if len(res_res) > 0: |
---|
| 36 | for r in res_res: |
---|
| 37 | res_imp.deleteRecord(r.key) |
---|
| 38 | res_deleted.append(r.key) |
---|
[2097] | 39 | msg = "%s deleted result %s from results_import" % (member,',\n'.join(res_deleted)) |
---|
[2007] | 40 | else: |
---|
| 41 | msg = "No results %s to delete from results_import" % key |
---|
| 42 | output.append(msg) |
---|
| 43 | logger.info(msg) |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | return "\n".join(output) |
---|
| 47 | |
---|