[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 3549 2008-07-01 08:12:09Z 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') |
---|
[3485] | 457 | session_id = mapping.get('session_id','') |
---|
| 458 | if session_id: |
---|
| 459 | level.getContent().edit(mapping={'session': "%s" % session_id,}) |
---|
[3372] | 460 | self.portal_workflow.doActionFor(level,'close') |
---|
| 461 | self._v_level_created += level_ident, |
---|
| 462 | mapping['key'] = key = "%(student_id)s|%(level_id)s|%(code)s" % vars() |
---|
[3431] | 463 | #overwrite semester and credits in create mode |
---|
[3372] | 464 | for k in ('semester','credits',): |
---|
| 465 | mapping[k] = getattr(self._v_courses[course_id],k) |
---|
| 466 | try: |
---|
| 467 | self.course_results.addRecord(**mapping) |
---|
| 468 | except ValueError: |
---|
| 469 | msg = "course result already exists: %s" % key |
---|
| 470 | break |
---|
| 471 | return key,msg,mapping |
---|
| 472 | ###) |
---|
| 473 | |
---|
[3374] | 474 | def edit(self,mapping): ###( |
---|
[3372] | 475 | msg = '' |
---|
| 476 | key = '' |
---|
| 477 | matric_no = mapping.get('matric_no','') |
---|
[3374] | 478 | id = mapping.get('id','') |
---|
[3372] | 479 | while True: |
---|
| 480 | result = self.findStudent('edit',student_id=id,matric_no=matric_no) |
---|
| 481 | msg = result['msg'] |
---|
[3172] | 482 | if msg: |
---|
| 483 | break |
---|
[3372] | 484 | student_record = result['student_record'] |
---|
[3336] | 485 | student_id = student_record.id |
---|
[3248] | 486 | level_id = mapping.get('level_id','') |
---|
| 487 | code = mapping.get('code','') |
---|
[3431] | 488 | #code = mapping['code'] |
---|
[3172] | 489 | mapping['key'] = key = "%(student_id)s|%(level_id)s|%(code)s" % vars() |
---|
[3330] | 490 | if self.course_results.getRecordByKey(key) is None: |
---|
| 491 | msg = "no course result with key %(key)s" % vars() |
---|
| 492 | break |
---|
| 493 | self.course_results.modifyRecord(**mapping) |
---|
[3172] | 494 | break |
---|
| 495 | return key,msg,mapping |
---|
| 496 | ###) |
---|
| 497 | |
---|
[3195] | 498 | def remove(self,mapping):###( |
---|
[3233] | 499 | key = '' |
---|
[3172] | 500 | msg = '' |
---|
[3374] | 501 | matric_no = mapping.get('matric_no','') |
---|
| 502 | id = mapping.get('id','') |
---|
[3172] | 503 | while True: |
---|
[3374] | 504 | result = self.findStudent('edit',student_id=id,matric_no=matric_no) |
---|
| 505 | msg = result['msg'] |
---|
[3172] | 506 | if msg: |
---|
| 507 | break |
---|
[3374] | 508 | student_record = result['student_record'] |
---|
[3172] | 509 | student_id = student_record.id |
---|
[3248] | 510 | level_id = mapping.get('level_id','') |
---|
| 511 | code = mapping.get('code','') |
---|
[3172] | 512 | key = "%(student_id)s|%(level_id)s|%(code)s" % vars() |
---|
| 513 | if self.course_results.getRecordByKey(key) is None: |
---|
[3233] | 514 | msg = "no course result with key %(key)s" % vars() |
---|
[3172] | 515 | break |
---|
| 516 | self.course_results.deleteRecord(key) |
---|
| 517 | break |
---|
| 518 | return key,msg,mapping |
---|
| 519 | ###) |
---|
| 520 | ###) |
---|
| 521 | |
---|
| 522 | class CertificateCourseImport(WAeUPImport):###( |
---|
| 523 | name = "certificate_course" |
---|
| 524 | plural_name = "%ss" % name |
---|
| 525 | commit_after = 100000 |
---|
[3219] | 526 | required_modes = ('create','edit') |
---|
[3172] | 527 | |
---|
| 528 | def create(self,mapping): |
---|
| 529 | if getattr(self,'_v_courses',None) is None: |
---|
| 530 | res = self.courses_catalog() |
---|
| 531 | self._v_courses= [course.code for course in res] |
---|
| 532 | if getattr(self,'_v_ceritficates',None) is None: |
---|
| 533 | res = self.portal_catalog(portal_type = "Certificate") |
---|
| 534 | self._v_certificates = {} |
---|
| 535 | for cert in res: |
---|
| 536 | self._v_certificates[cert.getId] = cert.getObject() |
---|
| 537 | msg = '' |
---|
| 538 | while True: |
---|
| 539 | certificate_course_id = mapping.get('code') |
---|
| 540 | if certificate_course_id not in self._v_courses: |
---|
[3233] | 541 | msg = "no course with id: %s" % certificate_course_id |
---|
[3172] | 542 | break |
---|
| 543 | cert_id = mapping['certificate_code'] |
---|
| 544 | cert = self._v_certificates.get(cert_id,None) |
---|
| 545 | if cert is None: |
---|
[3233] | 546 | msg = "no certificate with id: %s" % cert_id |
---|
[3172] | 547 | break |
---|
| 548 | level_id = mapping.get('level') |
---|
| 549 | level = getattr(cert,level_id,None) |
---|
| 550 | if level is None: |
---|
| 551 | cert.invokeFactory('StudyLevel', level_id) |
---|
| 552 | level = getattr(cert,level_id,None) |
---|
| 553 | elif hasattr(level,certificate_course_id): |
---|
[3233] | 554 | msg = "duplicate certificate course id: %(certificate_course_id)s " % vars() |
---|
[3172] | 555 | msg += "in %(cert_id)s/ %(level_id)s" % vars() |
---|
| 556 | break |
---|
| 557 | level.invokeFactory('CertificateCourse', certificate_course_id) |
---|
| 558 | c = getattr(level,certificate_course_id) |
---|
| 559 | c.getContent().edit(mapping=mapping) |
---|
| 560 | break |
---|
| 561 | return certificate_course_id,msg,mapping |
---|
| 562 | ###) |
---|
| 563 | |
---|
| 564 | class DepartmentImport(WAeUPImport):###( |
---|
| 565 | name = "department" |
---|
| 566 | plural_name = "%ss" % name |
---|
[3178] | 567 | commit_after = 1000 |
---|
[3207] | 568 | |
---|
[3172] | 569 | def create(self,mapping):###( |
---|
| 570 | "create a department in the correct faculty" |
---|
[3178] | 571 | faculty_id = mapping['faculty_code'] |
---|
[3172] | 572 | msg = '' |
---|
| 573 | if getattr(self,'_v_faculties',None) is None: |
---|
[3549] | 574 | res = self.portal_catalog(portal_type = "Faculty") |
---|
[3172] | 575 | self._v_faculties = {} |
---|
| 576 | for f in res: |
---|
| 577 | self._v_faculties[f.getId] = f.getObject() |
---|
[3178] | 578 | department_id = mapping.get('code','') |
---|
[3172] | 579 | while True: |
---|
[3178] | 580 | faculty = self._v_faculties.get(faculty_id,None) |
---|
| 581 | if faculty is None: |
---|
[3233] | 582 | msg = "no faculty with id: %s" % faculty_id |
---|
[3172] | 583 | break |
---|
| 584 | else: |
---|
[3178] | 585 | d = getattr(faculty,department_id,None) |
---|
[3172] | 586 | if d is None or d.portal_type == "Faculty": |
---|
| 587 | try: |
---|
[3178] | 588 | faculty.invokeFactory('Department', department_id) |
---|
[3172] | 589 | except BadRequest,E: |
---|
| 590 | msg = "%s" % E |
---|
| 591 | break |
---|
[3178] | 592 | d = getattr(faculty,department_id) |
---|
[3172] | 593 | d.invokeFactory('CoursesFolder','courses') |
---|
| 594 | courses = getattr(d,'courses') |
---|
| 595 | dict = {'Title': 'Courses'} |
---|
| 596 | courses.getContent().edit(mapping=dict) |
---|
| 597 | d.invokeFactory('CertificatesFolder','certificates') |
---|
| 598 | certificates = getattr(d,'certificates') |
---|
| 599 | dict = {'Title': 'Certificates'} |
---|
| 600 | certificates.getContent().edit(mapping=dict) |
---|
| 601 | d.getContent().edit(mapping=mapping) |
---|
| 602 | break |
---|
[3178] | 603 | return department_id,msg,mapping |
---|
[3172] | 604 | ###) |
---|
| 605 | |
---|
| 606 | def edit(self,mapping): ###( |
---|
[3178] | 607 | "edit a department in the correct faculty" |
---|
[3172] | 608 | academics_folder = self.portal_url.getPortalObject().campus.academics |
---|
[3178] | 609 | faculty_id = mapping['faculty_code'] |
---|
| 610 | department_id = mapping.get('code','') |
---|
[3172] | 611 | msg = '' |
---|
| 612 | while True: |
---|
| 613 | try: |
---|
[3178] | 614 | d = getattr(getattr(academics_folder,faculty_id),department_id,None) |
---|
[3172] | 615 | except KeyError: |
---|
[3233] | 616 | msg = "department %s or faculty %s wrong" % (department_id,faculty_id) |
---|
[3172] | 617 | break |
---|
[3178] | 618 | if d is None or d.portal_type == "Faculty": |
---|
[3233] | 619 | msg = "department %s not found" % (department_id) |
---|
[3178] | 620 | break |
---|
| 621 | d.getContent().edit(mapping=mapping) |
---|
[3172] | 622 | break |
---|
[3178] | 623 | return department_id,msg,mapping |
---|
[3172] | 624 | ###) |
---|
| 625 | ###) |
---|
| 626 | |
---|
| 627 | class FacultyImport(WAeUPImport):###( |
---|
| 628 | name = "faculty" |
---|
[3177] | 629 | plural_name = "faculties" |
---|
[3172] | 630 | commit_after = 100 |
---|
[3548] | 631 | |
---|
[3172] | 632 | |
---|
| 633 | def create(self,mapping): ###( |
---|
| 634 | "create a faculty" |
---|
| 635 | academics_folder = self.portal_url.getPortalObject().campus.academics |
---|
[3178] | 636 | faculty_id = mapping.get('code','') |
---|
[3172] | 637 | msg = '' |
---|
| 638 | while True: |
---|
[3178] | 639 | if faculty_id in academics_folder.objectIds(): |
---|
[3233] | 640 | msg = "faculty with id: %s exists" % faculty_id |
---|
[3172] | 641 | break |
---|
| 642 | try: |
---|
[3178] | 643 | academics_folder.invokeFactory('Faculty', faculty_id) |
---|
[3172] | 644 | except BadRequest,E: |
---|
| 645 | msg = "%s" % E |
---|
| 646 | break |
---|
[3178] | 647 | f = getattr(academics_folder,faculty_id,None) |
---|
[3172] | 648 | f.getContent().edit(mapping=mapping) |
---|
[3177] | 649 | break |
---|
[3178] | 650 | return faculty_id,msg,mapping |
---|
[3172] | 651 | ###) |
---|
| 652 | |
---|
| 653 | def edit(self,mapping): ###( |
---|
| 654 | "edit a faculty" |
---|
| 655 | academics_folder = self.portal_url.getPortalObject().campus.academics |
---|
[3178] | 656 | faculty_id = mapping['code'] |
---|
[3172] | 657 | msg = '' |
---|
| 658 | while True: |
---|
[3178] | 659 | f = getattr(academics_folder,faculty_id,None) |
---|
[3172] | 660 | if f is None: |
---|
[3233] | 661 | msg = "faculty with id: %s does not exist" % faculty_id |
---|
[3172] | 662 | f.getContent().edit(mapping=mapping) |
---|
[3177] | 663 | break |
---|
[3178] | 664 | return faculty_id,msg,mapping |
---|
[3172] | 665 | ###) |
---|
| 666 | ###) |
---|
| 667 | |
---|
| 668 | class StudentImport(WAeUPImport):###( |
---|
| 669 | name = "student" |
---|
| 670 | plural_name = "%ss" % name |
---|
| 671 | commit_after = 100 |
---|
[3207] | 672 | |
---|
[3172] | 673 | field2types_student = { ###( |
---|
| 674 | 'StudentApplication': |
---|
| 675 | {'id': 'application', |
---|
[3481] | 676 | #'title': 'Application Data', |
---|
[3172] | 677 | 'wf_transition_return': 'close', |
---|
| 678 | 'wf_transition_admit': 'remain', |
---|
| 679 | 'fields': |
---|
| 680 | ('jamb_reg_no', |
---|
| 681 | 'entry_mode', |
---|
| 682 | 'entry_session', |
---|
| 683 | 'jamb_score', |
---|
| 684 | 'app_email', |
---|
| 685 | 'jamb_age', |
---|
| 686 | 'jamb_state', |
---|
| 687 | 'jamb_lga', |
---|
| 688 | 'jamb_sex', |
---|
| 689 | ) |
---|
| 690 | }, |
---|
| 691 | #'StudentPume': |
---|
| 692 | # {'id': 'pume', |
---|
| 693 | # 'title': 'Pume Data', |
---|
| 694 | # 'wf_transition_return': 'close', |
---|
| 695 | # 'wf_transition_admit': 'close', |
---|
| 696 | # 'fields': |
---|
| 697 | # ('pume_score', |
---|
| 698 | # ) |
---|
| 699 | # }, |
---|
| 700 | 'StudentClearance': |
---|
| 701 | {'id': 'clearance', |
---|
[3481] | 702 | #'title': 'Clearance/Eligibility Record', |
---|
[3172] | 703 | 'wf_transition_return': 'close', |
---|
| 704 | 'wf_transition_admit': 'remain', |
---|
| 705 | 'fields': |
---|
| 706 | ('matric_no', |
---|
| 707 | 'nationality', |
---|
| 708 | 'lga', |
---|
| 709 | 'birthday', |
---|
| 710 | ) |
---|
| 711 | }, |
---|
| 712 | 'StudentPersonal': |
---|
| 713 | {'id': 'personal', |
---|
[3481] | 714 | #'title': 'Personal Data', |
---|
[3172] | 715 | 'wf_transition_return': 'open', |
---|
| 716 | 'wf_transition_admit': 'remain', |
---|
| 717 | 'fields': |
---|
| 718 | ('firstname', |
---|
| 719 | 'middlename', |
---|
| 720 | 'lastname', |
---|
| 721 | 'sex', |
---|
| 722 | 'email', |
---|
| 723 | 'phone', |
---|
| 724 | 'perm_address', |
---|
| 725 | ) |
---|
| 726 | }, |
---|
| 727 | 'StudentStudyCourse': |
---|
| 728 | {'id': 'study_course', |
---|
[3481] | 729 | #'title': 'Study Course', |
---|
[3172] | 730 | 'wf_transition_return': 'open', |
---|
| 731 | 'wf_transition_admit': 'remain', |
---|
| 732 | 'fields': |
---|
| 733 | ('study_course', |
---|
| 734 | 'current_level', |
---|
| 735 | 'current_session', |
---|
| 736 | 'current_mode', |
---|
| 737 | 'current_verdict', |
---|
| 738 | 'previous_verdict', |
---|
| 739 | ) |
---|
| 740 | }, |
---|
| 741 | # 'StudentStudyLevel': |
---|
| 742 | # {'id': 'current_level', |
---|
| 743 | # 'title': '', |
---|
| 744 | # 'wf_transition_return': 'open', |
---|
| 745 | # 'wf_transition_admit': 'remain', |
---|
| 746 | # 'fields': |
---|
| 747 | # ('verdict', |
---|
| 748 | # 'session', |
---|
| 749 | # ) |
---|
| 750 | # }, |
---|
| 751 | 'PaymentsFolder': |
---|
| 752 | {'id': 'payments', |
---|
[3481] | 753 | #'title': 'Payments', |
---|
[3172] | 754 | 'wf_transition_return': 'open', |
---|
| 755 | 'wf_transition_admit': 'open', |
---|
| 756 | 'fields': |
---|
| 757 | () |
---|
| 758 | }, |
---|
| 759 | } |
---|
| 760 | ###) |
---|
| 761 | |
---|
| 762 | def create(self,mapping): ###( |
---|
| 763 | "create student records due import" |
---|
| 764 | logger = logging.getLogger('WAeUPTool.mass_create_student') |
---|
| 765 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 766 | jamb_reg_no = mapping.get('jamb_reg_no',None) |
---|
[3185] | 767 | matric_no = mapping.get('matric_no',None) |
---|
[3172] | 768 | msg = '' |
---|
[3185] | 769 | student_id = mapping.get('id',None) |
---|
[3172] | 770 | while True: |
---|
[3185] | 771 | if student_id: |
---|
| 772 | msg = "student_id must not be specified in create mode" |
---|
| 773 | break |
---|
[3172] | 774 | if jamb_reg_no: |
---|
| 775 | res = self.students_catalog(jamb_reg_no = jamb_reg_no) |
---|
| 776 | if res: |
---|
[3404] | 777 | msg = "jamb_reg_no already assigned to student %s" % res[0].id |
---|
[3172] | 778 | break |
---|
| 779 | if matric_no: |
---|
| 780 | res = self.students_catalog(matric_no = matric_no) |
---|
| 781 | if res: |
---|
[3404] | 782 | msg = "matric_no already assigned to student %s" % res[0].id |
---|
[3172] | 783 | break |
---|
[3208] | 784 | if not matric_no and not jamb_reg_no: |
---|
[3185] | 785 | msg = "jamb_reg_no or matric_no must be specified" |
---|
| 786 | break |
---|
[3172] | 787 | student_id = self.waeup_tool.generateStudentId('?') |
---|
| 788 | students_folder.invokeFactory('Student', student_id) |
---|
| 789 | student_obj = getattr(students_folder,student_id) |
---|
| 790 | f2t = self.field2types_student |
---|
| 791 | d = {} |
---|
| 792 | transition = mapping.get('reg_transition','admit') |
---|
| 793 | if transition not in ('admit','return'): |
---|
| 794 | msg = "no valid transition provided" |
---|
| 795 | break |
---|
| 796 | for pt in f2t.keys(): |
---|
| 797 | student_obj.invokeFactory(pt,f2t[pt]['id']) |
---|
| 798 | sub_obj = getattr(student_obj,f2t[pt]['id']) |
---|
| 799 | sub_doc = sub_obj.getContent() |
---|
[3481] | 800 | #d['Title'] = f2t[pt]['title'] |
---|
[3172] | 801 | for field in f2t[pt]['fields']: |
---|
| 802 | d[field] = mapping.get(field,'') |
---|
[3207] | 803 | |
---|
[3172] | 804 | if pt == "StudentApplication": |
---|
| 805 | #d['jamb_sex'] = 'M' |
---|
| 806 | #if mapping.get('sex'): |
---|
| 807 | # d['jamb_sex'] = 'F' |
---|
| 808 | d['jamb_firstname'] = mapping.get('firstname',None) |
---|
| 809 | d['jamb_middlename'] = mapping.get('middlename',None) |
---|
| 810 | d['jamb_lastname'] = mapping.get('lastname',None) |
---|
[3207] | 811 | |
---|
[3172] | 812 | # if pt == "StudyCourse": |
---|
| 813 | # for von,zu in (('entry_mode','current_mode'), |
---|
| 814 | # ('entry_session','current_session')): |
---|
| 815 | # if mapping.get(zu,None) is None and mapping.get(von,None) is not None: |
---|
| 816 | # d[zu] = mapping[von] |
---|
| 817 | sub_doc.edit(mapping = d) |
---|
[3207] | 818 | |
---|
[3172] | 819 | #import pdb;pdb.set_trace() |
---|
| 820 | new_state = f2t[pt]['wf_transition_%(transition)s' % vars()] |
---|
| 821 | if new_state != "remain": |
---|
| 822 | self.portal_workflow.doActionFor(sub_obj,new_state,dest_container=sub_obj) |
---|
| 823 | self.portal_workflow.doActionFor(student_obj,transition) |
---|
| 824 | student_obj.manage_setLocalRoles(student_id, ['Owner',]) |
---|
[3179] | 825 | mapping['id'] = student_id |
---|
[3172] | 826 | break |
---|
| 827 | return student_id,msg,mapping |
---|
| 828 | ###) |
---|
| 829 | |
---|
[3179] | 830 | def edit(self,mapping): ###( |
---|
[3402] | 831 | "edit student records due import" |
---|
[3172] | 832 | wftool = self.portal_workflow |
---|
| 833 | logger = logging.getLogger('WAeUPTool.mass_edit_student') |
---|
| 834 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 835 | student_id = mapping.get('id',None) |
---|
| 836 | jamb_reg_no = mapping.get('jamb_reg_no',None) |
---|
| 837 | matric_no = mapping.get('matric_no',None) |
---|
| 838 | editable_keys = mapping.keys() |
---|
| 839 | msg = '' |
---|
| 840 | while True: |
---|
| 841 | if student_id: |
---|
| 842 | res = self.students_catalog(id = student_id) |
---|
| 843 | if not res: |
---|
| 844 | msg = "no student with id %s" % student_id |
---|
| 845 | break |
---|
| 846 | student_record = res[0] |
---|
| 847 | if matric_no and student_record.matric_no: |
---|
| 848 | if matric_no != student_record.matric_no: |
---|
[3402] | 849 | res = self.students_catalog(matric_no = matric_no) |
---|
| 850 | if res: |
---|
[3404] | 851 | msg = "matric_no already assigned to student %s" % res[0].id |
---|
[3402] | 852 | break |
---|
[3172] | 853 | msg = "old matric_no %s overwritten with %s" % (student_record.matric_no,matric_no) |
---|
| 854 | #logger.info("%s, old matric_no %s overwritten with %s" % (student_record.id,student_record.matric_no,matric_no)) |
---|
| 855 | if jamb_reg_no and student_record.jamb_reg_no: |
---|
| 856 | if jamb_reg_no != student_record.jamb_reg_no: |
---|
[3404] | 857 | res = self.students_catalog(jamb_reg_no = jamb_reg_no) |
---|
| 858 | if res: |
---|
| 859 | msg = "jamb_reg_no already assigned to student %s" % res[0].id |
---|
[3431] | 860 | break |
---|
[3404] | 861 | msg = "old jamb_reg_no %s overwritten with %s" % (student_record.jamb_reg_no,jamb_reg_no) |
---|
[3172] | 862 | #logger.info("%s, old reg_no %s overwritten with %s" % (student_record.id,student_record.jamb_reg_no,jamb_reg_no)) |
---|
| 863 | elif jamb_reg_no: |
---|
| 864 | res = self.students_catalog(jamb_reg_no = jamb_reg_no) |
---|
| 865 | if not res: |
---|
| 866 | msg = "no student with jamb_reg_no %s" % jamb_reg_no |
---|
| 867 | break |
---|
| 868 | student_record = res[0] |
---|
| 869 | editable_keys.remove('jamb_reg_no') |
---|
| 870 | elif matric_no: |
---|
| 871 | res = self.students_catalog(matric_no = matric_no) |
---|
| 872 | if not res: |
---|
| 873 | msg = "no student with matric_no %s" % matric_no |
---|
| 874 | break |
---|
| 875 | student_record = res[0] |
---|
| 876 | editable_keys.remove('matric_no') |
---|
| 877 | ## included only to change wf state from admitted to returning |
---|
| 878 | #if student_record.review_state not in ('admitted','objection_raised'): |
---|
| 879 | # return '%s' % student_record.id ,"student is not in state admitted or objection_raised" |
---|
| 880 | ## end inclusion |
---|
| 881 | student_id = student_record.id |
---|
| 882 | student_obj = getattr(students_folder,student_id) |
---|
| 883 | f2t = self.field2types_student |
---|
| 884 | d = {} |
---|
| 885 | any_change = False |
---|
| 886 | #special treatment for StudentStudyLevel |
---|
| 887 | d['verdict'] = mapping.get('current_verdict','') |
---|
| 888 | d['session'] = mapping.get('current_session','') |
---|
| 889 | current_level = mapping.get('current_level','') |
---|
| 890 | while d['session'] and d['verdict'] and current_level: |
---|
| 891 | sub_obj = getattr(student_obj,'study_course',None) |
---|
| 892 | if sub_obj is None: |
---|
| 893 | break |
---|
| 894 | level_obj = getattr(sub_obj,current_level,None) |
---|
| 895 | if level_obj is None: |
---|
| 896 | break |
---|
| 897 | any_change = True |
---|
| 898 | level_obj.getContent().edit(mapping = d) |
---|
| 899 | try: |
---|
| 900 | wftool.doActionFor(level_obj,'close') |
---|
| 901 | except: |
---|
| 902 | pass |
---|
| 903 | break |
---|
| 904 | for pt in f2t.keys(): |
---|
| 905 | #if pt == "StudentApplication": |
---|
| 906 | # d['jamb_sex'] = 'M' |
---|
| 907 | # if mapping.get('sex'): |
---|
| 908 | # d['jamb_sex'] = 'F' |
---|
| 909 | intersect = set(f2t[pt]['fields']).intersection(set(editable_keys)) |
---|
| 910 | if intersect and pt not in ('StudentStudyLevel',): |
---|
| 911 | object_id = f2t[pt]['id'] |
---|
| 912 | sub_obj = getattr(student_obj,object_id,None) |
---|
| 913 | if sub_obj is None: |
---|
| 914 | try: |
---|
| 915 | student_obj.invokeFactory(pt,object_id) |
---|
| 916 | except: |
---|
| 917 | continue |
---|
| 918 | sub_obj = getattr(student_obj,object_id) |
---|
[3481] | 919 | #if f2t[pt]['title'] != '': |
---|
| 920 | # d['Title'] = f2t[pt]['title'] |
---|
[3172] | 921 | sub_doc = sub_obj.getContent() |
---|
| 922 | for field in intersect: |
---|
| 923 | changed = False |
---|
| 924 | if getattr(sub_doc,field,None) != mapping.get(field,''): |
---|
| 925 | any_change = True |
---|
| 926 | changed = True |
---|
| 927 | d[field] = mapping.get(field,'') |
---|
| 928 | if changed: |
---|
| 929 | sub_doc.edit(mapping = d) |
---|
| 930 | ## included only to change wf state from admitted to returning |
---|
| 931 | # if student_record.review_state in ('admitted','objection_raised'): |
---|
| 932 | # new_state = f2t[pt]['wf_transition_return'] |
---|
| 933 | # sub_obj = getattr(student_obj,f2t[pt]['id'],None) |
---|
| 934 | # if sub_obj and new_state != "remain": |
---|
| 935 | # try: |
---|
| 936 | # self.portal_workflow.doActionFor(sub_obj,new_state,dest_container=sub_obj) |
---|
| 937 | # except: |
---|
| 938 | # #logger.info('%s, wf transition %s of %s failed' % (student_id,new_state,sub_obj.id)) |
---|
| 939 | # pass |
---|
| 940 | #if student_record.review_state in ('admitted','objection_raised'): |
---|
| 941 | # wfaction = 'return' |
---|
| 942 | # try: |
---|
| 943 | # self.portal_workflow.doActionFor(student_obj,wfaction) |
---|
| 944 | # logger.info('%s, wf state changed' % student_id) |
---|
| 945 | # any_change = True |
---|
| 946 | # except: |
---|
| 947 | # logger.info('%s, wf transition failed, old state = %s' % (student_id,student_record.review_state)) |
---|
| 948 | # pass |
---|
| 949 | ## end inclusion |
---|
| 950 | break |
---|
| 951 | # if not any_change: |
---|
| 952 | # msg = 'not modified' |
---|
| 953 | return student_id,msg,mapping |
---|
| 954 | ###) |
---|
[3179] | 955 | ###) |
---|
[3172] | 956 | |
---|
[3372] | 957 | class StudentStudyLevelImport(WAeUPImport):###( |
---|
| 958 | """ StudentStudyLevelImport """ |
---|
| 959 | name = "student_study_level" |
---|
| 960 | plural_name = "%ss" % name |
---|
| 961 | commit_after = 1000000 |
---|
| 962 | required_modes = ('create',) |
---|
| 963 | |
---|
[3381] | 964 | def create(self,mapping): ###( |
---|
[3372] | 965 | "edit student levels and create StudentStudyLevel object if not existent" |
---|
| 966 | wftool = self.portal_workflow |
---|
| 967 | logger = logging.getLogger('WAeUPTool.mass_create_level') |
---|
| 968 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 969 | student_id = mapping.get('id',None) |
---|
| 970 | matric_no = mapping.get('matric_no',None) |
---|
| 971 | editable_keys = mapping.keys() |
---|
| 972 | key = '' |
---|
| 973 | msg = '' |
---|
| 974 | while True: |
---|
| 975 | result = self.findStudent('create',student_id=student_id,matric_no=matric_no) |
---|
| 976 | msg = result['msg'] |
---|
| 977 | if msg: |
---|
| 978 | break |
---|
| 979 | student_record = result['student_record'] |
---|
| 980 | student_id = student_record.id |
---|
| 981 | mapping['id'] = student_id |
---|
| 982 | session = mapping.get('session','') |
---|
| 983 | level = key = mapping.get('code','') |
---|
| 984 | if not level.isdigit(): |
---|
| 985 | msg = 'student %s: imported level is empty' % (student_id,) |
---|
| 986 | break |
---|
[3381] | 987 | study_course_obj = getattr(getattr(students_folder,student_id),'study_course',None) |
---|
[3372] | 988 | if study_course_obj is None: |
---|
| 989 | msg = 'student %s: no study_course object' % student_id |
---|
| 990 | break |
---|
| 991 | level_obj = getattr(study_course_obj,level,None) |
---|
| 992 | if level_obj is None: |
---|
| 993 | # The only difference to the edit method is that we create a StudentStudyLevel object |
---|
| 994 | try: |
---|
| 995 | study_course_obj.invokeFactory('StudentStudyLevel',"%s" % level) |
---|
| 996 | level_obj = getattr(context,"%s" % level) |
---|
| 997 | except: |
---|
| 998 | continue |
---|
| 999 | level_obj.getContent().edit(mapping = mapping) |
---|
| 1000 | level_review_state = wftool.getInfoFor(level_obj,'review_state',None) |
---|
| 1001 | if level_review_state != "closed": |
---|
| 1002 | wftool.doActionFor(level_obj,'close') |
---|
| 1003 | break |
---|
| 1004 | return key,msg,mapping |
---|
| 1005 | ###) |
---|
| 1006 | |
---|
| 1007 | def edit(self,mapping): ###( |
---|
| 1008 | "edit student levels" |
---|
| 1009 | wftool = self.portal_workflow |
---|
| 1010 | logger = logging.getLogger('WAeUPTool.mass_edit_level') |
---|
| 1011 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 1012 | student_id = mapping.get('id',None) |
---|
| 1013 | matric_no = mapping.get('matric_no',None) |
---|
| 1014 | key = '' |
---|
| 1015 | msg = '' |
---|
| 1016 | while True: |
---|
| 1017 | result = self.findStudent('create',student_id=student_id,matric_no=matric_no) |
---|
| 1018 | msg = result['msg'] |
---|
| 1019 | if msg: |
---|
| 1020 | break |
---|
| 1021 | student_record = result['student_record'] |
---|
| 1022 | student_id = student_record.id |
---|
| 1023 | mapping['id'] = student_id |
---|
[3381] | 1024 | session = mapping.get('session','') |
---|
| 1025 | level = key = mapping.get('code','') |
---|
[3372] | 1026 | #import pdb;pdb.set_trace() |
---|
| 1027 | if not level.isdigit(): |
---|
| 1028 | msg = 'student %s: imported level is empty' % (student_id,) |
---|
| 1029 | break |
---|
[3381] | 1030 | study_course_obj = getattr(getattr(students_folder,student_id),'study_course',None) |
---|
[3372] | 1031 | if study_course_obj is None: |
---|
| 1032 | msg = 'student %s: no study_course object' % student_id |
---|
| 1033 | break |
---|
| 1034 | level_obj = getattr(study_course_obj,level,None) |
---|
| 1035 | if level_obj is None: |
---|
| 1036 | msg = 'student %s: no study_level object for level %s' % (student_id,level) |
---|
| 1037 | break |
---|
| 1038 | level_obj.getContent().edit(mapping = mapping) |
---|
| 1039 | break |
---|
| 1040 | return key,msg,mapping |
---|
| 1041 | ###) |
---|
[3381] | 1042 | ###) |
---|
[3372] | 1043 | |
---|
[3172] | 1044 | class VerdictImport(WAeUPImport):###( |
---|
| 1045 | """ VerdictImport """ |
---|
| 1046 | name = "verdict" |
---|
| 1047 | plural_name = "%ss" % name |
---|
| 1048 | commit_after = 100000 |
---|
| 1049 | required_modes = ('create','edit') |
---|
[3249] | 1050 | |
---|
[3372] | 1051 | def create(self,mapping): ###( |
---|
[3243] | 1052 | "edit student verdicts and create StudentStudyLevel object if not existent" |
---|
| 1053 | wftool = self.portal_workflow |
---|
| 1054 | logger = logging.getLogger('WAeUPTool.mass_edit_verdict') |
---|
| 1055 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 1056 | student_id = mapping.get('id',None) |
---|
| 1057 | matric_no = mapping.get('matric_no',None) |
---|
| 1058 | editable_keys = mapping.keys() |
---|
[3372] | 1059 | key = '' |
---|
[3243] | 1060 | while True: |
---|
[3372] | 1061 | result = self.findStudent('create',student_id=student_id,matric_no=matric_no) |
---|
| 1062 | #student_record,msg = self.getStudentRecord(mapping) |
---|
| 1063 | msg = result['msg'] |
---|
| 1064 | if msg: |
---|
| 1065 | break |
---|
| 1066 | student_record = result['student_record'] |
---|
| 1067 | student_id = student_record.id |
---|
| 1068 | mapping['id'] = student_id |
---|
| 1069 | d = {} |
---|
| 1070 | #import pdb;pdb.set_trace() |
---|
| 1071 | any_change = False |
---|
| 1072 | #special treatment for StudentStudyLevel |
---|
| 1073 | current_session = d['session'] = mapping.get('current_session','') |
---|
| 1074 | if current_session and student_record.session != current_session: |
---|
| 1075 | msg = 'student %s: imported session %s does not match current_session %s' % (student_id, |
---|
| 1076 | current_session, |
---|
| 1077 | student_record.session) |
---|
| 1078 | break |
---|
| 1079 | current_level = mapping.get('current_level','') |
---|
| 1080 | if not current_level.isdigit(): |
---|
| 1081 | msg = 'student %s: imported level is empty' % (student_id,) |
---|
| 1082 | break |
---|
| 1083 | if current_level and student_record.level != current_level: |
---|
| 1084 | msg = 'student %s: imported level %s does not match current_level %s' % (student_id, |
---|
| 1085 | current_level, |
---|
| 1086 | student_record.level) |
---|
| 1087 | break |
---|
| 1088 | student_review_state = student_record.review_state |
---|
| 1089 | if student_review_state == 'deactivated': |
---|
| 1090 | msg = "student %s in review_state %s" % (student_id, student_review_state) |
---|
| 1091 | break |
---|
| 1092 | if student_review_state not in ('courses_validated','returning'): |
---|
| 1093 | msg = "student %s in wrong review_state %s" % (student_id, student_review_state) |
---|
| 1094 | break |
---|
| 1095 | student_obj = getattr(students_folder,student_id) |
---|
| 1096 | # f2t = self.field2types_student |
---|
| 1097 | study_course_obj = getattr(student_obj,'study_course',None) |
---|
| 1098 | if study_course_obj is None: |
---|
| 1099 | msg = 'student %s: no study_course object' % student_id |
---|
| 1100 | break |
---|
| 1101 | level_obj = getattr(study_course_obj,current_level,None) |
---|
| 1102 | |
---|
| 1103 | if level_obj is None: |
---|
| 1104 | # The only difference to the edit method is that we create a StudentStudyLevel object |
---|
| 1105 | try: |
---|
| 1106 | study_course_obj.invokeFactory('StudentStudyLevel',"%s" % current_level) |
---|
| 1107 | level_obj = getattr(context,"%s" % current_level) |
---|
| 1108 | level_obj.portal_workflow.doActionFor(level,'open') |
---|
| 1109 | except: |
---|
| 1110 | continue |
---|
| 1111 | #msg = 'student %s: no study_level object for level %s' % (student_id, |
---|
| 1112 | # current_level) |
---|
| 1113 | #break |
---|
| 1114 | |
---|
| 1115 | verdict = d['verdict'] = d['current_verdict'] = mapping.get('current_verdict','') |
---|
| 1116 | |
---|
| 1117 | #if verdict == student_record.verdict: |
---|
| 1118 | # msg = 'student %s: verdict already set to %s' % (student_id, |
---|
| 1119 | # verdict) |
---|
| 1120 | |
---|
| 1121 | level_review_state = wftool.getInfoFor(level_obj,'review_state',None) |
---|
| 1122 | if level_review_state != "closed": |
---|
| 1123 | wftool.doActionFor(level_obj,'close') |
---|
| 1124 | # msg = 'student %s: level %s is not closed' % (student_id, |
---|
| 1125 | # current_level) |
---|
| 1126 | |
---|
| 1127 | study_course_obj.getContent().edit(mapping = d) |
---|
| 1128 | level_obj.getContent().edit(mapping = d) |
---|
| 1129 | if student_review_state != "returning": |
---|
| 1130 | wftool.doActionFor(student_obj,'return') |
---|
| 1131 | # try: |
---|
| 1132 | # wftool.doActionFor(level_obj,'close') |
---|
| 1133 | # except: |
---|
| 1134 | # pass |
---|
| 1135 | break |
---|
| 1136 | return student_id,msg,mapping |
---|
| 1137 | ###) |
---|
| 1138 | |
---|
| 1139 | def create_old(self,mapping): ###( |
---|
| 1140 | "edit student verdicts and create StudentStudyLevel object if not existent" |
---|
| 1141 | wftool = self.portal_workflow |
---|
| 1142 | logger = logging.getLogger('WAeUPTool.mass_edit_verdict') |
---|
| 1143 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 1144 | student_id = mapping.get('id',None) |
---|
| 1145 | matric_no = mapping.get('matric_no',None) |
---|
| 1146 | editable_keys = mapping.keys() |
---|
| 1147 | while True: |
---|
[3243] | 1148 | key = '' |
---|
| 1149 | msg = '' |
---|
| 1150 | if student_id: |
---|
| 1151 | student_record = self.students_catalog.getRecordByKey(student_id) |
---|
| 1152 | if student_record is None: |
---|
| 1153 | #return '',"no student with id %s" % student_id |
---|
| 1154 | msg = "no student with id %s" % student_id |
---|
| 1155 | break |
---|
| 1156 | if matric_no and student_record.matric_no and matric_no != student_record.matric_no: |
---|
| 1157 | msg = 'student %s: matric_no %s does not match %s' % (student_record.id, |
---|
| 1158 | student_record.matric_no, |
---|
| 1159 | matric_no) |
---|
| 1160 | break |
---|
| 1161 | mapping['matric_no'] = student_record.matric_no |
---|
| 1162 | elif matric_no: |
---|
| 1163 | res = self.students_catalog(matric_no = matric_no) |
---|
| 1164 | if not res: |
---|
| 1165 | msg = "no student with matric_no %s" % matric_no |
---|
| 1166 | break |
---|
| 1167 | student_record = res[0] |
---|
| 1168 | editable_keys.remove('matric_no') |
---|
| 1169 | else: |
---|
| 1170 | msg = "no id or matric_no specified" |
---|
| 1171 | break |
---|
| 1172 | student_id = student_record.id |
---|
| 1173 | mapping['id'] = student_id |
---|
| 1174 | d = {} |
---|
| 1175 | #import pdb;pdb.set_trace() |
---|
| 1176 | any_change = False |
---|
| 1177 | #special treatment for StudentStudyLevel |
---|
| 1178 | current_session = d['session'] = mapping.get('current_session','') |
---|
| 1179 | if current_session and student_record.session != current_session: |
---|
| 1180 | msg = 'student %s: imported session %s does not match current_session %s' % (student_id, |
---|
| 1181 | current_session, |
---|
| 1182 | student_record.session) |
---|
| 1183 | break |
---|
| 1184 | current_level = mapping.get('current_level','') |
---|
| 1185 | if not current_level.isdigit(): |
---|
| 1186 | msg = 'student %s: imported level is empty' % (student_id,) |
---|
| 1187 | break |
---|
| 1188 | if current_level and student_record.level != current_level: |
---|
| 1189 | msg = 'student %s: imported level %s does not match current_level %s' % (student_id, |
---|
| 1190 | current_level, |
---|
| 1191 | student_record.level) |
---|
| 1192 | break |
---|
| 1193 | student_review_state = student_record.review_state |
---|
| 1194 | if student_review_state == 'deactivated': |
---|
| 1195 | msg = "student %s in review_state %s" % (student_id, student_review_state) |
---|
| 1196 | break |
---|
| 1197 | if student_review_state not in ('courses_validated','returning'): |
---|
| 1198 | msg = "student %s in wrong review_state %s" % (student_id, student_review_state) |
---|
| 1199 | break |
---|
| 1200 | student_obj = getattr(students_folder,student_id) |
---|
| 1201 | # f2t = self.field2types_student |
---|
| 1202 | study_course_obj = getattr(student_obj,'study_course',None) |
---|
| 1203 | if study_course_obj is None: |
---|
| 1204 | msg = 'student %s: no study_course object' % student_id |
---|
| 1205 | break |
---|
| 1206 | level_obj = getattr(study_course_obj,current_level,None) |
---|
[3207] | 1207 | |
---|
[3243] | 1208 | if level_obj is None: |
---|
| 1209 | # The only difference to the edit method is that we create a StudentStudyLevel object |
---|
| 1210 | try: |
---|
| 1211 | study_course_obj.invokeFactory('StudentStudyLevel',"%s" % current_level) |
---|
| 1212 | level_obj = getattr(context,"%s" % current_level) |
---|
| 1213 | level_obj.portal_workflow.doActionFor(level,'open') |
---|
| 1214 | except: |
---|
[3249] | 1215 | continue |
---|
[3243] | 1216 | #msg = 'student %s: no study_level object for level %s' % (student_id, |
---|
| 1217 | # current_level) |
---|
| 1218 | #break |
---|
| 1219 | |
---|
| 1220 | verdict = d['verdict'] = d['current_verdict'] = mapping.get('current_verdict','') |
---|
| 1221 | |
---|
| 1222 | #if verdict == student_record.verdict: |
---|
| 1223 | # msg = 'student %s: verdict already set to %s' % (student_id, |
---|
| 1224 | # verdict) |
---|
| 1225 | |
---|
| 1226 | level_review_state = wftool.getInfoFor(level_obj,'review_state',None) |
---|
| 1227 | if level_review_state != "closed": |
---|
| 1228 | wftool.doActionFor(level_obj,'close') |
---|
| 1229 | # msg = 'student %s: level %s is not closed' % (student_id, |
---|
| 1230 | # current_level) |
---|
| 1231 | |
---|
| 1232 | study_course_obj.getContent().edit(mapping = d) |
---|
| 1233 | level_obj.getContent().edit(mapping = d) |
---|
| 1234 | if student_review_state != "returning": |
---|
| 1235 | wftool.doActionFor(student_obj,'return') |
---|
| 1236 | # try: |
---|
| 1237 | # wftool.doActionFor(level_obj,'close') |
---|
| 1238 | # except: |
---|
| 1239 | # pass |
---|
| 1240 | break |
---|
[3249] | 1241 | return student_id,msg,mapping |
---|
[3372] | 1242 | ###) |
---|
[3243] | 1243 | |
---|
[3372] | 1244 | def edit(self,mapping): ###( |
---|
| 1245 | "edit student verdicts" |
---|
| 1246 | wftool = self.portal_workflow |
---|
| 1247 | logger = logging.getLogger('WAeUPTool.mass_edit_verdict') |
---|
| 1248 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 1249 | student_id = mapping.get('id',None) |
---|
| 1250 | matric_no = mapping.get('matric_no',None) |
---|
| 1251 | editable_keys = mapping.keys() |
---|
| 1252 | key = '' |
---|
| 1253 | while True: |
---|
| 1254 | result = self.findStudent('edit',student_id=student_id,matric_no=matric_no) |
---|
| 1255 | #student_record,msg = self.getStudentRecord(mapping) |
---|
| 1256 | msg = result['msg'] |
---|
| 1257 | if msg: |
---|
| 1258 | break |
---|
| 1259 | student_record = result['student_record'] |
---|
| 1260 | key_used = result['key_used'] |
---|
[3375] | 1261 | if key_used in editable_keys: |
---|
[3374] | 1262 | editable_keys.remove(key_used) |
---|
[3372] | 1263 | student_id = student_record.id |
---|
| 1264 | mapping['id'] = student_id |
---|
| 1265 | d = {} |
---|
| 1266 | #import pdb;pdb.set_trace() |
---|
| 1267 | any_change = False |
---|
| 1268 | #special treatment for StudentStudyLevel |
---|
| 1269 | current_session = d['session'] = mapping.get('current_session','') |
---|
| 1270 | if current_session and student_record.session != current_session: |
---|
| 1271 | msg = 'student %s: imported session %s does not match current_session %s' % (student_id, |
---|
| 1272 | current_session, |
---|
| 1273 | student_record.session) |
---|
| 1274 | break |
---|
| 1275 | current_level = mapping.get('current_level','') |
---|
| 1276 | if not current_level.isdigit(): |
---|
| 1277 | msg = 'student %s: imported level is empty' % (student_id,) |
---|
| 1278 | break |
---|
| 1279 | if current_level and student_record.level != current_level: |
---|
| 1280 | msg = 'student %s: imported level %s does not match current_level %s' % (student_id, |
---|
| 1281 | current_level, |
---|
| 1282 | student_record.level) |
---|
| 1283 | break |
---|
| 1284 | student_review_state = student_record.review_state |
---|
| 1285 | if student_review_state == 'deactivated': |
---|
| 1286 | msg = "student %s in review_state %s" % (student_id, student_review_state) |
---|
| 1287 | break |
---|
| 1288 | if student_review_state not in ('courses_validated','returning'): |
---|
| 1289 | msg = "student %s in wrong review_state %s" % (student_id, student_review_state) |
---|
| 1290 | break |
---|
| 1291 | student_obj = getattr(students_folder,student_id) |
---|
| 1292 | # f2t = self.field2types_student |
---|
| 1293 | study_course_obj = getattr(student_obj,'study_course',None) |
---|
| 1294 | if study_course_obj is None: |
---|
| 1295 | msg = 'student %s: no study_course object' % student_id |
---|
| 1296 | break |
---|
| 1297 | level_obj = getattr(study_course_obj,current_level,None) |
---|
| 1298 | if level_obj is None: |
---|
| 1299 | msg = 'student %s: no study_level object for level %s' % (student_id, |
---|
| 1300 | current_level) |
---|
| 1301 | break |
---|
| 1302 | verdict = d['verdict'] = d['current_verdict'] = mapping.get('current_verdict','') |
---|
[3243] | 1303 | |
---|
[3372] | 1304 | #if verdict == student_record.verdict: |
---|
| 1305 | # msg = 'student %s: verdict already set to %s' % (student_id, |
---|
| 1306 | # verdict) |
---|
| 1307 | |
---|
| 1308 | level_review_state = wftool.getInfoFor(level_obj,'review_state',None) |
---|
| 1309 | if level_review_state != "closed": |
---|
| 1310 | wftool.doActionFor(level_obj,'close') |
---|
| 1311 | # msg = 'student %s: level %s is not closed' % (student_id, |
---|
| 1312 | # current_level) |
---|
| 1313 | |
---|
| 1314 | study_course_obj.getContent().edit(mapping = d) |
---|
| 1315 | level_obj.getContent().edit(mapping = d) |
---|
| 1316 | if student_review_state != "returning": |
---|
| 1317 | wftool.doActionFor(student_obj,'return') |
---|
| 1318 | # try: |
---|
| 1319 | # wftool.doActionFor(level_obj,'close') |
---|
| 1320 | # except: |
---|
| 1321 | # pass |
---|
| 1322 | break |
---|
| 1323 | return student_id,msg,mapping |
---|
| 1324 | ###) |
---|
| 1325 | |
---|
| 1326 | def edit_old(self,mapping): ###( |
---|
[3172] | 1327 | "edit student verdicts" |
---|
| 1328 | wftool = self.portal_workflow |
---|
| 1329 | logger = logging.getLogger('WAeUPTool.mass_edit_verdict') |
---|
| 1330 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 1331 | student_id = mapping.get('id',None) |
---|
| 1332 | matric_no = mapping.get('matric_no',None) |
---|
| 1333 | editable_keys = mapping.keys() |
---|
[3372] | 1334 | key = '' |
---|
[3172] | 1335 | while True: |
---|
| 1336 | msg = '' |
---|
| 1337 | if student_id: |
---|
| 1338 | student_record = self.students_catalog.getRecordByKey(student_id) |
---|
| 1339 | if student_record is None: |
---|
| 1340 | #return '',"no student with id %s" % student_id |
---|
| 1341 | msg = "no student with id %s" % student_id |
---|
| 1342 | break |
---|
| 1343 | if matric_no and student_record.matric_no and matric_no != student_record.matric_no: |
---|
| 1344 | msg = 'student %s: matric_no %s does not match %s' % (student_record.id, |
---|
| 1345 | student_record.matric_no, |
---|
| 1346 | matric_no) |
---|
| 1347 | break |
---|
| 1348 | mapping['matric_no'] = student_record.matric_no |
---|
| 1349 | elif matric_no: |
---|
| 1350 | res = self.students_catalog(matric_no = matric_no) |
---|
| 1351 | if not res: |
---|
| 1352 | msg = "no student with matric_no %s" % matric_no |
---|
| 1353 | break |
---|
| 1354 | student_record = res[0] |
---|
| 1355 | editable_keys.remove('matric_no') |
---|
| 1356 | else: |
---|
| 1357 | msg = "no id or matric_no specified" |
---|
| 1358 | break |
---|
| 1359 | student_id = student_record.id |
---|
| 1360 | mapping['id'] = student_id |
---|
| 1361 | d = {} |
---|
| 1362 | #import pdb;pdb.set_trace() |
---|
| 1363 | any_change = False |
---|
| 1364 | #special treatment for StudentStudyLevel |
---|
| 1365 | current_session = d['session'] = mapping.get('current_session','') |
---|
| 1366 | if current_session and student_record.session != current_session: |
---|
| 1367 | msg = 'student %s: imported session %s does not match current_session %s' % (student_id, |
---|
| 1368 | current_session, |
---|
| 1369 | student_record.session) |
---|
| 1370 | break |
---|
| 1371 | current_level = mapping.get('current_level','') |
---|
| 1372 | if not current_level.isdigit(): |
---|
| 1373 | msg = 'student %s: imported level is empty' % (student_id,) |
---|
| 1374 | break |
---|
| 1375 | if current_level and student_record.level != current_level: |
---|
| 1376 | msg = 'student %s: imported level %s does not match current_level %s' % (student_id, |
---|
| 1377 | current_level, |
---|
| 1378 | student_record.level) |
---|
| 1379 | break |
---|
| 1380 | student_review_state = student_record.review_state |
---|
| 1381 | if student_review_state == 'deactivated': |
---|
| 1382 | msg = "student %s in review_state %s" % (student_id, student_review_state) |
---|
| 1383 | break |
---|
| 1384 | if student_review_state not in ('courses_validated','returning'): |
---|
| 1385 | msg = "student %s in wrong review_state %s" % (student_id, student_review_state) |
---|
| 1386 | break |
---|
| 1387 | student_obj = getattr(students_folder,student_id) |
---|
| 1388 | # f2t = self.field2types_student |
---|
| 1389 | study_course_obj = getattr(student_obj,'study_course',None) |
---|
| 1390 | if study_course_obj is None: |
---|
| 1391 | msg = 'student %s: no study_course object' % student_id |
---|
| 1392 | break |
---|
| 1393 | level_obj = getattr(study_course_obj,current_level,None) |
---|
| 1394 | if level_obj is None: |
---|
| 1395 | msg = 'student %s: no study_level object for level %s' % (student_id, |
---|
| 1396 | current_level) |
---|
| 1397 | break |
---|
| 1398 | verdict = d['verdict'] = d['current_verdict'] = mapping.get('current_verdict','') |
---|
[3207] | 1399 | |
---|
[3172] | 1400 | #if verdict == student_record.verdict: |
---|
| 1401 | # msg = 'student %s: verdict already set to %s' % (student_id, |
---|
| 1402 | # verdict) |
---|
[3207] | 1403 | |
---|
[3172] | 1404 | level_review_state = wftool.getInfoFor(level_obj,'review_state',None) |
---|
| 1405 | if level_review_state != "closed": |
---|
| 1406 | wftool.doActionFor(level_obj,'close') |
---|
| 1407 | # msg = 'student %s: level %s is not closed' % (student_id, |
---|
| 1408 | # current_level) |
---|
[3207] | 1409 | |
---|
[3172] | 1410 | study_course_obj.getContent().edit(mapping = d) |
---|
| 1411 | level_obj.getContent().edit(mapping = d) |
---|
| 1412 | if student_review_state != "returning": |
---|
| 1413 | wftool.doActionFor(student_obj,'return') |
---|
| 1414 | # try: |
---|
| 1415 | # wftool.doActionFor(level_obj,'close') |
---|
| 1416 | # except: |
---|
| 1417 | # pass |
---|
| 1418 | break |
---|
| 1419 | return student_id,msg,mapping |
---|
| 1420 | ###) |
---|
[3372] | 1421 | ###) |
---|