Index: /WAeUP_SRP/trunk/skins/waeup_pins/search_pins.py
===================================================================
--- /WAeUP_SRP/trunk/skins/waeup_pins/search_pins.py	(revision 1133)
+++ /WAeUP_SRP/trunk/skins/waeup_pins/search_pins.py	(revision 1134)
@@ -18,6 +18,26 @@
 member = mtool.getAuthenticatedMember()
 roles = member.getRolesInContext(context)
-#from Products.zdb import set_trace
-#set_trace()
+pincat = context.portal_pins
+students = context.portal_url.getPortalObject().campus.students
+def check_hostel_pins(term):
+    items = pincat(prefix_batch = term)
+    not_found = []
+    #from Products.zdb import set_trace;set_trace()
+    for item in items:
+        if item.student == '':
+            continue
+        student = getattr(students,item.student,None)
+        if student is None:
+            not_found.append(item)
+        elif not "accommodation_2006" in student.objectIds():
+            not_found.append(item)
+        else:
+            acco = student.accommodation_2006
+            acco_doc = acco.getContent()
+            pin = "".join(str(acco_doc.acco_res_sc_pin).split('-'))
+            if pin != item.pin:
+                not_found.append(item)
+    return not_found
+        
 def set_used_pins(items, from_cat=False):
     l = []
@@ -99,5 +119,4 @@
 what = ds.get('search_mode')
 term = ds.get('search_string')
-pincat = context.portal_pins
 if term != "":
     if what == 'student' :
@@ -106,5 +125,8 @@
         items = items_1 + items_2
     elif what == 'pin':
-        items = pincat(pin = term.upper())
+        if context.portal_type == "ScratchCardBatch" and term == "HOS1":
+            items = check_hostel_pins(term)
+        else:
+            items = pincat(pin = term.upper())
     elif what == 'serial':
         try:
@@ -117,5 +139,4 @@
     else:
         items = []
-##  students_url = "%s/%s" % (context.portal_url(),'students')
         
 info['used'] = set_used_pins(items,from_cat=True)
