Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/pynslcd/group.py
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2013-08-12 22:42:56 +0200
committerArthur de Jong <arthur@arthurdejong.org>2013-08-17 12:31:36 +0200
commitd66162ad308878d2f3fb505a05742798283a8854 (patch)
treea7736f6cc1a1c065f69fb02ee49dfc8054d32886 /pynslcd/group.py
parentbfe22cc93563d86c8c35cd068810d7f8ac2dee33 (diff)
Use retrieve_by, group_by and group_columns in the cache
This removes custom retrieve() functions and Query classes from the database modules and uses retrieve_sql retrieve_by, group_by and group_columns to make a custom retrieval query. In the cache module this completely replaces how the query grouping is done. The Query class is now only used inside the cache and the CnAliasedQuery, RowGrouper and related classed have been removed.
Diffstat (limited to 'pynslcd/group.py')
-rw-r--r--pynslcd/group.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/pynslcd/group.py b/pynslcd/group.py
index 2028f1e..10e3423 100644
--- a/pynslcd/group.py
+++ b/pynslcd/group.py
@@ -99,13 +99,17 @@ class Cache(cache.Cache):
ON `group_member_cache`.`group` = `group_cache`.`cn`
'''
- def retrieve(self, parameters):
- query = cache.Query(self.retrieve_sql, parameters)
- # return results returning the members as a set
- q = itertools.groupby(query.execute(self.con),
- key=lambda x: (x['cn'], x['userPassword'], x['gidNumber']))
- for k, v in q:
- yield k + (set(x['memberUid'] for x in v if x['memberUid'] is not None), )
+ retrieve_by = dict(
+ memberUid='''
+ `cn` IN (
+ SELECT `a`.`group`
+ FROM `group_member_cache` `a`
+ WHERE `a`.`memberUid` = ?)
+ ''',
+ )
+
+ group_by = (0, ) # cn
+ group_columns = (3, ) # memberUid
class GroupRequest(common.Request):