source: WAeUP_SRP/trunk/skins/waeup_directory/search_members.py @ 929

Last change on this file since 929 was 924, checked in by joachim, 18 years ago

removed username from member_search mask, because there is no easy way to
not search for student-members. In my opinion search for firstname, lastname
and email is sufficient.
The local-role SectionReader? is set for Authenticated in exportimport.py,
but now the import takes 3 times as long. I think we have to remove this
setting from exportimport.

  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1## Script (Python) "search_members"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=dir, datastructure, **kw
8##title=
9##
10# $Id: search_members.py 924 2006-11-22 16:54:23Z joachim $
11
12from Products.CPSDirectory.BaseDirectory import SearchSizeLimitExceeded
13try:
14    from Products.AdvancedQuery import Eq, Between, Le,In
15    evalAdvancedQuery = context.portal_catalog.evalAdvancedQuery
16except:
17    evalAdvancedQuery = None
18
19datamodel = datastructure.getDataModel()
20
21mapping = {}
22for key, value in datamodel.items():
23    if value:
24        mapping[key] = value
25
26#result_fields = context.getDirectoryResultFields(dir.getId(),
27#                                                 dir.title_field)
28result_fields = [{'id': 'sn', 'title': 'label_last_name', 'sort': 'asc'},
29                  {'id': 'givenName', 'title': 'label_first_name'},
30                  {'id': 'email', 'title': 'label_email'},
31                  #{'id': id_field, 'title': 'label_user_name'},
32                  ]
33
34return_fields = []
35sort_by = None
36sort_direction = None
37process_fields = {}
38for field in result_fields:
39    return_fields.append(field['id'])
40    sorted = field.get('sort')
41    if sorted == 'asc':
42        sort_by = field['id']
43        sort_direction = 'asc'
44    elif sorted == 'desc':
45        sort_by = field['id']
46        sort_direction = 'desc'
47    if field.get('process'):
48        process_fields[field['id']] = field['process']
49
50# empty search will not return anything
51if not mapping:
52    return dir.search_members_results(results=[]), 'results'
53
54try:
55    results = dir.searchEntries(return_fields=return_fields, **mapping)
56except SearchSizeLimitExceeded, e:
57    rendered = dir.cpsdirectory_entry_search_errors(exception=e)
58    return rendered, 'results'
59
60for field, process_meth in process_fields.items():
61    meth = getattr(context, process_meth, None)
62    if not meth:
63        continue
64    for item in results:
65        value = item[1].get(field)
66        item[1][field] = meth(field, value)
67
68if sort_by:
69    items = [(str(item[1].get(sort_by, 'ZZZZ')).lower(), item) for item in results]
70    items.sort()
71    if sort_direction == 'desc':
72        items.reverse()
73    results = [item[1] for item in items]
74
75allres = []
76for item in results:
77    user_id = item[0]
78    data = item[1]
79    query = In('portal_type',('Faculty','Department')) &\
80            In('localUsersWithRoles',('user:%s' % user_id,))
81    res = evalAdvancedQuery(query)
82    facs = []
83    roles = []
84    for r in res:
85        p = r.getPath().split('/')
86        fac = p[4]
87        if len(p) == 5:
88            facs.append(fac)
89            roles.append(r)
90        elif len(p) > 5:
91            if fac not in facs:
92                roles.append(r)
93    item[1]['roles'] = roles
94rendered = dir.search_members_results(results=results)
95
96return rendered, 'results'
97
98
Note: See TracBrowser for help on using the repository browser.