Index: WAeUP_SRP/base/WAeUPImport.py
===================================================================
--- WAeUP_SRP/base/WAeUPImport.py	(revision 3242)
+++ WAeUP_SRP/base/WAeUPImport.py	(revision 3243)
@@ -386,5 +386,5 @@
             if not mapping.get('code',''):
                 msg =  "code is missing"
-                break              
+                break
             student_id = student_record.id
             level_id = mapping['level_id']
@@ -411,5 +411,5 @@
             if not mapping.get('code',''):
                 msg =  "code is missing"
-                break                
+                break
             student_id = student_record.id
             level_id = mapping['level_id']
@@ -859,7 +859,7 @@
     commit_after = 100000
     required_modes = ('create','edit')
-
-    def edit(self,mapping):
-        "edit student verdicts"
+    
+    def create(self,mapping):
+        "edit student verdicts and create StudentStudyLevel object if not existent"
         wftool = self.portal_workflow
         logger = logging.getLogger('WAeUPTool.mass_edit_verdict')
@@ -928,8 +928,17 @@
                 break
             level_obj = getattr(study_course_obj,current_level,None)
+
             if  level_obj is None:
-                msg = 'student %s: no study_level object for level %s' % (student_id,
-                                                                                current_level)
-                break
+                # The only difference to the edit method is that we create a StudentStudyLevel object
+                try:
+                    study_course_obj.invokeFactory('StudentStudyLevel',"%s" % current_level)
+                    level_obj = getattr(context,"%s" % current_level)
+                    level_obj.portal_workflow.doActionFor(level,'open')
+                except:
+                    continue             
+                #msg = 'student %s: no study_level object for level %s' % (student_id,
+                #                                                                current_level)
+                #break
+
             verdict = d['verdict'] = d['current_verdict']  = mapping.get('current_verdict','')
 
@@ -953,4 +962,100 @@
             #     pass
             break
+        return student_id,msg,mapping    
+
+
+    def edit(self,mapping):
+        "edit student verdicts"
+        wftool = self.portal_workflow
+        logger = logging.getLogger('WAeUPTool.mass_edit_verdict')
+        students_folder = self.portal_url.getPortalObject().campus.students
+        student_id = mapping.get('id',None)
+        matric_no = mapping.get('matric_no',None)
+        editable_keys = mapping.keys()
+        while True:
+            key = ''
+            msg = ''
+            if student_id:
+                student_record = self.students_catalog.getRecordByKey(student_id)
+                if student_record is None:
+                    #return '',"no student with id %s" % student_id
+                    msg = "no student with id %s" % student_id
+                    break
+                if matric_no and student_record.matric_no and matric_no != student_record.matric_no:
+                    msg = 'student %s: matric_no %s does not match %s' % (student_record.id,
+                                                                          student_record.matric_no,
+                                                                          matric_no)
+                    break
+                mapping['matric_no'] = student_record.matric_no
+            elif matric_no:
+                res = self.students_catalog(matric_no = matric_no)
+                if not res:
+                    msg = "no student with matric_no %s" % matric_no
+                    break
+                student_record = res[0]
+                editable_keys.remove('matric_no')
+            else:
+                msg = "no id or matric_no specified"
+                break
+            student_id = student_record.id
+            mapping['id'] = student_id
+            d = {}
+            #import pdb;pdb.set_trace()
+            any_change = False
+            #special treatment for StudentStudyLevel
+            current_session = d['session'] = mapping.get('current_session','')
+            if current_session and student_record.session != current_session:
+                msg = 'student %s: imported session %s does not match current_session %s' % (student_id,
+                                                                                            current_session,
+                                                                                            student_record.session)
+                break
+            current_level = mapping.get('current_level','')
+            if not current_level.isdigit():
+                msg = 'student %s: imported level is empty' % (student_id,)
+                break
+            if current_level and student_record.level != current_level:
+                msg = 'student %s: imported level %s does not match current_level %s' % (student_id,
+                                                                                        current_level,
+                                                                                        student_record.level)
+                break
+            student_review_state =  student_record.review_state
+            if student_review_state == 'deactivated':
+                msg = "student %s in review_state %s" % (student_id, student_review_state)
+                break
+            if student_review_state not in ('courses_validated','returning'):
+                msg = "student %s in wrong review_state %s" % (student_id, student_review_state)
+                break
+            student_obj = getattr(students_folder,student_id)
+            # f2t = self.field2types_student
+            study_course_obj = getattr(student_obj,'study_course',None)
+            if study_course_obj is None:
+                msg = 'student %s: no study_course object' % student_id
+                break
+            level_obj = getattr(study_course_obj,current_level,None)
+            if  level_obj is None:
+                msg = 'student %s: no study_level object for level %s' % (student_id,
+                                                                                current_level)
+                break
+            verdict = d['verdict'] = d['current_verdict']  = mapping.get('current_verdict','')
+
+            #if verdict == student_record.verdict:
+            #    msg = 'student %s: verdict already set to %s' % (student_id,
+            #                                                            verdict)
+
+            level_review_state = wftool.getInfoFor(level_obj,'review_state',None)
+            if level_review_state != "closed":
+                wftool.doActionFor(level_obj,'close')
+                # msg = 'student %s: level %s is not closed' % (student_id,
+                #                                                      current_level)
+
+            study_course_obj.getContent().edit(mapping = d)
+            level_obj.getContent().edit(mapping = d)
+            if student_review_state != "returning":
+                wftool.doActionFor(student_obj,'return')
+            # try:
+            #     wftool.doActionFor(level_obj,'close')
+            # except:
+            #     pass
+            break
         return student_id,msg,mapping
     ###)
