Пример #1
0
 def fetchlocationstoaddcontent(self):
     portal_state = getMultiAdapter((self.context, self.request), name=u"plone_portal_state")
     portal = portal_state.portal()
     
     results = getLocationListForAddContent(portal)
     
     output = {}
     items = []
     for eachobj in results:
         temp = {}
         temp['title'] = force_unicode(eachobj['object'].Title,'utf8')
         temp['UID'] = eachobj['object'].UID
         temp['occ'] = ''
         if eachobj['canAdd'] == False or 'Discussion' in eachobj['disallowedtypes']:
             temp['occ'] = 'disabledspaceselection'
         temp['depth'] = eachobj['depth']
         items.append(temp)
     
     output['items'] = items
     output = jsonlib.write(output)
     
 
     return output
Пример #2
0
    def update(self):
        self.addnewitems = []
        self.viewmenu = []
        self.currentcontextmenu = []        
        self.currentcontexttitle = ''
        
        self.contextualurl = ''
        self.contextuid = ''
        self.contextdisallowedtypes = []
        
        portal_state = getMultiAdapter((self.context, self.request),name=u'plone_portal_state')
        context_state = getMultiAdapter((self.context, self.request),name=u'plone_context_state')
        typetool= getToolByName(self.context, 'portal_types')
        object_typename = self.context.portal_type
        portal = portal_state.portal()
        
        self.spaceslist = getLocationListForAddContent(portal)        
        
        self.viewmenu = self.getAddMenuItems(portal,'views')
        self.anonymous = portal_state.anonymous()
        if not self.anonymous:
            for eachtype in spacesdefaultaddablenonfolderishtypes:
                object_typeobj = typetool[eachtype]
                if object_typeobj <> None:
                    self.addnewitems.append({'id': object_typeobj.id, 
                                             'title': object_typeobj.Title(), 
                                             'description':object_typeobj.Description(),
                                             'icon': object_typeobj.content_icon})
                    
            if self.context.portal_type == 'Folder':
                self.addnewitems = []
                for eachtype in spacesdefaultaddableforfolders:
                    object_typeobj = typetool[eachtype]
                    if object_typeobj <> None:
                        self.addnewitems.append({'id': object_typeobj.id, 
                                                 'title': object_typeobj.Title(), 
                                                 'description':object_typeobj.Description(),
                                                 'icon': object_typeobj.content_icon})
            self.addnewcontainers = []
            containers = ['ContentSpace', 'Course', 'Folder']
            for eachtype in containers:
                object_typeobj = typetool[eachtype]
                if object_typeobj <> None:
                    self.addnewcontainers.append({'id': object_typeobj.id, 
                                                  'title': object_typeobj.Title(),
                                                  'description':object_typeobj.Description(),
                                                  'icon': object_typeobj.content_icon})
            self.contenidoeducativo = []
            containers = ['Exam', 'Quiz', 'ZipContent', 'SCO']
            for eachtype in containers:
                object_typeobj = typetool[eachtype]
                if object_typeobj <> None:
                    self.contenidoeducativo.append({'id': object_typeobj.id, 
                                                  'title': object_typeobj.Title(),
                                                  'description':object_typeobj.Description(),
                                                  'icon': object_typeobj.content_icon})       
            
            
            self.addnewitems.sort(lambda x,y: cmp(x['title'].lower(),y['title'].lower()))

            
            menu = getUtility(IBrowserMenu, name='plone_contentmenu_factory')
            
            if object_typename in ('RecycleBin',):
                self.currentcontextmenu = []
            elif object_typename in ('Plone Site',):
                #get root object and check for it
                objRoot = getattr(portal,getRootID())
                if checkHasPermission('Add portal content', aq_inner(objRoot)):
                    self.currentcontextmenu = menu.getMenuItems(objRoot,self.request)
                    self.contextualurl = aq_inner(objRoot).absolute_url()
                    self.currentcontexttitle = objRoot.Title()
                    self.contextuid = objRoot.UID()
                    self.contextdisallowedtypes = objRoot.disallowedtypes()
            else:
                if object_typename in ('ContentRoot','ContentSpace', 'Course','Folder') and self.context.isPrincipiaFolderish and checkHasPermission('Add portal content',aq_inner(self.context)):                
                    self.currentcontextmenu = menu.getMenuItems(self.context, self.request)
                    self.contextualurl = aq_inner(self.context).absolute_url()
                    
                    if object_typename in ('ContentRoot','ContentSpace','Course','Folder'):
                        self.currentcontexttitle = context_state.object_title()
                        self.contextuid = aq_inner(self.context).UID()
                        self.contextdisallowedtypes = (aq_inner(self.context)).disallowedtypes()
                else:
                    currentobject = aq_inner(self.context)
                    parentList = currentobject.aq_chain
                    parentspace = None
                    found = 0
            
                    try:
                        for type in parentList:
                            if type.portal_type in ('ContentRoot','ContentSpace','Course'):
                                parentspace = type
                                if checkHasPermission('Add portal content',aq_inner(parentspace)):
                                    found = 1
                            if found == 1:
                                break
                    except AttributeError:
                        parentspace = None
                        pass
                    
                    if parentspace <> None:
                        self.currentcontextmenu = menu.getMenuItems(aq_inner(parentspace),self.request)
                        self.currentcontexttitle = parentspace.Title()
                        self.contextualurl = parentspace.absolute_url()
                        self.contextuid = parentspace.UID()
                        self.contextdisallowedtypes = parentspace.disallowedtypes()
            
            #strip out 'settings' item(s)
            self.currentcontextmenu = [ob for ob in self.currentcontextmenu if ob['extra']['id'] <> 'settings' and  ob['extra']['id'] <> '_settings']
            if self.contextuid == '':
                #best match element is brain                
                bestmatchedspace = getBestMatchedLocationForAddingContent(portal)
                if bestmatchedspace:
                    self.currentcontexttitle = bestmatchedspace.Title
                    self.contextuid = bestmatchedspace.UID
                    self.contextualurl = bestmatchedspace.getURL()
                    self.contextdisallowedtypes = bestmatchedspace.disallowedtypes
Пример #3
0
    def update(self):
        self.addnewitems = []
        self.viewmenu = []
        self.currentcontextmenu = []
        self.currentcontexttitle = ''

        self.contextualurl = ''
        self.contextuid = ''
        self.contextdisallowedtypes = []

        portal_state = getMultiAdapter((self.context, self.request),
                                       name=u'plone_portal_state')
        context_state = getMultiAdapter((self.context, self.request),
                                        name=u'plone_context_state')
        typetool = getToolByName(self.context, 'portal_types')
        object_typename = self.context.portal_type
        portal = portal_state.portal()

        self.spaceslist = getLocationListForAddContent(portal)

        self.viewmenu = self.getAddMenuItems(portal, 'views')
        self.anonymous = portal_state.anonymous()
        if not self.anonymous:
            for eachtype in spacesdefaultaddablenonfolderishtypes:
                object_typeobj = typetool[eachtype]
                if object_typeobj <> None:
                    self.addnewitems.append({
                        'id':
                        object_typeobj.id,
                        'title':
                        object_typeobj.Title(),
                        'description':
                        object_typeobj.Description(),
                        'icon':
                        object_typeobj.content_icon
                    })

            self.addnewcontainers = []
            object_typeobj = typetool['ContentSpace']
            self.addnewcontainers.append({
                'id':
                object_typeobj.id,
                'title':
                object_typeobj.Title(),
                'description':
                object_typeobj.Description(),
                'icon':
                object_typeobj.content_icon
            })

            self.addnewitems.sort(
                lambda x, y: cmp(x['title'].lower(), y['title'].lower()))

            menu = getUtility(IBrowserMenu, name='plone_contentmenu_factory')

            if object_typename in ('RecycleBin', ):
                self.currentcontextmenu = []
            elif object_typename in ('Plone Site', ):
                #get root object and check for it
                objRoot = getattr(portal, getRootID())
                if checkHasPermission('Add portal content', aq_inner(objRoot)):
                    self.currentcontextmenu = menu.getMenuItems(
                        objRoot, self.request)
                    self.contextualurl = aq_inner(objRoot).absolute_url()
                    self.currentcontexttitle = objRoot.Title()
                    self.contextuid = objRoot.UID()
                    self.contextdisallowedtypes = objRoot.disallowedtypes()
            else:
                if object_typename in (
                        'ContentRoot', 'ContentSpace'
                ) and self.context.isPrincipiaFolderish and checkHasPermission(
                        'Add portal content', aq_inner(self.context)):
                    self.currentcontextmenu = menu.getMenuItems(
                        self.context, self.request)
                    self.contextualurl = aq_inner(self.context).absolute_url()

                    if object_typename in ('ContentRoot', 'ContentSpace'):
                        self.currentcontexttitle = context_state.object_title()
                        self.contextuid = aq_inner(self.context).UID()
                        self.contextdisallowedtypes = (aq_inner(
                            self.context)).disallowedtypes()
                else:
                    currentobject = aq_inner(self.context)
                    parentList = currentobject.aq_chain
                    parentspace = None
                    found = 0

                    try:
                        for type in parentList:
                            if type.portal_type in ('ContentRoot',
                                                    'ContentSpace'):
                                parentspace = type
                                if checkHasPermission('Add portal content',
                                                      aq_inner(parentspace)):
                                    found = 1
                            if found == 1:
                                break
                    except AttributeError:
                        parentspace = None
                        pass

                    if parentspace <> None:
                        self.currentcontextmenu = menu.getMenuItems(
                            aq_inner(parentspace), self.request)
                        self.currentcontexttitle = parentspace.Title()
                        self.contextualurl = parentspace.absolute_url()
                        self.contextuid = parentspace.UID()
                        self.contextdisallowedtypes = parentspace.disallowedtypes(
                        )

            #strip out 'settings' item(s)
            self.currentcontextmenu = [
                ob for ob in self.currentcontextmenu
                if ob['extra']['id'] <> 'settings'
                and ob['extra']['id'] <> '_settings'
            ]
            if self.contextuid == '':
                #best match element is brain
                bestmatchedspace = getBestMatchedLocationForAddingContent(
                    portal)
                if bestmatchedspace:
                    self.currentcontexttitle = bestmatchedspace.Title
                    self.contextuid = bestmatchedspace.UID
                    self.contextualurl = bestmatchedspace.getURL()
                    self.contextdisallowedtypes = bestmatchedspace.disallowedtypes