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