Index: /WAeUP_SRP/trunk/ScratchCards.py
===================================================================
--- /WAeUP_SRP/trunk/ScratchCards.py	(revision 489)
+++ /WAeUP_SRP/trunk/ScratchCards.py	(revision 490)
@@ -45,7 +45,7 @@
     security = ClassSecurityInfo()
 
-    def __init__(self,**kw):
+    def __init__(self,id,**kw):
+        CPSDocument.__init__(self,id,**kw)
         self.table = PinTable()
-        CPSDocument.__init__(self, kw)
         
     security.declareProtected(View,"Title")
@@ -65,7 +65,9 @@
         for i in range(nr):
             pin = "%d%d" % (b_no,r.randint(999999999,1000000000))
-            while  self.table.searchResults(uid=pin):
-                pin = "%d%d" % (b_no,r.randint(999999999,1000000000))
-            table.addRecord(pin=pin,serial=i,student="")
+            import pdp;pdb.set_trace()
+            while len(res) > 0: 
+                pin = "%d%d" % (b_no,r.randint(9999,1000000000))
+                res = self.table.searchResults(uid=pin)
+            self.table.addRecord(pin=pin,serial=i,student="")
             print i,pin
 
Index: /WAeUP_SRP/trunk/WAeUPTables.py
===================================================================
--- /WAeUP_SRP/trunk/WAeUPTables.py	(revision 489)
+++ /WAeUP_SRP/trunk/WAeUPTables.py	(revision 490)
@@ -86,5 +86,5 @@
     def addRecord(self, **data):
         # The uid is the same as "bed".
-        uid = data['bed']
+        uid = data['pin']
         self.catalog_object(dict2ob(data), uid=uid)
         return uid
Index: /WAeUP_SRP/trunk/skins/waeup_student/widget_scratch_card_pin_render.pt
===================================================================
--- /WAeUP_SRP/trunk/skins/waeup_student/widget_scratch_card_pin_render.pt	(revision 490)
+++ /WAeUP_SRP/trunk/skins/waeup_student/widget_scratch_card_pin_render.pt	(revision 490)
@@ -0,0 +1,25 @@
+<tal:block define="mode options/mode;
+                   id here/getWidgetId;
+                   id_b string:${id}_b;
+                   id_n string:${id}_n;
+                   prefix options/prefix;
+                   value options/datastructure/?id;
+                   batch options/datastructure/?id_b;
+                   nr options/datastructure/?id_n;
+">
+<tal:block condition="python: mode == 'view'">
+<span tal:replace="value" />
+</tal:block>
+<tal:block define="name here/getHtmlWidgetId;"
+           condition="python: mode == 'edit'">
+  <span tal:replace="prefix" />-
+  <input type="text" size="2" maxlength="2"
+    tal:attributes="name string:${name}_b;
+                    id string:${name}_b;
+                    value batch" />-
+  <input type="text" size="10" maxlength="10"
+    tal:attributes="name string:${name}_n;
+                    id string:${name}_n;
+                    value nr" />
+</tal:block>
+</tal:block>
