- Timestamp:
- 19 Mar 2008, 11:43:23 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/base/WAeUPTables.py
r3348 r3354 921 921 if doc is None: 922 922 return None 923 if self._v_certificates.has_key(doc.study_course):923 if hasattr(self,"_v_certificates") and self._v_certificates.has_key(doc.study_course): 924 924 return self._v_certificates[doc.study_course]['department'] 925 925 certificate_res = self.portal_catalog(id = doc.study_course) … … 932 932 if doc is None: 933 933 return None 934 if self._v_certificates.has_key(doc.study_course):934 if hasattr(self,"_v_certificates") and self._v_certificates.has_key(doc.study_course): 935 935 return self._v_certificates[doc.study_course]['faculty'] 936 936 certificate_res = self.portal_catalog(id = doc.study_course) … … 943 943 if doc is None: 944 944 return None 945 if self._v_certificates.has_key(doc.study_course):945 if hasattr(self,"_v_certificates") and self._v_certificates.has_key(doc.study_course): 946 946 return self._v_certificates[doc.study_course]['end_level'] 947 947 certificate_res = self.portal_catalog(id = doc.study_course) … … 1179 1179 if event_type not in ('sys_modify_object'): 1180 1180 return 1181 if pt == 'StudentStudyCourse' and mt == 'CPS Proxy Folder':1182 if not hasattr(self,'_v_certificates'):1183 self._v_certificates = self.fill_certificates_dict()1184 1181 if mt == 'CPS Proxy Folder': 1185 1182 return 1183 if not hasattr(self,'_v_certificates'): 1184 self._v_certificates = self.fill_certificates_dict() 1186 1185 for field in self.affected_types[pt]['fields']: 1187 1186 if hasattr(self,'get_from_doc_%s' % field): … … 1196 1195 InitializeClass(StudentsCatalog) 1197 1196 1197 ###) 1198 1199 class CertificatesCatalog(WAeUPTable): ###( 1200 security = ClassSecurityInfo() 1201 1202 meta_type = 'WAeUP Certificates Catalog' 1203 name = "certificates_catalog" 1204 key = "code" 1205 def __init__(self,name=None): 1206 if name == None: 1207 name = self.name 1208 WAeUPTable.__init__(self, name) 1209 1210 def manage_catalogReindex(self, REQUEST, RESPONSE, URL1): ###( 1211 """ clear the catalog, then re-index everything """ 1212 1213 elapse = time.time() 1214 c_elapse = time.clock() 1215 1216 pgthreshold = self._getProgressThreshold() 1217 handler = (pgthreshold > 0) and ZLogHandler(pgthreshold) or None 1218 self.refreshCatalog(clear=1, pghandler=handler) 1219 1220 elapse = time.time() - elapse 1221 c_elapse = time.clock() - c_elapse 1222 1223 RESPONSE.redirect( 1224 URL1 + 1225 '/manage_catalogAdvanced?manage_tabs_message=' + 1226 urllib.quote('Catalog Updated \n' 1227 'Total time: %s\n' 1228 'Total CPU time: %s' % (`elapse`, `c_elapse`))) 1229 ###) 1230 1231 def reindexIndex(self, name, REQUEST,pghandler=None): ###( 1232 if isinstance(name, str): 1233 name = (name,) 1234 certificates = self.portal_catalog(portal_type="Certificate") 1235 num_objects = len(Certificates) 1236 if pghandler: 1237 pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects) 1238 for i in xrange(num_objects): 1239 if pghandler: pghandler.report(i) 1240 certificate_brain = certificates[i] 1241 certificate_object = certificate_brain.getObject() 1242 pl = certificate_brain.getPath().split('/') 1243 data = {} 1244 cid = data[self.key] = certificate_brain.getId 1245 data['faculty'] = pl[-4] 1246 data['department'] = pl[-3] 1247 doc = certificate_object.getContent() 1248 for field in name: 1249 if field not in (self.key,'faculty','department'): 1250 data[field] = getattr(doc,field) 1251 self.modifyRecord(**data) 1252 if pghandler: pghandler.finish() 1253 ###) 1254 1255 def refreshCatalog(self, clear=0, pghandler=None): ###( 1256 """ re-index everything we can find """ 1257 if clear: 1258 self._catalog.clear() 1259 certificates = self.portal_catalog(portal_type="Certificate") 1260 num_objects = len(certificates) 1261 if pghandler: 1262 pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects) 1263 #from pdb import set_trace;set_trace() 1264 for i in xrange(num_objects): 1265 if pghandler: pghandler.report(i) 1266 certificate_brain = certificates[i] 1267 certificate_doc = certificate_brain.getObject().getContent() 1268 pl = certificate_brain.getPath().split('/') 1269 data = {} 1270 for field in self.schema(): 1271 data[field] = getattr(certificate_doc,field,None) 1272 data[self.key] = certificate_brain.getId 1273 ai = pl.index('academics') 1274 data['faculty'] = pl[ai +1] 1275 data['department'] = pl[ai +2] 1276 if clear: 1277 self.addRecord(**data) 1278 else: 1279 self.modifyRecord(**data) 1280 if pghandler: pghandler.finish() 1281 ###) 1282 1283 security.declarePrivate('notify_event_listener') ###( 1284 def notify_event_listener(self,event_type,object,infos): 1285 "listen for events" 1286 if not infos.has_key('rpath'): 1287 return 1288 pt = getattr(object,'portal_type',None) 1289 mt = getattr(object,'meta_type',None) 1290 if pt != 'Certificate': 1291 return 1292 data = {} 1293 rpl = infos['rpath'].split('/') 1294 if event_type not in ("sys_add_object","sys_modify_object","sys_del_object"): 1295 return 1296 certificate_id = object.getId() 1297 data[self.key] = certificate_id 1298 if event_type == "sys_add_object" and mt == 'CPS Proxy Folder': 1299 try: 1300 self.addRecord(**data) 1301 except ValueError: 1302 return 1303 certificate_id = object.getId() 1304 doc = object.getContent() 1305 if doc is None: 1306 return 1307 for field in self.schema(): 1308 data[field] = getattr(doc,field,None) 1309 data[self.key] = certificate_id 1310 ai = rpl.index('academics') 1311 data['faculty'] = rpl[ai +1] 1312 data['department'] = rpl[ai +2] 1313 self.modifyRecord(**data) 1314 return 1315 if event_type == "sys_del_object": 1316 self.deleteRecord(certificate_id) 1317 return 1318 if event_type == "sys_modify_object" and mt == 'Certificate': 1319 #from pdb import set_trace;set_trace() 1320 for field in self.schema(): 1321 data[field] = getattr(object,field,None) 1322 certificate_id = object.aq_parent.getId() 1323 data[self.key] = certificate_id 1324 ai = rpl.index('academics') 1325 data['faculty'] = rpl[ai +1] 1326 data['department'] = rpl[ai +2] 1327 self.modifyRecord(**data) 1328 ###) 1329 1330 1331 InitializeClass(CertificatesCatalog) 1198 1332 ###) 1199 1333
Note: See TracChangeset for help on using the changeset viewer.