From 935bd2ad8079341123590d80658562d81ac87c86 Mon Sep 17 00:00:00 2001 From: Mark Hymers Date: Sun, 9 Aug 2009 14:46:18 +0100 Subject: [PATCH] add get_sections and get_priorities Signed-off-by: Mark Hymers --- daklib/dbconn.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/daklib/dbconn.py b/daklib/dbconn.py index 43c0b698..22fa262c 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -1233,6 +1233,29 @@ def get_priority(priority, session=None): __all__.append('get_priority') +def get_priorities(session=None): + """ + Returns dictionary of priority names -> id mappings + + @type session: Session + @param session: Optional SQL session object (a temporary one will be + generated if not supplied) + + @rtype: dictionary + @return: dictionary of priority names -> id mappings + """ + if session is None: + session = DBConn().session() + + ret = {} + q = session.query(Priority) + for x in q.all(): + ret[x.priority] = x.priority_id + + return ret + +__all__.append('get_priorities') + ################################################################################ class Queue(object): @@ -1469,6 +1492,29 @@ def get_section(section, session=None): __all__.append('get_section') +def get_sections(session=None): + """ + Returns dictionary of section names -> id mappings + + @type session: Session + @param session: Optional SQL session object (a temporary one will be + generated if not supplied) + + @rtype: dictionary + @return: dictionary of section names -> id mappings + """ + if session is None: + session = DBConn().session() + + ret = {} + q = session.query(Section) + for x in q.all(): + ret[x.section] = x.section_id + + return ret + +__all__.append('get_sections') + ################################################################################ class DBSource(object): -- 2.39.5