Example #1
0
def perform_request_knowledge_base_show(kb_id,
                                        ln=CFG_SITE_LANG,
                                        sortby="to",
                                        startat=0,
                                        search_term=""):
    """
    Show the content of a knowledge base.

    @param ln language
    @param kb a knowledge base id
    @param sortby the sorting criteria ('from' or 'to')
    @param startat start showing mapping rules at what number
    @param search_term search for this string in kb
    @return the content of the given knowledge base
    """
    kb = bibknowledge.get_kb_by_id(kb_id)
    name = kb.name
    mappings = bibknowledge.get_kb_mappings(name, sortby)

    kb_type = kb.kbtype
    # filter in only the requested rules if the user is searching..
    if search_term:
        newmappings = []
        for mapping in mappings:
            key = mapping['key']
            value = mapping['value']
            if key.count(search_term) > 0 or value.count(search_term) > 0:
                newmappings.append(mapping)
        # we were searching, so replace
        mappings = newmappings
    # if this bk is dynamic, get the configuration from the DB, and a list of
    # collections as a bonus
    dyn_config = None
    collections = None
    if kb_type == 'd':
        from invenio.legacy.search_engine \
            import get_alphabetically_ordered_collection_list
        dyn_config = kb.kbdefs.to_dict() if kb.kbdefs else {}
        collections = []
        collitems = get_alphabetically_ordered_collection_list()
        for collitem in collitems:
            collections.append(collitem[0])
    return bibknowledge_templates.tmpl_admin_kb_show(ln, kb_id, name, mappings,
                                                     sortby, startat, kb_type,
                                                     search_term, dyn_config,
                                                     collections)
Example #2
0
def perform_request_knowledge_base_show_attributes(kb_id,
                                                   ln=CFG_SITE_LANG,
                                                   sortby="to"):
    """
    Show the attributes of a knowledge base.

    @param ln language
    @param kb a knowledge base id
    @param sortby the sorting criteria ('from' or 'to')
    @return the content of the given knowledge base
    """
    kb = bibknowledge.get_kb_by_id(kb_id)
    name = kb.name
    description = kb.description
    kb_type = kb.kbtype
    return bibknowledge_templates.tmpl_admin_kb_show_attributes(
        ln, kb_id, name, description, sortby, kb_type)
Example #3
0
def perform_request_knowledge_base_show_attributes(kb_id, ln=CFG_SITE_LANG,
                                                   sortby="to"):
    """
    Show the attributes of a knowledge base.

    @param ln language
    @param kb a knowledge base id
    @param sortby the sorting criteria ('from' or 'to')
    @return the content of the given knowledge base
    """
    kb = bibknowledge.get_kb_by_id(kb_id)
    name = kb.name
    description = kb.description
    kb_type = kb.kbtype
    return bibknowledge_templates.tmpl_admin_kb_show_attributes(
        ln, kb_id, name,
        description,
        sortby, kb_type)
Example #4
0
def perform_request_knowledge_base_show(kb_id, ln=CFG_SITE_LANG, sortby="to",
                                        startat=0, search_term=""):
    """
    Show the content of a knowledge base.

    @param ln language
    @param kb a knowledge base id
    @param sortby the sorting criteria ('from' or 'to')
    @param startat start showing mapping rules at what number
    @param search_term search for this string in kb
    @return the content of the given knowledge base
    """
    kb = bibknowledge.get_kb_by_id(kb_id)
    name = kb.name
    mappings = bibknowledge.get_kb_mappings(name, sortby)

    kb_type = kb.kbtype
    # filter in only the requested rules if the user is searching..
    if search_term:
        newmappings = []
        for mapping in mappings:
            key = mapping['key']
            value = mapping['value']
            if key.count(search_term) > 0 or value.count(search_term) > 0:
                newmappings.append(mapping)
        # we were searching, so replace
        mappings = newmappings
    # if this bk is dynamic, get the configuration from the DB, and a list of
    # collections as a bonus
    dyn_config = None
    collections = None
    if kb_type == 'd':
        from invenio.legacy.search_engine \
            import get_alphabetically_ordered_collection_list
        dyn_config = kb.kbdefs.to_dict() if kb.kbdefs else {}
        collections = []
        collitems = get_alphabetically_ordered_collection_list()
        for collitem in collitems:
            collections.append(collitem[0])
    return bibknowledge_templates.tmpl_admin_kb_show(ln, kb_id, name,
                                                     mappings, sortby, startat,
                                                     kb_type, search_term,
                                                     dyn_config, collections)