Changeset 2094
- Timestamp:
- 13 Aug 2007, 12:01:11 (17 years ago)
- Location:
- WAeUP_SRP/trunk
- Files:
-
- 3 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/trunk/WAeUPTables.py
r2084 r2094 25 25 from AccessControl import ClassSecurityInfo 26 26 from Products.CMFCore.permissions import ModifyPortalContent 27 from Products.CMFCore.utils import getToolByName 28 from Products.CMFCore.CatalogTool import CatalogTool 29 from Products.CPSSchemas.StorageAdapter import MappingStorageAdapter 30 from Products.CPSSchemas.DataStructure import DataStructure 31 from Products.CPSSchemas.DataModel import DataModel 32 from Products.AdvancedQuery import Eq, Between, Le,In 27 33 import urllib 28 34 import DateTime,time … … 32 38 p_home = Globals.package_home(globals()) 33 39 i_home = Globals.INSTANCE_HOME 34 from Products.CMFCore.CatalogTool import CatalogTool35 from Products.AdvancedQuery import Eq, Between, Le,In36 40 37 41 ADDING_SHEDULED = "adding_sheduled" … … 53 57 implements(IWAeUPTable) 54 58 security = ClassSecurityInfo() 55 56 def refreshCatalog(self, clear=0, pghandler=None): 59 meta_type = None 60 61 def __init__(self,name=None): 62 if name == None: 63 name = self.name 64 ZCatalog.__init__(self,name) 65 66 def refreshCatalog(self, clear=0, pghandler=None): ###( 57 67 """ don't refresh for a normal table """ 58 68 … … 62 72 '/manage_catalogAdvanced?manage_tabs_message=Catalog%20refresh%20not%20implemented') 63 73 64 def manage_catalogClear(self, REQUEST=None, RESPONSE=None, URL1=None): 74 ###) 75 76 def manage_catalogClear(self, REQUEST=None, RESPONSE=None, URL1=None): ###( 65 77 """ clears the whole enchilada """ 66 78 … … 76 88 '/manage_catalogAdvanced?manage_tabs_message=Catalog%20cleared') 77 89 78 def addRecord(self, **data): 90 ###) 91 92 def addRecord(self, **data): ###( 79 93 # The uid is the same as "bed". 80 94 uid = data[self.key] … … 85 99 return uid 86 100 101 ###) 102 87 103 def deleteRecord(self, uid): 88 104 self.uncatalog_object(uid) … … 91 107 raise NotImplemented 92 108 93 def modifyRecord(self, record=None, **data): 109 def modifyRecord(self, record=None, **data): ###( 94 110 #records = self.searchResults(uid=uid) 95 111 uid = data[self.key] … … 109 125 self.catalog_object(dict2ob(record_data), uid) 110 126 111 def reindexIndex(self, name, REQUEST,pghandler=None): 127 ###) 128 129 def reindexIndex(self, name, REQUEST,pghandler=None): ###( 112 130 if isinstance(name, str): 113 name = (name,)131 name = (name,) 114 132 paths = self._catalog.uids.items() 115 133 i = 0 … … 125 143 update_metadata=0) 126 144 127 security.declareProtected(ModifyPortalContent,"exportAllRecords") 145 ###) 146 147 security.declareProtected(ModifyPortalContent,"exportAllRecords") ###( 128 148 def exportAllRecords(self): 129 149 "export a WAeUPTable" … … 144 164 current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") 145 165 open("%s/import/%s-%s.csv" % (i_home,self.getId(),current),"w+").write('\n'.join(csv)) 146 ###) 166 167 ###) 168 169 security.declarePrivate("_import") ###( 170 def _import(self,filename,schema,layout, mode,logger): 171 "import data from csv" 172 import transaction 173 import random 174 pm = self.portal_membership 175 member = pm.getAuthenticatedMember() 176 current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") 177 import_fn = "%s/import/%s.csv" % (i_home,filename) 178 imported_fn = "%s/import/%s_imported%s.csv" % (i_home,filename,current) 179 not_imported_fn = "%s/import/%s_not_imported%s.csv" % (i_home,filename,current) 180 start = True 181 tr_count = 1 182 total_imported = 0 183 total_not_imported = 0 184 total = 0 185 iname = "%s" % filename 186 if schema is None: 187 em = 'No schema specified' 188 logger.error(em) 189 return em 190 if layout is None: 191 em = 'No layout specified' 192 logger.error(em) 193 return em 194 validators = {} 195 for widget in layout.keys(): 196 validators[widget] = layout[widget].validate 197 # if mode == 'edit': 198 # importer = self.importEdit 199 # elif mode == 'add': 200 # importer = self.importAdd 201 # else: 202 # importer = None 203 not_imported = [] 204 imported = [] 205 valid_records = [] 206 invalid_records = [] 207 d = {} 208 d['mode'] = mode 209 d['imported'] = total_imported 210 d['not_imported'] = total_not_imported 211 d['valid_records'] = valid_records 212 d['invalid_records'] = invalid_records 213 d['import_fn'] = import_fn 214 d['imported_fn'] = imported_fn 215 d['not_imported_fn'] = not_imported_fn 216 try: 217 items = csv.DictReader(open(import_fn,"rb")) 218 except: 219 em = 'Error reading %s.csv' % filename 220 logger.error(em) 221 return d 222 for item in items: 223 if start: 224 start = False 225 logger.info('%s starts import from %s.csv' % (member,filename)) 226 #import_keys = [k for k in item.keys() if not k.startswith('ignore')] 227 attrs = csv.reader(open("%s/import/%s.csv" % (i_home,filename),"rb")).next() 228 import_keys = [k for k in attrs if not (k.startswith('ignore') or k.isupper())] 229 diff2schema = set(import_keys).difference(set(schema.keys())) 230 diff2layout = set(import_keys).difference(set(layout.keys())) 231 if diff2layout: 232 em = "not ignorable key(s) %s found in heading" % diff2layout 233 logger.info(em) 234 return d 235 s = ','.join(['"%s"' % fn for fn in import_keys]) 236 open(not_imported_fn,"a").write(s + ',"Error"'+ '\n') 237 #s = '"id",' + s 238 open(imported_fn,"a").write(s + '\n') 239 format = ','.join(['"%%(%s)s"' % fn for fn in import_keys]) 240 format_error = format + ',"%(Error)s"' 241 #format = '"%(id)s",'+ format 242 adapters = [MappingStorageAdapter(schema, item)] 243 dm = DataModel(item, adapters,context=self) 244 ds = DataStructure(data=item,datamodel=dm) 245 error_string = "" 246 for k in import_keys: 247 if not validators[k](ds,mode=mode): 248 error_string += " %s : %s" % (k,ds.getError(k)) 249 # if not error_string and importer: 250 # item.update(dm) 251 # item['id'],error = importer(item) 252 # if error: 253 # error_string += error 254 if error_string: 255 item['Error'] = error_string 256 invalid_records.append(dm) 257 not_imported.append(format_error % item) 258 total_not_imported += 1 259 else: 260 em = format % item 261 valid_records.append(dm) 262 imported.append(em) 263 #logger.info("%(total_imported)d of %(total)d %(em)s" % vars()) 264 tr_count += 1 265 total_imported += 1 266 total += 1 267 # if importer and total_imported and not total_imported % 1000: 268 # transaction.commit() 269 # if len(not_imported) > 0: 270 # open(not_imported_fn,"a").write('\n'.join(not_imported) + '\n') 271 # not_imported = [] 272 # if len(imported) > 0: 273 # open(imported_fn,"a").write('\n'.join(imported) + '\n') 274 # imported = [] 275 # em = '%d transactions committed\n' % (tr_count) 276 # regs = [] 277 # logger.info(em) 278 # tr_count = 0 279 if len(imported) > 0: 280 open(imported_fn,"a").write('\n'.join(imported)) 281 if len(not_imported) > 0: 282 open(not_imported_fn,"a").write('\n'.join(not_imported)) 283 #em = "Imported: %d, not imported: %d of total %d" % (total_imported,total_not_imported,total) 284 d['imported'] = total_imported 285 d['not_imported'] = total_not_imported 286 d['valid_records'] = valid_records 287 d['invalid_records'] = invalid_records 288 d['imported_fn'] = imported_fn 289 d['not_imported_fn'] = not_imported_fn 290 #logger.info(em) 291 return d 292 ###) 293 ###) 147 294 148 295 class AccommodationTable(WAeUPTable): ###( 149 296 150 297 meta_type = 'WAeUP Accommodation Tool' 151 name = " accommodation"298 name = "portal_accommodation" 152 299 key = "bed" 153 def __init__(self): 154 WAeUPTable.__init__(self, 'portal_accommodation') 300 def __init__(self,name=None): 301 if name == None: 302 name = self.name 303 WAeUPTable.__init__(self, name) 155 304 156 305 def searchAndReserveBed(self, student_id,bed_type): … … 177 326 from ZODB.POSException import ConflictError 178 327 meta_type = 'WAeUP Pin Tool' 179 name = "p ins"328 name = "portal_pins" 180 329 key = 'pin' 181 def __init__(self): 182 WAeUPTable.__init__(self, 'portal_pins') 330 def __init__(self,name=None): 331 if name == None: 332 name = self.name 333 WAeUPTable.__init__(self, name) 183 334 184 335 … … 222 373 223 374 meta_type = 'WAeUP PumeResults Tool' 224 name = "p umeresults"375 name = "portal_pumeresults" 225 376 key = "jamb_reg_no" 226 def __init__(self): 227 WAeUPTable.__init__(self, 'portal_pumeresults') 377 def __init__(self,name=None): 378 if name == None: 379 name = self.name 380 WAeUPTable.__init__(self, name) 228 381 229 382 230 383 InitializeClass(PumeResultsTable) 384 385 ###) 386 387 class ApplicantsCatalog(WAeUPTable): ###( 388 389 meta_type = 'New Students' 390 name = "applicants_catalog" 391 key = "reg_no" 392 security = ClassSecurityInfo() 393 394 def __init__(self,name=None): 395 if name == None: 396 name = self.name 397 WAeUPTable.__init__(self, name) 398 399 security.declareProtected(ModifyPortalContent,"importCSV")###( 400 def importCSV(self,filename="JAMB_data", 401 schema_id="application", 402 layout_id="application", 403 mode='add'): 404 """ import JAMB data """ 405 stool = getToolByName(self, 'portal_schemas') 406 ltool = getToolByName(self, 'portal_layouts') 407 schema = stool._getOb(schema_id) 408 if schema is None: 409 em = 'No such schema %s' % schema_id 410 logger.error(em) 411 return 412 layout = ltool._getOb(layout_id) 413 if layout is None: 414 em = 'No such layout %s' % layout_id 415 logger.error(em) 416 return 417 logger = logging.getLogger('WAeUPTables.Applicants.importCSV') 418 d = self._import(filename,schema,layout,mode,logger) 419 if len(d['valid_records']) > 0: 420 for record in d['valid_records']: 421 #import pdb;pdb.set_trace() 422 if mode == "add": 423 self.addRecord(**dict(record.items())) 424 logger.info("added %s" % record.items()) 425 elif mode == "edit": 426 self.modifyRecord(**dict(record.items())) 427 logger.info("edited %s" % record.items()) 428 else: 429 logger.info("invalid mode: %s" % mode) 430 logger.info("%(mode)sed %(imported)d records, invalid written to %(not_imported_fn)s" % d) 431 ###) 432 433 InitializeClass(ApplicantsCatalog) 231 434 232 435 ###) … … 281 484 ###) 282 485 283 def __init__(self): 284 WAeUPTable.__init__(self, 'students_catalog') 486 def __init__(self,name=None): 487 if name == None: 488 name = self.name 489 WAeUPTable.__init__(self, name) 285 490 return 286 491 … … 657 862 658 863 meta_type = 'WAeUP Courses Catalog' 659 name = "courses_catalog"864 name = "courses_catalog" 660 865 key = "code" 661 def __init__(self): 662 WAeUPTable.__init__(self, 'courses_catalog') 866 def __init__(self,name=None): 867 if name == None: 868 name = self.name 869 WAeUPTable.__init__(self, name) 663 870 664 871 def manage_catalogReindex(self, REQUEST, RESPONSE, URL1): ###( … … 792 999 name = "course_results" 793 1000 key = "key" #student_id + level + course_id 794 def __init__(self): 795 WAeUPTable.__init__(self, 'course_results') 1001 def __init__(self,name=None): 1002 if name == None: 1003 name = self.name 1004 WAeUPTable.__init__(self, name) 796 1005 self._queue = [] 797 1006 798 1007 def addRecord(self, **data): ###( 799 # The uid is the same as "bed". 1008 """add one record""" 1009 800 1010 uid = key = "%(student_id)s|%(level_id)s|%(course_id)s" % data 801 1011 if key in self._queue: … … 813 1023 return uid 814 1024 ###) 1025 1026 # def _p_resolveConflict(self, oldstate, committed, newstate): 1027 # # Apply the changes made in going from old to newstate to 1028 # # committed 1029 1030 # # Note that in the case of undo, the olddata is the data for 1031 # # the transaction being undone and newdata is the data for the 1032 # # transaction previous to the undone transaction. 1033 1034 # # Find the conflict policy on the new state to make sure changes 1035 # # to it will be applied 1036 1037 # # Committed is always the currently committed data. 1038 # import pdb;pdb.set_trace() 1039 # oldstate_data = oldstate['_queue'] 1040 # committed_data = committed['_queue'] 1041 # newstate_data = newstate['_queue'] 1042 1043 # # Merge newstate changes into committed 1044 # for uid, new in newstate_data.items(): 1045 1046 # # Decide if this is a change 1047 # old = oldstate_data.get(uid) 1048 # current = committed_data.get(uid) 1049 1050 1051 def addMultipleRecords(self, records): ###( 1052 """add many records""" 1053 added_keys = [] 1054 for data in records: 1055 uid = key = "%(student_id)s|%(level_id)s|%(course_id)s" % data 1056 added_keys.append(key) 1057 if key in self._queue: 1058 return uid 1059 data['queue_status'] = ADDING_SHEDULED 1060 data['%s' % self.key] = uid 1061 res = self.searchResults({"%s" % self.key : uid}) 1062 if len(res) > 0: 1063 raise ValueError("More than one record with uid %s" % uid) 1064 self.catalog_object(dict2ob(data), uid=uid) 1065 if not hasattr(self,'_queue'): 1066 self._queue = added_keys 1067 self._queue.extend(added_keys) 1068 self._p_changed = 1 1069 return uid 1070 ###) 815 1071 816 1072 def deleteRecord(self, uid): ###( … … 820 1076 ###) 821 1077 1078 def updateCourseResults(self,student_id,level_id,portal_catalog_results,course_results): ###( 1079 # query = Eq('path',"%s/campus/students/%s/study_course/%s" % 1080 # (self.portal_url.getPortalPath(), 1081 # student_id, 1082 # level_id)) &\ 1083 # Eq('portal_type', "StudentCourseResult") 1084 # level_results = self.portal_catalog_real.evalAdvancedQuery(query) 1085 # level_results = [r for r in course_results 1086 # if level_id in r.relative_path.split('/')] 1087 course_results_ids = [cr.getId for cr in course_results] 1088 for r in portal_catalog_results: 1089 if r.getId in course_results_ids: 1090 continue 1091 course_result_doc = r.getObject().getContent() 1092 data = {} 1093 course_id = r.getId 1094 for field in self.schema(): 1095 data[field] = getattr(course_result_doc,field,'') 1096 data['key'] = key = "%(student_id)s|%(level_id)s|%(course_id)s" % vars() 1097 data['student_id'] = student_id 1098 data['level_id'] = level_id 1099 data['queue_status'] = OBJECT_CREATED 1100 data['code'] = course_id 1101 self.catalog_object(dict2ob(data), uid=key) 1102 query = Eq('student_id',student_id) & Eq('level_id', level_id) 1103 return self.course_results.evalAdvancedQuery(query) 1104 ###) 1105 822 1106 def getCourses(self,student_id,level_id): ###( 1107 level_path = "%s/campus/students/%s/study_course/%s" % (self.portal_url.getPortalPath(), 1108 student_id, 1109 level_id) 1110 # portal_catalog_query = Eq('path',level_path) &\ 1111 # Eq('portal_type', "StudentCourseResult") 1112 # portal_catalog_results = self.portal_catalog_real.evalAdvancedQuery(portal_catalog_query) 1113 portal_catalog_results = self.portal_catalog(path = level_path, 1114 portal_type = "StudentCourseResult") 823 1115 query = Eq('student_id',student_id) & Eq('level_id', level_id) 1116 course_results = self.course_results.evalAdvancedQuery(query) 1117 if len(course_results) != len(portal_catalog_results): 1118 course_results = self.updateCourseResults(student_id, 1119 level_id, 1120 portal_catalog_results, 1121 course_results) 824 1122 carry_overs = [] 825 1123 normal = [] 826 1124 credits = 0 827 for brain in self.course_results.evalAdvancedQuery(query):1125 for brain in course_results: 828 1126 d = {} 829 1127 credits += int(brain.credits) … … 834 1132 if brain.core_or_elective: 835 1133 d['coe'] = 'Core' 836 d['title'] = self.courses_catalog.evalAdvancedQuery(Eq('code',brain.code))[0].title 837 if brain.code.endswith('_co'): 1134 id = code = d['id'] = brain.code 1135 is_carry_over = False 1136 if code.endswith('_co'): 1137 is_carry_over = True 1138 code = code[:-3] 1139 d['code'] = code 1140 d['title'] = self.courses_catalog.evalAdvancedQuery(Eq('code',code))[0].title 1141 if is_carry_over: 1142 d['coe'] = 'Core' 838 1143 carry_overs.append(d) 839 1144 else: … … 936 1241 course_result_brain = course_results[i] 937 1242 path_list = course_result_brain.getPath().split('/') 938 course_result_object = course_result_brain.getObject() 939 course_result_doc = course_result_object.getContent() 1243 course_result_doc = course_result_brain.getObject().getContent() 940 1244 data = {} 941 1245 level_id = path_list[-2] … … 972 1276 raise KeyError("No record for uid %s" % uid) 973 1277 record = records[0] 974 #import pdb;pdb.set_trace()975 1278 for field in ('core_or_elective','score'): 976 1279 value = getattr(object,field,None) 977 1280 data[field] = value 978 self.modifyRecord(record,**data) 1281 try: 1282 self.modifyRecord(record,**data) 1283 except KeyError: 1284 pass 1285 if pt == 'StudentStudyLevel' and event_type == "sys_del_object": 1286 #import pdb;pdb.set_trace() 1287 student_id = rpl[-3] 1288 level_id = rpl[-1] 1289 res = self.searchResults(student_id = student_id, 1290 level_id = level_id) 1291 for cr in res: 1292 self.deleteRecord(cr.key) 979 1293 ###) 980 1294 … … 987 1301 name = "online_payments_import" 988 1302 key = "order_id" 989 def __init__(self): 990 WAeUPTable.__init__(self, self.name) 1303 def __init__(self,name=None): 1304 if name == None: 1305 name = self.name 1306 WAeUPTable.__init__(self, name) 991 1307 992 1308 … … 999 1315 name = "returning_import" 1000 1316 key = "matric_no" 1001 def __init__(self): 1002 WAeUPTable.__init__(self, 'returning_import') 1317 def __init__(self,name=None): 1318 if name == None: 1319 name = self.name 1320 WAeUPTable.__init__(self, name) 1003 1321 1004 1322 … … 1011 1329 name = "results_import" 1012 1330 key = "key" 1013 def __init__(self): 1014 WAeUPTable.__init__(self, 'results_import') 1331 def __init__(self,name=None): 1332 if name == None: 1333 name = self.name 1334 WAeUPTable.__init__(self, name) 1015 1335 1016 1336 … … 1024 1344 name = "students_catalog" 1025 1345 key = "id" 1026 def __init__(self): 1027 WAeUPTable.__init__(self, 'payments_catalog') 1346 def __init__(self,name=None): 1347 if name == None: 1348 name = self.name 1349 WAeUPTable.__init__(self, name) 1028 1350 1029 1351 -
WAeUP_SRP/trunk/WAeUPTool.py
r2052 r2094 44 44 p_home = package_home(globals()) 45 45 i_home = INSTANCE_HOME 46 import DateTime 46 import DateTime,time 47 47 import logging 48 48 import transaction … … 95 95 96 96 ###) 97 98 security.declareProtected(ModifyPortalContent,'measureOaT') ###( 99 def measureOaT(self,method="a",probe="1000",nr_pts="1"): 100 """measure Object access Time""" 101 import random 102 if hasattr(self,'portal_catalog_real'): 103 aq_portal = self.portal_catalog_real.evalAdvancedQuery 104 else: 105 aq_portal = self.portal_catalog.evalAdvancedQuery 106 nr_pts = int(nr_pts) 107 probe = int(probe) 108 intervall = probe/10 109 objects = ("application","clearance","personal") 110 portal_types = ("StudentApplication","StudentClearance","StudentPersonal") 111 #i = random.randrange(num_objects) 112 count = 0 113 found = 0 114 not_found = 0 115 t_found = 0 116 t_not_found = 0 117 time_found = time_not_found = 0.0 118 t_time_found = t_time_not_found = 0.0 119 accessed = [] 120 t_min = 1000 121 t_max = 0 122 #import pdb;pdb.set_trace() 123 students = self.portal_catalog(portal_type="Student") 124 num_students = len(students) 125 if method == "d": 126 query = Eq('path','/uniben/campus/students') & In('portal_type',portal_types[:nr_pts]) 127 res = aq_portal(query) 128 brains = {} 129 for r in res: 130 sid = r.relative_path.split('/')[-2] 131 if brains.has_key(sid): 132 brains[sid][r.portal_type] = r 133 else: 134 brains[sid] = {r.portal_type : r} 135 brains_list = brains.keys() 136 num_objects = len(brains_list) 137 else: 138 num_objects = num_students 139 print "="*40 140 print "method: %s probes: %d nr_pts: %d num_objects: %d" % (method, 141 probe, 142 nr_pts, 143 num_objects) 144 print "nr found/not time found/not min/max" 145 elapse = time.time() 146 i_elapse = time.time() 147 c_elapse = time.clock() 148 for c in range(1,probe + 1): 149 i = random.randrange(num_objects) 150 if method in ('a','b','c'): 151 student_brain = students[i] 152 elif method == "d": 153 #import pdb;pdb.set_trace() 154 student_brain = brains[brains_list[i]] 155 if method == "c": 156 query = Eq('path',student_brain.getPath()) & In('portal_type',portal_types[:nr_pts]) 157 res = aq_portal(query) 158 this_portal_types = [r.portal_type for r in res] 159 for i in range(nr_pts): 160 oid = objects[i] 161 if method == "a": 162 try: 163 student_path = student_brain.getPath() 164 path = "%s/%s" % (student_path,oid) 165 doc = self.unrestrictedTraverse(path).getContent() 166 found += 1 167 i_time = time.time() - i_elapse 168 time_found += i_time 169 except: 170 not_found += 1 171 i_time = time.time() - i_elapse 172 time_not_found += i_time 173 pass 174 elif method == "b": 175 try: 176 student_object = student_brain.getObject() 177 doc = getattr(student_object,oid).getContent() 178 found += 1 179 i_time = time.time() - i_elapse 180 time_found += i_time 181 except: 182 i_time = time.time() - i_elapse 183 time_not_found += i_time 184 not_found += 1 185 pass 186 elif method == "c": 187 if portal_types[i] in this_portal_types: 188 found += 1 189 doc = res[this_portal_types.index(portal_types[i])].getObject().getContent() 190 i_time = time.time() - i_elapse 191 time_found += i_time 192 else: 193 not_found += 1 194 i_time = time.time() - i_elapse 195 time_not_found += i_time 196 elif method == "d": 197 if student_brain.has_key(portal_types[i]): 198 found += 1 199 doc = student_brain[portal_types[i]].getObject().getContent() 200 i_time = time.time() - i_elapse 201 time_found += i_time 202 else: 203 not_found += 1 204 i_time = time.time() - i_elapse 205 time_not_found += i_time 206 i_elapse = time.time() 207 if c and (c % intervall == 0): 208 #i_time = time.time() - i_elapse 209 t_per = 0.0 210 if found: 211 t_per = time_found/found 212 if t_per > t_max: 213 t_max = t_per 214 if t_per > 0.0 and t_per < t_min: 215 t_min = t_per 216 itf = 0.0 217 if found: 218 itf = time_found/found 219 itnf = 0.0 220 if not_found : 221 itnf = time_not_found / not_found 222 interval_time = time_found + time_not_found 223 s = "%(c)d: %(found)d/%(not_found)d " % vars() 224 s += "%(interval_time)6.2f %(itf)6.4f/%(itnf)6.4f " % vars() 225 s += "%(t_min)6.4f/%(t_max)6.4f" % vars() 226 print s 227 t_found += found 228 t_not_found += not_found 229 t_time_found += time_found 230 t_time_not_found += time_not_found 231 time_found = time_not_found = 0.0 232 found = not_found = 0 233 # t_found += found 234 # t_not_found += not_found 235 elapse = time.time() - elapse 236 itf = 0.0 237 if t_found: 238 itf = t_time_found/t_found 239 itnf = 0.0 240 if t_not_found: 241 itnf = t_time_not_found / t_not_found 242 #c_elapse = time.clock() - c_elapse 243 s = "%(probe)d: %(t_found)d/%(t_not_found)d " % vars() 244 s += "%(elapse)6.2f %(itf)6.4f/%(itnf)6.4f " % vars() 245 s += "%(t_min)6.4f/%(t_max)6.4f" % vars() 246 print "-"*40 247 print s 248 rel_found = float(t_found)/probe 249 rel_not_found = float(t_not_found)/probe 250 estimated_total_time = num_objects*(rel_found*itf + rel_not_found*itnf) 251 print estimated_total_time 252 ###) 97 253 98 254 security.declareProtected(ModifyPortalContent,'writeLog') ###( … … 1020 1176 start = False 1021 1177 adapters = [MappingStorageAdapter(schema, item)] 1022 dm = DataModel(item, adapters,context=self)1023 1178 logger.info('%s starts import from %s.csv' % (member,filename)) 1024 import_keys = [k for k in item.keys() if not k.startswith('ignore')] 1179 #import_keys = [k for k in item.keys() if not k.startswith('ignore')] 1180 attrs = csv.reader(open("%s/import/%s.csv" % (i_home,filename),"rb")).next() 1181 #import pdb;pdb.set_trace() 1182 import_keys = [k for k in attrs if not k.startswith('ignore')] 1025 1183 diff2schema = set(import_keys).difference(set(schema.keys())) 1026 1184 diff2layout = set(import_keys).difference(set(layout.keys())) … … 1035 1193 format_error = format + ',"%(Error)s"' 1036 1194 format = '"%(id)s",'+ format 1195 dm = DataModel(item, adapters,context=self) 1037 1196 ds = DataStructure(data=item,datamodel=dm) 1038 1197 error_string = "" -
WAeUP_SRP/trunk/Widgets.py
r2013 r2094 248 248 """WAeUP Session Widget.""" 249 249 meta_type = 'WAeUP Session Widget' 250 250 251 251 def _getSessions(self): 252 252 current_year = DateTime().year() … … 459 459 ###) 460 460 461 class WAeUPLGAWidget(CPSSelectWidget): ###( 462 """WAeUP LGA Widget.""" 463 meta_type = 'WAeUP LGA Widget' 464 _properties = CPSSelectWidget._properties + ( 465 {'id': 'state_field', 'type': 'string', 'mode': 'w', 466 'label': 'Name of the state field'}, 467 {'id': 'lga_field', 'type': 'string', 'mode': 'w', 468 'label': 'Name of the LGA Field (without state)'}, 469 ) 470 state_field = "state" 471 lga_field = "lga" 472 473 # XXX make a menu for the vocabulary. 474 vocabulary = 'local_gov_areas' 475 476 # Associating the widget label with an input area to improve the widget 477 # accessibility. 478 has_input_area = True 479 480 def _getLGAs(self): 481 voc = getattr(self.portal_vocabularies,self.vocabulary) 482 states = [] 483 lgas = [] 484 d = {} 485 for k,v in voc.items(): 486 parts = k.split('_') 487 state = parts[0] 488 lga = ' '.join(parts[1:]) 489 if state not in states: 490 states.append(state) 491 lgas.append(lga) 492 d[k] = v 493 return (d,states,lgas) 494 495 def validate(self, datastructure, **kw): 496 """Validate datastructure and update datamodel.""" 497 widget_id = self.getWidgetId() 498 value = datastructure[widget_id] 499 #import pdb;pdb.set_trace() 500 try: 501 v = str(value) 502 except ValueError: 503 datastructure.setError(widget_id, "'%s' not a valid lga key" % value) 504 return 0 505 v = v.lower() 506 combined,states,lgas = self._getLGAs() 507 one_field = False 508 if not self.state_field and not self.lga_field: 509 one_field = True 510 if v not in combined.keys(): 511 datastructure.setError(widget_id, "'%s' not a valid lga key" % v) 512 return 0 513 else: 514 if widget_id == self.state_field: 515 if v not in states: 516 datastructure.setError(widget_id, "'%s' not a valid state" % v) 517 return 0 518 elif widget_id == self.lga_field: 519 if v not in lgas: 520 datastructure.setError(widget_id, "'%s' not a valid lga" % v) 521 return 0 522 if datastructure[self.state_field]: 523 v = datastructure[self.state_field] + '_' + v 524 525 if self.is_required and not len(v): 526 datastructure.setError(widget_id, "lga required") 527 return 0 528 529 datamodel = datastructure.getDataModel() 530 if one_field: 531 datamodel[self.fields[0]] = v 532 else: 533 state = datastructure[self.state_field].lower() 534 lga = "_".join(datastructure[self.lga_field].lower().split()) 535 datamodel[self.fields[0]] = state + "_" + lga 536 return 1 537 538 def render(self, mode, datastructure, **kw): 539 """Render in mode from datastructure.""" 540 w_id = self 541 value = datastructure[self.getWidgetId()] 542 lgas,x,y = self._getLGAs(datastructure) 543 if mode == 'view': 544 return escape(lgas.get(value, value)) 545 elif mode == 'edit': 546 html_widget_id = self.getHtmlWidgetId() 547 res = renderHtmlTag('select', name=html_widget_id, id=html_widget_id) 548 in_selection = 0 549 vocabulary_items = lgas.items() 550 # if self.sorted: 551 # vocabulary_items.sort(key=operator.itemgetter(1)) 552 for k, v in vocabulary_items: 553 kw = {'value': k, 'contents': v} 554 if value == k: 555 kw['selected'] = 'selected' 556 in_selection = 1 557 res += renderHtmlTag('option', **kw) 558 if value and not in_selection: 559 kw = {'value': value, 'contents': 'invalid: '+ str(value), 560 'selected': 'selected'} 561 res += renderHtmlTag('option', **kw) 562 res += '</select>' 563 return res 564 raise RuntimeError('unknown mode %s' % mode) 565 566 InitializeClass(WAeUPLGAWidget) 567 568 widgetRegistry.register(WAeUPLGAWidget) 569 570 ###) 571 461 572 class WAeUPReservedRoomsWidget(CPSStringWidget): ###( 462 573 """ WAeUPReservedRooms Widget""" … … 590 701 value = datastructure[widget_id].upper() 591 702 err = 0 592 if not valid: #or not (len(value) == self.digits + self.letters and value[:self.digits].isdigit() and value[self.digits:].isalpha()): 593 #err = 'Invalid number, the expected format is: %s%s with N = Number, L = Letter' % (self.digits_str,self.letters_str) 703 #import pdb;pdb.set_trace() 704 if kw.has_key('mode'): 705 mode = kw['mode'] 706 else: 707 mode = "xxxx" 708 if not valid: 594 709 err = 'Invalid number' 595 710 elif self.reference == '': … … 600 715 else: 601 716 datastructure['pume'] = pume[0] 602 else: 603 #import pdb;pdb.set_trace() 717 elif mode == 'add': 718 pass 719 elif self.reference != '' and self.catalog == "new_students": 720 res = jamb_nr_catalog.searchResults({"%s" % self.reference: value}) 721 if len(res) != 1: 722 err = 'No record with this registration number.' 723 else: 724 datastructure['record'] = res[0] 725 else: 604 726 record = datastructure[self.reference] 605 727 #jamb_reg_no = getattr(record,widget_id) … … 1048 1170 do = 1 1049 1171 s_id = str(self.portal_membership.getAuthenticatedMember()) 1050 #import pdb;pdb.set_trace()1051 1172 if self.isStaff(): 1052 1173 do = 0 … … 1187 1308 ###) 1188 1309 1189 1190 1310 InitializeClass(ScratchcardPinWidget) 1191 1311 widgetRegistry.register(ScratchcardPinWidget) 1192 1193 1312 ###) 1313 1314 class PumePinWidget(ScratchcardPinWidget): ###( 1315 """ Pume Pin Widget""" 1316 meta_type = "Pume Pin Widget" 1317 1318 def validate(self, datastructure, **kw): ###( 1319 """Validate datastructure and update datamodel.""" 1320 s_logger = logging.getLogger('Widgets.ScratchcardPinWidget.validate') 1321 widget_id = self.getWidgetId() 1322 v = datastructure[widget_id] 1323 err = 0 1324 mapping = {} 1325 prefix= self.prefix 1326 if prefix.startswith('@'): 1327 prefix= getattr(self,self.prefix[1:])() 1328 b = datastructure[widget_id+'_b'].strip() 1329 n = datastructure[widget_id+'_n'].strip() 1330 pins = self.portal_pins 1331 pin = "%(prefix)s%(b)s%(n)s" % vars() 1332 pin_str = "%(prefix)s-%(b)s-%(n)s" % vars() 1333 do = 1 1334 s_id = str(self.portal_membership.getAuthenticatedMember()) 1335 import pdb;pdb.set_trace() 1336 if self.isStaff(): 1337 do = 0 1338 err ='You are not a Student. PIN neither checked nor used.' 1339 s_logger.info('%s tried to use scratch card %s' % (s_id,pin_str)) 1340 elif len(b) > 1 and b.find('-') > -1: 1341 do = 0 1342 err = 'PIN must not contain "-"' 1343 s_logger.info('%s entered invalid PIN containing "-"' % (s_id)) 1344 elif n.find('-') > -1: 1345 do = 0 1346 err = 'PIN must not contain "-"' 1347 s_logger.info('%s entered invalid PIN containing "-"' % (s_id)) 1348 elif len(n) != 10: 1349 do = 0 1350 err = 'Invalid PIN length' 1351 s_logger.info('%s entered invalid PIN with length %d' % (s_id,len(n))) 1352 elif self.reference == "": 1353 ref = s_id 1354 else: 1355 ref = datastructure[self.reference] 1356 if datastructure.errors: 1357 do = 0 1358 datastructure.setError(widget_id, 'PIN neither checked nor used.') 1359 s_logger.info('%s/%s entered wrong data together with PIN %s' % (s_id,ref,pin_str)) 1360 while do: 1361 ok = pins.searchAndSetRecord(pin,ref,prefix) 1362 if ok < -2 or ok > 2: 1363 err = 'Unknown error, please report!' 1364 s_logger.info('%s/%s caused unknown error with PIN %s' % (s_id,ref,pin_str)) 1365 break 1366 elif ok == -2: 1367 err = 'Service already is activated but with a different PIN.' 1368 s_logger.info('%s/%s repeatedly activated service but with different PIN %s' % (s_id,ref,pin_str)) 1369 break 1370 elif ok == -1: 1371 err = 'Invalid PIN' 1372 s_logger.info('%s/%s entered invalid PIN %s' % (s_id,ref,pin_str)) 1373 break 1374 if ok == 0: 1375 err = 'PIN already used' 1376 s_logger.info('%s/%s entered used PIN %s' % (s_id,ref,pin_str)) 1377 break 1378 if ok >= 1: 1379 #import pdb;pdb.set_trace() 1380 if self.isStudent(): 1381 err = "This is only for Pume application." 1382 s_logger.info('%s/%s applied for PUME with PIN %s' % (s_id,ref,pin_str)) 1383 break 1384 else: 1385 applicant = datastructure['record'] 1386 if not applicant.pin: 1387 s_logger.info('%s successfully used PIN %s' % (ref,pin_str)) 1388 d = {} 1389 d['reg_no'] = applicant.reg_no 1390 d['pin'] = n 1391 self.new_students.modifyRecord(**d) 1392 elif applicant.pin != pin_str: 1393 s_logger.info('%s/%s repeatedly applied for PUME with different PIN %s' % (s_id,ref,pin_str)) 1394 elif applicant.pin == pin_str: 1395 s_logger.info('%s/%s repeatedly applied for PUME with PIN %s' % (s_id,ref,pin_str)) 1396 break 1397 if err: 1398 datastructure.setError(widget_id, err,mapping) 1399 else: 1400 datamodel = datastructure.getDataModel() 1401 datamodel[self.fields[0]] = ScratchCardPin(prefix,b,n) 1402 datastructure[widget_id] = ScratchCardPin(prefix,b,n) 1403 datastructure[widget_id+'_p'] = prefix 1404 datastructure[widget_id+'_b'] = b 1405 datastructure[widget_id+'_n'] = n 1406 datastructure['s_id'] = s_id 1407 return not err 1408 ###) 1409 1410 InitializeClass(PumePinWidget) 1411 widgetRegistry.register(PumePinWidget) 1194 1412 ###) 1195 1413 -
WAeUP_SRP/trunk/__init__.py
r2039 r2094 10 10 11 11 from Products.CPSCore.interfaces import ICPSSite 12 from Products.CPSDirectory.DirectoryTool import DirectoryTypeRegistry 12 13 13 14 import PatchCPSWorkflowWorkflowDefinition … … 126 127 EXTENSION, 127 128 for_=ICPSSite) 129 ## DirectoryTypeRegistry.register(WAeUPTables.Applicants) 128 130 -
WAeUP_SRP/trunk/configure.zcml
r414 r2094 1 1 <configure 2 2 xmlns="http://namespaces.zope.org/zope" 3 xmlns:five="http://namespaces.zope.org/five" 4 xmlns:zcml="http://namespaces.zope.org/zcml" 3 5 > 4 6 … … 12 14 /> 13 15 16 <five:registerClass 17 class=".TableDirectory.NewStudentsDirectory" 18 meta_type="New Students Directory" 19 permission="cmf.ManagePortal" 20 global="False" 21 /> 22 14 23 </configure> -
WAeUP_SRP/trunk/doc/srp_documentation.mm
r2017 r2094 1 <map version="0. 8.0">1 <map version="0.9.0_Beta_8"> 2 2 <!-- To view this file, download free mind mapping software FreeMind from http://freemind.sourceforge.net --> 3 3 <node CREATED="1170079518946" ID="Freemind_Link_650524897" MODIFIED="1172489583516" TEXT="WAeUP Documentation"> … … 300 300 <node CREATED="1171711999584" ID="Freemind_Link_1070634598" MODIFIED="1171712315178" TEXT="Groups"/> 301 301 </node> 302 <node CREATED="1170931308473" FOLDED="true"ID="Freemind_Link_249696543" MODIFIED="1170931315740" TEXT="Catalogs">302 <node CREATED="1170931308473" ID="Freemind_Link_249696543" MODIFIED="1170931315740" TEXT="Catalogs"> 303 303 <node CREATED="1170931319920" ID="Freemind_Link_1633117071" MODIFIED="1171712108641" TEXT="Portal Catalog"/> 304 <node CREATED="1171712109062" ID="Freemind_Link_1264506858" LINK="../profiles/default/applicants_catalog.xml" MODIFIED="1187006324354" TEXT="Applicants Catalog"/> 304 305 <node CREATED="1171712109062" ID="Freemind_Link_769089546" LINK="../profiles/default/courses_catalog.xml" MODIFIED="1172055793074" TEXT="Courses Catalog"/> 306 <node CREATED="1171712109062" ID="Freemind_Link_964376607" LINK="../profiles/default/course_results.xml" MODIFIED="1186484772138" TEXT="Course Results"/> 305 307 <node CREATED="1171712109062" ID="Freemind_Link_879910437" LINK="../profiles/default/students_catalog.xml" MODIFIED="1172055153081" TEXT="Students Catalog"/> 306 308 <node CREATED="1171712063356" ID="Freemind_Link_1865945880" LINK="../profiles/default/returning_import.xml" MODIFIED="1172055126664" TEXT="Returning Import Table"/> -
WAeUP_SRP/trunk/exportimport.py
r2086 r2094 126 126 importWAeUPTable(site.results_import, '', context,'results_import') 127 127 importWAeUPTable(site.students_catalog, '', context,'students_catalog') 128 importWAeUPTable(site.applicants_catalog, '', context,'applicants_catalog') 128 129 importWAeUPTable(site.course_results, '', context,'course_results') 129 130 importWAeUPTable(site.portal_catalog_real, '', context,'portal_catalog_real') -
WAeUP_SRP/trunk/profiles/default/layouts.xml
r1861 r2094 6 6 <object name="acco_bed_booking" meta_type="CPS Layout"/> 7 7 <object name="academics_search" meta_type="CPS Layout"/> 8 <object name="application" meta_type="CPS Layout"/> 8 9 <object name="certificate" meta_type="CPS Layout"/> 9 10 <object name="certificate_course" meta_type="CPS Layout"/> -
WAeUP_SRP/trunk/profiles/default/schemas.xml
r2013 r2094 7 7 <object name="acco_hall" meta_type="CPS Schema"/> 8 8 <object name="acco_bed_booking" meta_type="CPS Schema"/> 9 <object name="application" meta_type="CPS Schema"/> 9 10 <object name="certificate" meta_type="CPS Schema"/> 10 11 <object name="certificate_course" meta_type="CPS Schema"/> -
WAeUP_SRP/trunk/profiles/default/toolset.xml
r2085 r2094 23 23 <required tool_id="students_catalog" 24 24 class="Products.WAeUP_SRP.WAeUPTables.StudentsCatalog"/> 25 <required tool_id="applicants_catalog" 26 class="Products.WAeUP_SRP.WAeUPTables.ApplicantsCatalog"/> 25 27 <required tool_id="course_results" 26 28 class="Products.WAeUP_SRP.WAeUPTables.CourseResults"/>
Note: See TracChangeset for help on using the changeset viewer.