source: WAeUP_SRP/trunk/Documents.py @ 17497

Last change on this file since 17497 was 4819, checked in by Henrik Bettermann, 15 years ago

fix typo (section titles should be better singular than plural)

File size: 2.6 KB
Line 
1#-*- mode: python; mode: fold -*-
2from Globals import InitializeClass
3from AccessControl import ClassSecurityInfo
4
5from Products.CMFCore.utils import UniqueObject, getToolByName
6from Products.CMFCore.permissions import View
7from Products.CMFCore.permissions import ModifyPortalContent
8from Products.CPSCore.CPSBase import CPSBase_adder, CPSBaseFolder
9from Products.CPSDocument.CPSDocument import CPSDocument
10
11
12import DateTime
13import csv,re
14import logging
15import Globals
16p_home = Globals.package_home(globals())
17i_home = Globals.INSTANCE_HOME
18
19
20class 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"""
32        return "Document Section"
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
55InitializeClass(DocumentsFolder)
56
57def 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
64class 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
75InitializeClass(WAeUPDocument)
76
77def addWAeUPDocument(container, id, REQUEST=None, **kw):
78    """Add a WAeUP Document."""
79    ob = WAeUPDocument(id, **kw)
80    return CPSBase_adder(container, ob, REQUEST=REQUEST)
81   
82   
83
84
85###)
86
87
Note: See TracBrowser for help on using the repository browser.