Ejemplo n.º 1
0
    def endElement(self, name):
        if name == 'skos:prefLabel':
            content = u''.join(self.__data).strip()
            self.__data = []
            self.setPref(self.__concept_id,
                         {'concept_id':self.__concept_id,
                          'concept_name':content})

        if name == 'skos:altLabel':
            content = u''.join(self.__data).strip()
            self.__data = []
            self.setAlt(self.__concept_id,
                        {'concept_id':self.__concept_id,
                         'alt_name':content})

        if name == 'skos:definition':
            content = u''.join(self.__data).strip()
            self.__data = []
            self.setDef(self.__concept_id,
                        {'concept_id':self.__concept_id,
                         'definition':content})

        if name == 'skos:scopeNote':
            content = u''.join(self.__data).strip()
            self.__data = []
            self.setScope(self.__concept_id,
                         {'concept_id':self.__concept_id,
                          'scope_note':content})

        if name == 'rdf:source':
            content = u''.join(self.__data).strip()
            self.__data = []
            self.__source_id = th_utils().utGenRandomId()
            self.setSrc(self.__source_id,
                        {'source_id':self.__source_id,
                         'source_name':content,
                         'concept_id':self.__concept_id})

        if name == 'thesaurus:def_src':
            content = u''.join(self.__data).strip()
            self.__data = []
            self.__source_id = th_utils().utGenRandomId()
            self.setDefSrc((self.__concept_id, self.__source_id),
                           {'source_id':self.__source_id,
                            'source_name':content,
                            'concept_id':self.__concept_id})

        self.__currentTag = ''
Ejemplo n.º 2
0
 def UncatalogObject(self, p_ob):
     """ uncatalog objects """
     if th_utils().utIsListType(p_ob):
         map(lambda x, y: x.uncatalog_object(x.BuildCatalogPath(y)),
             (self, ) * len(p_ob), p_ob)
     else:
         self.uncatalog_object(self.BuildCatalogPath(p_ob))
Ejemplo n.º 3
0
 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')
 def getThemeByID(self, theme_id="", lang=""):
     """ """
     query = [("meta_type", THEME_ITEM_METATYPE), ("theme_id", theme_id), ("langcode", lang)]
     result = th_utils().utListToObj(self.catalog.searchCatalog(query))
     if not result:
         result = DummyTheme(theme_id, "")
     return result
    def __build_alphabets_for_lang(self, lang):
        self.__alphabets_cache[lang] = []
        dict_lang_tree = {}

        for concept_ob in self.getAllConcepts():
            term_brain = self.getConceptTranslation(concept_ob.concept_id, lang)
            t = u""
            if term_brain.concept_name:
                t = self.catalog.getTermObj(term_brain).concept_name
            if t:
                l = None
                for x in self._unicode_map(lang):
                    if t[0] in x:
                        l = x[0].encode("utf-8")
                        break
                if l is not None:
                    if not dict_lang_tree.has_key(l):
                        dict_lang_tree[l] = []
                    if type(t) == type(u""):
                        t = t.encode("utf-8")
                    dict_lang_tree[l].append((t, term_brain.concept_id))

        for x in self._unicode_map(lang):
            if dict_lang_tree.has_key(x[0].encode("utf-8")):
                l_sorted = th_utils().utSortListByLocale(dict_lang_tree[x[0].encode("utf-8")], 0, lang)
                self.__alphabets_cache[lang].append((x[0].encode("utf-8"), copy(l_sorted)))
        self._p_changed = 1
Ejemplo n.º 6
0
 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')
 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')
    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]
Ejemplo n.º 9
0
    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]
    def searchThesaurusNames(self, query, lang=""):
        """ search thesaurus """
        results = []
        if not lang:
            lang = self.gl_get_selected_language()

        # search in terms
        l_query = [("meta_type", TERM_ITEM_METATYPE), ("concept_name", query), ("langcode", lang)]
        results.extend(self.catalog.searchCatalog(l_query))

        return th_utils().utSortObjsByLocaleAttr(self.eliminateDuplicates(results), "concept_name", 0, lang)
Ejemplo n.º 11
0
    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]
    def skos_import(self, file, langcode, REQUEST=None):
        """ """
        parser = theme_parser()

        # parse the SKOS information
        chandler = parser.parseHeader(file)

        if chandler is None:
            if REQUEST:
                self.setSessionErrorsTrans("Parsing error. The file could not be parsed.")
                return REQUEST.RESPONSE.redirect("import_html")

        # get the target language
        skos_lang = chandler.getLanguage()
        if skos_lang:
            target_language = skos_lang.encode("utf-8")
        else:
            target_language = langcode

        # get data
        body_info = chandler.getBody()

        # info
        count_themes = 0
        err_themes = []

        # set data
        for id, data in body_info.items():
            theme_id = id.encode("utf-8").split("/")[-1]

            if theme_id:
                if self.checkTheme(theme_id):
                    theme_name = data["name"]
                    self.__add_theme(theme_id, target_language, theme_name)
                    count_themes += 1
                else:
                    err_themes.append(theme_id)
            else:
                err_themes.append("None")

        if REQUEST:
            self.setSessionInfoTrans(
                ["File imported successfully.", ("Translations added: ${count_themes}", {"count_themes": count_themes})]
            )
            if err_themes:
                self.setSessionErrorsTrans(
                    [
                        "Translations not imported (by its theme_id):",
                        ("Errors: ${err_themes}", {"err_themes": th_utils().utJoinToString(err_themes, ", ")}),
                    ]
                )
            return REQUEST.RESPONSE.redirect("import_html?msg=done")
    def getThemeConcept(self, theme_id="", lang=""):
        """ """
        # get concepts
        query = [("meta_type", THEME_RELATION_ITEM_METATYPE), ("theme_id", theme_id)]
        l_relations = self.catalog.searchCatalog(query)

        # get terms
        l_results = []
        add_result = l_results.append
        for item in l_relations:
            term_ob = self.getConceptTranslation(item.concept_id, lang)
            add_result(term_ob)
        return th_utils().utSortObjsByLocaleAttr(l_results, "concept_name", 0, lang)
    def searchThesaurus(self, query, lang=""):
        """ search thesaurus """
        results = []
        if not lang:
            lang = self.gl_get_selected_language()

        # search in terms
        l_query = [("meta_type", TERM_ITEM_METATYPE), ("concept_name", query), ("langcode", lang)]
        results.extend(self.catalog.searchCatalog(l_query))

        # search in definitions
        l_query = [("meta_type", DEFINITION_ITEM_METATYPE), ("definition", query), ("langcode", lang)]
        for def_ob in self.catalog.searchCatalog(l_query):
            results.append(self.getTermByID(def_ob.concept_id, lang))

        return th_utils().utSortObjsByLocaleAttr(self.eliminateDuplicates(results), "concept_name", 0, lang)
    def getThemesList(self, lang=""):
        """ return the themes list """
        results = []
        add_theme_trans = results.append

        themes_list = []
        add_theme_id = themes_list.append

        query = [("meta_type", THEME_RELATION_ITEM_METATYPE)]
        th_relations = self.catalog.searchCatalog(query)

        for rel_ob in th_relations:
            theme_id = rel_ob.theme_id
            if theme_id not in themes_list:
                add_theme_id(theme_id)

        for th_id in themes_list:
            th_ob = self.getThemeByID(th_id, lang)
            if th_ob:
                add_theme_trans(th_ob)
            else:
                add_theme_trans(DummyTheme(th_id, ""))

        return th_utils().utSortObjsByLocaleAttr(results, "theme_name", 0, lang)
Ejemplo n.º 16
0
    def skos_import(self, file, langcode, REQUEST=None):
        """ """
        parser = term_parser()

        #parse the SKOS information
        chandler = parser.parseHeader(file)

        if chandler is None:
            if REQUEST:
                self.setSessionErrorsTrans(
                    'Parsing error. The file could not be parsed.')
                return REQUEST.RESPONSE.redirect('import_html')

        #get the target language
        skos_lang = chandler.getLanguage()
        if skos_lang: langcode = skos_lang.encode('utf-8')

        #get data
        pref_info = chandler.getPref()
        alt_info = chandler.getAlt()
        def_info = chandler.getDef()
        scope_info = chandler.getScope()
        src_info = chandler.getSrc()
        def_src_info = chandler.getDefSrc()

        #info
        count_terms = 0
        err_terms = []
        count_altterms = 0
        err_altterms = []
        count_def = 0
        err_defs = []
        count_scope = 0
        err_scope = []
        count_src = 0
        err_src = []
        count_def_src = 0
        err_def_src = []

        #set Terms
        for id, data in pref_info.items():
            concept_id = data['concept_id'].encode('utf-8').split('/')[-1]
            if concept_id:
                concept_name = data['concept_name']
                source_id = ''
                if self.checkTerm(concept_id):
                    self.__add_term(concept_id, langcode, concept_name,
                                    source_id)
                    count_terms += 1
                else:
                    err_terms.append(concept_id)
            else:
                err_terms.append('None')

        #set Alternatives terms
        for id, data in alt_info.items():
            concept_id = data['concept_id'].encode('utf-8').split('/')[-1]
            if concept_id:
                alt_terms_folder = self.getAltTermsFolder()
                alt_name = data['alt_name']
                if self.checkTerm(concept_id):
                    alt_terms_folder.manage_add_altterm(
                        concept_id, langcode, alt_name)
                    count_altterms += 1
                else:
                    err_altterms.append(concept_id)
            else:
                err_altterms.append('None')

        #set Definitions
        for id, data in def_info.items():
            concept_id = data['concept_id'].encode('utf-8').split('/')[-1]
            if concept_id:
                definitions_folder = self.getDefinitionsFolder()
                definition = data['definition']
                if self.checkTerm(concept_id):
                    #TODO: implement source
                    definitions_folder.manage_add_definition(
                        concept_id, langcode, definition, '')
                    count_def += 1
                else:
                    err_defs.append(concept_id)
            else:
                err_defs.append('None')

        #set ScopeNotes
        for id, data in scope_info.items():
            concept_id = data['concept_id'].encode('utf-8').split('/')[-1]
            if concept_id:
                scopenotes_folder = self.getScopeNotesFolder()
                scope_note = data['scope_note']
                if self.checkTerm(concept_id):
                    scopenotes_folder.manage_add_scope(concept_id, langcode,
                                                       scope_note)
                    count_scope += 1
                else:
                    err_scope.append(concept_id)
            else:
                err_scope.append('None')

        #set Terms sources
        for id, data in src_info.items():
            source_id = data['source_id']
            source_name = data['source_name']
            concept_id = data['concept_id'].encode('utf-8').split('/')[-1]

            if concept_id:
                if self.checkTerm(concept_id):
                    sources_folder = self.getSourceFolder()
                    #add source record
                    sources_folder.manage_add_source(source_id, source_name)
                    #update term record
                    self.update_source_id(concept_id, langcode, source_id)
                    count_src += 1
                else:
                    err_src.append(concept_id)
            else:
                err_src.append('None')

        #set Definitions sources
        for id, data in def_src_info.items():
            source_id = data['source_id']
            source_name = data['source_name']
            concept_id = data['concept_id'].encode('utf-8').split('/')[-1]

            if concept_id:
                if self.checkTerm(concept_id):
                    sources_folder = self.getSourceFolder()
                    definitions_folder = self.getDefinitionsFolder()
                    #add source record
                    sources_folder.manage_add_source(source_id, source_name)
                    #update definition record
                    definitions_folder.update_source_id(
                        concept_id, langcode, source_id)
                    count_def_src += 1
                else:
                    err_def_src.append(concept_id)
            else:
                err_def_src.append('None')

        if REQUEST:
            self.setSessionInfoTrans([
                'File imported successfully.',
                (
                    'Translations added: ${count_terms}',
                    {
                        'count_terms': count_terms
                    },
                ),
                (
                    'Alternative terms added: ${count_altterms}',
                    {
                        'count_altterms': count_altterms
                    },
                ),
                (
                    'Definitions added: ${count_def}',
                    {
                        'count_def': count_def
                    },
                ),
                (
                    'ScopeNotes added: ${count_scope}',
                    {
                        'count_scope': count_scope
                    },
                ),
                (
                    'Terms Sources added: ${count_src}',
                    {
                        'count_src': count_src
                    },
                ),
                (
                    'Definitions Sources added: ${count_def_src}',
                    {
                        'count_def_src': count_def_src
                    },
                ),
            ])
            msg_err = []
            if err_terms:
                msg_err.append((
                    'Translations not imported because the specified concept_id does not exist: ${err_terms}',
                    {
                        'err_terms':
                        th_utils().utJoinToString(err_terms, ', ')
                    },
                ))
            if err_altterms:
                msg_err.append((
                    'Alternative terms not imported because the specified concept_id does not exist: ${err_altterms}',
                    {
                        'err_altterms':
                        th_utils().utJoinToString(err_altterms, ', ')
                    },
                ))
            if err_defs:
                msg_err.append((
                    'Definitions not imported because the specified concept_id does not exist: ${err_defs}',
                    {
                        'err_defs': th_utils().utJoinToString(err_defs, ', ')
                    },
                ))
            if err_scope:
                msg_err.append((
                    'ScopeNotes not imported because the specified concept_id does not exist: ${err_scope}',
                    {
                        'err_scope':
                        th_utils().utJoinToString(err_scope, ', ')
                    },
                ))
            if err_src:
                msg_err.append((
                    'Term sources not imported because the specified concept_id does not exist: ${err_src}',
                    {
                        'err_src': th_utils().utJoinToString(err_src, ', ')
                    },
                ))
            if err_def_src:
                msg_err.append((
                    'Definition sources not imported because the specified concept_id does not exist: ${err_def_src}',
                    {
                        'err_def_src':
                        th_utils().utJoinToString(err_def_src, ', ')
                    },
                ))
            if msg_err:
                self.setSessionErrorsTrans(msg_err)
            return REQUEST.RESPONSE.redirect('import_html')
Ejemplo n.º 17
0
    def manage_delete_concepts(self, ids=[], delete_all='', REQUEST=None):
        """ delete concepts """
        del_count = 0
        #TODO: uncomment when Groups will be implemented
        #        if delete_all:  ids = self.getIdsList(ids, 1)
        #        else:           ids = self.getIdsList(ids)
        if delete_all: ids = self.getIdsList(ids, 1)
        ids = th_utils().utConvertToList(ids)
        self.__delete_concept(ids)

        #delete all related data
        for concept_id in ids:
            #delete all related terms
            query = [('meta_type', TERM_ITEM_METATYPE),
                     ('concept_id', concept_id)]
            term_list = self.catalog.searchCatalog(query)
            term_folder = self.getTermsFolder()
            for term_ob in term_list:
                term_folder.manage_delete_terms(
                    ['%s###%s' % (term_ob.concept_id, term_ob.langcode)])
                del_count += 1

            #delete all related definitions
            query = [('meta_type', DEFINITION_ITEM_METATYPE),
                     ('concept_id', concept_id)]
            def_list = self.catalog.searchCatalog(query)
            def_folder = self.getDefinitionsFolder()
            for def_ob in def_list:
                def_folder.manage_delete_definitions(
                    ['%s###%s' % (def_ob.concept_id, def_ob.langcode)])
                del_count += 1

            #delete all related altterms
            query = [('meta_type', ALTTERM_ITEM_METATYPE),
                     ('concept_id', concept_id)]
            alt_list = self.catalog.searchCatalog(query)
            alt_folder = self.getAltTermsFolder()
            for alt_ob in alt_list:
                alt_folder.manage_delete_altterms(
                    ['%s###%s' % (alt_ob.concept_id, alt_ob.langcode)])
                del_count += 1

            #delete all related scopes
            query = [('meta_type', SCOPE_ITEM_METATYPE),
                     ('concept_id', concept_id)]
            scope_list = self.catalog.searchCatalog(query)
            scope_folder = self.getScopeNotesFolder()
            for scope_ob in scope_list:
                scope_folder.manage_delete_scopes(
                    ['%s###%s' % (scope_ob.concept_id, scope_ob.langcode)])
                del_count += 1

            #delete all related theme relations
            query = [('meta_type', THEME_RELATION_ITEM_METATYPE),
                     ('concept_id', concept_id)]
            threl_list = self.catalog.searchCatalog(query)
            threl_folder = self.getThemeRelationsFolder()
            for threl_ob in threl_list:
                threl_folder.manage_delete_threlations(
                    ['%s###%s' % (threl_ob.concept_id, threl_ob.theme_id)])
                del_count += 1

            #delete all related concept relations
            query = [('meta_type', CONCEPT_RELATION_ITEM_METATYPE),
                     ('concept_id', concept_id)]
            cprel_list = self.catalog.searchCatalog(query)
            cprel_folder = self.getConceptRelationsFolder()
            for cprel_ob in cprel_list:
                cprel_folder.manage_delete_relations([
                    '%s###%s###%s' %
                    (cprel_ob.concept_id, cprel_ob.relation_id,
                     cprel_ob.relation_type)
                ])
                del_count += 1

            query = [('meta_type', CONCEPT_RELATION_ITEM_METATYPE),
                     ('relation_id', concept_id)]
            cprel_list = self.catalog.searchCatalog(query)
            cprel_folder = self.getConceptRelationsFolder()
            for cprel_ob in cprel_list:
                cprel_folder.manage_delete_relations([
                    '%s###%s###%s' %
                    (cprel_ob.concept_id, cprel_ob.relation_id,
                     cprel_ob.relation_type)
                ])
                del_count += 1

        if REQUEST:
            self.setSessionInfoTrans('Selected records deleted.', (
                '${del_count} related records were deleted.',
                {
                    'del_count': del_count
                },
            ))
            REQUEST.RESPONSE.redirect('concepts_html')
 def get_threlations_sorted(self):
     #get all theme relations sorted
     return th_utils().utSortObjsListByAttr(self.theme_relations.values(), 'concept_id', 0)
 def getAltTermByID(self, concept_id="", lang=""):
     """ """
     query = [("meta_type", ALTTERM_ITEM_METATYPE), ("concept_id", concept_id), ("langcode", lang)]
     return th_utils().utListToObj(self.catalog.searchCatalog(query))
 def get_definitions_sorted(self):
     #get all definitions sorted
     return th_utils().utSortObjsListByAttr(self.definitions.values(), 'concept_id', 0)
 def getIdsList(self, ids, all=0):
     """ """
     if all: return self.concepts.keys()
     return th_utils().getIdsList(ids)
Ejemplo n.º 22
0
 def get_relations_sorted(self):
     #get all relations sorted
     return th_utils().utSortObjsListByAttr(self.concept_relations.values(),
                                            'concept_id', 0)
 def getDefinition(self, concept_id="", lang=""):
     """ """
     query = [("meta_type", DEFINITION_ITEM_METATYPE), ("concept_id", concept_id), ("langcode", lang)]
     return th_utils().utListToObj(self.catalog.searchCatalog(query))
 def getSource(self, source_id=""):
     """ """
     query = [("meta_type", SOURCE_ITEM_METATYPE), ("source_id", source_id)]
     return th_utils().utListToObj(self.catalog.searchCatalog(query))
 def getScopeNote(self, concept_id="", lang=""):
     """ """
     query = [("meta_type", SCOPE_ITEM_METATYPE), ("concept_id", concept_id), ("langcode", lang)]
     return th_utils().utListToObj(self.catalog.searchCatalog(query))
Ejemplo n.º 26
0
 def get_scopes_sorted(self):
     #get all scope notes sorted
     return th_utils().utSortObjsListByAttr(self.scopes.values(),
                                            'concept_id', 0)
Ejemplo n.º 27
0
 def get_altterms_sorted(self):
     #get all alt_terms sorted
     return th_utils().utSortObjsListByAttr(self.altterms.values(), 'concept_id', 0)
 def getIdsList(self, ids, all=0):
     """ """
     if all: return self.theme_relations.keys()
     return th_utils().getIdsList(ids)
 def getConceptByID(self, concept_id=""):
     """ """
     query = [("meta_type", CONCEPT_ITEM_METATYPE), ("concept_id", concept_id)]
     return th_utils().utListToObj(self.catalog.searchCatalog(query))
 def get_concepts_sorted(self):
     #get all concepts sorted
     return th_utils().utSortObjsListByAttr(self.concepts.values(), 'concept_id', 0)
 def getAllConcepts(self):
     """ """
     query = [("meta_type", CONCEPT_ITEM_METATYPE)]
     return th_utils().utSortObjsListByAttr(self.catalog.searchCatalog(query), "concept_id", 0)
    def manage_delete_concepts(self, ids=[], delete_all='', REQUEST=None):
        """ delete concepts """
        del_count = 0
        #TODO: uncomment when Groups will be implemented
#        if delete_all:  ids = self.getIdsList(ids, 1)
#        else:           ids = self.getIdsList(ids)
        if delete_all:  ids = self.getIdsList(ids, 1)
        ids = th_utils().utConvertToList(ids)
        self.__delete_concept(ids)

        #delete all related data
        for concept_id in ids:
            #delete all related terms
            query = [('meta_type',TERM_ITEM_METATYPE),
                     ('concept_id',concept_id)]
            term_list = self.catalog.searchCatalog(query)
            term_folder = self.getTermsFolder()
            for term_ob in term_list:
                term_folder.manage_delete_terms(['%s###%s' % (term_ob.concept_id, term_ob.langcode)])
                del_count += 1

            #delete all related definitions
            query = [('meta_type',DEFINITION_ITEM_METATYPE),
                     ('concept_id',concept_id)]
            def_list = self.catalog.searchCatalog(query)
            def_folder = self.getDefinitionsFolder()
            for def_ob in def_list:
                def_folder.manage_delete_definitions(['%s###%s' % (def_ob.concept_id, def_ob.langcode)])
                del_count += 1

            #delete all related altterms
            query = [('meta_type',ALTTERM_ITEM_METATYPE),
                     ('concept_id',concept_id)]
            alt_list = self.catalog.searchCatalog(query)
            alt_folder = self.getAltTermsFolder()
            for alt_ob in alt_list:
                alt_folder.manage_delete_altterms(['%s###%s' % (alt_ob.concept_id, alt_ob.langcode)])
                del_count += 1

            #delete all related scopes
            query = [('meta_type',SCOPE_ITEM_METATYPE),
                     ('concept_id',concept_id)]
            scope_list = self.catalog.searchCatalog(query)
            scope_folder = self.getScopeNotesFolder()
            for scope_ob in scope_list:
                scope_folder.manage_delete_scopes(['%s###%s' % (scope_ob.concept_id, scope_ob.langcode)])
                del_count += 1

            #delete all related theme relations
            query = [('meta_type',THEME_RELATION_ITEM_METATYPE),
                     ('concept_id',concept_id)]
            threl_list = self.catalog.searchCatalog(query)
            threl_folder = self.getThemeRelationsFolder()
            for threl_ob in threl_list:
                threl_folder.manage_delete_threlations(['%s###%s' % (threl_ob.concept_id, threl_ob.theme_id)])
                del_count += 1

            #delete all related concept relations
            query = [('meta_type',CONCEPT_RELATION_ITEM_METATYPE),
                     ('concept_id',concept_id)]
            cprel_list = self.catalog.searchCatalog(query)
            cprel_folder = self.getConceptRelationsFolder()
            for cprel_ob in cprel_list:
                cprel_folder.manage_delete_relations(['%s###%s###%s' % (cprel_ob.concept_id, cprel_ob.relation_id, cprel_ob.relation_type)])
                del_count += 1

            query = [('meta_type',CONCEPT_RELATION_ITEM_METATYPE),
                     ('relation_id',concept_id)]
            cprel_list = self.catalog.searchCatalog(query)
            cprel_folder = self.getConceptRelationsFolder()
            for cprel_ob in cprel_list:
                cprel_folder.manage_delete_relations(['%s###%s###%s' % (cprel_ob.concept_id, cprel_ob.relation_id, cprel_ob.relation_type)])
                del_count += 1

        if REQUEST:
            self.setSessionInfoTrans('Selected records deleted.',
                ('${del_count} related records were deleted.', {'del_count': del_count}, ))
            REQUEST.RESPONSE.redirect('concepts_html')
Ejemplo n.º 33
0
 def get_themes_sorted(self):
     #get all themes sorted
     return th_utils().utSortObjsListByAttr(self.themes.values(),
                                            'langcode', 0)
 def UncatalogObject(self, p_ob):
     """ uncatalog objects """
     if th_utils().utIsListType(p_ob):  map(lambda x, y: x.uncatalog_object(x.BuildCatalogPath(y)), (self,)*len(p_ob), p_ob)
     else:                              self.uncatalog_object(self.BuildCatalogPath(p_ob))
Ejemplo n.º 35
0
    def skos_import(self, file, langcode, REQUEST=None):
        """ """
        parser = theme_parser()

        #parse the SKOS information
        chandler = parser.parseHeader(file)

        if chandler is None:
            if REQUEST:
                self.setSessionErrorsTrans(
                    'Parsing error. The file could not be parsed.')
                return REQUEST.RESPONSE.redirect('import_html')

        #get the target language
        skos_lang = chandler.getLanguage()
        if skos_lang: target_language = skos_lang.encode('utf-8')
        else: target_language = langcode

        #get data
        body_info = chandler.getBody()

        #info
        count_themes = 0
        err_themes = []

        #set data
        for id, data in body_info.items():
            theme_id = id.encode('utf-8').split('/')[-1]

            if theme_id:
                if self.checkTheme(theme_id):
                    theme_name = data['name']
                    self.__add_theme(theme_id, target_language, theme_name)
                    count_themes += 1
                else:
                    err_themes.append(theme_id)
            else:
                err_themes.append('None')

        if REQUEST:
            self.setSessionInfoTrans([
                'File imported successfully.',
                (
                    'Translations added: ${count_themes}',
                    {
                        'count_themes': count_themes
                    },
                )
            ])
            if err_themes:
                self.setSessionErrorsTrans([
                    'Translations not imported (by its theme_id):',
                    (
                        'Errors: ${err_themes}',
                        {
                            'err_themes':
                            th_utils().utJoinToString(err_themes, ', ')
                        },
                    )
                ])
            return REQUEST.RESPONSE.redirect('import_html?msg=done')
 def get_themes_sorted(self):
     # get all themes sorted
     return th_utils().utSortObjsListByAttr(self.themes.values(), "langcode", 0)
 def get_scopes_sorted(self):
     #get all scope notes sorted
     return th_utils().utSortObjsListByAttr(self.scopes.values(), 'concept_id', 0)
Ejemplo n.º 38
0
 def getIdsList(self, ids, all=0):
     """ """
     if all: return self.concept_relations.keys()
     return th_utils().getIdsList(ids)
Ejemplo n.º 39
0
 def getIdsList(self, ids, all=0):
     """ """
     if all: return self.definitions.keys()
     return th_utils().getIdsList(ids)
Ejemplo n.º 40
0
 def getIdsList(self, ids, all=0):
     """ """
     if all: return self.altterms.keys()
     return th_utils().getIdsList(ids)
Ejemplo n.º 41
0
    def skos_import(self, file, langcode, REQUEST=None):
        """ """
        parser = term_parser()

        #parse the SKOS information
        chandler = parser.parseHeader(file)

        if chandler is None:
            if REQUEST:
                self.setSessionErrorsTrans('Parsing error. The file could not be parsed.')
                return REQUEST.RESPONSE.redirect('import_html')

        #get the target language
        skos_lang = chandler.getLanguage()
        if skos_lang:   langcode = skos_lang.encode('utf-8')

        #get data
        pref_info =     chandler.getPref()
        alt_info =      chandler.getAlt()
        def_info =      chandler.getDef()
        scope_info =    chandler.getScope()
        src_info =      chandler.getSrc()
        def_src_info =  chandler.getDefSrc()

        #info
        count_terms =   0
        err_terms =     []
        count_altterms = 0
        err_altterms =  []
        count_def =     0
        err_defs =      []
        count_scope =   0
        err_scope =     []
        count_src =     0
        err_src =       []
        count_def_src = 0
        err_def_src =   []

        #set Terms
        for id, data in pref_info.items():
            concept_id = data['concept_id'].encode('utf-8').split('/')[-1]
            if concept_id:
                concept_name = data['concept_name']
                source_id = ''
                if self.checkTerm(concept_id):
                    self.__add_term(concept_id, langcode, concept_name, source_id)
                    count_terms += 1
                else:
                    err_terms.append(concept_id)
            else:
                err_terms.append('None')

        #set Alternatives terms
        for id, data in alt_info.items():
            concept_id = data['concept_id'].encode('utf-8').split('/')[-1]
            if concept_id:
                alt_terms_folder = self.getAltTermsFolder()
                alt_name = data['alt_name']
                if self.checkTerm(concept_id):
                    alt_terms_folder.manage_add_altterm(concept_id, langcode, alt_name)
                    count_altterms += 1
                else:
                    err_altterms.append(concept_id)
            else:
                err_altterms.append('None')

        #set Definitions
        for id, data in def_info.items():
            concept_id = data['concept_id'].encode('utf-8').split('/')[-1]
            if concept_id:
                definitions_folder = self.getDefinitionsFolder()
                definition = data['definition']
                if self.checkTerm(concept_id):
                    #TODO: implement source
                    definitions_folder.manage_add_definition(concept_id, langcode, definition, '')
                    count_def += 1
                else:
                    err_defs.append(concept_id)
            else:
                err_defs.append('None')

        #set ScopeNotes
        for id, data in scope_info.items():
            concept_id = data['concept_id'].encode('utf-8').split('/')[-1]
            if concept_id:
                scopenotes_folder = self.getScopeNotesFolder()
                scope_note = data['scope_note']
                if self.checkTerm(concept_id):
                    scopenotes_folder.manage_add_scope(concept_id, langcode, scope_note)
                    count_scope += 1
                else:
                    err_scope.append(concept_id)
            else:
                err_scope.append('None')

        #set Terms sources
        for id, data in src_info.items():
            source_id =     data['source_id']
            source_name =   data['source_name']
            concept_id =    data['concept_id'].encode('utf-8').split('/')[-1]

            if concept_id:
                if self.checkTerm(concept_id):
                    sources_folder = self.getSourceFolder()
                    #add source record
                    sources_folder.manage_add_source(source_id, source_name)
                    #update term record
                    self.update_source_id(concept_id, langcode, source_id)
                    count_src += 1
                else:
                    err_src.append(concept_id)
            else:
                err_src.append('None')

        #set Definitions sources
        for id, data in def_src_info.items():
            source_id =     data['source_id']
            source_name =   data['source_name']
            concept_id =    data['concept_id'].encode('utf-8').split('/')[-1]

            if concept_id:
                if self.checkTerm(concept_id):
                    sources_folder = self.getSourceFolder()
                    definitions_folder = self.getDefinitionsFolder()
                    #add source record
                    sources_folder.manage_add_source(source_id, source_name)
                    #update definition record
                    definitions_folder.update_source_id(concept_id, langcode, source_id)
                    count_def_src += 1
                else:
                    err_def_src.append(concept_id)
            else:
                err_def_src.append('None')

        if REQUEST:
            self.setSessionInfoTrans(['File imported successfully.',
                ('Translations added: ${count_terms}', {'count_terms':  count_terms}, ),
                ('Alternative terms added: ${count_altterms}', {'count_altterms':  count_altterms}, ),
                ('Definitions added: ${count_def}', {'count_def':  count_def}, ),
                ('ScopeNotes added: ${count_scope}', {'count_scope':  count_scope}, ),
                ('Terms Sources added: ${count_src}', {'count_src':  count_src}, ),
                ('Definitions Sources added: ${count_def_src}', {'count_def_src':  count_def_src}, ),
            ])
            msg_err = []
            if err_terms:
                msg_err.append(('Translations not imported because the specified concept_id does not exist: ${err_terms}',
                    {'err_terms': th_utils().utJoinToString(err_terms, ', ')}, ))
            if err_altterms:
                msg_err.append(('Alternative terms not imported because the specified concept_id does not exist: ${err_altterms}',
                    {'err_altterms': th_utils().utJoinToString(err_altterms, ', ')}, ))
            if err_defs:
                msg_err.append(('Definitions not imported because the specified concept_id does not exist: ${err_defs}',
                    {'err_defs': th_utils().utJoinToString(err_defs, ', ')}, ))
            if err_scope:
                msg_err.append(('ScopeNotes not imported because the specified concept_id does not exist: ${err_scope}',
                    {'err_scope': th_utils().utJoinToString(err_scope, ', ')}, ))
            if err_src:
                msg_err.append(('Term sources not imported because the specified concept_id does not exist: ${err_src}',
                    {'err_src': th_utils().utJoinToString(err_src, ', ')}, ))
            if err_def_src:
                msg_err.append(('Definition sources not imported because the specified concept_id does not exist: ${err_def_src}',
                    {'err_def_src': th_utils().utJoinToString(err_def_src, ', ')}, ))
            if msg_err:
                self.setSessionErrorsTrans(msg_err)
            return REQUEST.RESPONSE.redirect('import_html')
 def getIdsList(self, ids, all=0):
     """ """
     if all: return self.definitions.keys()
     return th_utils().getIdsList(ids)
Ejemplo n.º 43
0
 def get_sources_sorted(self):
     #get all sources sorted
     return th_utils().utSortObjsListByAttr(self.sources.values(), 'source_id', 0)