def update(self):
     portal_state = getMultiAdapter((self.context, self.request), name=u'plone_portal_state')
     context_state = getMultiAdapter((self.context, self.request), name=u'plone_context_state')
     tools = getMultiAdapter((self.context, self.request), name=u'plone_tools')
     plone_utils = getToolByName(self.context, 'plone_utils')
     typetool= getToolByName(self.context, 'portal_types')
     
     self.currentcontexttitle = ''
     self.contextualurl = ''
     self.contextuid = ''
     
     portal = portal_state.portal()
     self.canAddContent = canAddContent(portal)
     
     object_typename = self.context.portal_type
     
     self.anonymous = portal_state.anonymous()
     if not self.anonymous and self.canAddContent:
         menu = getUtility(IBrowserMenu, name='plone_contentmenu_factory')
         if object_typename in ('RecycleBin',):
             pass
         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.contextualurl = aq_inner(objRoot).absolute_url()
                 self.currentcontexttitle = objRoot.Title()
                 self.contextuid = objRoot.UID()
         else:
             if object_typename in ('ContentRoot','ContentSpace') and self.context.isPrincipiaFolderish and checkHasPermission('Add portal content',aq_inner(self.context)):
                 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()
             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.currentcontexttitle = parentspace.Title()
                     self.contextualurl = parentspace.absolute_url()
                     self.contextuid = parentspace.UID()
         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()                
示例#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
                    })

            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
    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
示例#4
0
    def update(self):
        portal_state = getMultiAdapter((self.context, self.request),
                                       name=u'plone_portal_state')
        context_state = getMultiAdapter((self.context, self.request),
                                        name=u'plone_context_state')
        tools = getMultiAdapter((self.context, self.request),
                                name=u'plone_tools')
        plone_utils = getToolByName(self.context, 'plone_utils')
        typetool = getToolByName(self.context, 'portal_types')

        self.currentcontexttitle = ''
        self.contextualurl = ''
        self.contextuid = ''

        portal = portal_state.portal()
        self.canAddContent = canAddContent(portal)

        object_typename = self.context.portal_type

        self.anonymous = portal_state.anonymous()
        if not self.anonymous and self.canAddContent:
            menu = getUtility(IBrowserMenu, name='plone_contentmenu_factory')
            if object_typename in ('RecycleBin', ):
                pass
            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.contextualurl = aq_inner(objRoot).absolute_url()
                    self.currentcontexttitle = objRoot.Title()
                    self.contextuid = objRoot.UID()
            else:
                if object_typename in (
                        'ContentRoot', 'ContentSpace'
                ) and self.context.isPrincipiaFolderish and checkHasPermission(
                        'Add portal content', aq_inner(self.context)):
                    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()
                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.currentcontexttitle = parentspace.Title()
                        self.contextualurl = parentspace.absolute_url()
                        self.contextuid = parentspace.UID()
            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()