source: WAeUP_SRP/base/skins/waeup_pins/search_pins.py @ 3078

Last change on this file since 3078 was 3076, checked in by joachim, 17 years ago

add archive and archive_delete, show all batches in pins_view

File size: 5.3 KB
Line 
1## Script (Python) "search_pins"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=REQUEST
8##title=
9##
10# $Id: search_students.py 911 2006-11-20 15:11:29Z henrik $
11"""
12list Students for ClearanceOfficers
13"""
14try:
15    from Products.zdb import set_trace
16except:
17    def set_trace():
18        pass
19
20request = REQUEST
21wftool = context.portal_workflow
22mtool = context.portal_membership
23member = mtool.getAuthenticatedMember()
24roles = member.getRolesInContext(context)
25pincat = context.portal_pins
26students = context.portal_url.getPortalObject().campus.students
27def check_hostel_pins(term):
28    items = pincat(prefix_batch = term)
29    not_found = []
30    #from Products.zdb import set_trace;set_trace()
31    for item in items:
32        if item.student == '':
33            continue
34        student = getattr(students,item.student,None)
35        if student is None:
36            not_found.append(item)
37        elif not "accommodation_2006" in student.objectIds():
38            not_found.append(item)
39        else:
40            acco = student.accommodation_2006
41            acco_doc = acco.getContent()
42            pin = "".join(str(acco_doc.acco_res_sc_pin).split('-'))
43            if pin != item.pin:
44                not_found.append(item)
45    return not_found
46
47def set_used_pins(items, from_cat=False):
48    l = []
49    for i in items:
50        item = {}
51        if from_cat:
52            sno = i.student
53            prefix = i.prefix_batch
54            serial = i.serial
55            pin = i.pin
56        else:
57            sno = i['student']
58            prefix = i.get('prefix_batch')
59            serial = i.get('serial')
60            pin = i.get('pin')
61        item['student'] = sno
62        item['prefix'] = prefix
63        item['serial'] = serial
64        if len(sno) > 0:
65            item['pin'] = pin
66        else:
67            if str(member) in ('admin','joachim'):
68                item['pin'] = "%s" % (pin,)
69            else:
70                item['pin'] = "%s%s****%s" % (i.prefix_batch,pin[-10:-7],pin[-3:])
71
72        if sno.startswith('disabled'):
73            item['student_url'] = None
74            item['student_id'] = sno
75        elif len(sno)==10 or '/' in sno:
76            #res = context.portal_catalog(SearchableText=sno,portal_type='StudentApplication')
77            res = context.students_catalog(jamb_reg_no=sno.upper())
78            if len(res) > 0:
79                item['student_url'] = "%s/campus/students/%s/application" % (context.portal_url(),res[0].id)
80                item['student_id'] = res[0].id
81            else:
82                item['student_url'] = None
83                item['student_id'] = ''
84        elif len(sno) == 7:
85            item['student_url'] = '%s/campus/students/%s' % (context.portal_url(),item['student'])
86            item['student_id'] = item['student']
87        else:
88            item['student_url'] = ''
89            item['student_id'] = "not used"
90        l.append(item)
91    return l
92
93lt = context.portal_layouts
94validate = request.has_key("cpsdocument_edit_button")
95default = {'search_mode': 'student',}
96rend,psm,ds = lt.renderLayout(layout_id= 'scratch_card_search',
97                      schema_id= 'student_search',
98                      context=context,
99                      mapping=validate and request,
100                      ob=default,
101                      layout_mode='edit',
102                      formaction="search_pins",
103                      commit = False,
104                      )
105info = {}
106info['used'] = []
107#from Products.zdb import set_trace;set_trace()
108if context.portal_type == "ScratchCardBatch":
109    info['batch_doc'] = context.getContent()
110    #info['used'] = set_used_pins(info['batch_doc'].getUsedPins())
111    info['used'] = []
112    info['unused'] = info['batch_doc'].getUnusedPins()
113    info['nr_used'] = info['batch_doc'].getNumberOfUsedPins()
114    view = context.batch_view
115elif context.portal_type == "ScratchCardBatchesFolder":
116    batches = context.objectIds()
117    batches.sort()
118    l = []
119    cols = 6
120    rows,rest = divmod(len(batches),cols)
121    for r in range(rows):
122        von = r*cols
123        l += batches[von:von+cols],
124    if rest:
125        von = r*cols + cols
126        l += batches[von:von+rest],
127    info['batches'] = l
128    view = context.pins_view
129if psm == '':
130    return view(rendered = rend,
131                psm = psm,
132                #psm = "%s, %s" % (psm,ds),
133                info = info,
134                allowed = True,
135                )
136what = ds.get('search_mode')
137term = ds.get('search_string')
138
139items=[]
140if term != "":
141    if what == 'student' :
142        items_1 = pincat(student = term.upper())
143        items_2 = pincat(student = term.lower())
144        items = items_1 + items_2
145    elif what == 'pin':
146        if context.portal_type == "ScratchCardBatch" and term == "HOS1":
147            items = check_hostel_pins(term)
148        else:
149            items = pincat(pin = term.upper())
150    elif what == 'serial':
151        try:
152            snr = int(term.strip())
153            items = pincat(serial = snr)
154        except ValueError:
155            psm = "invalid number"
156            items = []
157            pass
158    else:
159        items = []
160
161info['used'] = set_used_pins(items,from_cat=True)
162
163
164
165return view(rendered = rend,
166            psm = psm,
167            #psm = "%s, %s" % (psm,ds),
168            info = info,
169            allowed = True,
170            )
171
Note: See TracBrowser for help on using the repository browser.