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