Changeset 3248 for WAeUP_SRP/base


Ignore:
Timestamp:
28 Feb 2008, 08:03:50 (17 years ago)
Author:
joachim
Message:

check for required fields in item.

Location:
WAeUP_SRP/base
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/base/WAeUPImport.py

    r3243 r3248  
    6060        self.current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
    6161        self.waeup_tool = waeup_tool
     62        self.students_folder = waeup_tool.portal_url.getPortalObject().campus.students
     63        self.academics_folder = waeup_tool.portal_url.getPortalObject().campus.academics
    6264        self.schema_tool = getToolByName(waeup_tool, 'portal_schemas')
    6365        self.layout_tool = getToolByName(waeup_tool, 'portal_layouts')
     
    178180            self._v_certificate_list = []
    179181        if getattr(self,'_v_department_certificates',None) is None:
    180             res = self.portal_catalog(portal_type = "Department")
     182            departments = self.portal_catalog(portal_type = "Department")
    181183            self._v_department_certificates = {}
    182             for d in res:
    183                 self._v_department_certificates[d.getId] = getattr(d.getObject(),"certificates",None)
    184         did = mapping['department_code']
    185         msg = ''
    186         while True:
    187             d = self._v_department_certificates.get(did,None)
    188             if d is None:
    189                 msg =  "no department with id: %s" % did
    190                 break
    191             certificate_id = mapping.get('code')
     184            for d in departments:
     185                certificates_folder = getattr(d.getObject(),"certificates",None)
     186                self._v_department_certificates[d.getId] = certificates_folder.objectIds()
     187        department_id = mapping['department_code']
     188        msg = ''
     189        certificate_id = mapping.get('code')
     190        while True:
     191            department_certificates = self._v_department_certificates.get(department_id,None)
     192            if department_certificates is None:
     193                msg =  "No Department with ID: %s" % department_id
     194                break
    192195            if certificate_id in self._v_certificate_list:
    193                 msg =  "duplicate certificate id: %s" % did
    194                 break
    195             c = getattr(d,certificate_id,None)
    196             if c is not None:
    197                 msg =  "duplicate certificate id: %s" % did
     196                msg =  "Duplicate Certificate ID: %s" % department_id
     197                break
     198            if certificate_id in department_certificates:
     199                msg =  "Duplicate Certificate ID: %s" % department_id
    198200                break
    199201            try:
     
    267269    def edit(self,mapping): ###(
    268270        course_id = mapping.get('code','')
    269         res = self.portal_catalog(id=course_id)
    270         while True:
    271             if not res:
     271        course = self.courses_catalog.getRecordByKey(course_id)
     272        while True:
     273            if course is None:
    272274                msg =  "no course with id: %s" % course_id
    273275                break
    274             c = res[0].getObject()
    275             c.getContent().edit(mapping=mapping)
     276            course_object = getattr(getattr(self.academics_folder,course.department),course_id)
     277            course_object.getContent().edit(mapping=mapping)
    276278            break
    277279        return course_id,msg,mapping
     
    289291        id_field_found = False
    290292        msg = ''
     293        student_record = None
     294        id_count = 0
    291295        for id_key in ('id','matric_no'):
    292296            id_field = mapping.get(id_key,'')
    293297            if id_field:
    294                 if id_field_found:
    295                     msg = "%s must not be provided" % id_key
    296                     break
     298                id_count += 1
    297299                search_key = id_key
    298300                search_field = id_field
    299                 id_field_found = True
    300         #if search_key == "student_id":
    301         #    search_key = 'id'
    302         if not id_field_found:
    303             msg = "neither id nor matric_no provided"
    304             return None,msg
    305         query = Eq(search_key,search_field)
    306         res = self.students_catalog.evalAdvancedQuery(query)
    307         student_record = None
    308         if res:
    309             student_record = res[0]
    310             if search_key == "matric_no":
    311                 mapping['id'] = student_record.id
    312             elif search_key == "id":
    313                 mapping['matric_no'] = student_record.matric_no
    314         else:
    315             msg = "no student with %(search_key)s %(search_field)s" % vars()
     301        while True:
     302            if id_count > 1:
     303                msg = "both id and matric_no are provided"
     304                break
     305            elif id_count == 0:
     306                msg = "neither id nor matric_no provided"
     307                break
     308            query = Eq(search_key,search_field)
     309            res = self.students_catalog.evalAdvancedQuery(query)
     310            if res:
     311                student_record = res[0]
     312                if search_key == "matric_no":
     313                    mapping['id'] = student_record.id
     314                elif search_key == "id":
     315                    mapping['matric_no'] = student_record.matric_no
     316            else:
     317                msg = "no student with %(search_key)s %(search_field)s" % vars()
     318            break
    316319        return student_record,msg
    317320    ###)
     
    337340                break
    338341            student_id = student_record.id
    339             level_id = mapping['level_id']
    340             code = mapping['code']
     342            level_id = mapping.get('level_id','')
     343            code = mapping.get('code','')
    341344            if student_id not in self._v_level_created:
    342345                try:
     
    374377
    375378    def edit(self,mapping): ###(
    376         #import pdb;pdb.set_trace()
    377379        msg = ''
    378380        key = ''
     
    381383            if msg:
    382384                break
    383             if not mapping.get('level_id',''):
    384                 msg =  "level_id is missing"
    385                 break
    386             if not mapping.get('code',''):
    387                 msg =  "code is missing"
    388                 break
    389             student_id = student_record.id
    390             level_id = mapping['level_id']
     385            level_id = mapping.get('level_id','')
     386            code = mapping.get('code','')
    391387            code = mapping['code']
    392388            mapping['key'] = key = "%(student_id)s|%(level_id)s|%(code)s" % vars()
     
    406402            if msg:
    407403                break
    408             if not mapping.get('level_id',''):
    409                 msg =  "level_id is missing"
    410                 break
    411             if not mapping.get('code',''):
    412                 msg =  "code is missing"
    413                 break
    414404            student_id = student_record.id
    415             level_id = mapping['level_id']
    416             code = mapping['code']
     405            level_id = mapping.get('level_id','')
     406            code = mapping.get('code','')
    417407            key = "%(student_id)s|%(level_id)s|%(code)s" % vars()
    418408            if self.course_results.getRecordByKey(key) is None:
  • WAeUP_SRP/base/WAeUPTool.py

    r3219 r3248  
    14781478            total += 1
    14791479            import_mode = item.get('import_mode','edit')
    1480             if (import_mode in importer.required_modes and
    1481                 not set(importer.required_keys[import_mode]).issubset(set(import_keys))):
    1482                 diff2import = set(importer.required_keys[import_mode]).difference(set(import_keys))
    1483                 error_string += 'required key(s): "%s" not found in heading' % ", ".join(diff2import)
    14841480            import_method = getattr(importer, '%(import_mode)s' % vars(),None )
    14851481            if import_method is None:
    14861482                error_string += "no %(import_mode)s " % vars()
     1483            elif (import_mode in importer.required_modes and
     1484                not set(importer.required_keys[import_mode]).issubset(set(item.keys()))):
     1485                diff2import = set(importer.required_keys[import_mode]).difference(set(item.keys()))
     1486                error_string += 'required key(s): "%s" not found in record' % ", ".join(diff2import)
    14871487            else:
    14881488                for k in import_keys:
Note: See TracChangeset for help on using the changeset viewer.