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