当前位置: 首页>>代码示例>>Python>>正文


Python PersistentMapping.keys方法代码示例

本文整理汇总了Python中ZODB.PersistentMapping.PersistentMapping.keys方法的典型用法代码示例。如果您正苦于以下问题:Python PersistentMapping.keys方法的具体用法?Python PersistentMapping.keys怎么用?Python PersistentMapping.keys使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ZODB.PersistentMapping.PersistentMapping的用法示例。


在下文中一共展示了PersistentMapping.keys方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: AltTerms

# 需要导入模块: from ZODB.PersistentMapping import PersistentMapping [as 别名]
# 或者: from ZODB.PersistentMapping.PersistentMapping import keys [as 别名]
class AltTerms(SimpleItem, session_manager):
    """ AltTerms """

    meta_type = ALTTERMS_METATYPE
    product_name = NAAYATHESAURUS_PRODUCT_NAME
    icon = 'misc_/NaayaThesaurus/alt_terms.gif'

    manage_options = (
        {'label':'Properties',      'action':'properties_html'},
        {'label':'Management',      'action':'altterms_html'},
        {'label':'Statistics',      'action':'statistics_html'},
        {'label':'Undo',            'action':'manage_UndoForm'},)

    security = ClassSecurityInfo()

    def __init__(self, id, title):
        """ constructor """
        self.id =           id
        self.title =        title
        self.altterms =    PersistentMapping()


    #basic properties
    security.declareProtected(view_management_screens, 'manageBasicProperties')
    def manageBasicProperties(self, title='', REQUEST=None):
        """ manage basic properties for AltTerms """
        self.title = title
        self._p_changed = 1
        if REQUEST:
            self.setSessionInfoTrans('Saved changes.')
            return REQUEST.RESPONSE.redirect('properties_html')


    #alt_terms management
    def __add_altterm(self, concept_id, langcode, alt_name):
        #create a new item
        item = AltTermItem(concept_id, langcode, alt_name)
        self.altterms[(concept_id, langcode)] = item
        self.catalog.CatalogObject(item)

    def __update_altterm(self, concept_id, old_concept_id, langcode, old_langcode, alt_name):
        #modify an item
        item = self.altterms.get((old_concept_id, old_langcode))
        if item is not None:
            self.__delete_altterm((old_concept_id, old_langcode))
        self.__add_altterm(concept_id, langcode, alt_name)

    def __delete_altterm(self, ids):
        #delete 1 or more items
        if type(ids) != type((1,1)):
            ids = th_utils().utConvertToList(ids)
        else:
            ids = [ids]
        collection = self.get_altterms()

        for id in ids:
            self.catalog.UncatalogObject(collection[id])
            del collection[id]


    #altterm constraints
    security.declareProtected(view_management_screens, 'checkAltTerm')
    def checkAltTerm(self, concept_id):
        """ """
        if self.getConceptsFolder().get_concept_by_id(concept_id):
            return 1
        return 0

    security.declareProtected(view_management_screens, 'getIdsList')
    def getIdsList(self, ids, all=0):
        """ """
        if all: return self.altterms.keys()
        return th_utils().getIdsList(ids)


    #terms getters
    def get_altterms(self):
        #get all alt_terms
        return self.altterms

    def get_altterms_sorted(self):
        #get all alt_terms sorted
        return th_utils().utSortObjsListByAttr(self.altterms.values(), 'concept_id', 0)

    def get_altterm_by_id(self, id):
        #get an item
        try:    return self.altterms[id]
        except: return None

    def get_altterm_item_data(self,concept_id, langcode, orig_concept_id, orig_langcode, alt_name):
        #get an item data
        item = self.get_altterm_by_id((orig_concept_id, orig_langcode))
        if item is not None:
            if alt_name is None:
                alt_name = item.alt_name
            return ['update', concept_id, langcode, alt_name, orig_concept_id, orig_langcode]
        else:
            return ['add', concept_id, langcode, alt_name, '', '']


#.........这里部分代码省略.........
开发者ID:eaudeweb,项目名称:naaya.Products.NaayaThesaurus,代码行数:103,代码来源:AltTerms.py

示例2: PloneKupuLibraryTool

# 需要导入模块: from ZODB.PersistentMapping import PersistentMapping [as 别名]
# 或者: from ZODB.PersistentMapping.PersistentMapping import keys [as 别名]

#.........这里部分代码省略.........
        return getattr(self, '_default_library', '')

    security.declareProtected(permissions.ManageLibraries,
                              "zmi_set_default_library")
    def zmi_set_default_library(self, defid=''):
        """Return the libraries sequence for the ZMI view"""
        self._default_library = defid

    security.declareProtected(permissions.ManageLibraries, "zmi_get_type_mapping")
    def zmi_get_type_mapping(self):
        """Return the type mapping for the ZMI view:
           Old version of code. Returns name,types pairs plus a dummy"""
        return [(t.name, t.types) for t in self.zmi_get_resourcetypes()] + [('',())]

    security.declareProtected(permissions.ManageLibraries, "export_resource_types")
    def export_resource_types(self):
        """Build a list of resource types formatted for export.
        'blacklist' type lists are inverted so the listed types are the ones we don't want.
        """
        types = self.get_resourcetypes()
        typetool = getToolByName(self, 'portal_types')
        portal_types = dict([ (t.id, 1) for t in typetool.listTypeInfo()])
        for t in types:
            if t.newtype:
                t.types = self.invertTypeList(t.types)
                t.mode = 'blacklist'
            else:
                t.mode = 'whitelist'
        return types

    security.declareProtected("View", "get_resourcetypes")
    def get_resourcetypes(self):
        """Return the type mapping, but without the ZMI dummy entry"""
        keys = self._res_types.keys()
        keys.sort()
        real = []
        for name in keys:
            value = self._res_types[name]
            wrapped = Object(name=name, types=tuple(value), newtype=self.getNewTypeHandler(name))
            real.append(wrapped)
        return real

    security.declareProtected("View", "zmi_get_resourcetypes")
    def zmi_get_resourcetypes(self):
        """Return the type mapping for the ZMI view"""
        real = self.get_resourcetypes()
        real.append(Object(name='', types=()))
        return real

    security.declareProtected(permissions.ManageLibraries,
                              "zmi_update_resource_types")
    def zmi_update_resource_types(self, type_info=None, preview_action=None, default_resource=None, REQUEST=None):
        """Update resource types through the ZMI"""

        if type_info:
            self.updateResourceTypes(type_info)

        if preview_action:
            self.updatePreviewActions(preview_action)

        if default_resource is not None:
            self.default_resource = default_resource

        if REQUEST:
            REQUEST.RESPONSE.redirect(self.absolute_url() + '/zmi_resource_types')
开发者ID:nacho22martin,项目名称:tesis,代码行数:69,代码来源:plonelibrarytool.py

示例3: Themes

# 需要导入模块: from ZODB.PersistentMapping import PersistentMapping [as 别名]
# 或者: from ZODB.PersistentMapping.PersistentMapping import keys [as 别名]
class Themes(SimpleItem, session_manager):
    """ Themes """

    meta_type = THEMES_METATYPE
    product_name = NAAYATHESAURUS_PRODUCT_NAME
    icon = "misc_/NaayaThesaurus/themes.gif"

    manage_options = (
        {"label": "Basic properties", "action": "properties_html"},
        {"label": "Management", "action": "themes_html"},
        {"label": "Import", "action": "import_html"},
        {"label": "Statistics", "action": "statistics_html"},
        {"label": "Undo", "action": "manage_UndoForm"},
    )

    security = ClassSecurityInfo()

    def __init__(self, id, title):
        """ constructor """
        self.id = id
        self.title = title
        self.themes = PersistentMapping()

    # basic properties
    security.declareProtected(view_management_screens, "manageBasicProperties")

    def manageBasicProperties(self, title="", REQUEST=None):
        """ manage basic properties for Themes """
        self.title = title
        self._p_changed = 1
        if REQUEST:
            self.setSessionInfoTrans("Saved changes.")
            return REQUEST.RESPONSE.redirect("properties_html")

    # themes management
    def __add_theme(self, theme_id, langcode, name):
        # create a new item
        item = ThemeItem(theme_id, langcode, name)
        self.themes[(theme_id, langcode)] = item
        self.catalog.CatalogObject(item)

    def __update_theme(self, theme_id, old_theme_id, langcode, old_langcode, name):
        # modify an item
        item = self.themes.get((old_theme_id, old_langcode))
        if item is not None:
            self.__delete_theme((old_theme_id, old_langcode))
        self.__add_theme(theme_id, langcode, name)

    def __delete_theme(self, ids):
        # delete 1 or more items
        if type(ids) != type((1, 1)):
            ids = th_utils().utConvertToList(ids)
        else:
            ids = [ids]
        collection = self.get_themes()

        for id in ids:
            self.catalog.UncatalogObject(collection[id])
            del collection[id]

    # theme constraints
    security.declareProtected(view_management_screens, "checkTheme")

    def checkTheme(self, theme_id):
        """ """
        if theme_id in self.getThemeRelationsFolder().getDistinctThemes():
            return 1
        return 0

    security.declareProtected(view_management_screens, "getIdsList")

    def getIdsList(self, ids, all=0):
        """ """
        if all:
            return self.themes.keys()
        return th_utils().getIdsList(ids)

    # themes getters
    def get_themes(self):
        # get all themes
        return self.themes

    def get_themes_sorted(self):
        # get all themes sorted
        return th_utils().utSortObjsListByAttr(self.themes.values(), "langcode", 0)

    def get_theme_by_id(self, id):
        # get an item
        try:
            return self.themes[id]
        except:
            return None

    def get_theme_item_data(self, theme_id, langcode, orig_theme_id, orig_langcode, theme_name):
        # get an item data
        item = self.get_theme_by_id((orig_theme_id, orig_langcode))
        if item is not None:
            if theme_name is None:
                theme_name = item.theme_name
            return ["update", theme_id, langcode, theme_name, orig_theme_id, orig_langcode]
#.........这里部分代码省略.........
开发者ID:eaudeweb,项目名称:naaya.Products.NaayaThesaurus,代码行数:103,代码来源:Themes.py

示例4: csvreplicataTool

# 需要导入模块: from ZODB.PersistentMapping import PersistentMapping [as 别名]
# 或者: from ZODB.PersistentMapping.PersistentMapping import keys [as 别名]

#.........这里部分代码省略.........

        # Addition of the new replicable types, by default a new empty list
        # and creation of a temp variable to hold the new csv handled types
        newreplicabletypestempdict = {}
        for t in newreplicabletypes :
            newreplicabletypestempdict[t] = []
            if (not currentreplicablestypes.has_key(t)):
                    currentreplicablestypes[t] = ['default', ]

        # removal of the types that are not anymore replicables
        for k, v in currentreplicablestypes.items():
            if (not newreplicabletypestempdict.has_key(k)):
                del currentreplicablestypes[k]

        # save of the new values
        self.replicabletypes.update(currentreplicablestypes)

        # Redirection of the page now that the treatment is done
        REQUEST.RESPONSE.redirect(self.absolute_url()+'/csv_settings')

    def setExcludedFields(self, REQUEST):
        """
        """
        self.setExcludedfieldsclasses(
            REQUEST.get('excludedfieldsclasses').split('\n'));
        self.setExcludedfields(REQUEST.get('excludedfields').split('\n'));

        # Redirection of the page now that the treatment is done
        REQUEST.RESPONSE.redirect(self.absolute_url()+'/csv_settings')

    def getPortalTypeNames(self):
        """
        """
        l = getPortalTypes(self).keys()
        l.sort()
        return [(k, k) for k in l]

    def getReplicableTypesSorted(self):
        """
        """
        l = self.replicabletypes.keys()
        l.sort()
        return l

    def getTypeSchematas(self, type):
        """
        """
        attool = getToolByName(self, 'archetype_tool')
        pt = getPortalTypes(self)
        if pt.has_key(type):
            (package, name) = pt[type]
            t = attool.lookupType(package, name)
            return  t['klass'].schema.getSchemataNames()
        else:
            return []

    def setCSVHandledTypesSchematas(self, REQUEST):
        """
        """
        currentreplicablestypes = self.replicabletypes

        i = 0
        for ptn in self.getReplicableTypesSorted():
            i += 1
            if (type(ptn) is tuple):
                t = ptn[0]
开发者ID:tuxwerk,项目名称:Products.csvreplicata,代码行数:70,代码来源:csvreplicataTool.py

示例5: Concepts

# 需要导入模块: from ZODB.PersistentMapping import PersistentMapping [as 别名]
# 或者: from ZODB.PersistentMapping.PersistentMapping import keys [as 别名]
class Concepts(SimpleItem, session_manager):
    """ Concepts """

    meta_type = CONCEPTS_METATYPE
    product_name = NAAYATHESAURUS_PRODUCT_NAME
    icon = 'misc_/NaayaThesaurus/concepts.gif'

    manage_options = (
        {'label':'Properties',      'action':'properties_html'},
        {'label':'Management',      'action':'concepts_html'},
        {'label':'Import',   'action':'import_html'},
        {'label':'Statistics',      'action':'statistics_html'},
        {'label':'Undo',            'action':'manage_UndoForm'},)

    security = ClassSecurityInfo()

    def __init__(self, id, title):
        """ constructor """
        self.id =         id
        self.title =      title
        self.concepts =   PersistentMapping()


    #basic properties
    security.declareProtected(view_management_screens, 'manageBasicProperties')
    def manageBasicProperties(self, title='', REQUEST=None):
        """ manage basic properties for Concepts """
        self.title = title
        self._p_changed = 1
        if REQUEST:
            self.setSessionInfoTrans('Saved changes.')
            return REQUEST.RESPONSE.redirect('properties_html')


    #concepts management
    def __add_concept(self, concept_id):
        #create a new item
        item = ConceptItem(concept_id)
        self.concepts[concept_id] = item
        self.catalog.CatalogObject(item)

    def __update_concept(self, concept_id, old_concept_id):
        #modify an item
        item = self.concepts.get(old_concept_id)
        if item is not None:
            self.__delete_concept(old_concept_id)
        self.__add_concept(concept_id)

    def __delete_concept(self, ids):
        #delete 1 or more items
        ids = th_utils().utConvertToList(ids)
        collection = self.get_concepts()

        for id in ids:
            self.catalog.UncatalogObject(collection[id])
            del collection[id]


    #concept constraints
    security.declareProtected(view_management_screens, 'getIdsList')
    def getIdsList(self, ids, all=0):
        """ """
        if all: return self.concepts.keys()
        return th_utils().getIdsList(ids)


    #concepts getters
    def get_concepts(self):
        #get all concepts
        return self.concepts

    def get_concepts_sorted(self):
        #get all concepts sorted
        return th_utils().utSortObjsListByAttr(self.concepts.values(), 'concept_id', 0)

    def get_concept_by_id(self, concept_id):
        #get an item
        try:    return self.concepts[concept_id]
        except: return None

    def get_concept_item_data(self, concept_id):
        #get an item data
        item = self.get_concept_by_id(concept_id)
        if item is not None:
            return ['update', item.concept_id]
        else:
            return ['add', '']


    #concepts api
    security.declareProtected(view_management_screens, 'manage_add_concept')
    def manage_add_concept(self, concept_id='', REQUEST=None):
        """ manage concepts """
        if not concept_id: concept_id = th_utils().utGenRandomId()
        self.__add_concept(concept_id)
        if REQUEST:
            self.setSessionInfoTrans('Record added.')
            REQUEST.RESPONSE.redirect('concepts_html')

    security.declareProtected(view_management_screens, 'manage_update_concept')
#.........这里部分代码省略.........
开发者ID:eaudeweb,项目名称:naaya.Products.NaayaThesaurus,代码行数:103,代码来源:Concepts.py

示例6: Definitions

# 需要导入模块: from ZODB.PersistentMapping import PersistentMapping [as 别名]
# 或者: from ZODB.PersistentMapping.PersistentMapping import keys [as 别名]
class Definitions(SimpleItem, session_manager):
    """ Definitions """

    meta_type = DEFINITIONS_METATYPE
    product_name = NAAYATHESAURUS_PRODUCT_NAME
    icon = 'misc_/NaayaThesaurus/definitions.gif'

    manage_options = (
        {'label':'Properties',      'action':'properties_html'},
        {'label':'Management',      'action':'definitions_html'},
        {'label':'Statistics',      'action':'statistics_html'},
        {'label':'Undo',            'action':'manage_UndoForm'},)

    security = ClassSecurityInfo()

    def __init__(self, id, title):
        """ constructor """
        self.id =           id
        self.title =        title
        self.definitions =  PersistentMapping()


    #basic properties
    security.declareProtected(view_management_screens, 'manageBasicProperties')
    def manageBasicProperties(self, title='', REQUEST=None):
        """ manage basic properties for Definitions """
        self.title = title
        self._p_changed = 1
        if REQUEST:
            self.setSessionInfoTrans('Saved changes.')
            return REQUEST.RESPONSE.redirect('properties_html')


    #definitions management
    def __add_definition(self, concept_id, langcode, definition, source_id):
        #create a new item
        item = DefinitionItem(concept_id, langcode, definition, source_id)
        self.definitions[(concept_id, langcode)] = item
        self.catalog.CatalogObject(item)

    def __update_definition(self, concept_id, old_concept_id, langcode, old_langcode,
                          definition, source_id):
        #modify an item
        item = self.definitions.get((old_concept_id, old_langcode))
        if item is not None:
            self.__delete_definition((old_concept_id, old_langcode))
        self.__add_definition(concept_id, langcode, definition, source_id)

    security.declareProtected(view_management_screens, 'update_source_id')
    def update_source_id(self, concept_id, langcode, source_id):
        """ update the source_id list """
        definition_ob = self.get_definition_by_id((concept_id, langcode))
        if definition_ob.source_id: upd_source_id = "%s %s" % (definition_ob.source_id, source_id)
        else:                       upd_source_id = source_id
        self.__update_definition(concept_id, concept_id, langcode, langcode, definition_ob.definition, upd_source_id)

    def __delete_definition(self, ids):
        #delete 1 or more items
        if type(ids) != type((1,1)):
            ids = th_utils().utConvertToList(ids)
        else:
            ids = [ids]
        collection = self.get_definitions()

        for id in ids:
            self.catalog.UncatalogObject(collection[id])
            del collection[id]


    #definition constraints
    security.declareProtected(view_management_screens, 'checkDefinition')
    def checkDefinition(self, concept_id):
        """ """
        if self.getConceptsFolder().get_concept_by_id(concept_id):
            return 1
        return 0

    security.declareProtected(view_management_screens, 'getIdsList')
    def getIdsList(self, ids, all=0):
        """ """
        if all: return self.definitions.keys()
        return th_utils().getIdsList(ids)


    #definitions getters
    def get_definitions(self):
        #get all definitions
        return self.definitions

    def get_definitions_sorted(self):
        #get all definitions sorted
        return th_utils().utSortObjsListByAttr(self.definitions.values(), 'concept_id', 0)

    def get_definition_by_id(self, id):
        #get an item
        try:    return self.definitions[id]
        except: return None

    def get_definition_item_data(self, concept_id, langcode, orig_concept_id, orig_langcode, definition, source_id):
        #get an item data
#.........这里部分代码省略.........
开发者ID:eaudeweb,项目名称:naaya.Products.NaayaThesaurus,代码行数:103,代码来源:Definitions.py

示例7: MapLayer

# 需要导入模块: from ZODB.PersistentMapping import PersistentMapping [as 别名]
# 或者: from ZODB.PersistentMapping.PersistentMapping import keys [as 别名]

#.........这里部分代码省略.........
        """        
        try:            
            ownerName = self.owner_info()['id']
            member =  self.portal_membership.getAuthenticatedMember()  
            userName = member.getUserName()            
            if userName == ownerName:
                return True
            else:
                return False            
            
        except:
            logger.exception('error')
            return False    
    
    def getSecurity(self):
        """
        @summary: returns the current security definitions dict
        @return: dict containing security info for roles defined in plone
        """            
        return dict(self.security)
    
    def getMetadata(self):
        """
        @summary: gets the metadata template for the layer
        @return: an html interface with metadata information
        """        
        return self.Map_Layer_Details_Stripped(self)
    
    def setSecurityVarOnly(self,securityDict):
        """
        """
        try:
            tmpDict = {}           
            for k in securityDict.keys():
                if k == 'fields':
                    continue
                
                cDict = {}
                if securityDict[k]['Render'] in ['false',0]:
                    cDict['Render'] = 0                
                if securityDict[k]['Render'] in ['true',1]:
                    cDict['Render'] = 1                
                if securityDict[k]['Extract'] in ['false',0]:
                    cDict['Extract'] = 0 
                if securityDict[k]['Extract'] in ['true',1]:
                    cDict['Extract'] = 1
                tmpDict[k] = cDict                
            
            # get a diff between current security settings and the passed security settings
            changed = {}
            for k in tmpDict.keys():
                if not k in self.security.keys():
                    changed[k] = tmpDict[k]   # its a new key
                if k in self.security.keys():
                    if self.security[k]['Render'] != tmpDict[k]['Render']:
                        changed[k] = tmpDict[k]        
            
            self.security = tmpDict        
            # only let the changes be propagated to children 
            
            # get all fields
            fields = []
            items =  self.objectItems()        
            for i in items:
                if i[1].meta_type == 'LayerField':                                
                    fields.append(i[1])                        
开发者ID:BGCX261,项目名称:zmetadata-svn-to-git,代码行数:70,代码来源:MapLayer.py

示例8: Terms

# 需要导入模块: from ZODB.PersistentMapping import PersistentMapping [as 别名]
# 或者: from ZODB.PersistentMapping.PersistentMapping import keys [as 别名]
class Terms(SimpleItem, session_manager):
    """ Terms """

    meta_type = TERMS_METATYPE
    product_name = NAAYATHESAURUS_PRODUCT_NAME
    icon = 'misc_/NaayaThesaurus/terms.gif'

    manage_options = (
        {'label':'Properties',      'action':'properties_html'},
        {'label':'Management',      'action':'terms_html'},
        {'label':'Import',   'action':'import_html'},
        {'label':'Statistics',      'action':'statistics_html'},
        {'label':'Undo',            'action':'manage_UndoForm'},)

    security = ClassSecurityInfo()

    def __init__(self, id, title):
        """ constructor """
        self.id =       id
        self.title =    title
        self.terms =    PersistentMapping()


    #basic properties
    security.declareProtected(view_management_screens, 'manageBasicProperties')
    def manageBasicProperties(self, title='', REQUEST=None):
        """ manage basic properties for Terms """
        self.title = title
        self._p_changed = 1
        if REQUEST:
            self.setSessionInfoTrans('Saved changes.')
            return REQUEST.RESPONSE.redirect('properties_html')


    #terms management
    def __add_term(self, concept_id, langcode, concept_name, source_id):
        #create a new item
        item = TermItem(concept_id, langcode, concept_name, source_id)
        self.terms[(concept_id, langcode)] = item
        self.catalog.CatalogObject(item)

    def __update_term(self, concept_id, old_concept_id, langcode, old_langcode,
                      concept_name, source_id):
        #modify an item
        item = self.terms.get((old_concept_id, old_langcode))
        if item is not None:
            self.__delete_term((old_concept_id, old_langcode))
        self.__add_term(concept_id, langcode, concept_name, source_id)

    security.declareProtected(view_management_screens, 'update_source_id')
    def update_source_id(self, concept_id, langcode, source_id):
        """ update the source_id list """
        term_ob = self.get_term_by_id((concept_id, langcode))
        if term_ob.source_id: upd_source_id = "%s %s" % (term_ob.source_id, source_id)
        else:                 upd_source_id = source_id
        self.__update_term(concept_id, concept_id, langcode, langcode, term_ob.concept_name, upd_source_id)

    def __delete_term(self, ids):
        #delete 1 or more items
        if type(ids) != type((1,1)):
            ids = th_utils().utConvertToList(ids)
        else:
            ids = [ids]
        collection = self.get_terms()

        for id in ids:
            self.catalog.UncatalogObject(collection[id])
            del collection[id]


    #term constraints
    security.declareProtected(view_management_screens, 'checkTerm')
    def checkTerm(self, concept_id):
        """ """
        if self.getConceptsFolder().get_concept_by_id(concept_id):
            return 1
        return 0

    security.declareProtected(view_management_screens, 'getIdsList')
    def getIdsList(self, ids, all=0):
        """ """
        if all: return self.terms.keys()
        return th_utils().getIdsList(ids)


    #terms getters
    def get_terms(self):
        #get all terms
        return self.terms

    def get_terms_sorted(self):
        #get all terms sorted
        return th_utils().utSortObjsListByAttr(self.terms.values(), 'concept_id', 0)

    def get_term_by_id(self, id):
        #get an item
        try:    return self.terms[id]
        except: return None

    def get_term_item_data(self, concept_id, langcode, orig_concept_id, orig_langcode, concept_name, source_id):
#.........这里部分代码省略.........
开发者ID:eaudeweb,项目名称:naaya.Products.NaayaThesaurus,代码行数:103,代码来源:Terms.py

示例9: nisAuthSource

# 需要导入模块: from ZODB.PersistentMapping import PersistentMapping [as 别名]
# 或者: from ZODB.PersistentMapping.PersistentMapping import keys [as 别名]
class nisAuthSource(Folder):
    """ Authenticate Users against NIS 
    
    This folder has 2 modes:
    1. Authenticates only those users for which you add a local role
    2. Authenticates without local roles.  
    
    Since #1 uses local roles, it should play nice with Prop sources and memberships, 
    where #2 will not. """

    meta_type='Authentication Source'
    title='NIS Authentication'
    icon ='misc_/exUserFolder/exUserFolderPlugin.gif'
    manage_editForm=manage_editnisAuthSourceForm
        
    def __init__(self,default_role,NoLocalRoles):
        self.id='nisAuthSource'
        self.default_role=default_role
        self.NoLocalRoles=NoLocalRoles
        self.data=PersistentMapping()
        self.manage_addUserForm=DTMLFile('manage_addNISUserForm',globals())
        self.manage_editUserForm=DTMLFile('manage_editNISUserForm',globals()) #not used.  No way to plug it into exUserFolder.py
    
    def manage_editAuthSource(self,REQUEST):
        """ """
        self.default_role=REQUEST['nisauth_default_role']
        self.NoLocalRoles=REQUEST.has_key('nisauth_NoLocalRoles')

    # Create a User to store local roles
    def createUser(self, username, password, roles):
        import pdb
        pdb.set_trace()
        """ Add A Username """
        if self.NoLocalRoles:
            return self.MessageDialog(self,REQUEST=REQUEST,
                        title  ='Create Error', 
                        message='Cannot create user.  No local roles allowed',
                        action ='manage_main')
        else:
            if self._listOneNISUser(username) and (not self.data.has_key(username)):
                if type(roles) != type([]):
                    if roles:
                        roles=list(roles)
                    else:
                        roles=[self.default_role]
                self.data[username]=PersistentMapping()
                self.data[username].update({'username': username,
                                            'roles': roles})
            else:
                return self.MessageDialog(self,REQUEST=REQUEST,
                            title  ='Create Error', 
                            message='Cannot create user.  Username not in NIS',
                            action ='manage_main')

    # Update a user's roles
    # Passwords are managed via the users NIS unix accounts, not here
    def updateUser(self, username, password, roles):
        if self.NoLocalRoles:
            return self.MessageDialog(self,REQUEST=REQUEST,
                        title  ='Create Error', 
                        message='Cannot create user.  No local roles allowed',
                        action ='manage_main')
        else:
            self.data[username].update({'roles':roles})

    # Encrypt a password
    def cryptPassword_old(self, username, password):
        NISuser=self._listOneNISUser(username)
        if self.NoLocalRoles:
            user=NISuser
        else:
            user=self.listOneUser(username)
        salt = NISuser['password'][:2]
        secret = crypt(password, salt)
        return secret

    # Delete a set of local users
    def deleteUsers(self, userids):
        if self.NoLocalRoles:
            return self.MessageDialog(self,REQUEST=REQUEST,
                        title  ='Create Error', 
                        message='Cannot create user.  No local roles allowed',
                        action ='manage_main')
        for name in userids:
            del self.data[name]

    # Return a list of usernames
    def listUserNames(self,listNIS=None):
        if self.NoLocalRoles or listNIS:
            usernames=self._listNISUserNames()
        else:
            usernames=self.data.keys()
            usernames.sort()
        return usernames
        
    # Return one user matching the username
    # Should be a dictionary;
    # {'username':username, 'password':cryptedPassword, 'roles':list_of_roles}
    def listOneUser(self, username):
        users = []
#.........这里部分代码省略.........
开发者ID:denys-duchier,项目名称:Scolar,代码行数:103,代码来源:nisAuthSource.py

示例10: ThemeRelations

# 需要导入模块: from ZODB.PersistentMapping import PersistentMapping [as 别名]
# 或者: from ZODB.PersistentMapping.PersistentMapping import keys [as 别名]
class ThemeRelations(SimpleItem, session_manager):
    """ ThemeRelations """

    meta_type = THEME_RELATION_METATYPE
    product_name = NAAYATHESAURUS_PRODUCT_NAME
    icon = 'misc_/NaayaThesaurus/theme_relations.gif'

    manage_options = (
        {'label':'Properties',      'action':'properties_html'},
        {'label':'Management',      'action':'theme_relations_html'},
        {'label':'Statistics',      'action':'statistics_html'},
        {'label':'Undo',            'action':'manage_UndoForm'},)

    security = ClassSecurityInfo()

    def __init__(self, id, title):
        """ constructor """
        self.id =              id
        self.title =           title
        self.theme_relations = PersistentMapping()


    #basic properties
    security.declareProtected(view_management_screens, 'manageBasicProperties')
    def manageBasicProperties(self, title='', REQUEST=None):
        """ manage basic properties for ThemeRelations """
        self.title = title
        self._p_changed = 1
        if REQUEST:
            self.setSessionInfoTrans('Saved changes.')
            return REQUEST.RESPONSE.redirect('properties_html')


    #theme relations management
    def __add_threlation(self, concept_id, theme_id):
        #create a new item
        item = ThemeRelationItem(concept_id, theme_id)
        self.theme_relations[(concept_id, theme_id)] = item
        self.catalog.CatalogObject(item)

    def __update_threlation(self, concept_id, old_concept_id, theme_id, old_theme_id):
        #modify an item
        item = self.theme_relations.get((old_concept_id, old_theme_id))
        if item is not None:
            self.__delete_threlation((old_concept_id, old_theme_id))
        self.__add_threlation(concept_id, theme_id)

    def __delete_threlation(self, ids):
        #delete 1 or more items
        if type(ids) != type((1,1)):
            ids = th_utils().utConvertToList(ids)
        else:
            ids = [ids]
        collection = self.get_threlations()

        for id in ids:
            self.catalog.UncatalogObject(collection[id])
            del collection[id]


    #theme relations constraints
    security.declareProtected(view_management_screens, 'checkThRel')
    def checkThRel(self, concept_id):
        """ """
        if self.getConceptsFolder().get_concept_by_id(concept_id):
            return 1
        return 0

    security.declareProtected(view_management_screens, 'getIdsList')
    def getIdsList(self, ids, all=0):
        """ """
        if all: return self.theme_relations.keys()
        return th_utils().getIdsList(ids)

    security.declareProtected(view_management_screens, 'infoOnDelete')
    def infoOnDelete(self, ids, all=0):
        """ """
        results = []
        dic_cp = {}
        lst_cp = []

        for rel_id in self.getIdsList(ids, all):
            rel_ob = self.get_threlation_by_id(rel_id)
            try:    lst_cp = dic_cp[rel_ob.concept_id]
            except: lst_cp= []
            lst_cp.append(rel_ob)
            dic_cp[rel_ob.concept_id] = lst_cp
            results.append(rel_ob)

        for concept_id in dic_cp.keys():
            query = [('meta_type',THEME_RELATION_ITEM_METATYPE),
                     ('concept_id',concept_id)]
            if len(dic_cp[concept_id]) == len(self.catalog.searchCatalog(query)):
                dic_cp[concept_id] = 1
            else:
                dic_cp[concept_id] = 0

        return (results, dic_cp)


#.........这里部分代码省略.........
开发者ID:eaudeweb,项目名称:naaya.Products.NaayaThesaurus,代码行数:103,代码来源:ThemeRelations.py

示例11: Source

# 需要导入模块: from ZODB.PersistentMapping import PersistentMapping [as 别名]
# 或者: from ZODB.PersistentMapping.PersistentMapping import keys [as 别名]
class Source(SimpleItem):
    """ Source """

    meta_type = SOURCE_METATYPE
    product_name = NAAYATHESAURUS_PRODUCT_NAME
    icon = 'misc_/NaayaThesaurus/source.gif'

    manage_options = (
        {'label':'Properties',  'action':'properties_html'},
        {'label':'Management',      'action':'sources_html'},
        {'label':'Statistics',      'action':'statistics_html'},
        {'label':'Undo',        'action':'manage_UndoForm'},)

    security = ClassSecurityInfo()

    def __init__(self, id, title):
        """ constructor """
        self.id =       id
        self.title =    title
        self.sources =  PersistentMapping()


    #basic properties
    security.declareProtected(view_management_screens, 'manageBasicProperties')
    def manageBasicProperties(self, title='', REQUEST=None):
        """ manage basic properties for Source """
        self.title = title
        self._p_changed = 1
        if REQUEST:
            self.setSessionInfoTrans('Saved changes.')
            return REQUEST.RESPONSE.redirect('properties_html')


    #sources management
    def __add_source(self, source_id, source_name):
        #create a new item
        item = SourceItem(source_id, source_name)
        self.sources[source_id] = item
        self.catalog.CatalogObject(item)

    def __update_source(self, source_id, old_source_id, source_name):
        #modify an item
        item = self.sources.get(old_source_id)
        if item is not None:
            self.__delete_source(old_source_id)
        self.__add_source(source_id, source_name)

    def __delete_source(self, ids):
        #delete 1 or more items
        ids = th_utils().utConvertToList(ids)
        collection = self.get_sources()

        for id in ids:
            self.catalog.UncatalogObject(collection[id])
            del collection[id]


    #source constrints
    security.declareProtected(view_management_screens, 'getIdsList')
    def getIdsList(self, ids, all=0):
        """ """
        if all: return self.sources.keys()
        return th_utils().getIdsList(ids)

    #sources getters
    def get_sources(self):
        #get all sources
        return self.sources

    def get_sources_sorted(self):
        #get all sources sorted
        return th_utils().utSortObjsListByAttr(self.sources.values(), 'source_id', 0)

    def get_source_by_id(self, id):
        #get an item
        try:    return self.sources[id]
        except: return None

    def get_source_item_data(self, id):
        #get an item data
        item = self.get_source_by_id(id)
        if item is not None: 
            return ['update', item.source_id, item.source_name]
        else:
            return ['add', '', '']


    #sources api
    security.declareProtected(view_management_screens, 'manage_add_source')
    def manage_add_source(self, source_id='', source_name='', REQUEST=None):
        """ manage sources """
        if not source_id: source_id = th_utils().utGenRandomId()
        self.__add_source(source_id, source_name)
        if REQUEST:
            self.setSessionInfoTrans('Record added.')
            REQUEST.RESPONSE.redirect('sources_html')

    security.declareProtected(view_management_screens, 'manage_update_source')
    def manage_update_source(self, source_id='', old_source_id='', source_name='', REQUEST=None):
        """ update source """
#.........这里部分代码省略.........
开发者ID:eaudeweb,项目名称:naaya.Products.NaayaThesaurus,代码行数:103,代码来源:Source.py

示例12: ConceptRelations

# 需要导入模块: from ZODB.PersistentMapping import PersistentMapping [as 别名]
# 或者: from ZODB.PersistentMapping.PersistentMapping import keys [as 别名]
class ConceptRelations(SimpleItem, session_manager):
    """ ConceptRelations """

    meta_type = CONCEPT_RELATIONS_METATYPE
    product_name = NAAYATHESAURUS_PRODUCT_NAME
    icon = 'misc_/NaayaThesaurus/concept_relations.gif'

    manage_options = (
        {'label':'Properties',      'action':'properties_html'},
        {'label':'Management',      'action':'concept_relations_html'},
        {'label':'Import',   'action':'import_html'},
        {'label':'Statistics',      'action':'statistics_html'},
        {'label':'Undo',            'action':'manage_UndoForm'},)

    security = ClassSecurityInfo()

    def __init__(self, id, title):
        """ constructor """
        self.id =                   id
        self.title =                title
        self.concept_relations =    PersistentMapping()


    #basic properties
    security.declareProtected(view_management_screens, 'manageBasicProperties')
    def manageBasicProperties(self, title='', REQUEST=None):
        """ manage basic properties for ConceptRelations """
        self.title = title
        self._p_changed = 1
        if REQUEST:
            self.setSessionInfoTrans('Saved changes.')
            return REQUEST.RESPONSE.redirect('properties_html')


    #concept relations management
    def __add_relation(self, concept_id, relation_id, relation_type):
        #create a new item
        item = ConceptRelationsItem(concept_id, relation_id, relation_type)
        self.concept_relations[(concept_id, relation_id, relation_type)] = item
        self.catalog.CatalogObject(item)

    def __update_relation(self, concept_id, old_concept_id, relation_id,
                        old_relation_id, relation_type, old_relation_type):
        #modify an item
        l_old_id = (old_concept_id, old_relation_id, old_relation_type)
        item = self.concept_relations.get(l_old_id)
        if item is not None:
            self.__delete_relation(l_old_id)
        self.__add_relation(concept_id, relation_id, relation_type)

    def __delete_relation(self, ids):
        #delete 1 or more items
        if type(ids) != type((1,1)):
            ids = th_utils().utConvertToList(ids)
        else:
            ids = [ids]
        collection = self.get_relations()

        for id in ids:
            self.catalog.UncatalogObject(collection[id])
            del collection[id]


    #concept relations constraints
    security.declareProtected(view_management_screens, 'checkCpRel')
    def checkCpRel(self, concept_id):
        """ """
        if self.getConceptsFolder().get_concept_by_id(concept_id):
            return 1
        return 0

    security.declareProtected(view_management_screens, 'getIdsList')
    def getIdsList(self, ids, all=0):
        """ """
        if all: return self.concept_relations.keys()
        return th_utils().getIdsList(ids)


    #relations getters
    def get_relations(self):
        #get all relations
        return self.concept_relations

    def get_relations_sorted(self):
        #get all relations sorted
        return th_utils().utSortObjsListByAttr(self.concept_relations.values(), 'concept_id', 0)

    def get_relation_by_id(self, id):
        #get an item
        try:    return self.concept_relations[id]
        except: return None

    def get_relations_item_data(self, concept_id, relation_id, relation_type,
                                orig_concept_id, orig_relation_id, orig_relation_type):
        #get an item data
        item = self.get_relation_by_id((orig_concept_id, orig_relation_id, orig_relation_type))
        if item is not None:
            return ['update', concept_id, relation_id, relation_type,
                    orig_concept_id, orig_relation_id, orig_relation_type]
        else:
#.........这里部分代码省略.........
开发者ID:eaudeweb,项目名称:naaya.Products.NaayaThesaurus,代码行数:103,代码来源:ConceptRelations.py


注:本文中的ZODB.PersistentMapping.PersistentMapping.keys方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。