Changeset 3057 for WAeUP_SRP/base


Ignore:
Timestamp:
28 Jan 2008, 15:53:22 (17 years ago)
Author:
joachim
Message:

implemented mass_delete_course_result.
if course-result-data is imported in edit-mode and the filename ends with
"_toDelete.csv" the course-results are deleted.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/base/WAeUPTool.py

    r3053 r3057  
    15951595    security.declareProtected(ModifyPortalContent,'mass_edit_course_result') ###(
    15961596    def mass_edit_course_result(self,mapping):
    1597         #import pdb;pdb.set_trace()
    1598         # if getattr(self,'_v_courses',None) is None:
    1599         #     res = self.courses_catalog()
    1600         #     self._v_courses = {}
    1601         #     for brain in res:
    1602         #         self._v_courses[brain.code] = brain
    1603         # course_id = mapping.get('code')
    1604         # if course_id not in self._v_courses.keys():
    1605         #     return '', "No course with ID: %s" % did
    16061597        id_key = ''
    16071598        for id_key in ('student_id','matric_no'):
     
    16231614        code = mapping['code']
    16241615        mapping['key'] = key = "%(student_id)s|%(level_id)s|%(code)s" % vars()
    1625         # for k in ('semester',):
    1626         #     mapping[k] = getattr(self._v_courses[course_id],k)
    16271616        try:
    16281617            self.course_results.modifyRecord(**mapping)
    16291618        except KeyError:
    16301619            return '', "No course result to edit: %s" % key
     1620        return key,''
     1621    ###)
     1622
     1623    security.declareProtected(ModifyPortalContent,'mass_delete_course_result') ###(
     1624    def mass_delete_course_result(self,mapping):
     1625        id_key = ''
     1626        for id_key in ('student_id','matric_no'):
     1627            id_field = mapping.get(id_key,None)
     1628            if id_field is not None:
     1629                student_id = id_field
     1630                break
     1631        query = Eq(id_key,id_field)
     1632        res = self.students_catalog.evalAdvancedQuery(query)
     1633        if not res:
     1634            return '', "No student with %(id_field)s: %(id_key)s" % vars()
     1635        if id_field != "student_id":
     1636            mapping['student_id'] = res[0].id
     1637        if not res:
     1638            return '', "no student with %(id_key)s %(id_field)s" % vars()
     1639        student_rec = res[0]
     1640        student_id = student_rec.id
     1641        level_id = mapping['level_id']
     1642        code = mapping['code']
     1643        key = "%(student_id)s|%(level_id)s|%(code)s" % vars()
     1644        # for k in ('semester',):
     1645        #     mapping[k] = getattr(self._v_courses[course_id],k)
     1646        if self.course_results.getRecordByKey(key) is None:
     1647            return '', "no course-result with %(key)s" % vars()
     1648        self.course_results.deleteRecord(key)
    16311649        return key,''
    16321650    ###)
     
    20362054        mode = "create"
    20372055        if edit:
    2038             mode = "edit"
     2056            if filename.endswith('_toDelete'):
     2057                mode = "delete"
     2058            else:
     2059                mode = "edit"
    20392060        importer_name = "mass_%(mode)s_%(name)s" % vars()
    20402061        importer = getattr(self, '%s' % importer_name,None)
     
    21112132                tr_count += 1
    21122133                total_imported += 1
    2113                 logger.info("%(total_imported)d of %(total)d %(em)s" % vars())
     2134                logger.info("%(total_imported)d %(mode)sed of %(total)d %(em)s" % vars())
    21142135
    21152136            if total and not total % commit_after:
     
    21352156            open("%s/import/%s_not_imported%s.csv" % (i_home,filename,current),"a").write(
    21362157                                                '\n'.join(not_imported))
    2137         em = "Finished import from %s.csv: %d imported, %d not imported (of total %d)" % (filename,total_imported,total_not_imported,total)
     2158        if mode == 'delete':
     2159            mode = 'delet'
     2160        em = "Finished %(mode)sing from %(filename)s.csv: %(total_imported)d %(mode)sed, %(total_not_imported)d not %(mode)sed (of total %(total)d)" % vars()
    21382161        logger.info(em)
    21392162        return em
Note: See TracChangeset for help on using the changeset viewer.