Changeset 751 for WAeUP_SRP/trunk/skins


Ignore:
Timestamp:
25 Oct 2006, 22:36:37 (18 years ago)
Author:
joachim
Message:

fixed searchStudents

File:
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/skins/waeup_student/searchStudents.py

    r750 r751  
    6363err = False
    6464with_review = state != "all"
    65 onlyreview = with_review and not term
     65only_review = with_review and not term
    6666##with_level_results = state.startswith("category") or\
    6767##                     state in ('content_addable',) and\
    6868##                     evalAdvancedQuery is not None
    69 bools = "with_review = %s<br\> onlyreview = %s<br\>" % (with_review,onlyreview)
     69bools = "with_review = %s<br\> only_review = %s<br\>" % (with_review,only_review)
    7070if not term and not with_review:
    7171    psm = "You must specify a search string when searching 'all states'."
     
    8686st_queries = ('jamb_reg_no','matric_no','name')
    8787query_step = 0
    88 review_query = None
    89 if onlyreview:
    90     query_step = 1
    91     query =   In('portal_type',student_subobjects) & Eq('review_state',state)
    92     #res = evalAdvancedQuery(query)
    93 elif what == "student_id":
    94     if with_review:
    95         query_step = 3
    96         res = catalog(portal_type='Student',
    97                       id = term.strip(),
    98                       review_state=state)
    99     else:
    100         query_step = 4
    101         res = catalog(portal_type='Student',
    102                       id = term.strip())
    103 elif what in st_queries:
    104     if what == "jamb_reg_no":
    105         query_step = 5
    106         pt = ('StudentApplication',)
    107         st = "%s*" % term.strip().lower()
    108     elif what == "matric_no":
    109         query_step = 6
    110         pt = ('StudentClearance',)
    111         st = "%s*" % term.strip().lower()
    112     elif what == "name":
    113         query_step = 7
    114         pt = portal_type_query
    115         st = "%s*" % term.strip()
    116     if with_review:
    117         review_query = In('portal_type',student_subobjects) & Eq('review_state',state)
    118     query = (In('portal_type',pt) & Eq('SearchableText',st))
    119 ##    try:
    120 ##        res = catalog(portal_type=pt,SearchableText=st)
    121 ##    except:
    122 ##        return context.students_manager_view(rendered = rend,
    123 ##                             psm = 'Search string "%s" not allowed.' % term,
    124 ##                             #psm = "%s, %s" % (psm,ds),
    125 ##                             students = items,
    126 ##                             is_manager = is_manager,
    127 ##                             )
    128 ##elif what in st_queries and with_level_results and evalAdvancedQuery:
    129 ##    if what == "jamb_reg_no":
    130 ##        query_step = 8
    131 ##        pt = 'StudentApplication'
    132 ##        st = "%s*" % term.strip().lower()
    133 ##    elif what == "matric_no":
    134 ##        query_step = 9
    135 ##        pt = 'StudentClearance'
    136 ##        st = "%s*" % term.strip().lower()
    137 ##    elif what == "name":
    138 ##        query_step = 10
    139 ##        pt = portal_type_query
    140 ##        st = "%s*" % term.strip()
    141 ##    query = Eq('portal_type',pt) & Eq('SearchableText',"%s*" % term.strip().lower())\
    142 ##                | ((Eq('portal_type','StudentStudyLevel') |
    143 ##                   Eq('portal_type','StudentStudyCourse')) & Eq('review_state',state))
    144 if review_query:
    145     res = evalAdvancedQuery(query | review_query)
    146 else:
     88review_res = None
     89query = None
     90if len(term) > 0:
     91    if what == "student_id":
     92        query_step = 1
     93        query = Eq('portal_type','Student') & Eq('id', term.strip())
     94    elif what in st_queries:
     95        if what == "jamb_reg_no":
     96            query_step = 2
     97            pt = ('StudentApplication',)
     98            st = "%s" % term.strip().lower()
     99        elif what == "matric_no":
     100            query_step = 3
     101            pt = ('StudentClearance',)
     102            st = "%s" % term.strip().lower()
     103        elif what == "name":
     104            query_step = 4
     105            pt = ('StudentPersonal')
     106            st = "%s" % term.strip()
     107        query = In('portal_type',pt) & Eq('SearchableText',"%s*" % term.strip())
    147108    res = evalAdvancedQuery(query)
    148 ##try:
    149 ##    if review_query:
    150 ##        res = evalAdvancedQuery(query) & evalAdvancedQuery(review_query)
    151 ##    else:
    152 ##        res = evalAdvancedQuery(query)
    153 ##except:
    154 ##    return context.students_manager_view(rendered = rend,
    155 ##                         psm = 'Advanced Query failed' % term,
    156 ##                         #psm = "%s, %s" % (psm,ds),
    157 ##                         students = items,
    158 ##                         is_manager = is_manager,
    159 ##                         )
    160 students = []
    161 raw_res = len(res)
    162 all = []
     109if with_review:
     110    query_step += 10
     111    review_res = evalAdvancedQuery(In('portal_type',student_subobjects) & Eq('review_state',state))
     112search_set = []
    163113if res:
    164114    for r in res:
     
    169119        else:
    170120            student = r.getObject()
    171         if student in all:
    172             items.append(student)
    173             continue
    174         all.append(student)
    175 if onlyreview:
    176     items = all
     121        search_set.append(student)
     122review_set = []
     123if review_res:
     124    for r in review_res:
     125        if r.portal_type in ("StudentStudyLevel",):
     126            student = r.getObject().aq_parent.aq_parent
     127        elif r.portal_type in student_subobjects:
     128            student = r.getObject().aq_parent
     129        else:
     130            student = r.getObject()
     131        review_set.append(student)
     132all = []
     133if only_review:
     134    all = review_set
     135elif with_review:
     136    for i in search_set:
     137        if i in review_set:
     138            all.append(i)
     139else:
     140    all = search_set
     141for a in all:
     142    if a in items:
     143        continue
     144    items.append(a)
     145students = []
    177146if items:
    178147    for item in items:
     
    180149        students.append(info)
    181150    return context.students_manager_view(rendered = rend,
    182                              psm = "%d matching Students found QS = %s" % (len(items),query_step),
     151                             psm = "%d,%d matching Students found QS = %s" %\
     152                                    (len(review_set),len(search_set),query_step),
    183153                             #psm = "%d found QS = %s items: %s" % (len(items),query_step,items),
    184154                             students = students,
     
    186156                             )
    187157return context.students_manager_view(rendered = rend,
    188                              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),
     158                             psm = """Step: %s found: %s Your search for "%s" in %s with state %s failed.<br\>%s""" % (query_step,len(items),st,what,state,bools),
    189159                             students = students,
    190160                             is_manager = is_manager,
Note: See TracChangeset for help on using the changeset viewer.