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