Changeset 563 for WAeUP_SRP


Ignore:
Timestamp:
27 Sep 2006, 06:54:55 (18 years ago)
Author:
joachim
Message:

import of csv data ready, startet work on student search

Location:
WAeUP_SRP/trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/Academics.py

    r557 r563  
    4949    security.declareProtected(ModifyPortalContent,"loadFacultiesFromCSV")###(
    5050    def loadFacultiesFromCSV(self):
     51        """install Universityspecific Faculies from CSV values"""
     52        #return
     53        name = 'Faculties'
     54        no_import = False
     55        logger = logging.getLogger('%s_csv_import' % name)
     56        logger.info('Start loading from %s.csv' % name)
     57        academics = self.portal_catalog({'meta_type': 'AcademicsFolder'})[-1].getObject()
     58        try:
     59            faculties = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
     60        except:
     61            logger.error('Error reading %s.csv' % name)
     62            return
     63        l = self.portal_catalog({'meta_type': "Faculty"})
     64        facs = {}
     65        for f in l:
     66            facs[f.id] = f.getObject()
     67        fields = ("code",
     68                  "review_state",
     69                  "title",
     70                  "title_prefix",
     71                  "college_code",
     72                  "degree_grade",
     73                  "bank_code",
     74                  )
     75        format = ' '.join(['%%(%s)s ' % fn for fn in fields])
     76        for faculty in faculties:
     77            processing = "processing %s" % format
     78            logger.info(processing % faculty)
     79            fid = faculty.get('code')
     80            f = facs.get(fid,None)
     81            if f is None:
     82                #self.log('Creating Faculty %(id)s = %(Title)s' % faculty)
     83                logger.info('Creating Faculty with ID %(code)s %(title)s' % faculty)
     84                academics.invokeFactory('Faculty', fid)
     85                f = getattr(self,fid)
     86                d = {'Title': faculty.get('title')}
     87            else:
     88                d = {}
     89            f.getContent().edit(mapping=faculty)
     90        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
     91    ###)
     92
     93
     94    security.declareProtected(ModifyPortalContent,"loadDepartmentsFromCSV")###(
     95    def loadDepartmentsFromCSV(self):
     96        """install Universityspecific Faculies from CSV values"""
     97        #return
     98        name = 'Departments'
     99        no_import = False
     100        logger = logging.getLogger('loaddepartments')
     101        fields = ("code",
     102                  "review_state",
     103                  "title",
     104                  "title_prefix",
     105                  "faculty_code",
     106                  )
     107        format = ' '.join(['%%(%s)s ' % fn for fn in fields])
     108        try:
     109            deps = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
     110        except:
     111            logger.error('Error reading %s.csv' % name)
     112            return
     113        no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
     114        heading = ' '.join(['"%s"' % fn for fn in fields])
     115        no_import.write('%s\n' % heading)
     116        l = self.portal_catalog({'meta_type': "Faculty"})
     117        facs = {}
     118        for f in l:
     119            facs[f.id] = f.getObject()
     120        for dep in deps:
     121            processing = "processing %s" % format
     122            logger.info(processing % dep)
     123            fid = dep['faculty_code']
     124            f = facs.get(fid,None)
     125            if f is None:
     126                logger.info( "No Faculty with ID: %s" % fid)
     127                no_import.write( "No Faculty with ID: %s\n" % fid)
     128                no_import.write(format % dep + "\n")
     129            else:
     130                did = dep.get('code')
     131                d = getattr(f,did,None)
     132                if d is None or d.portal_type == "Faculty":
     133                    logger.info('Creating Department %(code)s = %(title)s' % dep)
     134                    f.invokeFactory('Department', did)
     135                    d = getattr(f,did)
     136                    d.invokeFactory('CoursesFolder','courses')
     137                    courses = getattr(d,'courses')
     138                    dict = {'Title': 'Courses'}
     139                    courses.getContent().edit(mapping=dict)
     140                    d.invokeFactory('CertificatesFolder','certificates')
     141                    certificates = getattr(d,'certificates')
     142                    dict = {'Title': 'Certificates'}
     143                    certificates.getContent().edit(mapping=dict)
     144                d.getContent().edit(mapping=dep)
     145                   
     146        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
     147    ###)
     148
     149    security.declareProtected(ModifyPortalContent,"loadCoursesFromCSV")###(
     150    def loadCoursesFromCSV(self):
     151        """install Universityspecific Courses from CSV values"""
     152        #return
     153        wf = self.portal_workflow
     154        name = 'Courses'
     155        no_import = False
     156        logger = logging.getLogger('loadcourses')
     157        fields = ("code",
     158                  "review_state",
     159                  "title",
     160                  "faculty_code",
     161                  "department_code",
     162                  "credits",
     163                  "org_code",
     164                  "passmark",
     165                  "semester",
     166                  "session",
     167                  )
     168        format = ' '.join(['%%(%s)s ' % fn for fn in fields])
     169        try:
     170            courses = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
     171        except:
     172            logger.error('Error reading %s.csv' % name)
     173            return
     174        no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
     175        heading = ' '.join(['"%s"' % fn for fn in fields])
     176        no_import.write('%s\n' % heading)
     177        l = self.portal_catalog({'meta_type': "Faculty"})
     178        facs = {}
     179        for f in l:
     180            facs[f.id] = f.getObject()
     181        dl = self.portal_catalog({'meta_type': "Department"})
     182        deps = {}
     183        for d in dl:
     184            deps[d.id] = d.getObject()
     185        cl = self.portal_catalog({'meta_type': "Course"})
     186        course_list = [ c.id for c in cl]
     187        for course in courses:
     188            processing = "processing %s" % format
     189            logger.info(processing % course)
     190            depid = course.get('department_code').upper()
     191            if depid in deps.keys():
     192                dept= deps.get(depid)
     193            else:
     194                msg = "Department %(department_code)s for Course %(code)s not found" % course
     195                logger.info(msg)
     196                no_import.write(msg)
     197                no_import.write(format % course + "\n")
     198                continue
     199            course_id = course.get('code')
     200            cf = dept.courses
     201            c = getattr(cf,course_id,None)
     202            if c is None:
     203                logger.info('Creating Course %(code)s  %(title)s in Department %(department_code)s' % course)
     204                cf.invokeFactory('Course', course_id)
     205                c = getattr(cf,course_id)
     206            c.getContent().edit(mapping=course)
     207            review_state = course.get('review_state')
     208            if review_state == "checked" and wf.getInfoFor(c,'review_state',None) != 'checked':
     209                self.portal_workflow.doActionFor(c,'approve')
     210
     211        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
     212    ###)
     213
     214    security.declareProtected(ModifyPortalContent,"loadCertificatesFromCSV")###(
     215
     216    def loadCertificatesFromCSV(self):
     217        """install Universityspecific Certificates from CSV values"""
     218        #return
     219        name = 'Certificates'
     220        wf = self.portal_workflow
     221        no_import_list = []
     222        logger = logging.getLogger('loadcertificates')
     223        fields = ("code",
     224                  "review_state",
     225                  "title",
     226                  "faculty_code",
     227                  "department_code",
     228                  "category",
     229                  "end_level",
     230                  "m_prefix",
     231                  "max_elect",
     232                  "max_pass",
     233                  "n_core",
     234                  "nr_years",
     235                  "original_code",
     236                  "probation_credits",
     237                  "promotion_credits",
     238                  "start_level",
     239                  "admin_status",
     240                  )
     241        format = ' '.join(['%%(%s)s ' % fn for fn in fields])
     242        try:
     243            courses = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
     244        except:
     245            logger.error('Error reading %s.csv' % name)
     246            return
     247        try:
     248            certificates = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
     249        except:
     250            logger.error('Error reading %s.csv' % name)
     251            return
     252        f_ids = [f.id for f in self.portal_catalog({'meta_type': "Faculty"})]
     253        dl = self.portal_catalog({'meta_type': "Department"})
     254        deps = {}
     255        for d in dl:
     256            deps[d.id] = d.getObject()
     257        for certificate in certificates:
     258            processing = "processing %s" % format
     259            logger.info(processing % certificate)
     260            depid = certificate.get('department_code')
     261            facid = certificate.get('faculty_code')
     262            if facid not in f_ids:
     263                msg = 'Faculty %(faculty_code)s for %(code)s %(title)s not found' % certificate
     264                logger.info(msg)
     265                no_import_list.append(msg)
     266                no_import_list.append(format % certificate + "\n")
     267                continue
     268            if not deps.has_key(depid):
     269                msg = 'Department %(department_code)s for %(code)s %(title)s not found' % certificate
     270                logger.info(msg)
     271                no_import_list.append(msg)
     272                no_import_list.append(format % certificate + "\n")
     273                continue
     274            dep = deps[depid]
     275            cf= dep.certificates
     276            code = certificate.get('code')
     277            certificate_id = code
     278            c = getattr(cf,certificate_id,None)
     279            if c is None:
     280                logger.info('Creating certificate %(code)s  %(title)s in Department %(department_code)s' % certificate)
     281                cf.invokeFactory('Certificate', certificate_id)
     282                c = getattr(cf,certificate_id)
     283            c.getContent().edit(mapping=certificate)
     284            review_state = c.get('review_state')
     285            if review_state == "checked" and wf.getInfoFor(c,'review_state',None) != 'checked':
     286                self.portal_workflow.doActionFor(c,'approve')
     287        if no_import_list:
     288            no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
     289            heading = ' '.join(['"%s"' % fn for fn in fields])
     290            no_import.write('%s\n' % heading)
     291            for line in no_import_list:
     292                no_import.write(line)
     293        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
     294    ###)
     295
     296    security.declareProtected(ModifyPortalContent,"loadCertificateCoursesFromCSV")###(
     297    def loadCertificateCoursesFromCSV(self):
     298        """install Certificate Courses from CSV values"""
     299        #return
     300        logger = logging.getLogger('loadcertificatecourses')
     301        name = 'CertificateCourses'
     302        wf = self.portal_workflow
     303        no_import_list = []
     304        logger = logging.getLogger('loadcertificates')
     305        fields = ("code",
     306                  "review_state",
     307                  "faculty_code",
     308                  "department_code",
     309                  "certificate_code",
     310                  "level",
     311                  "semester",
     312                  "core_or_elective",
     313                  )
     314        format = ' '.join(['%%(%s)s ' % fn for fn in fields])
     315        try:
     316            cert_courses = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
     317        except:
     318            logger.error('Error reading %s.csv' % name)
     319            return
     320        d_ids = [d.id for d in self.portal_catalog({'meta_type': "Department"})]
     321        c_ids = [c.id for c in self.portal_catalog({'meta_type': "Course"})]
     322        l = self.portal_catalog({'meta_type': "Certificate"})
     323        certs = {}
     324        for f in l:
     325            certs[f.id] = f.getObject()
     326        for cert_course in cert_courses:
     327            processing = "processing %s" % format
     328            logger.info(processing % cert_course)
     329            depid = cert_course.get('department_code')
     330            course_code = cert_course.get('code')
     331            code = cert_course.get('certificate_code')
     332            if not code in certs.keys():
     333                em = 'CertCode %(certificate_code)s for %(code)s not found\n' % cert_course
     334                logger.info(em)
     335                no_import_list.append(em)
     336                no_import_list.append(format % cert_course + "\n")
     337                continue
     338            certificate = certs[code]
     339            certificate_code = certificate.getId()
     340            if course_code not in c_ids:
     341                em = 'Course %(code)s for %(certificate_code)s Level %(level)s not found in Courses\n' % cert_course
     342                logger.info(em)
     343                no_import_list.append(em)
     344                no_import_list.append(format % cert_course + "\n")
     345                continue
     346            if depid not in d_ids:
     347                em = 'Department %(department_code)s for %(certificate_code)s not found\n' % cert_course
     348                logger.info(em)
     349                no_import_list.append(em)
     350                no_import_list.append(format % cert_course + "\n")
     351                continue
     352            level = cert_course.get('level')
     353            l = getattr(certificate,level,None)
     354            if l is None:
     355                logger.info('Creating Level %(level)s in certificate %(certificate_code)s' % cert_course)
     356                certificate.invokeFactory('StudyLevel', level)
     357                l = getattr(certificate, level)
     358                l.getContent().edit(mapping={'Title': "Level %s" % level})
     359            certificate.orderObjects('id')
     360            if hasattr(l,course_code):
     361                msg = 'Duplicate %(code)s in Level %(level)s' % cert_course
     362                logger.info(msg)
     363                no_import_list.append(msg + "\n")
     364                no_import_list.append(format % cert_course + "\n")
     365                continue
     366            l.invokeFactory('CertificateCourse',course_code)
     367            logger.info('Creating CertificateCourse %(code)s in certificate %(certificate_code)s Level %(level)s' % cert_course)
     368            cc = getattr(l,course_code)
     369            semester = 'first'
     370            try:
     371                sem = int(cert_course.get('semester'))
     372                cert_course['semester'] = ('first','second')[sem - 1]
     373            except:
     374                pass
     375            cert_course['core_or_elective'] = eval(cert_course['core_or_elective'])
     376            cc.getContent().edit(mapping=cert_course)
     377            review_state = cc.get('review_state')
     378            if review_state == "checked" and wf.getInfoFor(cc,'review_state',None) != 'checked':
     379                self.portal_workflow.doActionFor(cc,'approve')
     380        if no_import_list:
     381            no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
     382            heading = ' '.join(['"%s"' % fn for fn in fields])
     383            no_import.write('%s\n' % heading)
     384            for line in no_import_list:
     385                no_import.write(line)
     386        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
     387    ###)
     388
     389    security.declareProtected(ModifyPortalContent,"loadFacultiesFromOrgCSV")###(
     390    def loadFacultiesFromOrgCSV(self):
    51391        """install Universityspecific Faculies from CSV values"""
    52392        #return
     
    106446    ###)
    107447
    108     security.declareProtected(ModifyPortalContent,"loadDepartmentsFromCSV")###(
    109     def loadDepartmentsFromCSV(self):
     448    security.declareProtected(ModifyPortalContent,"loadDepartmentsFromOrgCSV")###(
     449    def loadDepartmentsFromOrgCSV(self):
    110450        """install Universityspecific Faculies from CSV values"""
    111451        #return
     
    153493    ###)
    154494
    155     security.declareProtected(ModifyPortalContent,"loadCoursesFromCSV")###(
    156     def loadCoursesFromCSV(self):
     495    security.declareProtected(ModifyPortalContent,"loadCoursesFromOrgCSV")###(
     496    def loadCoursesFromOrgCSV(self):
    157497        """install Universityspecific Courses from CSV values"""
    158498        #return
     
    231571    ###)
    232572
    233     security.declareProtected(ModifyPortalContent,"loadCertificatesFromCSV")###(
    234 
    235     def loadCertificatesFromCSV(self):
     573    security.declareProtected(ModifyPortalContent,"loadCertificatesFromOrgCSV")###(
     574
     575    def loadCertificatesFromOrgCSV(self):
    236576        """install Universityspecific Certificates from CSV values"""
    237577        #return
     
    308648    ###)
    309649
    310     security.declareProtected(ModifyPortalContent,"loadCertificateCoursesFromCSV")###(
    311     def loadCertificateCoursesFromCSV(self):
     650    security.declareProtected(ModifyPortalContent,"loadCertificateCoursesFromOrgCSV")###(
     651    def loadCertificateCoursesFromOrgCSV(self):
    312652        """install Certificate Courses from CSV values"""
    313653        #return
  • WAeUP_SRP/trunk/profiles/default/schemas/certificate.xml

    r535 r563  
    11<?xml version="1.0"?>
    22<object name="certificate" meta_type="CPS Schema">
     3 <field name="title" meta_type="CPS String Field"/>
    34 <field name="admin_status" meta_type="CPS String Field"/>
    45 <field name="category" meta_type="CPS String Field"/>
  • WAeUP_SRP/trunk/profiles/default/schemas/course.xml

    r535 r563  
    33 <field name="adm_status" meta_type="CPS String Field"/>
    44 <field name="category" meta_type="CPS String Field"/>
     5 <field name="title" meta_type="CPS String Field"/>
    56 <field name="code" meta_type="CPS String Field">
    67  <property name="is_searchabletext">False</property>
  • WAeUP_SRP/trunk/profiles/default/schemas/department.xml

    r486 r563  
    22<object name="department" meta_type="CPS Schema">
    33 <field name="code" meta_type="CPS String Field"/>
     4 <field name="title" meta_type="CPS String Field"/>
    45 <field name="title_prefix" meta_type="CPS String Field"/>
    56</object>
  • WAeUP_SRP/trunk/profiles/default/schemas/faculty.xml

    r486 r563  
    55 <field name="college_code" meta_type="CPS String Field"/>
    66 <field name="degree_grade" meta_type="CPS String Field"/>
     7 <field name="title" meta_type="CPS String Field"/>
    78 <field name="title_prefix" meta_type="CPS String Field"/>
    89</object>
  • WAeUP_SRP/trunk/profiles/default/types/StudyLevel.xml

    r538 r563  
    1212 <property name="filter_content_types">True</property>
    1313 <property name="allowed_content_types">
    14   <element value="Semester"/>
     14  <element value="CertificateCourse"/>
    1515 </property>
    1616 <property name="allow_discussion">False</property>
  • WAeUP_SRP/trunk/skins/waeup_academics/courses_index_view.pt

    r556 r563  
    6565                    <strong tal:content="row/title" /></a> </td>
    6666                <td tal:content="row/id"> </td>
     67                <td tal:content="row/review_state"> </td>
    6768                <td><a href="edit" tal:attributes="href string:${row/url}/cpsdocument_edit_form">[edit]</a></td>
    6869              </tr>
  • WAeUP_SRP/trunk/skins/waeup_academics/getCoursesInfo.py

    r556 r563  
    4242    row['title'] = rd.Title()
    4343    row['url'] = ro.absolute_url()
     44    row['review_state'] = wf.getInfoFor(ro,'review_state','None')
    4445    items.append(row)
    4546info['courses'] = items
  • WAeUP_SRP/trunk/skins/waeup_student/getStudentInfo.py

    r538 r563  
    1313"""
    1414request = context.REQUEST
    15 
     15form = request.form
     16fget = form.get
    1617wf = context.portal_workflow
    1718mtool = context.portal_membership
    1819member = mtool.getAuthenticatedMember()
    1920path_info = request.get('PATH_INFO').split('/')
    20 
     21roles = member.getRoles()
    2122info = {}
     23info['is_manager'] = 'Manager' in roles or 'SectionManager' in roles
    2224member_id = str(member)
    23 ##if member_id not in path_info:
    24 ##    return None
    2525if student is None:
    2626    students = getattr(context,'students',None)
  • WAeUP_SRP/trunk/skins/waeup_student/students_manager_view.pt

    r543 r563  
    1 <metal:html tal:define="info context/getStudentInfo">
     1<metal:html tal:define="info context/searchStudents;
     2                        students info/students;
     3                        is_manager info/is_manager;">
    24
    35  <metal:body use-macro="here/main_template/macros/master">
     
    911      </span>
    1012      <span tal:condition="isManager">
    11       <h3>All Students</h3>
     13      <h3>Search Students by</h3>
    1214        <br />
    13         <table tal:define="students python: context.objectValues()">
     15        <form  action="." method="post" tal:attributes="action context/absolute_url">
     16          <table>           
     17            <tr>           
     18              <td>StudentId</td><td><input type="text" name="student_id" /></td>
     19              <td>JAMB Id</td><td><input type="text" name="jamb_id" /></td>
     20            </tr>
     21            <tr>
     22              <td>Matric No</td><td><input type="text" name="matric_no" /></td>
     23              <td>Student Name</td><td><input type="text" name="name" /></td>
     24            </tr>
     25            </table>
     26      </form>
     27        <table tal:condition="students">
    1428          <tr tal:repeat="student students">
    1529            <td><a href="id" tal:attributes="href string:${student/absolute_url}"
Note: See TracChangeset for help on using the changeset viewer.