source: WAeUP_SRP/trunk/skins/waeup_student/searchStudents.py @ 729

Last change on this file since 729 was 727, checked in by joachim, 19 years ago

improved student import,
renamed layout/schema student_course_results to student_course_result

File size: 6.6 KB
RevLine 
[565]1## Script (Python) "cpsdocument_edit"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
[584]7##parameters=
[565]8##title=
9##
10# $Id: student_edit.py 486 2006-09-06 10:09:39Z joachim $
11"""
12return Info about the current Student
13"""
[727]14try:
15    from Products.AdvancedQuery import Eq, Between, Le
16    evalAdvancedQuery = context.portal_catalog.evalAdvancedQuery
17except:
18    evalAdvancedQuery = None
19   
[565]20request = context.REQUEST
21form = request.form
22fget = form.get
[572]23info = {}
[565]24wf = context.portal_workflow
[572]25catalog = context.portal_catalog
[664]26#student_wf_states = wf.waeup_student_wf.states.keys()
27#info['wf_states'] = student_wf_states
28#info['wf_states'][0] = " ----- "
[584]29lt = context.portal_layouts
30pr = context.portal_registration
[565]31path_info = request.get('PATH_INFO').split('/')
[603]32is_manager = context.isManager
[584]33validate = request.has_key("cpsdocument_edit_button")
34items = []
[603]35default = {'search_mode': 'name',
[663]36        'review_state': 'all',
[587]37        'search_string': ''
[584]38        }
[603]39
[584]40rend,psm,ds = lt.renderLayout(layout_id= 'student_search',
41                      schema_id= 'student_search',
42                      context=context,
43                      mapping=validate and request,
44                      ob=default,
45                      layout_mode='edit',
46                      formaction="searchStudents"
47                      )
48if psm == '':
49    return context.students_manager_view(rendered = rend,
50                             psm = psm,
51                             #psm = "%s, %s" % (psm,ds),
52                             students = items,
53                             is_manager = is_manager,
54                             )
55what = ds.get('search_mode')
56state = ds.get('review_state')
[678]57st = term = ds.get('search_string')
[589]58err = False
[599]59with_review = state != "all"
[727]60onlyreview = with_review and not term
61with_level_results = state.startswith("category") and evalAdvancedQuery is not None
62bools = "with_review = %s<br\> onlyreview = %s<br\> with_level_results = %s" % (with_review,onlyreview,with_level_results)
[599]63if not term and not with_review:
[603]64    psm = "You must specify a search string when searching 'all states'."
[589]65    err = True
66elif '*' in term:
[596]67    psm = "you cannot use the '*' alone"
[589]68    err = True
[603]69if err:
[587]70    return context.students_manager_view(rendered = rend,
[589]71                             psm = psm,
[587]72                             #psm = "%s, %s" % (psm,ds),
73                             students = items,
74                             is_manager = is_manager,
75                             )
[572]76items = []
77res = []
78portal_type_query = {'query':['Student','StudentApplication','StudentPersonal']}
[603]79st_queries = ('jamb_reg_no','matric_no','name')
[727]80query_step = 0
81if onlyreview and not with_level_results:
82    query_step = 1
83    query =  Eq('portal_type','Student') & Eq('review_state',state)
84    res = evalAdvancedQuery(query)
85##    res = catalog(portal_type='Student',
86##                  review_state=state)
87elif onlyreview and with_level_results:
88    query_step = 2
89    query =  Eq('portal_type','StudentStudyLevel') & Eq('review_state',state)
90    res = evalAdvancedQuery(query)
[584]91elif what == "student_id":
[596]92    if with_review:
[727]93        query_step = 3
[596]94        res = catalog(portal_type='Student',
95                      id = term.strip(),
96                      review_state=state)
97    else:
[727]98        query_step = 4
[596]99        res = catalog(portal_type='Student',
100                      id = term.strip())
[727]101elif what in st_queries and not with_level_results:
[603]102    if what == "jamb_reg_no":
[727]103        query_step = 5
[589]104        pt = 'StudentApplication'
105        st = "%s*" % term.strip().lower()
106    elif what == "matric_no":
[727]107        query_step = 6
[589]108        pt = 'StudentClearance'
109        st = "%s*" % term.strip().lower()
110    elif what == "name":
[727]111        query_step = 7
[589]112        pt = portal_type_query
113        st = "%s*" % term.strip()
[663]114    try:
115        res = catalog(portal_type=pt,SearchableText=st)
116    except:
117        return context.students_manager_view(rendered = rend,
118                             psm = 'Search string "%s" not allowed.' % term,
119                             #psm = "%s, %s" % (psm,ds),
120                             students = items,
121                             is_manager = is_manager,
122                             )
[727]123elif what in st_queries and with_level_results and evalAdvancedQuery:
124    if what == "jamb_reg_no":
125        query_step = 8
126        pt = 'StudentApplication'
127        st = "%s*" % term.strip().lower()
128    elif what == "matric_no":
129        query_step = 9
130        pt = 'StudentClearance'
131        st = "%s*" % term.strip().lower()
132    elif what == "name":
133        query_step = 10
134        pt = portal_type_query
135        st = "%s*" % term.strip()
136    query = Eq('portal_type',pt) & Eq('SearchableText',"%s*" % term.strip().lower())\
137                | Eq('portal_type','StudentStudyLevel') & Eq('review_state',state)
138    try:
139        res = evalAdvancedQuery(query)
140    except:
141        return context.students_manager_view(rendered = rend,
142                             psm = 'Advanced Query failed' % term,
143                             #psm = "%s, %s" % (psm,ds),
144                             students = items,
145                             is_manager = is_manager,
146                             )
[663]147students = []
[727]148raw_res = len(res)
[572]149if res:
150    for r in res:
[727]151        if r.portal_type in ("StudentApplication","StudentPersonal",):
[589]152            student = r.getObject().aq_parent
[727]153        elif r.portal_type in ("StudentStudyLevel",):
154            student = r.getObject().aq_parent.aq_parent
[663]155##            pp = '/'.join(r.getPath().split('/')[:-1])
156##            student_cat = catalog(pathindex=pp,portal_type='Student')[0]
157##            student_rs = student_cat.review_state
158##            student = student_cat.getObject()
[572]159        else:
[589]160            student = r.getObject()
[663]161        student_rs = wf.getInfoFor(student,'review_state','keiner')
[727]162        if (with_review and student_rs != state and not with_level_results) or student in items:
[663]163            continue
164        items.append(student)
[584]165if items:
166    for item in items:
167        students.append(context.getStudentInfo(item))
[663]168    return context.students_manager_view(rendered = rend,
[584]169                             psm = "%d matching Students found" % len(items),
170                             students = students,
171                             is_manager = is_manager,
172                             )
[663]173return context.students_manager_view(rendered = rend,
[727]174                             psm = """Step: %s found: %s Your search for "%s" in %s with state %s failed.<br\>%s""" % (query_step,raw_res,st,what,state,bools),
[663]175                             students = students,
176                             is_manager = is_manager,
177                             )
Note: See TracBrowser for help on using the repository browser.