[2013] | 1 | #-*- mode: python; mode: fold -*- |
---|
| 2 | from Globals import InitializeClass |
---|
| 3 | from AccessControl import ClassSecurityInfo |
---|
| 4 | |
---|
| 5 | from Products.CMFCore.utils import UniqueObject, getToolByName |
---|
| 6 | from Products.CMFCore.permissions import View |
---|
| 7 | from Products.CMFCore.permissions import ModifyPortalContent |
---|
| 8 | from Products.CPSCore.CPSBase import CPSBase_adder, CPSBaseFolder |
---|
| 9 | from Products.CPSDocument.CPSDocument import CPSDocument |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | import DateTime |
---|
| 13 | import csv,re |
---|
| 14 | import logging |
---|
| 15 | import Globals |
---|
| 16 | p_home = Globals.package_home(globals()) |
---|
| 17 | i_home = Globals.INSTANCE_HOME |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | class DocumentsFolder(CPSDocument): ###( |
---|
| 21 | """ |
---|
| 22 | WAeUP DocumentsFolder containing StudyCourses |
---|
| 23 | """ |
---|
| 24 | meta_type = 'DocumentsFolder' |
---|
| 25 | portal_type = meta_type |
---|
| 26 | security = ClassSecurityInfo() |
---|
| 27 | use_catalog_for_folder_contents = True |
---|
| 28 | |
---|
| 29 | security.declareProtected(View,"Title") |
---|
| 30 | def Title(self): |
---|
| 31 | """compose title""" |
---|
[4819] | 32 | return "Document Section" |
---|
[2013] | 33 | |
---|
| 34 | def exportLocalRoles(self,portal_type): ###( |
---|
| 35 | name = '%sLocalRoles' % portal_type |
---|
| 36 | logger = logging.getLogger('Documents.DocumentsFolder.exportLocalRoles') |
---|
| 37 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
| 38 | logger.info('Start exporting %(name)s to %(name)s_%(current)s.csv' % vars()) |
---|
| 39 | objects = [f.getObject() for f in self.portal_catalog({'meta_type': portal_type})] |
---|
| 40 | export = [] |
---|
| 41 | export.append('"code","users"') |
---|
| 42 | #import pdb;pdb.set_trace() |
---|
| 43 | for obj in objects: |
---|
| 44 | lr = {} |
---|
| 45 | for (username, roles) in obj.get_local_roles(): |
---|
| 46 | lr[ 'user:' + username ] = [x for x in roles] |
---|
| 47 | for (groupname, roles) in obj.get_local_group_roles(): |
---|
| 48 | lr[ 'group:' + group ] = [x for x in roles] |
---|
| 49 | logger.info('Exporting %s %s ' % (obj.id, lr)) |
---|
| 50 | export.append('"%s","%s"' % (obj.getId(),lr)) |
---|
| 51 | open("%s/import/%s-%s.csv" % (i_home,name,current),"w+").write('\n'.join(export)) |
---|
| 52 | ###) |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | InitializeClass(DocumentsFolder) |
---|
| 56 | |
---|
| 57 | def addDocumentsFolder(container, id, REQUEST=None, **kw): |
---|
| 58 | """Add a DocumentsFolder.""" |
---|
| 59 | ob = DocumentsFolder(id, **kw) |
---|
| 60 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 61 | |
---|
| 62 | ###) |
---|
| 63 | |
---|
| 64 | class WAeUPDocument(CPSDocument): ###( |
---|
| 65 | """ |
---|
| 66 | WAeUP Document |
---|
| 67 | """ |
---|
| 68 | meta_type = 'WAeUP Document' |
---|
| 69 | portal_type = meta_type |
---|
| 70 | security = ClassSecurityInfo() |
---|
| 71 | |
---|
| 72 | def __init__(self, id, **kw): |
---|
| 73 | CPSDocument.__init__(self, id, **kw) |
---|
| 74 | |
---|
| 75 | InitializeClass(WAeUPDocument) |
---|
| 76 | |
---|
| 77 | def addWAeUPDocument(container, id, REQUEST=None, **kw): |
---|
| 78 | """Add a WAeUP Document.""" |
---|
| 79 | ob = WAeUPDocument(id, **kw) |
---|
| 80 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
[3824] | 81 | |
---|
| 82 | |
---|
[2013] | 83 | |
---|
[3824] | 84 | |
---|
[2013] | 85 | ###) |
---|
| 86 | |
---|
| 87 | |
---|