Changeset 2434 for WAeUP_SRP/base
- Timestamp:
- 25 Oct 2007, 14:35:59 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/base/WAeUPTables.py
r2396 r2434 1297 1297 self._queue = [] 1298 1298 1299 def addRecord(self, **data): ###(1300 """add one record"""1301 1302 uid = key = "%(student_id)s|%(level_id)s|%(course_id)s" % data1303 if key in self._queue:1304 return uid1305 data['queue_status'] = ADDING_SHEDULED1306 data['%s' % self.key] = uid1307 res = self.searchResults({"%s" % self.key : uid})1308 if len(res) > 0:1309 raise ValueError("More than one record with uid %s" % uid)1310 self.catalog_object(dict2ob(data), uid=uid)1311 if not hasattr(self,'_queue'):1312 self._queue = []1313 self._queue.append(key)1314 self._p_changed = 11315 return uid1316 ###)1317 1318 # def _p_resolveConflict(self, oldstate, committed, newstate):1319 # # Apply the changes made in going from old to newstate to1320 # # committed1321 1322 # # Note that in the case of undo, the olddata is the data for1323 # # the transaction being undone and newdata is the data for the1324 # # transaction previous to the undone transaction.1325 1326 # # Find the conflict policy on the new state to make sure changes1327 # # to it will be applied1328 1329 # # Committed is always the currently committed data.1330 # import pdb;pdb.set_trace()1331 # oldstate_data = oldstate['_queue']1332 # committed_data = committed['_queue']1333 # newstate_data = newstate['_queue']1334 1335 # # Merge newstate changes into committed1336 # for uid, new in newstate_data.items():1337 1338 # # Decide if this is a change1339 # old = oldstate_data.get(uid)1340 # current = committed_data.get(uid)1341 1342 1343 1299 def addMultipleRecords(self, records): ###( 1344 1300 """add many records""" … … 1346 1302 for data in records: 1347 1303 uid = key = "%(student_id)s|%(level_id)s|%(course_id)s" % data 1348 added_keys.append(key)1349 if key in self._queue:1350 return uid1351 data['queue_status'] = ADDING_SHEDULED1352 1304 data['%s' % self.key] = uid 1353 1305 res = self.searchResults({"%s" % self.key : uid}) … … 1355 1307 raise ValueError("More than one record with uid %s" % uid) 1356 1308 self.catalog_object(dict2ob(data), uid=uid) 1357 if not hasattr(self,'_queue'):1358 self._queue = added_keys1359 self._queue.extend(added_keys)1360 self._p_changed = 11361 1309 return uid 1362 1310 ###) 1363 1311 1364 def deleteRecord(self, uid): ###( 1365 self.uncatalog_object(uid) 1366 if uid in self._queue: 1367 self._queue.remove(uid) 1368 ###) 1369 1370 def updateCourseResults(self,student_id,level_id,portal_catalog_results,course_results): ###( 1371 # query = Eq('path',"%s/campus/students/%s/study_course/%s" % 1372 # (self.portal_url.getPortalPath(), 1373 # student_id, 1374 # level_id)) &\ 1375 # Eq('portal_type', "StudentCourseResult") 1376 # level_results = self.portal_catalog_real.evalAdvancedQuery(query) 1377 # level_results = [r for r in course_results 1378 # if level_id in r.relative_path.split('/')] 1379 course_results_ids = [cr.getId for cr in course_results] 1380 for r in portal_catalog_results: 1381 if r.getId in course_results_ids: 1312 def deleteResultsHere(self,level_id,student_id): ###( 1313 #import pdb;pdb.set_trace() 1314 query = Eq('student_id',student_id) & Eq('level_id', level_id) 1315 course_results = self.course_results.evalAdvancedQuery(query) 1316 for result in course_results: 1317 self.deleteRecord(result.key) 1318 ###) 1319 1320 def moveResultsHere(self,level,student_id): ###( 1321 #import pdb;pdb.set_trace() 1322 level_id = level.getId() 1323 query = Eq('student_id',student_id) & Eq('level_id', level_id) 1324 course_results = self.course_results.evalAdvancedQuery(query) 1325 existing_courses = [cr.code for cr in course_results] 1326 to_delete = [] 1327 for code,obj in level.objectItems(): 1328 to_delete += code 1329 carry_over = False 1330 if code.endswith('_co'): 1331 carry_over = True 1332 code = code[:-3] 1333 if code in existing_courses: 1382 1334 continue 1383 course_result_doc = r.getObject().getContent()1335 course_result_doc = obj.getContent() 1384 1336 data = {} 1385 course_id = r.getId1337 course_id = code 1386 1338 for field in self.schema(): 1387 1339 data[field] = getattr(course_result_doc,field,'') … … 1389 1341 data['student_id'] = student_id 1390 1342 data['level_id'] = level_id 1391 data['queue_status'] = OBJECT_CREATED1343 #data['queue_status'] = OBJECT_CREATED 1392 1344 data['code'] = course_id 1345 data['carry_over'] = carry_over 1393 1346 self.catalog_object(dict2ob(data), uid=key) 1347 level.manage_delObjects(to_delete) 1348 ###) 1349 1350 def getCourses(self,student_id,level_id): ###( 1394 1351 query = Eq('student_id',student_id) & Eq('level_id', level_id) 1395 return self.course_results.evalAdvancedQuery(query) 1396 ###) 1397 1398 def getCourses(self,student_id,level_id): ###( 1352 course_results = self.course_results.evalAdvancedQuery(query) 1353 carry_overs = [] 1354 normal = [] 1355 credits = 0 1356 for brain in course_results: 1357 d = {} 1358 credits += int(brain.credits) 1359 for field in self.schema(): 1360 d[field] = getattr(brain,field,'') 1361 #d['sheduled'] = brain.queue_status == ADDING_SHEDULED 1362 d['coe'] = 'Elective' 1363 if brain.core_or_elective: 1364 d['coe'] = 'Core' 1365 id = code = d['id'] = brain.code 1366 is_carry_over = False 1367 if code.endswith('_co'): 1368 is_carry_over = True 1369 code = code[:-3] 1370 d['code'] = code 1371 d['title'] = self.courses_catalog.evalAdvancedQuery(Eq('code',code))[0].title 1372 if is_carry_over: 1373 d['coe'] = 'Core' 1374 carry_overs.append(d) 1375 else: 1376 normal.append(d) 1377 normal.sort(cmp=lambda x,y: cmp(x['semester'], y['semester'])) 1378 carry_overs.sort(cmp=lambda x,y: cmp(x['semester'], y['semester'])) 1379 return credits,carry_overs,normal 1380 ###) 1381 1382 def queue_getCourses(self,student_id,level_id): ###( 1399 1383 level_path = "%s/campus/students/%s/study_course/%s" % (self.portal_url.getPortalPath(), 1400 1384 student_id, … … 1441 1425 ###) 1442 1426 1443 def addObject(self,record): ###(1444 key = record.key1445 student_id,level_id,course_id = key.split('|')1446 level = getattr(getattr(self.portal_url.getPortalObject().campus.students,student_id).study_course,level_id)1447 cr_id = level.invokeFactory('StudentCourseResult', course_id)1448 course_result = getattr(level,cr_id)1449 self.portal_workflow.doActionFor(course_result,'open')1450 d = {}1451 for field in self.schema():1452 d[field] = getattr(record,field,'')1453 course_result.getContent().edit(mapping=d)1454 ###)1455 1456 security.declareProtected(ModifyPortalContent,"process_queue") ###(1457 def process_queue(self,limit=None):1458 """adds objects and removes them from the queue.1459 If limit is specified, at most (limit) events are removed.1460 """1461 if not hasattr(self,'_queue'):1462 return 01463 queue= self._queue1464 if not limit or len(queue) <= limit:1465 keys = self._queue[:]1466 else:1467 keys = queue[:limit]1468 if not keys:1469 records = self.evalAdvancedQuery(Eq('queue_status',ADDING_SHEDULED))1470 else:1471 records = self.evalAdvancedQuery(In("%s" % self.key,keys))1472 for record in records:1473 if record.queue_status == OBJECT_CREATED:1474 continue1475 self.addObject(record)1476 data = {}1477 data['key'] = record.key1478 data['queue_status'] = OBJECT_CREATED1479 self.modifyRecord(**data)1480 count = 01481 for key in keys:1482 count +=11483 if key in self._queue:1484 self._queue.remove(key)1485 self._p_changed = 11486 return count,len(self._queue)1487 ###)1488 1489 def manage_catalogClear(self, REQUEST=None, RESPONSE=None, URL1=None): ###(1490 """ clears the whole enchilada """1491 self._catalog.clear()1492 1493 if REQUEST and RESPONSE:1494 RESPONSE.redirect(1495 URL1 +1496 '/manage_catalogAdvanced?manage_tabs_message=Catalog%20Cleared')1497 ###)1498 1499 def manage_catalogReindex(self, REQUEST, RESPONSE, URL1): ###(1500 """ clear the catalog, then re-index everything """1501 1502 elapse = time.time()1503 c_elapse = time.clock()1504 1505 pgthreshold = self._getProgressThreshold()1506 handler = (pgthreshold > 0) and ZLogHandler(pgthreshold) or None1507 self.refreshCatalog(clear=1, pghandler=handler)1508 1509 elapse = time.time() - elapse1510 c_elapse = time.clock() - c_elapse1511 1512 RESPONSE.redirect(1513 URL1 +1514 '/manage_catalogAdvanced?manage_tabs_message=' +1515 urllib.quote('Catalog Updated \n'1516 'Total time: %s\n'1517 'Total CPU time: %s' % (`elapse`, `c_elapse`)))1518 ###)1519 1520 def refreshCatalog(self, clear=1, pghandler=None): ###(1521 """ re-index everything we can find """1522 students_folder = self.portal_url.getPortalObject().campus.students1523 if clear:1524 self._catalog.clear()1525 course_results = self.portal_catalog(portal_type="StudentCourseResult")1526 num_objects = len(course_results)1527 if pghandler:1528 pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects)1529 #import pdb;pdb.set_trace()1530 for i in xrange(num_objects):1531 if pghandler:1532 pghandler.report(i)1533 course_result_brain = course_results[i]1534 path_list = course_result_brain.getPath().split('/')1535 course_result_doc = course_result_brain.getObject().getContent()1536 data = {}1537 level_id = path_list[-2]1538 course_id = path_list[-1]1539 student_id = path_list[-4]1540 for field in self.schema():1541 data[field] = getattr(course_result_doc,field,'')1542 data['key'] = key = "%(student_id)s|%(level_id)s|%(course_id)s" % vars()1543 data['student_id'] = student_id1544 data['level_id'] = level_id1545 data['queue_status'] = OBJECT_CREATED1546 self.catalog_object(dict2ob(data), uid=key)1547 if pghandler: pghandler.finish()1548 ###)1549 1550 security.declarePrivate('notify_event_listener') ###(1551 def notify_event_listener(self,event_type,object,infos):1552 "listen for events"1553 if not infos.has_key('rpath'):1554 return1555 pt = getattr(object,'portal_type',None)1556 mt = getattr(object,'meta_type',None)1557 data = {}1558 rpl = infos['rpath'].split('/')1559 if mt == 'CPS Proxy Folder':1560 return1561 if pt == 'StudentCourseResult' and event_type == "sys_modify_object":1562 data["%s" % self.key] = uid = "%s|%s|%s" % (rpl[-5],rpl[-3],rpl[-2])1563 records = self.searchResults({"%s" % self.key : uid})1564 if len(records) > 1:1565 # Can not happen, but anyway...1566 raise ValueError("More than one record with uid %s" % uid)1567 if len(records) == 0:1568 raise KeyError("No record for uid %s" % uid)1569 record = records[0]1570 for field in ('core_or_elective','score'):1571 value = getattr(object,field,None)1572 data[field] = value1573 try:1574 self.modifyRecord(record,**data)1575 except KeyError:1576 pass1577 if pt == 'StudentStudyLevel' and event_type == "sys_del_object":1578 #import pdb;pdb.set_trace()1579 student_id = rpl[-3]1580 level_id = rpl[-1]1581 res = self.searchResults(student_id = student_id,1582 level_id = level_id)1583 for cr in res:1584 self.deleteRecord(cr.key)1585 ###)1586 1587 1427 InitializeClass(CourseResults) 1588 1428 ###)
Note: See TracChangeset for help on using the changeset viewer.