From 601198884d58c0f3825e7108a9adb4dc4353ff5c Mon Sep 17 00:00:00 2001 From: Michaƫl Ball Date: Wed, 24 Dec 2014 17:52:04 +0000 Subject: Better searching methods --- models/track.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'models/track.py') diff --git a/models/track.py b/models/track.py index 264db81..90eba9f 100644 --- a/models/track.py +++ b/models/track.py @@ -271,21 +271,37 @@ class Track: set_clause = utils.update_clause_from_dict(dirty_attributes) dirty_attributes[id] = self.id - + sql = " ".join(("UPDATE track"), set_clause, "WHERE id = :id") db.execute(sql, dirty_attributes) db.commit() def search(**search_params): + """Find a track with the given params + + Args: + tracknumber: dict, with 'data' and 'operator' keys + name: dict, with 'data' and 'operator' keys + grouping: dict, with 'data' and 'operator' keys + filename: dict, with 'data' and 'operator' keys + """ + db = DbManager() tracks = [] - where_clause = utils.make_where_clause(search_params) + # unpack search params + where_params = {} + value_params = {} + for (attr, value) in search_params.items(): + where_params[attr] = value["operator"] + value_params[attr] = value["data"] + + where_clause = utils.make_where_clause(where_params) result = None if where_clause: statement = " ".join(("SELECT * FROM track", where_clause)) - result = db.execute(statement, search_params) + result = db.execute(statement, value_params) else: result = db.execute("SELECT * FROM track") -- cgit v1.2.3