[3172] | 1 | #-*- mode: python; mode: fold -*- |
---|
| 2 | # (C) Copyright 2005 The WAeUP group <http://www.waeup.org> |
---|
| 3 | # Author: Joachim Schmitz (js@aixtraware.de) |
---|
| 4 | # |
---|
| 5 | # This program is free software; you can redistribute it and/or modify |
---|
| 6 | # it under the terms of the GNU General Public License version 2 as published |
---|
| 7 | # by the Free Software Foundation. |
---|
| 8 | # |
---|
| 9 | # This program is distributed in the hope that it will be useful, |
---|
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | # GNU General Public License for more details. |
---|
| 13 | # |
---|
| 14 | # You should have received a copy of the GNU General Public License |
---|
| 15 | # along with this program; if not, write to the Free Software |
---|
| 16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
| 17 | # 02111-1307, USA. |
---|
| 18 | # |
---|
| 19 | # $Id: WAeUPImport.py 3481 2008-05-01 05:53:28Z henrik $ |
---|
| 20 | """The WAeUP Tool Box. |
---|
| 21 | """ |
---|
| 22 | |
---|
| 23 | #from AccessControl import ClassSecurityInfo |
---|
| 24 | #from Acquisition import aq_inner |
---|
| 25 | #from Acquisition import aq_parent |
---|
| 26 | #from Globals import DTMLFile |
---|
| 27 | #from Globals import InitializeClass |
---|
[3277] | 28 | from OFS.SimpleItem import SimpleItem |
---|
[3172] | 29 | from zExceptions import BadRequest |
---|
| 30 | |
---|
| 31 | #from Products.CMFCore.utils import getToolByName |
---|
| 32 | #from Products.CPSSchemas.DataStructure import DataStructure |
---|
| 33 | #from Products.CPSSchemas.DataModel import DataModel |
---|
| 34 | #from Products.CPSSchemas.StorageAdapter import MappingStorageAdapter |
---|
[3277] | 35 | from Products.CMFCore.ActionProviderBase import ActionProviderBase |
---|
[3172] | 36 | #from Products.CMFCore.permissions import View |
---|
| 37 | #from Products.ZCatalog.ZCatalog import ZCatalog |
---|
| 38 | #from Products.CMFCore.permissions import ModifyPortalContent |
---|
| 39 | #from Products.CMFCore.permissions import ManagePortal |
---|
[3277] | 40 | from Products.CMFCore.utils import UniqueObject |
---|
[3172] | 41 | #from Products.CMFCore.URLTool import URLTool |
---|
| 42 | from Products.CMFCore.utils import getToolByName |
---|
| 43 | from Globals import package_home,INSTANCE_HOME |
---|
| 44 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
| 45 | import csv,re,os,sys |
---|
| 46 | from shutil import copy2 |
---|
| 47 | import DateTime,time |
---|
| 48 | import logging |
---|
| 49 | p_home = package_home(globals()) |
---|
| 50 | i_home = INSTANCE_HOME |
---|
| 51 | from utils import makeDigest |
---|
| 52 | |
---|
[3314] | 53 | NO_KEY = '----' |
---|
[3316] | 54 | IGNORE = 'ignore' |
---|
[3277] | 55 | class WAeUPImport(UniqueObject, SimpleItem, ActionProviderBase): ###( |
---|
[3172] | 56 | """ WAeUPImport """ |
---|
| 57 | required_modes = ('create',) |
---|
| 58 | |
---|
[3277] | 59 | def __init__(self,waeup_tool): ###( |
---|
| 60 | self.students_folder = waeup_tool.portal_url.getPortalObject().campus.students |
---|
[3172] | 61 | self.member = member = waeup_tool.portal_membership.getAuthenticatedMember() |
---|
[3320] | 62 | self.import_date = DateTime.DateTime() |
---|
| 63 | self.imported_by = str(member) |
---|
| 64 | #self.current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
[3172] | 65 | self.waeup_tool = waeup_tool |
---|
[3248] | 66 | self.academics_folder = waeup_tool.portal_url.getPortalObject().campus.academics |
---|
[3172] | 67 | self.schema_tool = getToolByName(waeup_tool, 'portal_schemas') |
---|
| 68 | self.layout_tool = getToolByName(waeup_tool, 'portal_layouts') |
---|
| 69 | self.portal_workflow = getToolByName(waeup_tool, 'portal_workflow') |
---|
| 70 | self.portal_url = getToolByName(waeup_tool, 'portal_url') |
---|
[3178] | 71 | self.portal_catalog = waeup_tool.portal_catalog |
---|
[3172] | 72 | self.students_catalog = waeup_tool.students_catalog |
---|
| 73 | self.courses_catalog = waeup_tool.courses_catalog |
---|
| 74 | self.course_results = waeup_tool.course_results |
---|
[3250] | 75 | self.applicants_catalog = waeup_tool.applicants_catalog |
---|
[3191] | 76 | #self.mode = mode |
---|
| 77 | # self.import_method = getattr(self, '%s' % mode,None) |
---|
[3172] | 78 | errors = [] |
---|
[3191] | 79 | # if self.import_method is None: |
---|
| 80 | # errors.append('No importer method %s' % mode) |
---|
[3178] | 81 | self.pending_path = "%s/import/%s.pending" % (i_home,self.plural_name) |
---|
| 82 | self.pending_tmp = "%s/import/%s.pending.tmp" % (i_home,self.plural_name) |
---|
| 83 | self.pending_backup = "%s/import/%s.pending.old" % (i_home,self.plural_name) |
---|
[3172] | 84 | self.pending_fn = os.path.split(self.pending_path)[1] |
---|
[3178] | 85 | self.imported_path = "%s/import/%s.imported" % (i_home,self.plural_name) |
---|
[3172] | 86 | self.imported_fn = os.path.split(self.imported_path)[1] |
---|
| 87 | iname = "import_%s" % self.name |
---|
[3249] | 88 | self.logger = logging.getLogger('WAeUPImport.%sImport' % self.plural_name.capitalize()) |
---|
[3172] | 89 | self.schema = self.schema_tool._getOb(iname,None) |
---|
[3250] | 90 | #self.pending_schema = self.schema_tool._getOb("%s_pending" % iname,None) |
---|
[3172] | 91 | self.layout = self.layout_tool._getOb(iname,None) |
---|
[3250] | 92 | while True: |
---|
| 93 | if self.schema is None: |
---|
| 94 | errors.append('no schema %s' % iname) |
---|
| 95 | # if self.pending_schema is None: |
---|
| 96 | # self.pending_schema = self.schema |
---|
| 97 | if self.layout is None: |
---|
| 98 | errors.append('no such layout %s' % iname) |
---|
| 99 | if errors: |
---|
| 100 | break |
---|
| 101 | self.data_keys = self.schema.keys() |
---|
| 102 | self.csv_keys = self.schema.keys() |
---|
| 103 | info = {} |
---|
| 104 | info['imported_from'] = '' |
---|
[3326] | 105 | info['import_record_no'] = 0 |
---|
[3325] | 106 | info['imported_by'] = self.imported_by |
---|
[3320] | 107 | info['import_date'] = self.import_date.strftime("%d/%m/%y %H:%M:%S") |
---|
[3250] | 108 | info['error'] = '' |
---|
| 109 | self.info = info |
---|
| 110 | self.csv_keys.extend(self.info) |
---|
| 111 | self.validators = {} |
---|
| 112 | for widget in self.layout.keys(): |
---|
| 113 | self.validators[widget] = self.layout[widget].validate |
---|
| 114 | self.required_keys = {} |
---|
| 115 | for mode in self.required_modes: |
---|
| 116 | self.required_keys[mode] = [self.layout.getIdUnprefixed(id) |
---|
| 117 | for id,widget in self.layout.objectItems() |
---|
| 118 | if widget.is_required] |
---|
| 119 | break |
---|
[3172] | 120 | self.init_errors = ','.join(errors) |
---|
[3277] | 121 | ###) |
---|
[3172] | 122 | |
---|
[3372] | 123 | def findStudent(self,mode,student_id=None, matric_no=None, jamb_reg_no=None): ###( |
---|
| 124 | student_record = None |
---|
| 125 | msg = '' |
---|
| 126 | key_used = '' |
---|
| 127 | while True: |
---|
| 128 | if student_id: |
---|
| 129 | key_used = 'student_id' |
---|
| 130 | res = self.students_catalog(id = student_id) |
---|
| 131 | if not res: |
---|
| 132 | msg = "no student with id %s" % student_id |
---|
| 133 | break |
---|
| 134 | student_record = res[0] |
---|
| 135 | if matric_no and student_record.matric_no: |
---|
| 136 | if matric_no != student_record.matric_no: |
---|
| 137 | msg = "old matric_no %s overwritten with %s" % (student_record.matric_no,matric_no) |
---|
| 138 | #logger.info("%s, old matric_no %s overwritten with %s" % (student_record.id,student_record.matric_no,matric_no)) |
---|
| 139 | if jamb_reg_no and student_record.jamb_reg_no: |
---|
| 140 | if jamb_reg_no != student_record.jamb_reg_no: |
---|
| 141 | msg = "old reg_no %s overwritten with %s" % (student_record.jamb_reg_no,jamb_reg_no) |
---|
| 142 | #logger.info("%s, old reg_no %s overwritten with %s" % (student_record.id,student_record.jamb_reg_no,jamb_reg_no)) |
---|
| 143 | elif jamb_reg_no: |
---|
| 144 | key_used = 'jamb_reg_no' |
---|
| 145 | res = self.students_catalog(jamb_reg_no = jamb_reg_no) |
---|
| 146 | if res: |
---|
[3383] | 147 | if mode == 'create': |
---|
[3372] | 148 | msg = "jamb_reg_no exists" |
---|
| 149 | break |
---|
| 150 | else: |
---|
| 151 | if mode == 'edit': |
---|
| 152 | msg = "no student with jamb_reg_no %s" % jamb_reg_no |
---|
| 153 | break |
---|
| 154 | student_record = res[0] |
---|
| 155 | elif matric_no: |
---|
| 156 | key_used = 'matric_no' |
---|
| 157 | res = self.students_catalog(matric_no = matric_no) |
---|
| 158 | if not res: |
---|
| 159 | msg = "no student with matric_no %s" % matric_no |
---|
| 160 | break |
---|
| 161 | student_record = res[0] |
---|
[3382] | 162 | else: |
---|
[3383] | 163 | msg = "neither id, matric_no nor reg_no specified" |
---|
[3372] | 164 | break |
---|
| 165 | d = {} |
---|
| 166 | d['student_record'] = student_record |
---|
[3383] | 167 | d['key_used'] = key_used |
---|
| 168 | d['msg'] = msg |
---|
[3372] | 169 | return d |
---|
| 170 | ###) |
---|
| 171 | |
---|
[3277] | 172 | def makeIdLists(self): ###( |
---|
[3172] | 173 | pending_digests = [] |
---|
| 174 | pending = [] |
---|
| 175 | # pending_student_ids = [] |
---|
| 176 | # pending_matric_nos = [] |
---|
| 177 | # pending_reg_ns = [] |
---|
| 178 | if os.path.exists(self.pending_path): |
---|
| 179 | datafile = open(self.pending_path,"r") |
---|
[3325] | 180 | reader = csv.reader(datafile) |
---|
| 181 | old_headline = reader.next() |
---|
| 182 | #datafile.seek(0) |
---|
| 183 | pending_csv_reader = csv.DictReader(datafile,old_headline,) |
---|
| 184 | #pending_csv_reader.next() # skip headline |
---|
[3172] | 185 | for item in pending_csv_reader: |
---|
| 186 | digest = makeDigest(item,self.data_keys) |
---|
| 187 | if digest not in pending_digests: |
---|
| 188 | pending_digests += digest, |
---|
| 189 | pending += item, |
---|
[3178] | 190 | datafile.close() |
---|
[3268] | 191 | #copy2(self.pending_path,self.pending_backup) |
---|
[3172] | 192 | return pending, pending_digests |
---|
[3277] | 193 | ###) |
---|
| 194 | |
---|
[3292] | 195 | def checkHeadline(self,headline): ###( |
---|
[3315] | 196 | """ check the headline of a csv file """ |
---|
[3277] | 197 | import_keys = [k.strip() for k in headline if not (k.strip().startswith('ignore') |
---|
| 198 | or k.strip() in self.info.keys())] |
---|
[3316] | 199 | # import_keys = [k.strip() for k in headline if not (k.strip() in self.info.keys())] |
---|
[3277] | 200 | diff2schema = set(import_keys).difference(set(self.schema.keys())) |
---|
| 201 | diff2layout = set(import_keys).difference(set(self.layout.keys())) |
---|
| 202 | #if diff2schema and diff2schema != set(['id',]): |
---|
| 203 | if diff2schema: |
---|
| 204 | return list(diff2schema) |
---|
| 205 | return [] |
---|
[3292] | 206 | ###) |
---|
[3314] | 207 | |
---|
| 208 | def getHeadlineFields(self,headline,values): ###( |
---|
[3315] | 209 | """ check the headline of a csv file """ |
---|
[3316] | 210 | # import_keys = [k.strip() for k in headline if not (k.strip().startswith('ignore') |
---|
| 211 | # or k.strip() in self.info.keys())] |
---|
| 212 | import_keys = [k.strip() for k in headline if not (k.strip() in self.info.keys())] |
---|
[3347] | 213 | info_keys = [k.strip() for k in headline if k.strip() in self.info.keys()] |
---|
[3314] | 214 | si = set(import_keys) |
---|
| 215 | ss = set(self.schema.keys()) |
---|
[3315] | 216 | |
---|
[3314] | 217 | invalid_keys = si - ss |
---|
| 218 | keys = [] |
---|
| 219 | i = 0 |
---|
[3316] | 220 | duplicates = False |
---|
| 221 | singels = [] |
---|
| 222 | msg = '' |
---|
| 223 | while True: |
---|
| 224 | if len(values) != len(import_keys): |
---|
[3347] | 225 | if len(values) == len(import_keys) + len(info_keys): |
---|
| 226 | msg += "fields from pending file in headline" |
---|
| 227 | else: |
---|
| 228 | msg += "%d fields in headline but %d values" % (len(import_keys),len(values)) |
---|
[3316] | 229 | break |
---|
| 230 | for k in import_keys: |
---|
| 231 | if k in singels: |
---|
[3318] | 232 | keys += (k,'%s' % k,values[i],'(duplicate)'), |
---|
[3325] | 233 | msg += ("duplicate %s," % k) |
---|
[3318] | 234 | keys[singels.index(k)] = (k,'%s' % k,values[singels.index(k)],'(duplicate)') |
---|
[3316] | 235 | elif k in invalid_keys and not k.startswith(IGNORE): |
---|
[3318] | 236 | keys += (k,NO_KEY,values[i],'(invalid)'), |
---|
[3316] | 237 | else: |
---|
| 238 | keys += (k,k,values[i],''), |
---|
| 239 | i += 1 |
---|
| 240 | singels += k, |
---|
| 241 | break |
---|
| 242 | return msg,keys |
---|
[3314] | 243 | ###) |
---|
[3172] | 244 | ###) |
---|
| 245 | |
---|
| 246 | class ApplicationImport(WAeUPImport):###( |
---|
[3250] | 247 | name = "application" |
---|
[3172] | 248 | plural_name = "%ss" % name |
---|
| 249 | commit_after = 1000 |
---|
| 250 | |
---|
| 251 | def create(self,mapping):###( |
---|
| 252 | reg_no = mapping.get('reg_no') |
---|
| 253 | msg = '' |
---|
| 254 | while True: |
---|
| 255 | try: |
---|
| 256 | self.applicants_catalog.addRecord(**mapping) |
---|
| 257 | except ValueError: |
---|
| 258 | msg = "applicant record with reg_no %s already exists" % reg_no |
---|
| 259 | break |
---|
| 260 | return reg_no,msg,mapping |
---|
| 261 | ###) |
---|
| 262 | |
---|
| 263 | def edit(self,mapping):###( |
---|
| 264 | reg_no = mapping.get('reg_no') |
---|
| 265 | status = mapping.get('status') |
---|
| 266 | msg = '' |
---|
| 267 | while True: |
---|
| 268 | res = self.applicants_catalog(reg_no = reg_no) |
---|
| 269 | if len(res): |
---|
| 270 | if res[0].status == 'created' and status != 'created': |
---|
| 271 | msg = "student object with id %s for %s already created, status cannot be changed" % (res[0].student_id, reg_no) |
---|
| 272 | elif status == 'created' and res[0].status != 'created': |
---|
| 273 | msg = "student object for %s has not yet been created, status cannot be set to 'created'" % (reg_no) |
---|
| 274 | else: |
---|
| 275 | self.applicants_catalog.modifyRecord(**mapping) |
---|
| 276 | else: |
---|
| 277 | msg = "applicant record with reg_no %s does not exist" % reg_no |
---|
| 278 | break |
---|
| 279 | return reg_no,msg,mapping |
---|
| 280 | ###) |
---|
| 281 | |
---|
| 282 | ###) |
---|
| 283 | |
---|
| 284 | class CertificateImport(WAeUPImport):###( |
---|
| 285 | name = "certificate" |
---|
| 286 | plural_name = "%ss" % name |
---|
| 287 | commit_after = 100000 |
---|
| 288 | |
---|
| 289 | def create(self,mapping):###( |
---|
| 290 | if getattr(self,'_v_certificate_list',None) is None: |
---|
| 291 | self._v_certificate_list = [] |
---|
| 292 | if getattr(self,'_v_department_certificates',None) is None: |
---|
[3248] | 293 | departments = self.portal_catalog(portal_type = "Department") |
---|
[3172] | 294 | self._v_department_certificates = {} |
---|
[3355] | 295 | for department in departments: |
---|
| 296 | certificates_container = getattr(department.getObject(),"certificates",None) |
---|
| 297 | self._v_department_certificates[department.getId] = {'container': certificates_container, |
---|
| 298 | 'certificates': certificates_container.objectIds(), |
---|
| 299 | } |
---|
[3248] | 300 | department_id = mapping['department_code'] |
---|
[3172] | 301 | msg = '' |
---|
[3248] | 302 | certificate_id = mapping.get('code') |
---|
[3172] | 303 | while True: |
---|
[3248] | 304 | department_certificates = self._v_department_certificates.get(department_id,None) |
---|
| 305 | if department_certificates is None: |
---|
| 306 | msg = "No Department with ID: %s" % department_id |
---|
[3172] | 307 | break |
---|
[3355] | 308 | certificates_container = department_certificates['container'] |
---|
| 309 | certificates = department_certificates['certificates'] |
---|
[3172] | 310 | if certificate_id in self._v_certificate_list: |
---|
[3248] | 311 | msg = "Duplicate Certificate ID: %s" % department_id |
---|
[3172] | 312 | break |
---|
[3355] | 313 | if certificate_id in certificates: |
---|
[3248] | 314 | msg = "Duplicate Certificate ID: %s" % department_id |
---|
[3172] | 315 | break |
---|
| 316 | try: |
---|
[3355] | 317 | certificates_container.invokeFactory('Certificate', certificate_id) |
---|
[3172] | 318 | except BadRequest,E: |
---|
| 319 | msg = "%s" % E |
---|
| 320 | break |
---|
| 321 | self._v_certificate_list.append(certificate_id) |
---|
[3355] | 322 | certificate = getattr(certificates_container,certificate_id) |
---|
| 323 | certificate.getContent().edit(mapping=mapping) |
---|
[3172] | 324 | break |
---|
| 325 | return certificate_id,msg,mapping |
---|
| 326 | ###) |
---|
| 327 | |
---|
| 328 | def edit(self,mapping):###( |
---|
| 329 | certificate_id = mapping.get('code') |
---|
| 330 | res = self.portal_catalog(id=certificate_id) |
---|
| 331 | msg = '' |
---|
| 332 | while True: |
---|
| 333 | if not res: |
---|
[3233] | 334 | msg = "no certificate with id: %s" % certificate_id |
---|
[3172] | 335 | break |
---|
| 336 | c = res[0].getObject() |
---|
| 337 | c.getContent().edit(mapping=mapping) |
---|
| 338 | break |
---|
| 339 | return certificate_id,msg,mapping |
---|
| 340 | ###) |
---|
| 341 | ###) |
---|
| 342 | |
---|
| 343 | class CourseImport(WAeUPImport):###( |
---|
| 344 | name = "course" |
---|
| 345 | plural_name = "%ss" % name |
---|
| 346 | commit_after = 1000 |
---|
| 347 | |
---|
| 348 | def create(self,mapping):###( |
---|
| 349 | if getattr(self,'_v_course_list',None) is None: |
---|
| 350 | self._v_course_list = [] |
---|
[3179] | 351 | if getattr(self,'_v_department_courses',None) is None: |
---|
| 352 | departments = self.portal_catalog(portal_type = "Department") |
---|
[3172] | 353 | self._v_department_courses = {} |
---|
[3179] | 354 | for department in departments: |
---|
[3355] | 355 | courses_container = getattr(department.getObject(),"courses",None) |
---|
| 356 | if courses_container is not None: |
---|
| 357 | self._v_department_courses[department.getId] = {'container': courses_container, |
---|
| 358 | 'courses': courses_container.objectIds(), |
---|
| 359 | } |
---|
[3179] | 360 | department_id = mapping['department_code'] |
---|
| 361 | course_id = mapping.get('code','') |
---|
[3172] | 362 | msg = '' |
---|
| 363 | while True: |
---|
[3179] | 364 | department_courses = self._v_department_courses.get(department_id,None) |
---|
| 365 | if department_courses is None: |
---|
[3233] | 366 | msg = "no department with id: %(department_id)s" % vars() |
---|
[3172] | 367 | break |
---|
[3355] | 368 | courses_container = department_courses['container'] |
---|
| 369 | courses = department_courses['courses'] |
---|
[3172] | 370 | if course_id in self._v_course_list: |
---|
[3233] | 371 | msg = "duplicate course id: %(course_id)s" % vars() |
---|
[3172] | 372 | break |
---|
[3355] | 373 | if course_id in courses: |
---|
[3233] | 374 | msg = "course %(course_id)s already exists in department %(department_id)s" % vars() |
---|
[3172] | 375 | break |
---|
| 376 | try: |
---|
[3355] | 377 | courses_container.invokeFactory('Course', course_id) |
---|
[3172] | 378 | except BadRequest,E: |
---|
| 379 | msg = "%s" % E |
---|
| 380 | break |
---|
| 381 | self._v_course_list.append(course_id) |
---|
[3355] | 382 | course = getattr(courses_container,course_id) |
---|
[3179] | 383 | course.getContent().edit(mapping=mapping) |
---|
[3172] | 384 | break |
---|
| 385 | return course_id,msg,mapping |
---|
| 386 | ###) |
---|
| 387 | |
---|
| 388 | def edit(self,mapping): ###( |
---|
[3179] | 389 | course_id = mapping.get('code','') |
---|
[3248] | 390 | course = self.courses_catalog.getRecordByKey(course_id) |
---|
[3355] | 391 | msg = '' |
---|
[3172] | 392 | while True: |
---|
[3248] | 393 | if course is None: |
---|
[3233] | 394 | msg = "no course with id: %s" % course_id |
---|
[3172] | 395 | break |
---|
[3355] | 396 | course_object = getattr(getattr(getattr(getattr(self.academics_folder,course.faculty), |
---|
| 397 | course.department), |
---|
| 398 | 'courses'), |
---|
| 399 | course_id) |
---|
[3248] | 400 | course_object.getContent().edit(mapping=mapping) |
---|
[3172] | 401 | break |
---|
| 402 | return course_id,msg,mapping |
---|
| 403 | ###) |
---|
| 404 | ###) |
---|
| 405 | |
---|
| 406 | class CourseResultImport(WAeUPImport):###( |
---|
| 407 | """ CourseresultImport """ |
---|
| 408 | name = "course_result" |
---|
| 409 | plural_name = "%ss" % name |
---|
| 410 | commit_after = 1000000 |
---|
[3233] | 411 | required_modes = ('create','edit','remove') |
---|
[3172] | 412 | |
---|
| 413 | def create(self,mapping):###( |
---|
| 414 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 415 | if getattr(self,'_v_courses',None) is None: |
---|
| 416 | res = self.courses_catalog() |
---|
| 417 | self._v_courses = {} |
---|
| 418 | for brain in res: |
---|
| 419 | self._v_courses[brain.code] = brain |
---|
| 420 | if getattr(self,'_v_level_created',None) is None: |
---|
| 421 | self._v_level_created = [] |
---|
[3372] | 422 | if getattr(self,'_v_student_study_course',None) is None: |
---|
| 423 | self._v_student_study_course = {} |
---|
[3172] | 424 | msg = '' |
---|
| 425 | key = '' |
---|
[3372] | 426 | matric_no = mapping.get('matric_no','') |
---|
| 427 | id = mapping.get('id','') |
---|
[3172] | 428 | while True: |
---|
| 429 | course_id = mapping.get('code') |
---|
| 430 | if course_id not in self._v_courses.keys(): |
---|
[3233] | 431 | msg = "no course with id: %s" % course_id |
---|
[3172] | 432 | break |
---|
[3372] | 433 | result = self.findStudent('create',student_id=id,matric_no=matric_no) |
---|
| 434 | msg = result['msg'] |
---|
| 435 | if msg: |
---|
| 436 | break |
---|
| 437 | student_record = result['student_record'] |
---|
| 438 | student_id = mapping['student_id'] = student_record.id |
---|
| 439 | level_id = mapping.get('level_id','') |
---|
| 440 | code = mapping.get('code','') |
---|
| 441 | level_ident = "%(student_id)s_%(level_id)s" % vars() |
---|
| 442 | if level_ident not in self._v_level_created: |
---|
| 443 | context = self._v_student_study_course.get(student_id,None) |
---|
| 444 | if context is None: |
---|
| 445 | try: |
---|
| 446 | context = getattr(getattr(students_folder, |
---|
| 447 | "%(student_id)s" % vars()), |
---|
| 448 | 'study_course') |
---|
| 449 | self._v_student_study_course[student_id] = context |
---|
| 450 | except: |
---|
| 451 | msg = "could not create level %(level_id)s for %(student_id)s" % vars() |
---|
| 452 | break |
---|
| 453 | if level_id not in context.objectIds(): |
---|
| 454 | context.invokeFactory('StudentStudyLevel',"%(level_id)s" % vars()) |
---|
| 455 | level = getattr(context,"%(level_id)s" % vars()) |
---|
| 456 | self.portal_workflow.doActionFor(level,'open') |
---|
| 457 | level.getContent().edit(mapping={'session': "%(session_id)s" % mapping,}) |
---|
| 458 | self.portal_workflow.doActionFor(level,'close') |
---|
| 459 | self._v_level_created += level_ident, |
---|
| 460 | mapping['key'] = key = "%(student_id)s|%(level_id)s|%(code)s" % vars() |
---|
[3431] | 461 | #overwrite semester and credits in create mode |
---|
[3372] | 462 | for k in ('semester','credits',): |
---|
| 463 | mapping[k] = getattr(self._v_courses[course_id],k) |
---|
| 464 | try: |
---|
| 465 | self.course_results.addRecord(**mapping) |
---|
| 466 | except ValueError: |
---|
| 467 | msg = "course result already exists: %s" % key |
---|
| 468 | break |
---|
| 469 | return key,msg,mapping |
---|
| 470 | ###) |
---|
| 471 | |
---|
[3374] | 472 | def edit(self,mapping): ###( |
---|
[3372] | 473 | msg = '' |
---|
| 474 | key = '' |
---|
| 475 | matric_no = mapping.get('matric_no','') |
---|
[3374] | 476 | id = mapping.get('id','') |
---|
[3372] | 477 | while True: |
---|
| 478 | result = self.findStudent('edit',student_id=id,matric_no=matric_no) |
---|
| 479 | msg = result['msg'] |
---|
[3172] | 480 | if msg: |
---|
| 481 | break |
---|
[3372] | 482 | student_record = result['student_record'] |
---|
[3336] | 483 | student_id = student_record.id |
---|
[3248] | 484 | level_id = mapping.get('level_id','') |
---|
| 485 | code = mapping.get('code','') |
---|
[3431] | 486 | #code = mapping['code'] |
---|
[3172] | 487 | mapping['key'] = key = "%(student_id)s|%(level_id)s|%(code)s" % vars() |
---|
[3330] | 488 | if self.course_results.getRecordByKey(key) is None: |
---|
| 489 | msg = "no course result with key %(key)s" % vars() |
---|
| 490 | break |
---|
| 491 | self.course_results.modifyRecord(**mapping) |
---|
[3172] | 492 | break |
---|
| 493 | return key,msg,mapping |
---|
| 494 | ###) |
---|
| 495 | |
---|
[3195] | 496 | def remove(self,mapping):###( |
---|
[3233] | 497 | key = '' |
---|
[3172] | 498 | msg = '' |
---|
[3374] | 499 | matric_no = mapping.get('matric_no','') |
---|
| 500 | id = mapping.get('id','') |
---|
[3172] | 501 | while True: |
---|
[3374] | 502 | result = self.findStudent('edit',student_id=id,matric_no=matric_no) |
---|
| 503 | msg = result['msg'] |
---|
[3172] | 504 | if msg: |
---|
| 505 | break |
---|
[3374] | 506 | student_record = result['student_record'] |
---|
[3172] | 507 | student_id = student_record.id |
---|
[3248] | 508 | level_id = mapping.get('level_id','') |
---|
| 509 | code = mapping.get('code','') |
---|
[3172] | 510 | key = "%(student_id)s|%(level_id)s|%(code)s" % vars() |
---|
| 511 | if self.course_results.getRecordByKey(key) is None: |
---|
[3233] | 512 | msg = "no course result with key %(key)s" % vars() |
---|
[3172] | 513 | break |
---|
| 514 | self.course_results.deleteRecord(key) |
---|
| 515 | break |
---|
| 516 | return key,msg,mapping |
---|
| 517 | ###) |
---|
| 518 | ###) |
---|
| 519 | |
---|
| 520 | class CertificateCourseImport(WAeUPImport):###( |
---|
| 521 | name = "certificate_course" |
---|
| 522 | plural_name = "%ss" % name |
---|
| 523 | commit_after = 100000 |
---|
[3219] | 524 | required_modes = ('create','edit') |
---|
[3172] | 525 | |
---|
| 526 | def create(self,mapping): |
---|
| 527 | if getattr(self,'_v_courses',None) is None: |
---|
| 528 | res = self.courses_catalog() |
---|
| 529 | self._v_courses= [course.code for course in res] |
---|
| 530 | if getattr(self,'_v_ceritficates',None) is None: |
---|
| 531 | res = self.portal_catalog(portal_type = "Certificate") |
---|
| 532 | self._v_certificates = {} |
---|
| 533 | for cert in res: |
---|
| 534 | self._v_certificates[cert.getId] = cert.getObject() |
---|
| 535 | msg = '' |
---|
| 536 | while True: |
---|
| 537 | certificate_course_id = mapping.get('code') |
---|
| 538 | if certificate_course_id not in self._v_courses: |
---|
[3233] | 539 | msg = "no course with id: %s" % certificate_course_id |
---|
[3172] | 540 | break |
---|
| 541 | cert_id = mapping['certificate_code'] |
---|
| 542 | cert = self._v_certificates.get(cert_id,None) |
---|
| 543 | if cert is None: |
---|
[3233] | 544 | msg = "no certificate with id: %s" % cert_id |
---|
[3172] | 545 | break |
---|
| 546 | level_id = mapping.get('level') |
---|
| 547 | level = getattr(cert,level_id,None) |
---|
| 548 | if level is None: |
---|
| 549 | cert.invokeFactory('StudyLevel', level_id) |
---|
| 550 | level = getattr(cert,level_id,None) |
---|
| 551 | elif hasattr(level,certificate_course_id): |
---|
[3233] | 552 | msg = "duplicate certificate course id: %(certificate_course_id)s " % vars() |
---|
[3172] | 553 | msg += "in %(cert_id)s/ %(level_id)s" % vars() |
---|
| 554 | break |
---|
| 555 | level.invokeFactory('CertificateCourse', certificate_course_id) |
---|
| 556 | c = getattr(level,certificate_course_id) |
---|
| 557 | c.getContent().edit(mapping=mapping) |
---|
| 558 | break |
---|
| 559 | return certificate_course_id,msg,mapping |
---|
| 560 | ###) |
---|
| 561 | |
---|
| 562 | class DepartmentImport(WAeUPImport):###( |
---|
| 563 | name = "department" |
---|
| 564 | plural_name = "%ss" % name |
---|
[3178] | 565 | commit_after = 1000 |
---|
[3207] | 566 | |
---|
[3172] | 567 | def create(self,mapping):###( |
---|
| 568 | "create a department in the correct faculty" |
---|
[3178] | 569 | faculty_id = mapping['faculty_code'] |
---|
[3172] | 570 | msg = '' |
---|
| 571 | if getattr(self,'_v_faculties',None) is None: |
---|
[3178] | 572 | res = self.portal_catalog(portal_type = "Department") |
---|
[3172] | 573 | self._v_faculties = {} |
---|
| 574 | for f in res: |
---|
| 575 | self._v_faculties[f.getId] = f.getObject() |
---|
[3178] | 576 | department_id = mapping.get('code','') |
---|
[3172] | 577 | while True: |
---|
[3178] | 578 | faculty = self._v_faculties.get(faculty_id,None) |
---|
| 579 | if faculty is None: |
---|
[3233] | 580 | msg = "no faculty with id: %s" % faculty_id |
---|
[3172] | 581 | break |
---|
| 582 | else: |
---|
[3178] | 583 | d = getattr(faculty,department_id,None) |
---|
[3172] | 584 | if d is None or d.portal_type == "Faculty": |
---|
| 585 | try: |
---|
[3178] | 586 | faculty.invokeFactory('Department', department_id) |
---|
[3172] | 587 | except BadRequest,E: |
---|
| 588 | msg = "%s" % E |
---|
| 589 | break |
---|
[3178] | 590 | d = getattr(faculty,department_id) |
---|
[3172] | 591 | d.invokeFactory('CoursesFolder','courses') |
---|
| 592 | courses = getattr(d,'courses') |
---|
| 593 | dict = {'Title': 'Courses'} |
---|
| 594 | courses.getContent().edit(mapping=dict) |
---|
| 595 | d.invokeFactory('CertificatesFolder','certificates') |
---|
| 596 | certificates = getattr(d,'certificates') |
---|
| 597 | dict = {'Title': 'Certificates'} |
---|
| 598 | certificates.getContent().edit(mapping=dict) |
---|
| 599 | d.getContent().edit(mapping=mapping) |
---|
| 600 | break |
---|
[3178] | 601 | return department_id,msg,mapping |
---|
[3172] | 602 | ###) |
---|
| 603 | |
---|
| 604 | def edit(self,mapping): ###( |
---|
[3178] | 605 | "edit a department in the correct faculty" |
---|
[3172] | 606 | academics_folder = self.portal_url.getPortalObject().campus.academics |
---|
[3178] | 607 | faculty_id = mapping['faculty_code'] |
---|
| 608 | department_id = mapping.get('code','') |
---|
[3172] | 609 | msg = '' |
---|
| 610 | while True: |
---|
| 611 | try: |
---|
[3178] | 612 | d = getattr(getattr(academics_folder,faculty_id),department_id,None) |
---|
[3172] | 613 | except KeyError: |
---|
[3233] | 614 | msg = "department %s or faculty %s wrong" % (department_id,faculty_id) |
---|
[3172] | 615 | break |
---|
[3178] | 616 | if d is None or d.portal_type == "Faculty": |
---|
[3233] | 617 | msg = "department %s not found" % (department_id) |
---|
[3178] | 618 | break |
---|
| 619 | d.getContent().edit(mapping=mapping) |
---|
[3172] | 620 | break |
---|
[3178] | 621 | return department_id,msg,mapping |
---|
[3172] | 622 | ###) |
---|
| 623 | ###) |
---|
| 624 | |
---|
| 625 | class FacultyImport(WAeUPImport):###( |
---|
| 626 | name = "faculty" |
---|
[3177] | 627 | plural_name = "faculties" |
---|
[3172] | 628 | commit_after = 100 |
---|
| 629 | |
---|
| 630 | def create(self,mapping): ###( |
---|
| 631 | "create a faculty" |
---|
| 632 | academics_folder = self.portal_url.getPortalObject().campus.academics |
---|
[3178] | 633 | faculty_id = mapping.get('code','') |
---|
[3172] | 634 | msg = '' |
---|
| 635 | while True: |
---|
[3178] | 636 | if faculty_id in academics_folder.objectIds(): |
---|
[3233] | 637 | msg = "faculty with id: %s exists" % faculty_id |
---|
[3172] | 638 | break |
---|
| 639 | logger.info('Creating Faculty %(code)s, %(title)s' % mapping) |
---|
| 640 | try: |
---|
[3178] | 641 | academics_folder.invokeFactory('Faculty', faculty_id) |
---|
[3172] | 642 | except BadRequest,E: |
---|
| 643 | msg = "%s" % E |
---|
| 644 | break |
---|
[3178] | 645 | f = getattr(academics_folder,faculty_id,None) |
---|
[3172] | 646 | f.getContent().edit(mapping=mapping) |
---|
[3177] | 647 | break |
---|
[3178] | 648 | return faculty_id,msg,mapping |
---|
[3172] | 649 | ###) |
---|
| 650 | |
---|
| 651 | def edit(self,mapping): ###( |
---|
| 652 | "edit a faculty" |
---|
| 653 | academics_folder = self.portal_url.getPortalObject().campus.academics |
---|
[3178] | 654 | faculty_id = mapping['code'] |
---|
[3172] | 655 | msg = '' |
---|
| 656 | while True: |
---|
[3178] | 657 | f = getattr(academics_folder,faculty_id,None) |
---|
[3172] | 658 | if f is None: |
---|
[3233] | 659 | msg = "faculty with id: %s does not exist" % faculty_id |
---|
[3172] | 660 | f.getContent().edit(mapping=mapping) |
---|
[3177] | 661 | break |
---|
[3178] | 662 | return faculty_id,msg,mapping |
---|
[3172] | 663 | ###) |
---|
| 664 | ###) |
---|
| 665 | |
---|
| 666 | class StudentImport(WAeUPImport):###( |
---|
| 667 | name = "student" |
---|
| 668 | plural_name = "%ss" % name |
---|
| 669 | commit_after = 100 |
---|
[3207] | 670 | |
---|
[3172] | 671 | field2types_student = { ###( |
---|
| 672 | 'StudentApplication': |
---|
| 673 | {'id': 'application', |
---|
[3481] | 674 | #'title': 'Application Data', |
---|
[3172] | 675 | 'wf_transition_return': 'close', |
---|
| 676 | 'wf_transition_admit': 'remain', |
---|
| 677 | 'fields': |
---|
| 678 | ('jamb_reg_no', |
---|
| 679 | 'entry_mode', |
---|
| 680 | 'entry_session', |
---|
| 681 | 'jamb_score', |
---|
| 682 | 'app_email', |
---|
| 683 | 'jamb_age', |
---|
| 684 | 'jamb_state', |
---|
| 685 | 'jamb_lga', |
---|
| 686 | 'jamb_sex', |
---|
| 687 | ) |
---|
| 688 | }, |
---|
| 689 | #'StudentPume': |
---|
| 690 | # {'id': 'pume', |
---|
| 691 | # 'title': 'Pume Data', |
---|
| 692 | # 'wf_transition_return': 'close', |
---|
| 693 | # 'wf_transition_admit': 'close', |
---|
| 694 | # 'fields': |
---|
| 695 | # ('pume_score', |
---|
| 696 | # ) |
---|
| 697 | # }, |
---|
| 698 | 'StudentClearance': |
---|
| 699 | {'id': 'clearance', |
---|
[3481] | 700 | #'title': 'Clearance/Eligibility Record', |
---|
[3172] | 701 | 'wf_transition_return': 'close', |
---|
| 702 | 'wf_transition_admit': 'remain', |
---|
| 703 | 'fields': |
---|
| 704 | ('matric_no', |
---|
| 705 | 'nationality', |
---|
| 706 | 'lga', |
---|
| 707 | 'birthday', |
---|
| 708 | ) |
---|
| 709 | }, |
---|
| 710 | 'StudentPersonal': |
---|
| 711 | {'id': 'personal', |
---|
[3481] | 712 | #'title': 'Personal Data', |
---|
[3172] | 713 | 'wf_transition_return': 'open', |
---|
| 714 | 'wf_transition_admit': 'remain', |
---|
| 715 | 'fields': |
---|
| 716 | ('firstname', |
---|
| 717 | 'middlename', |
---|
| 718 | 'lastname', |
---|
| 719 | 'sex', |
---|
| 720 | 'email', |
---|
| 721 | 'phone', |
---|
| 722 | 'perm_address', |
---|
| 723 | ) |
---|
| 724 | }, |
---|
| 725 | 'StudentStudyCourse': |
---|
| 726 | {'id': 'study_course', |
---|
[3481] | 727 | #'title': 'Study Course', |
---|
[3172] | 728 | 'wf_transition_return': 'open', |
---|
| 729 | 'wf_transition_admit': 'remain', |
---|
| 730 | 'fields': |
---|
| 731 | ('study_course', |
---|
| 732 | 'current_level', |
---|
| 733 | 'current_session', |
---|
| 734 | 'current_mode', |
---|
| 735 | 'current_verdict', |
---|
| 736 | 'previous_verdict', |
---|
| 737 | ) |
---|
| 738 | }, |
---|
| 739 | # 'StudentStudyLevel': |
---|
| 740 | # {'id': 'current_level', |
---|
| 741 | # 'title': '', |
---|
| 742 | # 'wf_transition_return': 'open', |
---|
| 743 | # 'wf_transition_admit': 'remain', |
---|
| 744 | # 'fields': |
---|
| 745 | # ('verdict', |
---|
| 746 | # 'session', |
---|
| 747 | # ) |
---|
| 748 | # }, |
---|
| 749 | 'PaymentsFolder': |
---|
| 750 | {'id': 'payments', |
---|
[3481] | 751 | #'title': 'Payments', |
---|
[3172] | 752 | 'wf_transition_return': 'open', |
---|
| 753 | 'wf_transition_admit': 'open', |
---|
| 754 | 'fields': |
---|
| 755 | () |
---|
| 756 | }, |
---|
| 757 | } |
---|
| 758 | ###) |
---|
| 759 | |
---|
| 760 | def create(self,mapping): ###( |
---|
| 761 | "create student records due import" |
---|
| 762 | logger = logging.getLogger('WAeUPTool.mass_create_student') |
---|
| 763 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 764 | jamb_reg_no = mapping.get('jamb_reg_no',None) |
---|
[3185] | 765 | matric_no = mapping.get('matric_no',None) |
---|
[3172] | 766 | msg = '' |
---|
[3185] | 767 | student_id = mapping.get('id',None) |
---|
[3172] | 768 | while True: |
---|
[3185] | 769 | if student_id: |
---|
| 770 | msg = "student_id must not be specified in create mode" |
---|
| 771 | break |
---|
[3172] | 772 | if jamb_reg_no: |
---|
| 773 | res = self.students_catalog(jamb_reg_no = jamb_reg_no) |
---|
| 774 | if res: |
---|
[3404] | 775 | msg = "jamb_reg_no already assigned to student %s" % res[0].id |
---|
[3172] | 776 | break |
---|
| 777 | if matric_no: |
---|
| 778 | res = self.students_catalog(matric_no = matric_no) |
---|
| 779 | if res: |
---|
[3404] | 780 | msg = "matric_no already assigned to student %s" % res[0].id |
---|
[3172] | 781 | break |
---|
[3208] | 782 | if not matric_no and not jamb_reg_no: |
---|
[3185] | 783 | msg = "jamb_reg_no or matric_no must be specified" |
---|
| 784 | break |
---|
[3172] | 785 | student_id = self.waeup_tool.generateStudentId('?') |
---|
| 786 | students_folder.invokeFactory('Student', student_id) |
---|
| 787 | student_obj = getattr(students_folder,student_id) |
---|
| 788 | f2t = self.field2types_student |
---|
| 789 | d = {} |
---|
| 790 | transition = mapping.get('reg_transition','admit') |
---|
| 791 | if transition not in ('admit','return'): |
---|
| 792 | msg = "no valid transition provided" |
---|
| 793 | break |
---|
| 794 | for pt in f2t.keys(): |
---|
| 795 | student_obj.invokeFactory(pt,f2t[pt]['id']) |
---|
| 796 | sub_obj = getattr(student_obj,f2t[pt]['id']) |
---|
| 797 | sub_doc = sub_obj.getContent() |
---|
[3481] | 798 | #d['Title'] = f2t[pt]['title'] |
---|
[3172] | 799 | for field in f2t[pt]['fields']: |
---|
| 800 | d[field] = mapping.get(field,'') |
---|
[3207] | 801 | |
---|
[3172] | 802 | if pt == "StudentApplication": |
---|
| 803 | #d['jamb_sex'] = 'M' |
---|
| 804 | #if mapping.get('sex'): |
---|
| 805 | # d['jamb_sex'] = 'F' |
---|
| 806 | d['jamb_firstname'] = mapping.get('firstname',None) |
---|
| 807 | d['jamb_middlename'] = mapping.get('middlename',None) |
---|
| 808 | d['jamb_lastname'] = mapping.get('lastname',None) |
---|
[3207] | 809 | |
---|
[3172] | 810 | # if pt == "StudyCourse": |
---|
| 811 | # for von,zu in (('entry_mode','current_mode'), |
---|
| 812 | # ('entry_session','current_session')): |
---|
| 813 | # if mapping.get(zu,None) is None and mapping.get(von,None) is not None: |
---|
| 814 | # d[zu] = mapping[von] |
---|
| 815 | sub_doc.edit(mapping = d) |
---|
[3207] | 816 | |
---|
[3172] | 817 | #import pdb;pdb.set_trace() |
---|
| 818 | new_state = f2t[pt]['wf_transition_%(transition)s' % vars()] |
---|
| 819 | if new_state != "remain": |
---|
| 820 | self.portal_workflow.doActionFor(sub_obj,new_state,dest_container=sub_obj) |
---|
| 821 | self.portal_workflow.doActionFor(student_obj,transition) |
---|
| 822 | student_obj.manage_setLocalRoles(student_id, ['Owner',]) |
---|
[3179] | 823 | mapping['id'] = student_id |
---|
[3172] | 824 | break |
---|
| 825 | return student_id,msg,mapping |
---|
| 826 | ###) |
---|
| 827 | |
---|
[3179] | 828 | def edit(self,mapping): ###( |
---|
[3402] | 829 | "edit student records due import" |
---|
[3172] | 830 | wftool = self.portal_workflow |
---|
| 831 | logger = logging.getLogger('WAeUPTool.mass_edit_student') |
---|
| 832 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 833 | student_id = mapping.get('id',None) |
---|
| 834 | jamb_reg_no = mapping.get('jamb_reg_no',None) |
---|
| 835 | matric_no = mapping.get('matric_no',None) |
---|
| 836 | editable_keys = mapping.keys() |
---|
| 837 | msg = '' |
---|
| 838 | while True: |
---|
| 839 | if student_id: |
---|
| 840 | res = self.students_catalog(id = student_id) |
---|
| 841 | if not res: |
---|
| 842 | msg = "no student with id %s" % student_id |
---|
| 843 | break |
---|
| 844 | student_record = res[0] |
---|
| 845 | if matric_no and student_record.matric_no: |
---|
| 846 | if matric_no != student_record.matric_no: |
---|
[3402] | 847 | res = self.students_catalog(matric_no = matric_no) |
---|
| 848 | if res: |
---|
[3404] | 849 | msg = "matric_no already assigned to student %s" % res[0].id |
---|
[3402] | 850 | break |
---|
[3172] | 851 | msg = "old matric_no %s overwritten with %s" % (student_record.matric_no,matric_no) |
---|
| 852 | #logger.info("%s, old matric_no %s overwritten with %s" % (student_record.id,student_record.matric_no,matric_no)) |
---|
| 853 | if jamb_reg_no and student_record.jamb_reg_no: |
---|
| 854 | if jamb_reg_no != student_record.jamb_reg_no: |
---|
[3404] | 855 | res = self.students_catalog(jamb_reg_no = jamb_reg_no) |
---|
| 856 | if res: |
---|
| 857 | msg = "jamb_reg_no already assigned to student %s" % res[0].id |
---|
[3431] | 858 | break |
---|
[3404] | 859 | msg = "old jamb_reg_no %s overwritten with %s" % (student_record.jamb_reg_no,jamb_reg_no) |
---|
[3172] | 860 | #logger.info("%s, old reg_no %s overwritten with %s" % (student_record.id,student_record.jamb_reg_no,jamb_reg_no)) |
---|
| 861 | elif jamb_reg_no: |
---|
| 862 | res = self.students_catalog(jamb_reg_no = jamb_reg_no) |
---|
| 863 | if not res: |
---|
| 864 | msg = "no student with jamb_reg_no %s" % jamb_reg_no |
---|
| 865 | break |
---|
| 866 | student_record = res[0] |
---|
| 867 | editable_keys.remove('jamb_reg_no') |
---|
| 868 | elif matric_no: |
---|
| 869 | res = self.students_catalog(matric_no = matric_no) |
---|
| 870 | if not res: |
---|
| 871 | msg = "no student with matric_no %s" % matric_no |
---|
| 872 | break |
---|
| 873 | student_record = res[0] |
---|
| 874 | editable_keys.remove('matric_no') |
---|
| 875 | ## included only to change wf state from admitted to returning |
---|
| 876 | #if student_record.review_state not in ('admitted','objection_raised'): |
---|
| 877 | # return '%s' % student_record.id ,"student is not in state admitted or objection_raised" |
---|
| 878 | ## end inclusion |
---|
| 879 | student_id = student_record.id |
---|
| 880 | student_obj = getattr(students_folder,student_id) |
---|
| 881 | f2t = self.field2types_student |
---|
| 882 | d = {} |
---|
| 883 | any_change = False |
---|
| 884 | #special treatment for StudentStudyLevel |
---|
| 885 | d['verdict'] = mapping.get('current_verdict','') |
---|
| 886 | d['session'] = mapping.get('current_session','') |
---|
| 887 | current_level = mapping.get('current_level','') |
---|
| 888 | while d['session'] and d['verdict'] and current_level: |
---|
| 889 | sub_obj = getattr(student_obj,'study_course',None) |
---|
| 890 | if sub_obj is None: |
---|
| 891 | break |
---|
| 892 | level_obj = getattr(sub_obj,current_level,None) |
---|
| 893 | if level_obj is None: |
---|
| 894 | break |
---|
| 895 | any_change = True |
---|
| 896 | level_obj.getContent().edit(mapping = d) |
---|
| 897 | try: |
---|
| 898 | wftool.doActionFor(level_obj,'close') |
---|
| 899 | except: |
---|
| 900 | pass |
---|
| 901 | break |
---|
| 902 | for pt in f2t.keys(): |
---|
| 903 | #if pt == "StudentApplication": |
---|
| 904 | # d['jamb_sex'] = 'M' |
---|
| 905 | # if mapping.get('sex'): |
---|
| 906 | # d['jamb_sex'] = 'F' |
---|
| 907 | intersect = set(f2t[pt]['fields']).intersection(set(editable_keys)) |
---|
| 908 | if intersect and pt not in ('StudentStudyLevel',): |
---|
| 909 | object_id = f2t[pt]['id'] |
---|
| 910 | sub_obj = getattr(student_obj,object_id,None) |
---|
| 911 | if sub_obj is None: |
---|
| 912 | try: |
---|
| 913 | student_obj.invokeFactory(pt,object_id) |
---|
| 914 | except: |
---|
| 915 | continue |
---|
| 916 | sub_obj = getattr(student_obj,object_id) |
---|
[3481] | 917 | #if f2t[pt]['title'] != '': |
---|
| 918 | # d['Title'] = f2t[pt]['title'] |
---|
[3172] | 919 | sub_doc = sub_obj.getContent() |
---|
| 920 | for field in intersect: |
---|
| 921 | changed = False |
---|
| 922 | if getattr(sub_doc,field,None) != mapping.get(field,''): |
---|
| 923 | any_change = True |
---|
| 924 | changed = True |
---|
| 925 | d[field] = mapping.get(field,'') |
---|
| 926 | if changed: |
---|
| 927 | sub_doc.edit(mapping = d) |
---|
| 928 | ## included only to change wf state from admitted to returning |
---|
| 929 | # if student_record.review_state in ('admitted','objection_raised'): |
---|
| 930 | # new_state = f2t[pt]['wf_transition_return'] |
---|
| 931 | # sub_obj = getattr(student_obj,f2t[pt]['id'],None) |
---|
| 932 | # if sub_obj and new_state != "remain": |
---|
| 933 | # try: |
---|
| 934 | # self.portal_workflow.doActionFor(sub_obj,new_state,dest_container=sub_obj) |
---|
| 935 | # except: |
---|
| 936 | # #logger.info('%s, wf transition %s of %s failed' % (student_id,new_state,sub_obj.id)) |
---|
| 937 | # pass |
---|
| 938 | #if student_record.review_state in ('admitted','objection_raised'): |
---|
| 939 | # wfaction = 'return' |
---|
| 940 | # try: |
---|
| 941 | # self.portal_workflow.doActionFor(student_obj,wfaction) |
---|
| 942 | # logger.info('%s, wf state changed' % student_id) |
---|
| 943 | # any_change = True |
---|
| 944 | # except: |
---|
| 945 | # logger.info('%s, wf transition failed, old state = %s' % (student_id,student_record.review_state)) |
---|
| 946 | # pass |
---|
| 947 | ## end inclusion |
---|
| 948 | break |
---|
| 949 | # if not any_change: |
---|
| 950 | # msg = 'not modified' |
---|
| 951 | return student_id,msg,mapping |
---|
| 952 | ###) |
---|
[3179] | 953 | ###) |
---|
[3172] | 954 | |
---|
[3372] | 955 | class StudentStudyLevelImport(WAeUPImport):###( |
---|
| 956 | """ StudentStudyLevelImport """ |
---|
| 957 | name = "student_study_level" |
---|
| 958 | plural_name = "%ss" % name |
---|
| 959 | commit_after = 1000000 |
---|
| 960 | required_modes = ('create',) |
---|
| 961 | |
---|
[3381] | 962 | def create(self,mapping): ###( |
---|
[3372] | 963 | "edit student levels and create StudentStudyLevel object if not existent" |
---|
| 964 | wftool = self.portal_workflow |
---|
| 965 | logger = logging.getLogger('WAeUPTool.mass_create_level') |
---|
| 966 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 967 | student_id = mapping.get('id',None) |
---|
| 968 | matric_no = mapping.get('matric_no',None) |
---|
| 969 | editable_keys = mapping.keys() |
---|
| 970 | key = '' |
---|
| 971 | msg = '' |
---|
| 972 | while True: |
---|
| 973 | result = self.findStudent('create',student_id=student_id,matric_no=matric_no) |
---|
| 974 | msg = result['msg'] |
---|
| 975 | if msg: |
---|
| 976 | break |
---|
| 977 | student_record = result['student_record'] |
---|
| 978 | student_id = student_record.id |
---|
| 979 | mapping['id'] = student_id |
---|
| 980 | session = mapping.get('session','') |
---|
| 981 | level = key = mapping.get('code','') |
---|
| 982 | if not level.isdigit(): |
---|
| 983 | msg = 'student %s: imported level is empty' % (student_id,) |
---|
| 984 | break |
---|
[3381] | 985 | study_course_obj = getattr(getattr(students_folder,student_id),'study_course',None) |
---|
[3372] | 986 | if study_course_obj is None: |
---|
| 987 | msg = 'student %s: no study_course object' % student_id |
---|
| 988 | break |
---|
| 989 | level_obj = getattr(study_course_obj,level,None) |
---|
| 990 | if level_obj is None: |
---|
| 991 | # The only difference to the edit method is that we create a StudentStudyLevel object |
---|
| 992 | try: |
---|
| 993 | study_course_obj.invokeFactory('StudentStudyLevel',"%s" % level) |
---|
| 994 | level_obj = getattr(context,"%s" % level) |
---|
| 995 | except: |
---|
| 996 | continue |
---|
| 997 | level_obj.getContent().edit(mapping = mapping) |
---|
| 998 | level_review_state = wftool.getInfoFor(level_obj,'review_state',None) |
---|
| 999 | if level_review_state != "closed": |
---|
| 1000 | wftool.doActionFor(level_obj,'close') |
---|
| 1001 | break |
---|
| 1002 | return key,msg,mapping |
---|
| 1003 | ###) |
---|
| 1004 | |
---|
| 1005 | def edit(self,mapping): ###( |
---|
| 1006 | "edit student levels" |
---|
| 1007 | wftool = self.portal_workflow |
---|
| 1008 | logger = logging.getLogger('WAeUPTool.mass_edit_level') |
---|
| 1009 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 1010 | student_id = mapping.get('id',None) |
---|
| 1011 | matric_no = mapping.get('matric_no',None) |
---|
| 1012 | key = '' |
---|
| 1013 | msg = '' |
---|
| 1014 | while True: |
---|
| 1015 | result = self.findStudent('create',student_id=student_id,matric_no=matric_no) |
---|
| 1016 | msg = result['msg'] |
---|
| 1017 | if msg: |
---|
| 1018 | break |
---|
| 1019 | student_record = result['student_record'] |
---|
| 1020 | student_id = student_record.id |
---|
| 1021 | mapping['id'] = student_id |
---|
[3381] | 1022 | session = mapping.get('session','') |
---|
| 1023 | level = key = mapping.get('code','') |
---|
[3372] | 1024 | #import pdb;pdb.set_trace() |
---|
| 1025 | if not level.isdigit(): |
---|
| 1026 | msg = 'student %s: imported level is empty' % (student_id,) |
---|
| 1027 | break |
---|
[3381] | 1028 | study_course_obj = getattr(getattr(students_folder,student_id),'study_course',None) |
---|
[3372] | 1029 | if study_course_obj is None: |
---|
| 1030 | msg = 'student %s: no study_course object' % student_id |
---|
| 1031 | break |
---|
| 1032 | level_obj = getattr(study_course_obj,level,None) |
---|
| 1033 | if level_obj is None: |
---|
| 1034 | msg = 'student %s: no study_level object for level %s' % (student_id,level) |
---|
| 1035 | break |
---|
| 1036 | level_obj.getContent().edit(mapping = mapping) |
---|
| 1037 | break |
---|
| 1038 | return key,msg,mapping |
---|
| 1039 | ###) |
---|
[3381] | 1040 | ###) |
---|
[3372] | 1041 | |
---|
[3172] | 1042 | class VerdictImport(WAeUPImport):###( |
---|
| 1043 | """ VerdictImport """ |
---|
| 1044 | name = "verdict" |
---|
| 1045 | plural_name = "%ss" % name |
---|
| 1046 | commit_after = 100000 |
---|
| 1047 | required_modes = ('create','edit') |
---|
[3249] | 1048 | |
---|
[3372] | 1049 | def create(self,mapping): ###( |
---|
[3243] | 1050 | "edit student verdicts and create StudentStudyLevel object if not existent" |
---|
| 1051 | wftool = self.portal_workflow |
---|
| 1052 | logger = logging.getLogger('WAeUPTool.mass_edit_verdict') |
---|
| 1053 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 1054 | student_id = mapping.get('id',None) |
---|
| 1055 | matric_no = mapping.get('matric_no',None) |
---|
| 1056 | editable_keys = mapping.keys() |
---|
[3372] | 1057 | key = '' |
---|
[3243] | 1058 | while True: |
---|
[3372] | 1059 | result = self.findStudent('create',student_id=student_id,matric_no=matric_no) |
---|
| 1060 | #student_record,msg = self.getStudentRecord(mapping) |
---|
| 1061 | msg = result['msg'] |
---|
| 1062 | if msg: |
---|
| 1063 | break |
---|
| 1064 | student_record = result['student_record'] |
---|
| 1065 | student_id = student_record.id |
---|
| 1066 | mapping['id'] = student_id |
---|
| 1067 | d = {} |
---|
| 1068 | #import pdb;pdb.set_trace() |
---|
| 1069 | any_change = False |
---|
| 1070 | #special treatment for StudentStudyLevel |
---|
| 1071 | current_session = d['session'] = mapping.get('current_session','') |
---|
| 1072 | if current_session and student_record.session != current_session: |
---|
| 1073 | msg = 'student %s: imported session %s does not match current_session %s' % (student_id, |
---|
| 1074 | current_session, |
---|
| 1075 | student_record.session) |
---|
| 1076 | break |
---|
| 1077 | current_level = mapping.get('current_level','') |
---|
| 1078 | if not current_level.isdigit(): |
---|
| 1079 | msg = 'student %s: imported level is empty' % (student_id,) |
---|
| 1080 | break |
---|
| 1081 | if current_level and student_record.level != current_level: |
---|
| 1082 | msg = 'student %s: imported level %s does not match current_level %s' % (student_id, |
---|
| 1083 | current_level, |
---|
| 1084 | student_record.level) |
---|
| 1085 | break |
---|
| 1086 | student_review_state = student_record.review_state |
---|
| 1087 | if student_review_state == 'deactivated': |
---|
| 1088 | msg = "student %s in review_state %s" % (student_id, student_review_state) |
---|
| 1089 | break |
---|
| 1090 | if student_review_state not in ('courses_validated','returning'): |
---|
| 1091 | msg = "student %s in wrong review_state %s" % (student_id, student_review_state) |
---|
| 1092 | break |
---|
| 1093 | student_obj = getattr(students_folder,student_id) |
---|
| 1094 | # f2t = self.field2types_student |
---|
| 1095 | study_course_obj = getattr(student_obj,'study_course',None) |
---|
| 1096 | if study_course_obj is None: |
---|
| 1097 | msg = 'student %s: no study_course object' % student_id |
---|
| 1098 | break |
---|
| 1099 | level_obj = getattr(study_course_obj,current_level,None) |
---|
| 1100 | |
---|
| 1101 | if level_obj is None: |
---|
| 1102 | # The only difference to the edit method is that we create a StudentStudyLevel object |
---|
| 1103 | try: |
---|
| 1104 | study_course_obj.invokeFactory('StudentStudyLevel',"%s" % current_level) |
---|
| 1105 | level_obj = getattr(context,"%s" % current_level) |
---|
| 1106 | level_obj.portal_workflow.doActionFor(level,'open') |
---|
| 1107 | except: |
---|
| 1108 | continue |
---|
| 1109 | #msg = 'student %s: no study_level object for level %s' % (student_id, |
---|
| 1110 | # current_level) |
---|
| 1111 | #break |
---|
| 1112 | |
---|
| 1113 | verdict = d['verdict'] = d['current_verdict'] = mapping.get('current_verdict','') |
---|
| 1114 | |
---|
| 1115 | #if verdict == student_record.verdict: |
---|
| 1116 | # msg = 'student %s: verdict already set to %s' % (student_id, |
---|
| 1117 | # verdict) |
---|
| 1118 | |
---|
| 1119 | level_review_state = wftool.getInfoFor(level_obj,'review_state',None) |
---|
| 1120 | if level_review_state != "closed": |
---|
| 1121 | wftool.doActionFor(level_obj,'close') |
---|
| 1122 | # msg = 'student %s: level %s is not closed' % (student_id, |
---|
| 1123 | # current_level) |
---|
| 1124 | |
---|
| 1125 | study_course_obj.getContent().edit(mapping = d) |
---|
| 1126 | level_obj.getContent().edit(mapping = d) |
---|
| 1127 | if student_review_state != "returning": |
---|
| 1128 | wftool.doActionFor(student_obj,'return') |
---|
| 1129 | # try: |
---|
| 1130 | # wftool.doActionFor(level_obj,'close') |
---|
| 1131 | # except: |
---|
| 1132 | # pass |
---|
| 1133 | break |
---|
| 1134 | return student_id,msg,mapping |
---|
| 1135 | ###) |
---|
| 1136 | |
---|
| 1137 | def create_old(self,mapping): ###( |
---|
| 1138 | "edit student verdicts and create StudentStudyLevel object if not existent" |
---|
| 1139 | wftool = self.portal_workflow |
---|
| 1140 | logger = logging.getLogger('WAeUPTool.mass_edit_verdict') |
---|
| 1141 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 1142 | student_id = mapping.get('id',None) |
---|
| 1143 | matric_no = mapping.get('matric_no',None) |
---|
| 1144 | editable_keys = mapping.keys() |
---|
| 1145 | while True: |
---|
[3243] | 1146 | key = '' |
---|
| 1147 | msg = '' |
---|
| 1148 | if student_id: |
---|
| 1149 | student_record = self.students_catalog.getRecordByKey(student_id) |
---|
| 1150 | if student_record is None: |
---|
| 1151 | #return '',"no student with id %s" % student_id |
---|
| 1152 | msg = "no student with id %s" % student_id |
---|
| 1153 | break |
---|
| 1154 | if matric_no and student_record.matric_no and matric_no != student_record.matric_no: |
---|
| 1155 | msg = 'student %s: matric_no %s does not match %s' % (student_record.id, |
---|
| 1156 | student_record.matric_no, |
---|
| 1157 | matric_no) |
---|
| 1158 | break |
---|
| 1159 | mapping['matric_no'] = student_record.matric_no |
---|
| 1160 | elif matric_no: |
---|
| 1161 | res = self.students_catalog(matric_no = matric_no) |
---|
| 1162 | if not res: |
---|
| 1163 | msg = "no student with matric_no %s" % matric_no |
---|
| 1164 | break |
---|
| 1165 | student_record = res[0] |
---|
| 1166 | editable_keys.remove('matric_no') |
---|
| 1167 | else: |
---|
| 1168 | msg = "no id or matric_no specified" |
---|
| 1169 | break |
---|
| 1170 | student_id = student_record.id |
---|
| 1171 | mapping['id'] = student_id |
---|
| 1172 | d = {} |
---|
| 1173 | #import pdb;pdb.set_trace() |
---|
| 1174 | any_change = False |
---|
| 1175 | #special treatment for StudentStudyLevel |
---|
| 1176 | current_session = d['session'] = mapping.get('current_session','') |
---|
| 1177 | if current_session and student_record.session != current_session: |
---|
| 1178 | msg = 'student %s: imported session %s does not match current_session %s' % (student_id, |
---|
| 1179 | current_session, |
---|
| 1180 | student_record.session) |
---|
| 1181 | break |
---|
| 1182 | current_level = mapping.get('current_level','') |
---|
| 1183 | if not current_level.isdigit(): |
---|
| 1184 | msg = 'student %s: imported level is empty' % (student_id,) |
---|
| 1185 | break |
---|
| 1186 | if current_level and student_record.level != current_level: |
---|
| 1187 | msg = 'student %s: imported level %s does not match current_level %s' % (student_id, |
---|
| 1188 | current_level, |
---|
| 1189 | student_record.level) |
---|
| 1190 | break |
---|
| 1191 | student_review_state = student_record.review_state |
---|
| 1192 | if student_review_state == 'deactivated': |
---|
| 1193 | msg = "student %s in review_state %s" % (student_id, student_review_state) |
---|
| 1194 | break |
---|
| 1195 | if student_review_state not in ('courses_validated','returning'): |
---|
| 1196 | msg = "student %s in wrong review_state %s" % (student_id, student_review_state) |
---|
| 1197 | break |
---|
| 1198 | student_obj = getattr(students_folder,student_id) |
---|
| 1199 | # f2t = self.field2types_student |
---|
| 1200 | study_course_obj = getattr(student_obj,'study_course',None) |
---|
| 1201 | if study_course_obj is None: |
---|
| 1202 | msg = 'student %s: no study_course object' % student_id |
---|
| 1203 | break |
---|
| 1204 | level_obj = getattr(study_course_obj,current_level,None) |
---|
[3207] | 1205 | |
---|
[3243] | 1206 | if level_obj is None: |
---|
| 1207 | # The only difference to the edit method is that we create a StudentStudyLevel object |
---|
| 1208 | try: |
---|
| 1209 | study_course_obj.invokeFactory('StudentStudyLevel',"%s" % current_level) |
---|
| 1210 | level_obj = getattr(context,"%s" % current_level) |
---|
| 1211 | level_obj.portal_workflow.doActionFor(level,'open') |
---|
| 1212 | except: |
---|
[3249] | 1213 | continue |
---|
[3243] | 1214 | #msg = 'student %s: no study_level object for level %s' % (student_id, |
---|
| 1215 | # current_level) |
---|
| 1216 | #break |
---|
| 1217 | |
---|
| 1218 | verdict = d['verdict'] = d['current_verdict'] = mapping.get('current_verdict','') |
---|
| 1219 | |
---|
| 1220 | #if verdict == student_record.verdict: |
---|
| 1221 | # msg = 'student %s: verdict already set to %s' % (student_id, |
---|
| 1222 | # verdict) |
---|
| 1223 | |
---|
| 1224 | level_review_state = wftool.getInfoFor(level_obj,'review_state',None) |
---|
| 1225 | if level_review_state != "closed": |
---|
| 1226 | wftool.doActionFor(level_obj,'close') |
---|
| 1227 | # msg = 'student %s: level %s is not closed' % (student_id, |
---|
| 1228 | # current_level) |
---|
| 1229 | |
---|
| 1230 | study_course_obj.getContent().edit(mapping = d) |
---|
| 1231 | level_obj.getContent().edit(mapping = d) |
---|
| 1232 | if student_review_state != "returning": |
---|
| 1233 | wftool.doActionFor(student_obj,'return') |
---|
| 1234 | # try: |
---|
| 1235 | # wftool.doActionFor(level_obj,'close') |
---|
| 1236 | # except: |
---|
| 1237 | # pass |
---|
| 1238 | break |
---|
[3249] | 1239 | return student_id,msg,mapping |
---|
[3372] | 1240 | ###) |
---|
[3243] | 1241 | |
---|
[3372] | 1242 | def edit(self,mapping): ###( |
---|
| 1243 | "edit student verdicts" |
---|
| 1244 | wftool = self.portal_workflow |
---|
| 1245 | logger = logging.getLogger('WAeUPTool.mass_edit_verdict') |
---|
| 1246 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 1247 | student_id = mapping.get('id',None) |
---|
| 1248 | matric_no = mapping.get('matric_no',None) |
---|
| 1249 | editable_keys = mapping.keys() |
---|
| 1250 | key = '' |
---|
| 1251 | while True: |
---|
| 1252 | result = self.findStudent('edit',student_id=student_id,matric_no=matric_no) |
---|
| 1253 | #student_record,msg = self.getStudentRecord(mapping) |
---|
| 1254 | msg = result['msg'] |
---|
| 1255 | if msg: |
---|
| 1256 | break |
---|
| 1257 | student_record = result['student_record'] |
---|
| 1258 | key_used = result['key_used'] |
---|
[3375] | 1259 | if key_used in editable_keys: |
---|
[3374] | 1260 | editable_keys.remove(key_used) |
---|
[3372] | 1261 | student_id = student_record.id |
---|
| 1262 | mapping['id'] = student_id |
---|
| 1263 | d = {} |
---|
| 1264 | #import pdb;pdb.set_trace() |
---|
| 1265 | any_change = False |
---|
| 1266 | #special treatment for StudentStudyLevel |
---|
| 1267 | current_session = d['session'] = mapping.get('current_session','') |
---|
| 1268 | if current_session and student_record.session != current_session: |
---|
| 1269 | msg = 'student %s: imported session %s does not match current_session %s' % (student_id, |
---|
| 1270 | current_session, |
---|
| 1271 | student_record.session) |
---|
| 1272 | break |
---|
| 1273 | current_level = mapping.get('current_level','') |
---|
| 1274 | if not current_level.isdigit(): |
---|
| 1275 | msg = 'student %s: imported level is empty' % (student_id,) |
---|
| 1276 | break |
---|
| 1277 | if current_level and student_record.level != current_level: |
---|
| 1278 | msg = 'student %s: imported level %s does not match current_level %s' % (student_id, |
---|
| 1279 | current_level, |
---|
| 1280 | student_record.level) |
---|
| 1281 | break |
---|
| 1282 | student_review_state = student_record.review_state |
---|
| 1283 | if student_review_state == 'deactivated': |
---|
| 1284 | msg = "student %s in review_state %s" % (student_id, student_review_state) |
---|
| 1285 | break |
---|
| 1286 | if student_review_state not in ('courses_validated','returning'): |
---|
| 1287 | msg = "student %s in wrong review_state %s" % (student_id, student_review_state) |
---|
| 1288 | break |
---|
| 1289 | student_obj = getattr(students_folder,student_id) |
---|
| 1290 | # f2t = self.field2types_student |
---|
| 1291 | study_course_obj = getattr(student_obj,'study_course',None) |
---|
| 1292 | if study_course_obj is None: |
---|
| 1293 | msg = 'student %s: no study_course object' % student_id |
---|
| 1294 | break |
---|
| 1295 | level_obj = getattr(study_course_obj,current_level,None) |
---|
| 1296 | if level_obj is None: |
---|
| 1297 | msg = 'student %s: no study_level object for level %s' % (student_id, |
---|
| 1298 | current_level) |
---|
| 1299 | break |
---|
| 1300 | verdict = d['verdict'] = d['current_verdict'] = mapping.get('current_verdict','') |
---|
[3243] | 1301 | |
---|
[3372] | 1302 | #if verdict == student_record.verdict: |
---|
| 1303 | # msg = 'student %s: verdict already set to %s' % (student_id, |
---|
| 1304 | # verdict) |
---|
| 1305 | |
---|
| 1306 | level_review_state = wftool.getInfoFor(level_obj,'review_state',None) |
---|
| 1307 | if level_review_state != "closed": |
---|
| 1308 | wftool.doActionFor(level_obj,'close') |
---|
| 1309 | # msg = 'student %s: level %s is not closed' % (student_id, |
---|
| 1310 | # current_level) |
---|
| 1311 | |
---|
| 1312 | study_course_obj.getContent().edit(mapping = d) |
---|
| 1313 | level_obj.getContent().edit(mapping = d) |
---|
| 1314 | if student_review_state != "returning": |
---|
| 1315 | wftool.doActionFor(student_obj,'return') |
---|
| 1316 | # try: |
---|
| 1317 | # wftool.doActionFor(level_obj,'close') |
---|
| 1318 | # except: |
---|
| 1319 | # pass |
---|
| 1320 | break |
---|
| 1321 | return student_id,msg,mapping |
---|
| 1322 | ###) |
---|
| 1323 | |
---|
| 1324 | def edit_old(self,mapping): ###( |
---|
[3172] | 1325 | "edit student verdicts" |
---|
| 1326 | wftool = self.portal_workflow |
---|
| 1327 | logger = logging.getLogger('WAeUPTool.mass_edit_verdict') |
---|
| 1328 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 1329 | student_id = mapping.get('id',None) |
---|
| 1330 | matric_no = mapping.get('matric_no',None) |
---|
| 1331 | editable_keys = mapping.keys() |
---|
[3372] | 1332 | key = '' |
---|
[3172] | 1333 | while True: |
---|
| 1334 | msg = '' |
---|
| 1335 | if student_id: |
---|
| 1336 | student_record = self.students_catalog.getRecordByKey(student_id) |
---|
| 1337 | if student_record is None: |
---|
| 1338 | #return '',"no student with id %s" % student_id |
---|
| 1339 | msg = "no student with id %s" % student_id |
---|
| 1340 | break |
---|
| 1341 | if matric_no and student_record.matric_no and matric_no != student_record.matric_no: |
---|
| 1342 | msg = 'student %s: matric_no %s does not match %s' % (student_record.id, |
---|
| 1343 | student_record.matric_no, |
---|
| 1344 | matric_no) |
---|
| 1345 | break |
---|
| 1346 | mapping['matric_no'] = student_record.matric_no |
---|
| 1347 | elif matric_no: |
---|
| 1348 | res = self.students_catalog(matric_no = matric_no) |
---|
| 1349 | if not res: |
---|
| 1350 | msg = "no student with matric_no %s" % matric_no |
---|
| 1351 | break |
---|
| 1352 | student_record = res[0] |
---|
| 1353 | editable_keys.remove('matric_no') |
---|
| 1354 | else: |
---|
| 1355 | msg = "no id or matric_no specified" |
---|
| 1356 | break |
---|
| 1357 | student_id = student_record.id |
---|
| 1358 | mapping['id'] = student_id |
---|
| 1359 | d = {} |
---|
| 1360 | #import pdb;pdb.set_trace() |
---|
| 1361 | any_change = False |
---|
| 1362 | #special treatment for StudentStudyLevel |
---|
| 1363 | current_session = d['session'] = mapping.get('current_session','') |
---|
| 1364 | if current_session and student_record.session != current_session: |
---|
| 1365 | msg = 'student %s: imported session %s does not match current_session %s' % (student_id, |
---|
| 1366 | current_session, |
---|
| 1367 | student_record.session) |
---|
| 1368 | break |
---|
| 1369 | current_level = mapping.get('current_level','') |
---|
| 1370 | if not current_level.isdigit(): |
---|
| 1371 | msg = 'student %s: imported level is empty' % (student_id,) |
---|
| 1372 | break |
---|
| 1373 | if current_level and student_record.level != current_level: |
---|
| 1374 | msg = 'student %s: imported level %s does not match current_level %s' % (student_id, |
---|
| 1375 | current_level, |
---|
| 1376 | student_record.level) |
---|
| 1377 | break |
---|
| 1378 | student_review_state = student_record.review_state |
---|
| 1379 | if student_review_state == 'deactivated': |
---|
| 1380 | msg = "student %s in review_state %s" % (student_id, student_review_state) |
---|
| 1381 | break |
---|
| 1382 | if student_review_state not in ('courses_validated','returning'): |
---|
| 1383 | msg = "student %s in wrong review_state %s" % (student_id, student_review_state) |
---|
| 1384 | break |
---|
| 1385 | student_obj = getattr(students_folder,student_id) |
---|
| 1386 | # f2t = self.field2types_student |
---|
| 1387 | study_course_obj = getattr(student_obj,'study_course',None) |
---|
| 1388 | if study_course_obj is None: |
---|
| 1389 | msg = 'student %s: no study_course object' % student_id |
---|
| 1390 | break |
---|
| 1391 | level_obj = getattr(study_course_obj,current_level,None) |
---|
| 1392 | if level_obj is None: |
---|
| 1393 | msg = 'student %s: no study_level object for level %s' % (student_id, |
---|
| 1394 | current_level) |
---|
| 1395 | break |
---|
| 1396 | verdict = d['verdict'] = d['current_verdict'] = mapping.get('current_verdict','') |
---|
[3207] | 1397 | |
---|
[3172] | 1398 | #if verdict == student_record.verdict: |
---|
| 1399 | # msg = 'student %s: verdict already set to %s' % (student_id, |
---|
| 1400 | # verdict) |
---|
[3207] | 1401 | |
---|
[3172] | 1402 | level_review_state = wftool.getInfoFor(level_obj,'review_state',None) |
---|
| 1403 | if level_review_state != "closed": |
---|
| 1404 | wftool.doActionFor(level_obj,'close') |
---|
| 1405 | # msg = 'student %s: level %s is not closed' % (student_id, |
---|
| 1406 | # current_level) |
---|
[3207] | 1407 | |
---|
[3172] | 1408 | study_course_obj.getContent().edit(mapping = d) |
---|
| 1409 | level_obj.getContent().edit(mapping = d) |
---|
| 1410 | if student_review_state != "returning": |
---|
| 1411 | wftool.doActionFor(student_obj,'return') |
---|
| 1412 | # try: |
---|
| 1413 | # wftool.doActionFor(level_obj,'close') |
---|
| 1414 | # except: |
---|
| 1415 | # pass |
---|
| 1416 | break |
---|
| 1417 | return student_id,msg,mapping |
---|
| 1418 | ###) |
---|
[3372] | 1419 | ###) |
---|