Index: /WAeUP_SRP/base/WAeUPTables.py
===================================================================
--- /WAeUP_SRP/base/WAeUPTables.py	(revision 2433)
+++ /WAeUP_SRP/base/WAeUPTables.py	(revision 2434)
@@ -1297,48 +1297,4 @@
         self._queue = []
 
-    def addRecord(self, **data): ###(
-        """add one record"""
-
-        uid = key = "%(student_id)s|%(level_id)s|%(course_id)s" % data
-        if key in self._queue:
-            return uid
-        data['queue_status'] = ADDING_SHEDULED
-        data['%s' % self.key] = uid
-        res = self.searchResults({"%s" % self.key : uid})
-        if len(res) > 0:
-            raise ValueError("More than one record with uid %s" % uid)
-        self.catalog_object(dict2ob(data), uid=uid)
-        if not hasattr(self,'_queue'):
-            self._queue = []
-        self._queue.append(key)
-        self._p_changed = 1
-        return uid
-    ###)
-
-    # def _p_resolveConflict(self, oldstate, committed, newstate):
-    #     # Apply the changes made in going from old to newstate to
-    #     # committed
-
-    #     # Note that in the case of undo, the olddata is the data for
-    #     # the transaction being undone and newdata is the data for the
-    #     # transaction previous to the undone transaction.
-
-    #     # Find the conflict policy on the new state to make sure changes
-    #     # to it will be applied
-
-    #     # Committed is always the currently committed data.
-    #     import pdb;pdb.set_trace()
-    #     oldstate_data  =  oldstate['_queue']
-    #     committed_data = committed['_queue']
-    #     newstate_data  =  newstate['_queue']
-
-    #     # Merge newstate changes into committed
-    #     for uid, new in newstate_data.items():
-
-    #         # Decide if this is a change
-    #         old = oldstate_data.get(uid)
-    #         current = committed_data.get(uid)
-
-
     def addMultipleRecords(self, records): ###(
         """add many records"""
@@ -1346,8 +1302,4 @@
         for data in records:
             uid = key = "%(student_id)s|%(level_id)s|%(course_id)s" % data
-            added_keys.append(key)
-            if key in self._queue:
-                return uid
-            data['queue_status'] = ADDING_SHEDULED
             data['%s' % self.key] = uid
             res = self.searchResults({"%s" % self.key : uid})
@@ -1355,33 +1307,33 @@
                 raise ValueError("More than one record with uid %s" % uid)
             self.catalog_object(dict2ob(data), uid=uid)
-        if not hasattr(self,'_queue'):
-            self._queue = added_keys
-        self._queue.extend(added_keys)
-        self._p_changed = 1
         return uid
     ###)
 
-    def deleteRecord(self, uid): ###(
-        self.uncatalog_object(uid)
-        if uid in self._queue:
-            self._queue.remove(uid)
-    ###)
-
-    def updateCourseResults(self,student_id,level_id,portal_catalog_results,course_results): ###(
-        # query = Eq('path',"%s/campus/students/%s/study_course/%s" %
-        #            (self.portal_url.getPortalPath(),
-        #             student_id,
-        #             level_id)) &\
-        #             Eq('portal_type', "StudentCourseResult")
-        # level_results = self.portal_catalog_real.evalAdvancedQuery(query)
-        # level_results = [r for r in course_results
-        #                  if level_id in r.relative_path.split('/')]
-        course_results_ids = [cr.getId for cr in course_results]
-        for r in portal_catalog_results:
-            if r.getId in course_results_ids:
+    def deleteResultsHere(self,level_id,student_id): ###(
+        #import pdb;pdb.set_trace()
+        query = Eq('student_id',student_id) & Eq('level_id', level_id)
+        course_results = self.course_results.evalAdvancedQuery(query)
+        for result in course_results:
+            self.deleteRecord(result.key)
+    ###)
+
+    def moveResultsHere(self,level,student_id): ###(
+        #import pdb;pdb.set_trace()
+        level_id = level.getId()
+        query = Eq('student_id',student_id) & Eq('level_id', level_id)
+        course_results = self.course_results.evalAdvancedQuery(query)
+        existing_courses = [cr.code for cr in course_results] 
+        to_delete = []
+        for code,obj in level.objectItems():
+            to_delete += code
+            carry_over = False
+            if code.endswith('_co'):
+                carry_over = True
+                code  = code[:-3] 
+            if code in existing_courses:
                 continue
-            course_result_doc = r.getObject().getContent()
+            course_result_doc = obj.getContent()
             data = {}
-            course_id = r.getId
+            course_id = code
             for field in self.schema():
                 data[field] = getattr(course_result_doc,field,'')
@@ -1389,12 +1341,44 @@
             data['student_id'] = student_id
             data['level_id'] = level_id
-            data['queue_status'] = OBJECT_CREATED
+            #data['queue_status'] = OBJECT_CREATED
             data['code'] = course_id
+            data['carry_over'] = carry_over
             self.catalog_object(dict2ob(data), uid=key)
+        level.manage_delObjects(to_delete)
+    ###)
+
+    def getCourses(self,student_id,level_id): ###(
         query = Eq('student_id',student_id) & Eq('level_id', level_id)
-        return self.course_results.evalAdvancedQuery(query)
-    ###)
-
-    def getCourses(self,student_id,level_id): ###(
+        course_results = self.course_results.evalAdvancedQuery(query)
+        carry_overs = []
+        normal = []
+        credits = 0
+        for brain in course_results:
+            d = {}
+            credits += int(brain.credits)
+            for field in self.schema():
+                d[field] = getattr(brain,field,'')
+            #d['sheduled'] = brain.queue_status == ADDING_SHEDULED
+            d['coe'] = 'Elective'
+            if brain.core_or_elective:
+                d['coe'] = 'Core'
+            id = code = d['id'] = brain.code
+            is_carry_over = False
+            if code.endswith('_co'):
+                is_carry_over = True
+                code = code[:-3]
+            d['code'] = code
+            d['title'] = self.courses_catalog.evalAdvancedQuery(Eq('code',code))[0].title
+            if is_carry_over:
+                d['coe'] = 'Core'
+                carry_overs.append(d)
+            else:
+                normal.append(d)
+        normal.sort(cmp=lambda x,y: cmp(x['semester'], y['semester']))
+        carry_overs.sort(cmp=lambda x,y: cmp(x['semester'], y['semester']))
+        return credits,carry_overs,normal
+    ###)
+
+    def queue_getCourses(self,student_id,level_id): ###(
         level_path = "%s/campus/students/%s/study_course/%s" % (self.portal_url.getPortalPath(),
                                                                 student_id,
@@ -1441,148 +1425,4 @@
     ###)
 
-    def addObject(self,record): ###(
-        key = record.key
-        student_id,level_id,course_id = key.split('|')
-        level = getattr(getattr(self.portal_url.getPortalObject().campus.students,student_id).study_course,level_id)
-        cr_id = level.invokeFactory('StudentCourseResult', course_id)
-        course_result = getattr(level,cr_id)
-        self.portal_workflow.doActionFor(course_result,'open')
-        d = {}
-        for field in self.schema():
-            d[field] = getattr(record,field,'')
-        course_result.getContent().edit(mapping=d)
-    ###)
-
-    security.declareProtected(ModifyPortalContent,"process_queue") ###(
-    def process_queue(self,limit=None):
-        """adds objects and removes them from the queue.
-        If limit is specified, at most (limit) events are removed.
-        """
-        if not hasattr(self,'_queue'):
-            return 0
-        queue= self._queue
-        if not limit or len(queue) <= limit:
-            keys = self._queue[:]
-        else:
-            keys = queue[:limit]
-        if not keys:
-            records = self.evalAdvancedQuery(Eq('queue_status',ADDING_SHEDULED))
-        else:
-            records = self.evalAdvancedQuery(In("%s" % self.key,keys))
-        for record in records:
-            if record.queue_status == OBJECT_CREATED:
-                continue
-            self.addObject(record)
-            data = {}
-            data['key'] = record.key
-            data['queue_status'] = OBJECT_CREATED
-            self.modifyRecord(**data)
-        count = 0
-        for key in keys:
-            count +=1
-            if key in self._queue:
-                self._queue.remove(key)
-        self._p_changed = 1
-        return count,len(self._queue)
-    ###)
-
-    def manage_catalogClear(self, REQUEST=None, RESPONSE=None, URL1=None): ###(
-        """ clears the whole enchilada """
-        self._catalog.clear()
-
-        if REQUEST and RESPONSE:
-            RESPONSE.redirect(
-              URL1 +
-              '/manage_catalogAdvanced?manage_tabs_message=Catalog%20Cleared')
-    ###)
-
-    def manage_catalogReindex(self, REQUEST, RESPONSE, URL1): ###(
-        """ clear the catalog, then re-index everything """
-
-        elapse = time.time()
-        c_elapse = time.clock()
-
-        pgthreshold = self._getProgressThreshold()
-        handler = (pgthreshold > 0) and ZLogHandler(pgthreshold) or None
-        self.refreshCatalog(clear=1, pghandler=handler)
-
-        elapse = time.time() - elapse
-        c_elapse = time.clock() - c_elapse
-
-        RESPONSE.redirect(
-            URL1 +
-            '/manage_catalogAdvanced?manage_tabs_message=' +
-            urllib.quote('Catalog Updated \n'
-                         'Total time: %s\n'
-                         'Total CPU time: %s' % (`elapse`, `c_elapse`)))
-    ###)
-
-    def refreshCatalog(self, clear=1, pghandler=None): ###(
-        """ re-index everything we can find """
-        students_folder = self.portal_url.getPortalObject().campus.students
-        if clear:
-            self._catalog.clear()
-        course_results = self.portal_catalog(portal_type="StudentCourseResult")
-        num_objects = len(course_results)
-        if pghandler:
-            pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects)
-        #import pdb;pdb.set_trace()
-        for i in xrange(num_objects):
-            if pghandler:
-                pghandler.report(i)
-            course_result_brain = course_results[i]
-            path_list = course_result_brain.getPath().split('/')
-            course_result_doc = course_result_brain.getObject().getContent()
-            data = {}
-            level_id = path_list[-2]
-            course_id = path_list[-1]
-            student_id = path_list[-4]
-            for field in self.schema():
-                data[field] = getattr(course_result_doc,field,'')
-            data['key'] = key = "%(student_id)s|%(level_id)s|%(course_id)s" % vars()
-            data['student_id'] = student_id
-            data['level_id'] = level_id
-            data['queue_status'] = OBJECT_CREATED
-            self.catalog_object(dict2ob(data), uid=key)
-        if pghandler: pghandler.finish()
-    ###)
-
-    security.declarePrivate('notify_event_listener') ###(
-    def notify_event_listener(self,event_type,object,infos):
-        "listen for events"
-        if not infos.has_key('rpath'):
-            return
-        pt = getattr(object,'portal_type',None)
-        mt = getattr(object,'meta_type',None)
-        data = {}
-        rpl = infos['rpath'].split('/')
-        if mt == 'CPS Proxy Folder':
-            return
-        if pt == 'StudentCourseResult' and event_type == "sys_modify_object":
-            data["%s" % self.key] = uid = "%s|%s|%s" % (rpl[-5],rpl[-3],rpl[-2])
-            records = self.searchResults({"%s" % self.key : uid})
-            if len(records) > 1:
-                # Can not happen, but anyway...
-                raise ValueError("More than one record with uid %s" % uid)
-            if len(records) == 0:
-                raise KeyError("No record for uid %s" % uid)
-            record = records[0]
-            for field in ('core_or_elective','score'):
-                value = getattr(object,field,None)
-                data[field] = value
-            try:
-                self.modifyRecord(record,**data)
-            except KeyError:
-                pass
-        if pt == 'StudentStudyLevel' and event_type == "sys_del_object":
-            #import pdb;pdb.set_trace()
-            student_id = rpl[-3]
-            level_id = rpl[-1]
-            res = self.searchResults(student_id = student_id,
-                                     level_id = level_id)
-            for cr in res:
-                self.deleteRecord(cr.key)
-    ###)
-
 InitializeClass(CourseResults)
 ###)
