本文整理汇总了Python中ZODB.PersistentMapping.PersistentMapping.values方法的典型用法代码示例。如果您正苦于以下问题:Python PersistentMapping.values方法的具体用法?Python PersistentMapping.values怎么用?Python PersistentMapping.values使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZODB.PersistentMapping.PersistentMapping
的用法示例。
在下文中一共展示了PersistentMapping.values方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Map
# 需要导入模块: from ZODB.PersistentMapping import PersistentMapping [as 别名]
# 或者: from ZODB.PersistentMapping.PersistentMapping import values [as 别名]
class Map(SimpleItem):
def __init__(self, id):
self.id = id
self.channels = PersistentMapping()
self.policy = defaultPolicy
def setPolicy(self, name):
self.policy = lookupPolicy(name, defaultPolicy)
def setPriority(self, channel, pri):
if not isinstance(channel, Channel):
id = channel.id
else:
id = channel
channel = self.channels[id]
channel['priority'] = int(pri)
def addChannel(self, channel, **kwargs):
enabled = kwargs.get('enabled', 1)
priority = kwargs.get('priority', 0)
self.channels[channel.id] = {'channel' : channel,
'enabled' : enabled,
'priority': priority,
}
def Channels(self):
return self.channels.values()
示例2: AltTerms
# 需要导入模块: from ZODB.PersistentMapping import PersistentMapping [as 别名]
# 或者: from ZODB.PersistentMapping.PersistentMapping import values [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, '', '']
#.........这里部分代码省略.........
示例3: Themes
# 需要导入模块: from ZODB.PersistentMapping import PersistentMapping [as 别名]
# 或者: from ZODB.PersistentMapping.PersistentMapping import values [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]
#.........这里部分代码省略.........
示例4: SilvaFind
# 需要导入模块: from ZODB.PersistentMapping import PersistentMapping [as 别名]
# 或者: from ZODB.PersistentMapping.PersistentMapping import values [as 别名]
class SilvaFind(Query, Content, SimpleItem):
__doc__ = _("""Silva Find is a powerful search feature that allows easy
creation of search forms and result pages. Users can add a Find
anywhere and define which fields to make searchable by site visitors
and/or which fields to limit to a preset value. Users also can
determine which fields should be displayed in the search results. All
metadata sets/fields are supported.""")
security = ClassSecurityInfo()
meta_type = "Silva Find"
grok.implements(IFind)
silvaconf.icon('SilvaFind.png')
def __init__(self, id):
Content.__init__(self, id)
Query.__init__(self)
self.shownFields = PersistentMapping()
self.shownResultsFields = PersistentMapping()
# by default we only show fulltext search
# and a couple of resultfields
self.shownFields['fulltext'] = True
self.shownResultsFields['link'] = True
self.shownResultsFields['ranking'] = True
self.shownResultsFields['resultcount'] = True
self.shownResultsFields['icon'] = True
self.shownResultsFields['date'] = True
self.shownResultsFields['textsnippet'] = True
self.shownResultsFields['thumbnail'] = True
self.shownResultsFields['breadcrumbs'] = True
# ACCESSORS
security.declareProtected(SilvaPermissions.View, 'getPublicResultFields')
def getPublicResultFields(self):
return filter(lambda field: self.isResultShown(field.getName()),
self.getResultFields())
security.declareProtected(SilvaPermissions.View, 'getPublicSearchFields')
def getPublicSearchFields(self):
return filter(lambda field: self.isCriterionShown(field.getName()),
self.getSearchFields())
security.declareProtected(SilvaPermissions.View, 'isCriterionShown')
def isCriterionShown(self, fieldName):
return self.shownFields.get(fieldName, False)
security.declareProtected(SilvaPermissions.View, 'isResultShown')
def isResultShown(self, fieldName):
return self.shownResultsFields.get(fieldName, False)
security.declareProtected(SilvaPermissions.View, 'havePublicSearchFields')
def havePublicSearchFields(self):
# BBB map(bool) is here for previously non-boolean stored values
return reduce(operator.or_, map(bool, self.shownFields.values()))
security.declareProtected(SilvaPermissions.View, 'searchResults')
def searchResults(self, request={}, validate=True):
options = self.getSearchCriterias(request)
if validate:
queryEmpty = True
for key, value in options.items():
if key in ['path', 'meta_type']:
# these fields do not count as a real search query
# they are always there to filter unwanted results
continue
if type(value) is unicode and value.strip():
queryEmpty = False
break
elif type(value) is list:
queryEmpty = False
break
query = options.get('fulltext', '').strip()
if query and query[0] in ['?', '*']:
raise ValueError(
_(u'Search query can not start with wildcard character.'))
if queryEmpty:
raise ValueError(
_(u'You need to fill at least one field in the search form.'))
options['publication_status'] = ['public']
catalog = self.get_root().service_catalog
try:
results = catalog.searchResults(options)
except ParseError:
raise ValueError(
_(u'Search query contains only common or reserved words.'))
return results
def getSearchCriterias(self, request):
options = {}
for field in self.getSearchFields():
name = field.getName()
if (self.shownFields.get(name, False) or name == 'path'):
queryPart = getMultiAdapter((field, self, request), IQueryPart)
value = queryPart.getIndexValue()
if value is None:
value = ''
options[queryPart.getIndexId()] = value
return options
示例5: Concepts
# 需要导入模块: from ZODB.PersistentMapping import PersistentMapping [as 别名]
# 或者: from ZODB.PersistentMapping.PersistentMapping import values [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')
#.........这里部分代码省略.........
示例6: Definitions
# 需要导入模块: from ZODB.PersistentMapping import PersistentMapping [as 别名]
# 或者: from ZODB.PersistentMapping.PersistentMapping import values [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
#.........这里部分代码省略.........
示例7: Terms
# 需要导入模块: from ZODB.PersistentMapping import PersistentMapping [as 别名]
# 或者: from ZODB.PersistentMapping.PersistentMapping import values [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):
#.........这里部分代码省略.........
示例8: nisAuthSource
# 需要导入模块: from ZODB.PersistentMapping import PersistentMapping [as 别名]
# 或者: from ZODB.PersistentMapping.PersistentMapping import values [as 别名]
#.........这里部分代码省略.........
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 = []
udata={}
NISuser=self._listOneNISUser(username)
if NISuser and len(NISuser)>0:
if self.NoLocalRoles:
udata=NISuser
else:
udata['username'] = username
udata['password']=NISuser['password']
udata['roles']=self.data[username]['roles']
if udata is not None:
users.append(udata)
return users
# Return a list of user dictionaries the same as listOneUser
def listUsers(self):
if self.NoLocalRoles:
users=self._listNISUsers()
else:
NISusers=self._listNISUsers()
NISusers_dict={}
for user in NISusers:
NISusers_dict[ user['username'] ]=user
users=self.data.values()
for num in range(0,len(users)):
username=users[num]['username']
users[num]['password']=NISusers_dict[username]['password']
return users
def _listNISUserNames(self):
nis_users=nis.cat('passwd.byname')
usernames=nis_users.keys()
usernames.sort()
return usernames
def _listOneNISUser(self,username):
roles=[self.default_role]
try:
nis_user=nis.match(username,'passwd.byname')
username,passwd,other=string.split(nis_user,':',2)
data={'username':username,
'password':passwd,
'roles':roles}
except nis.error:
data=None
return data
def _listNISUsers(self):
users=[]
roles=[self.default_role]
try:
nis_users=nis.cat('passwd.byname')
userlist=nis_users.keys()
userlist.sort()
for user in userlist:
username,passwd,other=string.split(nis_users[user],':',2)
data={'username':username,
'password':passwd,
'roles':roles}
users.append(data)
except nis.error:
data=None
return users
#
# You can define this to go off and do the authentication instead of
# using the basic one inside the User Object
#
remoteAuthMethod=None
def postInitialisation(self, REQUEST):
pass
示例9: ThemeRelations
# 需要导入模块: from ZODB.PersistentMapping import PersistentMapping [as 别名]
# 或者: from ZODB.PersistentMapping.PersistentMapping import values [as 别名]
#.........这里部分代码省略.........
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)
#theme relations getters
def get_threlations(self):
#get all theme relations
return self.theme_relations
def get_threlations_sorted(self):
#get all theme relations sorted
return th_utils().utSortObjsListByAttr(self.theme_relations.values(), 'concept_id', 0)
def get_threlation_by_id(self, id):
#get an item
try: return self.theme_relations[id]
except: return None
def get_threlation_item_data(self, concept_id, theme_id, orig_concept_id, orig_theme_id):
#get an item data
item = self.get_threlation_by_id((orig_concept_id, orig_theme_id))
if item is not None:
return ['update', concept_id, theme_id, orig_concept_id, orig_theme_id]
else:
return ['add', concept_id, theme_id, '', '']
#themes api
security.declareProtected(view_management_screens, 'manage_add_threlation')
def manage_add_threlation(self, concept_id='', theme_id='', REQUEST=None):
""" manage theme relations """
err = 0
if self.checkThRel(concept_id):
self.__add_threlation(concept_id, theme_id)
else:
err = 1
if REQUEST:
if err:
self.setSessionConceptId(concept_id)
self.setSessionThemeId(theme_id)
self.setSessionErrorsTrans('${concept_id} is not a valid concept ID.', concept_id=concept_id)
else:
self.setSessionInfoTrans('Record added.')
示例10: Source
# 需要导入模块: from ZODB.PersistentMapping import PersistentMapping [as 别名]
# 或者: from ZODB.PersistentMapping.PersistentMapping import values [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 """
#.........这里部分代码省略.........
示例11: ConceptRelations
# 需要导入模块: from ZODB.PersistentMapping import PersistentMapping [as 别名]
# 或者: from ZODB.PersistentMapping.PersistentMapping import values [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:
#.........这里部分代码省略.........