Changeset 526 for WAeUP_SRP


Ignore:
Timestamp:
16 Sep 2006, 12:00:33 (18 years ago)
Author:
joachim
Message:

export of Faculties,Departments,Courses,Certificates
and CertificateCourses? as CSV

Location:
WAeUP_SRP/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/Academics.py

    r458 r526  
    1717#registerDirectory('skins/waeup_faculty', globals())
    1818
     19import DateTime
    1920import csv,re
    2021import logging
     
    7677            else:
    7778                d = {}
    78 ##                if not no_import:
    79 ##                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
    80 ##                    no_import.write('"Session","FacultyCode","Description","CollegeCode","FacultyKey","Status","degree_grade","Bankcode"\n')
    81 ##                logger.info('Faculty with ID %(FacultyCode)s %(Description)s already exists' % faculty)
    82 ##                no_import.write('"%(Session)s","%(FacultyCode)s","%(Description)s","%(CollegeCode)s","%(FacultyKey)s","%(Status)s","%(degree_grade)s","%(Bankcode)s"\n' % faculty)
    8379            d['bank_code'] = faculty.get("Bankcode")
    8480            d["degree_grade"] = faculty.get("degree_grade")
     
    8783            d['college_code'] = faculty.get('CollegeCode')
    8884            f.getContent().edit(mapping=d)
    89         return self.academics.academics_contents()
     85        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
    9086    ###)
    9187
     
    106102            logger.info('dumping %s %s ' % (faculty.id, faculty.title))
    107103            print yaml.dump(faculty)
    108         return self.academics.temporary_view_all()
    109         return self.temporary_view_all()
     104        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
    110105
    111106    ###)
     
    155150                    dict = {'Title': 'Certificates'}
    156151                    certificates.getContent().edit(mapping=dict)
    157         return self.academics.academics_contents()
     152        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
    158153    ###)
    159154
     
    233228                dict['passmark'] = 0
    234229            c.getContent().edit(mapping=dict)
    235         return self.academics.academics_contents()
     230        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
    236231    ###)
    237232
     
    310305            print
    311306            c.getContent().edit(mapping=dict)
    312         return self.academics.academics_contents()
     307        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
    313308    ###)
    314309
     
    419414            dict['level'] = cert_course.get('Level')
    420415            cc.getContent().edit(mapping=dict)
    421         return self.academics.academics_contents()
    422     ###)
     416        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
     417    ###)
     418
     419    security.declareProtected(ModifyPortalContent,"exportFacultiesToCSV")###(
     420    def exportFacultiesToCSV(self):
     421        """export Faculies to CSV"""
     422        #return
     423        name = 'Faculty'
     424        no_import = False
     425        logger = logging.getLogger('%s_export' % name)
     426        current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
     427        logger.info('Start exporting %(name)s to %(name)s_%(current)s.csv' % vars())
     428        objects = [f.getObject() for f in self.portal_catalog({'meta_type': name})]
     429        export = []
     430        export.append('"code","review_state","title","title_prefix","college_code","degree_grade","bank_code"')
     431        for obj in objects:
     432            logger.info('exporting %s %s ' % (obj.id, obj.title))
     433            obj_d = obj.getContent()
     434            di = {}
     435            di['code'] = obj_d.code
     436            di['title'] = obj_d.title
     437            di['title_prefix'] = obj_d.title_prefix
     438            di['college_code'] = obj_d.college_code
     439            di['degree_grade'] = obj_d.degree_grade
     440            di['bank_code'] = obj_d.bank_code
     441            di['code'] = di['code'] or obj.id
     442            di['review_state'] = self.portal_workflow.getInfoFor(obj,'review_state','no_state')
     443            export.append('"%(code)s","%(review_state)s","%(title)s","%(title_prefix)s","%(college_code)s","%(degree_grade)s","%(bank_code)s"' % di)
     444        open("%s/import/%s-%s.csv" % (i_home,name,current),"w+").write('\n'.join(export))
     445        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
     446
     447    ###)
     448
     449    security.declareProtected(ModifyPortalContent,"exportDepartmentsToCSV")###(
     450    def exportDepartmentsToCSV(self):
     451        """export Faculies to CSV"""
     452        #return
     453        import copy
     454        name = 'Department'
     455        no_import = False
     456        logger = logging.getLogger('%s_export' % name)
     457        current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
     458        logger.info('Start exporting %(name)s to %(name)s_%(current)s.csv' % vars())
     459        faculties = [f.getObject() for f in self.portal_catalog({'meta_type': 'Faculty'})]
     460        export = []
     461        export.append('"code","review_state","title","title_prefix","faculty_code"')
     462        #import pdb;pdb.set_trace()
     463        for faculty in faculties:
     464            di = {}
     465            di['faculty_code'] = faculty.id
     466            for department in faculty.objectValues():
     467                department_d = department.getContent()
     468                try:
     469                    di['code'] = department_d.code
     470                    di['title'] = department_d.title
     471                    di['title_prefix'] = department_d.title_prefix
     472                    di['code'] = di['code'] or department.id
     473                    di['review_state'] = self.portal_workflow.getInfoFor(department,'review_state','no_state')
     474                    export.append('"%(code)s","%(review_state)s","%(title)s","%(title_prefix)s","%(faculty_code)s""' % di)
     475                    logger.info('exporting %s %s ' % (department.id, department.title))
     476                except:
     477                    logger.info('could not export %s %s ' % (department.id, department.title))
     478                    continue
     479        open("%s/import/%s-%s.csv" % (i_home,name,current),"w+").write('\n'.join(export))
     480        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
     481    ###)
     482
     483    security.declareProtected(ModifyPortalContent,"exportCoursesToCSV")###(
     484    def exportCoursesToCSV(self):
     485        """export Courses to CSV"""
     486        #return
     487        name = 'Course'
     488        no_import = False
     489        logger = logging.getLogger('%s_export' % name)
     490        current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
     491        logger.info('Start exporting %(name)s to %(name)s_%(current)s.csv' % vars())
     492        faculties = [f.getObject() for f in self.portal_catalog({'meta_type': 'Faculty'})]
     493        export = []
     494        heading = '"code","review_state","title","faculty_code","department_code",'
     495        heading += '"credits","org_code","passmark","semester","session"'
     496        dataline = '"%(code)s","%(review_state)s","%(title)s","%(faculty_code)s","%(department_code)s",'
     497        dataline += '"%(credits)s","%(org_code)s","%(passmark)s","%(semester)s","%(session)s"'
     498        export.append(heading)
     499        #import pdb;pdb.set_trace()
     500        for faculty in faculties:
     501            di = {}
     502            di['faculty_code'] = faculty.id
     503            for department in faculty.objectValues():
     504                di['department_code'] = department.id
     505                for course in department.courses.objectValues():
     506                    course_d = course.getContent()
     507                    try:
     508                        di['code'] = course_d.code
     509                        di['title'] = course_d.title
     510                        di['category'] = course_d.category
     511                        di['adm_status'] = course_d.adm_status
     512                        di['credits'] = course_d.credits
     513                        di['former_code'] = course_d.former_code
     514                        di['org_code'] = course_d.org_code
     515                        di['passmark'] = course_d.passmark
     516                        di['semester'] = course_d.semester
     517                        di['session'] = course_d.session
     518                        di['code'] = di['code'] or course.id
     519                        di['review_state'] = self.portal_workflow.getInfoFor(course,'review_state','no_state')
     520                        export.append(dataline % di)
     521                        logger.info('exporting %s %s ' % (course.id, course.title))
     522                    except:
     523                        logger.info('could not export %s %s ' % (course.id, course.title))
     524                    continue
     525        open("%s/import/%s-%s.csv" % (i_home,name,current),"w+").write('\n'.join(export))
     526        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
     527    ###)
     528
     529    security.declareProtected(ModifyPortalContent,"exportCertificatesToCSV")###(
     530    def exportCertificatesToCSV(self):
     531        """export Certificates to CSV"""
     532        #return
     533        name = 'Certificate'
     534        no_import = False
     535        logger = logging.getLogger('%s_export' % name)
     536        current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
     537        logger.info('Start exporting %(name)s to %(name)s_%(current)s.csv' % vars())
     538        faculties = [f.getObject() for f in self.portal_catalog({'meta_type': 'Faculty'})]
     539        export = []
     540        heading = '"code","review_state","title","faculty_code","department_code",'
     541        heading += '"category","end_level","m_prefix","max_elect","max_pass",'
     542        heading += '"n_core","nr_years","original_code","probation_credits",'
     543        heading += '"promotion_credits","start_level","admin_status"'
     544        dataline = '"(code)s","%(review_state)s","%(title)s","%(faculty_code)s","%(department_code)s",'
     545        dataline += '"%(category)s","%(end_level)s","%(m_prefix)s","%(max_elect)s","%(max_pass)s",'
     546        dataline += '"%(n_core)s","%(nr_years)s","%(original_code)s","%(probation_credits)s",'
     547        dataline += '"%(promotion_credits)s","%(start_level)s","%(admin_status)s"'
     548        export.append(heading)
     549        #import pdb;pdb.set_trace()
     550        for faculty in faculties:
     551            di = {}
     552            di['faculty_code'] = faculty.id
     553            for department in faculty.objectValues():
     554                di['department_code'] = department.id
     555                for certificate in department.certificates.objectValues():
     556                    certificate_d = certificate.getContent()
     557                    di['code'] = certificate_d.get('code',None)
     558                    di['title'] = certificate_d.get('title',None)
     559                    di['category'] = certificate_d.get('category',None)
     560                    di['admin_status'] = certificate_d.get('admin_status',None)
     561                    di['end_level'] = certificate_d.get('end_level',None)
     562                    di['m_prefix'] = certificate_d.get('m_prefix',None)
     563                    di['max_elect'] = certificate_d.get('max_elect',None)
     564                    di['max_load'] = certificate_d.get('max_load',None)
     565                    di['max_pass'] = certificate_d.get('max_pass',None)
     566                    di['n_core'] = certificate_d.get('n_core',None)
     567                    di['nr_years'] = certificate_d.get('nr_years',None)
     568                    di['original_code'] = certificate_d.get('original_code',None)
     569                    di['probation_credits'] = certificate_d.get('probation_credits',None)
     570                    di['promotion_credits'] = certificate_d.get('promotion_credits',None)
     571                    di['start_level'] = certificate_d.get('start_level',None)
     572                    di['code'] = di['code'] or certificate.id
     573                    di['review_state'] = self.portal_workflow.getInfoFor(certificate,'review_state','no_state')
     574                    try:
     575                        export.append(dataline % di)
     576                        logger.info('exporting %s %s ' % (certificate.id, certificate.title))
     577                    except:
     578                        logger.info('could not export %s %s ' % (certificate.id, certificate.title))
     579                    continue
     580        open("%s/import/%s-%s.csv" % (i_home,name,current),"w+").write('\n'.join(export))
     581        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
     582    ###)
     583
     584    security.declareProtected(ModifyPortalContent,"exportCertificateCoursesToCSV")###(
     585    def exportCertificateCoursesToCSV(self):
     586        """export CertificateCourses to CSV"""
     587        #return
     588        name = 'CertificateCourse'
     589        no_import = False
     590        logger = logging.getLogger('%s_export' % name)
     591        current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
     592        logger.info('Start exporting %(name)s to %(name)s_%(current)s.csv' % vars())
     593        faculties = [f.getObject() for f in self.portal_catalog({'meta_type': 'Faculty'})]
     594        export = []
     595        heading = '"code","review_state","faculty_code","department_code",'
     596        heading += '"certificate_code","level","semester","core_or_elective"'
     597        dataline = '"%(code)s","%(review_state)s","%(faculty_code)s","%(department_code)s",'
     598        dataline += '"%(certificate_code)s","%(level)s","%(semester)s","%(core_or_elective)s"'
     599        export.append(heading)
     600        #import pdb;pdb.set_trace()
     601        semesters = ['first','second']
     602        for faculty in faculties:
     603            di = {}
     604            di['faculty_code'] = faculty.id
     605            for department in faculty.objectValues():
     606                di['department_code'] = department.id
     607                for certificate in department.certificates.objectValues():
     608                    di['certificate_code'] = certificate.id
     609                    for level in certificate.objectValues():
     610                        di['level'] = level.id
     611                        for sem in semesters:
     612                            semester = getattr(level,sem,None)
     613                            if semester is not None:
     614                                di['semester'] = semesters.index(sem) + 1
     615                                for course in semester.objectValues():
     616                                    course_d = course.getContent()
     617                                    di['code'] = course_d.get('code',None)
     618                                    di['core_or_elective'] = course_d.get('core_or_elective',None)
     619                                    di['code'] = di['code'] or course.id
     620                                    di['review_state'] = self.portal_workflow.getInfoFor(course,'review_state','no_state')
     621                                    try:
     622                                        export.append(dataline % di)
     623                                        logger.info('exporting %s %s ' % (certificate.id, certificate.title))
     624                                    except:
     625                                        logger.info('could not export %s %s ' % (certificate.id, certificate.title))
     626                                        continue
     627        open("%s/import/%s-%s.csv" % (i_home,name,current),"w+").write('\n'.join(export))
     628        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
     629    ###)
     630
    423631
    424632InitializeClass(AcademicsFolder)
  • WAeUP_SRP/trunk/profiles/default/actionicons.xml

    r508 r526  
    179179 <action-icon category="import"
    180180              action_id="import_fulltime_students"
    181               title="Import Fulltime Students" priority="1"
     181              title="Import Fulltime Students" priority="5"
    182182              icon_expr="actionicon_submit.png"/>
    183183 <action-icon category="import" action_id="import_jamb_data"
    184               title="Import JAMB Data" priority="3"
     184              title="Import JAMB Data" priority="6"
    185185              icon_expr="actionicon_submit.png"/>
    186186 <action-icon category="import"
    187187              action_id="import_fulltime_student_results"
    188188              title="Import Fulltime Student Results"
    189               priority="2" icon_expr="actionicon_submit.png"/>
     189              priority="7" icon_expr="actionicon_submit.png"/>
     190 <action-icon category="import"
     191              action_id="export_faculties"
     192              title="Export Faculties"
     193              priority="8" icon_expr="actionicon_submit.png"/>
     194 <action-icon category="import"
     195              action_id="export_departments"
     196              title="Export Departments"
     197              priority="9" icon_expr="actionicon_submit.png"/>
     198 <action-icon category="import"
     199              action_id="export_courses"
     200              title="Export Courses"
     201              priority="10" icon_expr="actionicon_submit.png"/>
     202 <action-icon category="import"
     203              action_id="export_certificates"
     204              title="Export Certificates"
     205              priority="11" icon_expr="actionicon_submit.png"/>
     206 <action-icon category="import"
     207              action_id="export_certificate_courses"
     208              title="Export Certificate Courses"
     209              priority="12" icon_expr="actionicon_submit.png"/>
    190210 <action-icon category="student_navigation" action_id="student_home"
    191211              title="Home" priority="0"
  • WAeUP_SRP/trunk/profiles/default/types/AcademicsFolder.xml

    r486 r526  
    7777  <permission value="Modify portal content"/>
    7878 </action>
    79  <action title="EXPORT: Faculties" action_id="export_faculties"
    80     category="object" condition_expr=""
    81     url_expr="string:${object_url}/yamlDumpFaculties" visible="False">
     79 <action title="EXPORT: Faculties"
     80         action_id="export_faculties"
     81         category="import" condition_expr=""
     82         url_expr="string:${object_url}/exportFacultiesToCSV" visible="True">
    8283  <permission value="Modify portal content"/>
    8384 </action>
     85 <action title="EXPORT: Departments"
     86         action_id="export_departments"
     87         category="import" condition_expr=""
     88         url_expr="string:${object_url}/exportDepartmentsToCSV" visible="True">
     89  <permission value="Modify portal content"/>
     90 </action>
     91 <action title="EXPORT: Courses"
     92         action_id="export_courses"
     93         category="import" condition_expr=""
     94         url_expr="string:${object_url}/exportCoursesToCSV" visible="True">
     95  <permission value="Modify portal content"/>
     96 </action>
     97   <action title="EXPORT: Certificates"
     98         action_id="export_certificates"
     99         category="import" condition_expr=""
     100         url_expr="string:${object_url}/exportCertificatesToCSV" visible="True">
     101  <permission value="Modify portal content"/>
     102 </action>
     103 <action title="EXPORT: CertificateCourses"
     104         action_id="export_certificate_courses"
     105         category="import" condition_expr=""
     106         url_expr="string:${object_url}/exportCertificateCoursesToCSV" visible="True">
     107  <permission value="Modify portal content"/>
     108 </action>
     109
     110
    84111</object>
Note: See TracChangeset for help on using the changeset viewer.