コード例 #1
0
ファイル: dblayer.py プロジェクト: jma/invenio
def get_groupnames_like(uid, pattern):
    """Get groupnames like pattern. Will return only groups that user is allowed to see
    """
    rlike_op = rlike()
    groups = {}
    if pattern:
        # For this use case external groups are like invisible one
        query1 = (
            "SELECT id, name FROM usergroup WHERE name "
            + rlike_op
            + " %s AND join_policy like 'V%%' AND join_policy<>'VE'"
        )
        try:
            res = run_sql(query1, (pattern,))
        except OperationalError:
            res = ()
        # The line belows inserts into groups dictionary every tuple the database returned,
        # assuming field0=key and field1=value
        map(lambda x: groups.setdefault(x[0], x[1]), res)
        query2 = """SELECT g.id, g.name
                    FROM usergroup g, user_usergroup ug
                    WHERE g.id=ug.id_usergroup AND ug.id_user=%s AND g.name " + rlike_op +  " %s"""
        try:
            res = run_sql(query2, (uid, pattern))
        except OperationalError:
            res = ()
        map(lambda x: groups.setdefault(x[0], x[1]), res)
    return groups
コード例 #2
0
ファイル: citerank_indexer.py プロジェクト: k3njiy/invenio
def get_external_links_from_db(ref, dict_of_ids, reference_indicator):
    """returns a dictionary containing the number of
    external links for each recid
    external link=citation that is not in our database """
    rlike_op = rlike()
    ext_links = {}
    dict_all_ref = {}
    for recid in dict_of_ids:
        dict_all_ref[recid] = 0
        ext_links[dict_of_ids[recid]] = 0
    reference_db_id = reference_indicator[0:2]
    reference_tag_regex = reference_indicator + "[a-z]"
    tag_list = run_sql("select id from bib" + reference_db_id + \
                         "x where tag " + rlike_op + " %s", (
                                               reference_tag_regex, ))
    tag_set = set()
    for tag in tag_list:
        tag_set.add(tag[0])
    ref_list = run_sql("select id_bibrec, id_bibxxx, field_number from \
                       bibrec_bib" + reference_db_id + "x group by \
                       id_bibrec, field_number")
    for item in ref_list:
        recid = int(item[0])
        id_bib = int(item[1])
        if recid in dict_of_ids and id_bib in tag_set:
            dict_all_ref[recid] += 1
    for recid in dict_of_ids:
        total_links = dict_all_ref[recid]
        internal_links = ref[dict_of_ids[recid]]
        ext_links[dict_of_ids[recid]] = total_links - internal_links
        if ext_links[dict_of_ids[recid]] < 0:
            ext_links[dict_of_ids[recid]] = 0
    write_message("External link information extracted", verbose=2)
    write_message("External links: %s" % str(ext_links), verbose=9)
    return ext_links
コード例 #3
0
ファイル: dblayer.py プロジェクト: jma/invenio
def get_nicknames_like(pattern):
    """get nicknames like pattern"""
    rlike_op = rlike()
    if pattern:
        try:
            res = run_sql("""SELECT nickname FROM "user" WHERE nickname """ + rlike_op + """ %s""", (pattern,))
        except OperationalError:
            res = ()
        return res
    return ()
コード例 #4
0
def get_nicknames_like(pattern):
    """get nicknames like pattern"""
    rlike_op = rlike()
    if pattern:
        try:
            res = run_sql(
                """SELECT nickname FROM "user" WHERE nickname """ + rlike_op +
                """ %s""", (pattern, ))
        except OperationalError:
            res = ()
        return res
    return ()
コード例 #5
0
ファイル: dblayer.py プロジェクト: k3njiy/invenio
def get_visible_group_list(uid, pattern=""):
    """List the group the user can join (not already member
    of the group regardless user's status).
     @return: groups {id : name} whose name matches pattern
    """
    rlike_op = rlike()
    grpID = []
    groups = {}
    #list the group the user is member of"""
    query = """SELECT distinct(id_usergroup)
               FROM user_usergroup
               WHERE id_user=%s """
    uid = int(uid)
    res = run_sql(query, (uid,))
    map(lambda x: grpID.append(int(x[0])), res)
    query2 = """SELECT id,name
                FROM usergroup
                WHERE (join_policy='%s' OR join_policy='%s')""" % (
                        CFG_WEBSESSION_GROUP_JOIN_POLICY['VISIBLEOPEN'],
                        CFG_WEBSESSION_GROUP_JOIN_POLICY['VISIBLEMAIL'])

    if len(grpID) == 1 :
        query2 += """ AND id!=%i""" % grpID[0]
    elif len(grpID) > 1:
        query2 += """ AND id NOT IN %s""" % str(tuple(grpID))

    if pattern:
        try:
            res2 = run_sql(
                query2 + """ AND name """ + rlike_op + """ %s ORDER BY name""",
                (pattern,))
        except OperationalError:
            res2 = ()
    else:
        res2 = run_sql(query2 + """ ORDER BY name""")

    map(lambda x: groups.setdefault(x[0], x[1]), res2)
    return groups
コード例 #6
0
def get_visible_group_list(uid, pattern=""):
    """List the group the user can join (not already member
    of the group regardless user's status).
     @return: groups {id : name} whose name matches pattern
    """
    rlike_op = rlike()
    grpID = []
    groups = {}
    #list the group the user is member of"""
    query = """SELECT distinct(id_usergroup)
               FROM user_usergroup
               WHERE id_user=%s """
    uid = int(uid)
    res = run_sql(query, (uid, ))
    map(lambda x: grpID.append(int(x[0])), res)
    query2 = """SELECT id,name
                FROM usergroup
                WHERE (join_policy='%s' OR join_policy='%s')""" % (
        CFG_WEBSESSION_GROUP_JOIN_POLICY['VISIBLEOPEN'],
        CFG_WEBSESSION_GROUP_JOIN_POLICY['VISIBLEMAIL'])

    if len(grpID) == 1:
        query2 += """ AND id!=%i""" % grpID[0]
    elif len(grpID) > 1:
        query2 += """ AND id NOT IN %s""" % str(tuple(grpID))

    if pattern:
        try:
            res2 = run_sql(
                query2 + """ AND name """ + rlike_op + """ %s ORDER BY name""",
                (pattern, ))
        except OperationalError:
            res2 = ()
    else:
        res2 = run_sql(query2 + """ ORDER BY name""")

    map(lambda x: groups.setdefault(x[0], x[1]), res2)
    return groups
コード例 #7
0
def get_groupnames_like(uid, pattern):
    """Get groupnames like pattern. Will return only groups that user is allowed to see
    """
    rlike_op = rlike()
    groups = {}
    if pattern:
        # For this use case external groups are like invisible one
        query1 = "SELECT id, name FROM usergroup WHERE name " + rlike_op + " %s AND join_policy like 'V%%' AND join_policy<>'VE'"
        try:
            res = run_sql(query1, (pattern, ))
        except OperationalError:
            res = ()
        # The line belows inserts into groups dictionary every tuple the database returned,
        # assuming field0=key and field1=value
        map(lambda x: groups.setdefault(x[0], x[1]), res)
        query2 = """SELECT g.id, g.name
                    FROM usergroup g, user_usergroup ug
                    WHERE g.id=ug.id_usergroup AND ug.id_user=%s AND g.name """ + rlike_op + """ %s"""
        try:
            res = run_sql(query2, (uid, pattern))
        except OperationalError:
            res = ()
        map(lambda x: groups.setdefault(x[0], x[1]), res)
    return groups
コード例 #8
0
ファイル: citerank_indexer.py プロジェクト: k3njiy/invenio
def get_external_links_from_db_old(ref, dict_of_ids, reference_indicator):
    """returns a dictionary containing the number of
    external links for each recid
    external link=citation that is not in our database """
    ext_links = {}
    reference_tag_regex = reference_indicator + "[a-z]"
    rlike_op = rlike()
    for recid in dict_of_ids:
        query = "select COUNT(DISTINCT field_number) from bibrec_bib99x \
                where id_bibrec='%s' and id_bibxxx in \
                (select id from bib99x where tag " + rlike_op + " '%s');" \
                    % (str(recid), reference_tag_regex)
        result_set = run_sql(query)
        if result_set:
            total_links = int(result_set[0][0])
            internal_links = ref[dict_of_ids[recid]]
            ext_links[dict_of_ids[recid]] = total_links - internal_links
            if ext_links[dict_of_ids[recid]] < 0:
                ext_links[dict_of_ids[recid]] = 0
        else:
            ext_links[dict_of_ids[recid]] = 0
    write_message("External link information extracted", verbose=2)
    write_message("External links: %s" % str(ext_links), verbose=9)
    return ext_links