From 2608982885477e2f41579240d24a26864f718123 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sat, 24 Dec 2011 19:08:20 +0100 Subject: [PATCH] Add search level one() method And create a _fix_query_dict which converts '_id' to 'id'. --- mediagoblin/db/sql/base.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mediagoblin/db/sql/base.py b/mediagoblin/db/sql/base.py index b8d5cc96..38b04334 100644 --- a/mediagoblin/db/sql/base.py +++ b/mediagoblin/db/sql/base.py @@ -4,13 +4,26 @@ from sqlalchemy.orm import scoped_session, sessionmaker Session = scoped_session(sessionmaker()) +def _fix_query_dict(query_dict): + if '_id' in query_dict: + query_dict['id'] = query_dict.pop('_id') + + class GMGTableBase(object): query = Session.query_property() @classmethod def find(cls, query_dict={}): + _fix_query_dict(query_dict) return cls.query.filter_by(**query_dict) @classmethod def find_one(cls, query_dict={}): + _fix_query_dict(query_dict) return cls.query.filter_by(**query_dict).first() + + @classmethod + def one(cls, query_dict): + retval = cls.find_one(query_dict) + assert retval is not None + return retval -- 2.25.1