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