Changeset 238 for waeup_product


Ignore:
Timestamp:
1 Jun 2006, 16:57:18 (19 years ago)
Author:
joachim
Message:

=import csv

Location:
waeup_product/trunk
Files:
8 added
12 edited
1 moved

Legend:

Unmodified
Added
Removed
  • waeup_product/trunk/Academics.py

    r223 r238  
    1717#registerDirectory('skins/waeup_faculty', globals())
    1818
    19 class Faculty(CPSDocument): ###(
     19class SCFolder(CPSDocument): ###(
    2020    """
    21     WAeUP Faculty containing Departments
     21    WAeUP StudyCourseFolder containing StudyCourses
    2222    """
    23     meta_type = 'Faculty'
     23    meta_type = 'SCFolder'
    2424    portal_type = meta_type
    2525    security = ClassSecurityInfo()
     
    3131    def Title(self):
    3232        """compose title"""
    33         return "Faculty of %s" % (self.title)
     33        return "SCFolder of %s" % (self.title)
     34
     35InitializeClass(SCFolder)
     36
     37def addSCFolder(container, id, REQUEST=None, **kw):
     38    """Add a SCFolder."""
     39    ob = SCFolder(id, **kw)
     40    return CPSBase_adder(container, ob, REQUEST=REQUEST)
     41
     42###)
     43
     44class StudyCourse(CPSDocument): ###(
     45    """
     46    WAeUP StudyCourse
     47    """
     48    meta_type = 'StudyCourse'
     49    portal_type = meta_type
     50    security = ClassSecurityInfo()
     51   
     52    def __init__(self, id, **kw):
     53        CPSDocument.__init__(self, id, **kw)
     54
     55##    security.declareProtected(View,"Title")
     56##    def Title(self):
     57##        """compose title"""
     58##        return "StudyCourse of %s" % (self.title)
     59
     60InitializeClass(StudyCourse)
     61
     62def addStudyCourse(container, id, REQUEST=None, **kw):
     63    """Add a StudyCourse."""
     64    ob = StudyCourse(id, **kw)
     65    return CPSBase_adder(container, ob, REQUEST=REQUEST)
     66
     67###)
     68
     69class Faculty(CPSDocument): ###(
     70    """
     71    WAeUP Faculty containing Departments
     72    """
     73    meta_type = 'Faculty'
     74    portal_type = meta_type
     75    security = ClassSecurityInfo()
     76   
     77##    def __init__(self, id, **kw):
     78##        CPSDocument.__init__(self, id, **kw)
     79
     80    security.declareProtected(View,"Title")
     81    def Title(self):
     82        """compose title"""
     83        return "%s" % (self.title)
    3484
    3585InitializeClass(Faculty)
     
    4191
    4292###)
    43 
    4493
    4594class Department(CPSDocument): ###(
     
    65114###)
    66115
    67 ##course_fti = { ###(
    68 ##    'title': 'WAeUP Course',
    69 ##    'description': '',
    70 ##    'content_icon': '',
    71 ##    'content_meta_type': 'Course',
    72 ##    'factory': 'addCourse',
    73 ##    'immediate_view': 'cpsdocument_view',
    74 ##    'global_allow': True,
    75 ##    'filter_content_types': True,
    76 ##    'allowed_content_types': (),
    77 ##    'allow_discussion': False,
    78 ##}
    79 #####)
    80 
    81116class Course(CPSDocument): ###(
    82117    """
     
    90125    def Title(self):
    91126        """compose title"""
    92         content = self.getContent()
    93         heading = getattr(content,'heading',None)
    94         if heading is None:
    95             return self.title
    96         return heading
     127        return self.title
    97128   
    98129InitializeClass(Course)
  • waeup_product/trunk/__init__.py

    r206 r238  
    1414from Products.WAeUP.Accommodation import AccoFolder, addAccoFolder
    1515from Products.WAeUP.Accommodation import Accommodation, addAccommodation
    16 from Products.WAeUP.Faculty import Faculty, addFaculty
    17 from Products.WAeUP.Faculty import Department, addDepartment
    18 from Products.WAeUP.Faculty import Course, addCourse
    19 from Products.WAeUP.Faculty import CourseTicket, addCourseTicket
     16from Products.WAeUP.Academics import SCFolder, addSCFolder
     17from Products.WAeUP.Academics import StudyCourse, addStudyCourse
     18from Products.WAeUP.Academics import Faculty, addFaculty
     19from Products.WAeUP.Academics import Department, addDepartment
     20from Products.WAeUP.Academics import Course, addCourse
     21from Products.WAeUP.Academics import CourseTicket, addCourseTicket
    2022from Products.WAeUP.Students import Student, addStudent
    2123from Products.WAeUP.Students import StudentPersonal, addStudentPersonal
     
    3133contentClasses = (
    3234    University,
     35    SCFolder,
     36    StudyCourse,
    3337    Faculty,
    3438    Department,
     
    4852contentConstructors = (
    4953    addUniversity,
     54    addSCFolder,
     55    addStudyCourse,
    5056    addFaculty,
    5157    addDepartment,
     
    6571fti = (
    6672    {}, # University
     73    {}, #SCFolder
     74    {}, #StudyCourse
    6775    {}, # Faculty
    6876    {}, # Department
  • waeup_product/trunk/exportimport.py

    r211 r238  
    1212association in the `configure.zcml` file.
    1313"""
     14import csv,re
    1415
    1516# Zope3 component architecture
     
    3031from Products.GenericSetup.interfaces import ISetupEnviron
    3132from Products.WAeUP.interfaces import IWAeUPTool
     33import Globals
     34p_home = Globals.package_home(globals())
     35i_home = Globals.INSTANCE_HOME
    3236
    3337TOOL = 'portal_waeup'
     
    3741# im- / export steps defined in the corresponding XML files in the
    3842# WAeUP/profiles/default/ directory.
    39 
    40 
    41 def setupStructure(context): ###(
    42     sections = getattr(context,'sections')
    43     portal = getattr(sections,'uniportal',None)
    44     if portal is None:
    45         sections.invokeFactory('University','uniportal')
    46         portal = getattr(context,'uniportal',None)
    47         portal.getContent().edit(mapping={'Title':SRPP_TITLE})
    48     students =  getattr(portal,'students',None)
    49     if students is None:
    50         portal.invokeFactory('StudentsFolder','students')
    51         students = getattr(portal,'students').getContent()
    52         students.edit(mapping={'Title':'Students'})
    53     academics = getattr(portal,'academics',None)
    54     if academics is None:
    55         portal.invokeFactory('AcademicsFolder','academics')
    56         academics = getattr(portal,'academics')
    57         academics.getContent().edit(mapping={'Title':'Academics'})
    58     installFaculties(academics)
    59     if not hasattr(portal,'accommodation'):
    60         portal.invokeFactory('AccoFolder','accommodation')
    61         accommodation = getattr(portal,'accommodation').getContent()
    62         accommodation.edit(mapping={'Title':'Accommodation'})
    63 ###)
    64 
    6543
    6644def installFaculties( academics): ###(
     
    152130###)
    153131
     132def loadFacultiesFromCSV(academics,site,context): ###(
     133    """install Universityspecific Faculies from CSV values"""
     134    logger = context.getLogger('loadfaculties')
     135    faculties = csv.DictReader(open("%s/import/faculty.csv" % i_home,"rb"))
     136    for faculty in faculties:
     137        fid = faculty['FacultyKey']
     138        f = getattr(academics,fid,None)
     139        if f is None:
     140            #self.log('Creating Faculty %(id)s = %(Title)s' % faculty)
     141            logger.info('Creating Faculty %(FacultyKey)s = %(Description)s' % faculty)
     142            academics.invokeFactory('Faculty', fid)
     143            f = getattr(academics,fid)
     144            d = {'Title': faculty['Description']}
     145            f.getContent().edit(mapping=d)
     146###)
     147
     148def loadDepartmentsFromCSV(academics,site,context): ###(
     149    """install Universityspecific Faculies from CSV values"""
     150    logger = context.getLogger('loaddepartments')
     151    deps = csv.DictReader(open("%s/import/departments.csv" % i_home,"rb"))
     152    for dep in deps:
     153        fid = dep['FacultyCode']
     154        f = getattr(academics,fid,None)
     155        if f is None:
     156            logger.info( "No Faculty with ID: %s" % fid)
     157        else:
     158            did = dep.get('DeptCode')
     159            d = getattr(f,did,None)
     160            if d is None:
     161                #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep)
     162                logger.info('Creating Department %(DeptCode)s = %(Description)s' % dep)
     163                f.invokeFactory('Department', did)
     164                d = getattr(f,did)
     165                dict = {'Title': dep['Description']}
     166                d.getContent().edit(mapping=dict)
     167###)
     168
     169def loadCoursesFromCSV(academics,site,context): ###(
     170    """install Universityspecific Faculies from CSV values"""
     171    logger = context.getLogger('loadcourses')
     172    courses = csv.DictReader(open("%s/import/courses.csv" % i_home,"rb"))
     173    for course in courses:
     174        if course.get("FORMERCODE") != '':
     175            continue
     176        depid = course['Dept']
     177        res = site.portal_catalog({'meta_type': "Department",
     178                                      'id': depid})
     179        if not res:
     180            continue
     181        dept=res[0].getObject()
     182        course_id = ''.join(re.split('\W+',course.get('CourseCode')))
     183        if len(course_id) != 6:
     184            logger.info("invalid course_code %(CourseCode)s" % course)
     185            #print course_id,course.get('CourseCode'),course.get('Description')
     186            continue
     187        c = getattr(dept,course_id,None)
     188        if c is None:
     189            #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep)
     190            logger.info('Creating Course %(CourseCode)s  %(Description)s in Department %(Dept)s' % course)
     191            dept.invokeFactory('Course', course_id)
     192            c = getattr(dept,course_id)
     193        dict = {'Title': course['Description']}
     194        dict['code'] = course_id
     195        dict['credit'] = course.get('Credits')
     196        #dict['level'] = course.get('CourseCode').split()[1][0]
     197        dict['level'] = "%c00" % course_id[3]
     198        dict['semester'] = "%(Semester)s" % course
     199        dict['passmark'] = course.get('PassMark')
     200        c.getContent().edit(mapping=dict)
     201###)
     202
     203def setupStructure(site,context): ###(
     204    sections = getattr(site,'sections')
     205    portal = getattr(sections,'uniportal',None)
     206    if portal is None:
     207        sections.invokeFactory('University','uniportal')
     208        portal = getattr(site,'uniportal',None)
     209        portal.getContent().edit(mapping={'Title':SRPP_TITLE})
     210    students =  getattr(portal,'students',None)
     211    if students is None:
     212        portal.invokeFactory('StudentsFolder','students')
     213        students = getattr(portal,'students').getContent()
     214        students.edit(mapping={'Title':'Students'})
     215    academics = getattr(portal,'academics',None)
     216    if academics is None:
     217        portal.invokeFactory('AcademicsFolder','academics')
     218        academics = getattr(portal,'academics')
     219        academics.getContent().edit(mapping={'Title':'Academics'})
     220    loadFacultiesFromCSV(academics,site,context)
     221    loadDepartmentsFromCSV(academics,site,context)
     222    loadCoursesFromCSV(academics,site,context)
     223    studycourses = getattr(academics,'studycourses',None)
     224    if studycourses is None:
     225        academics.invokeFactory('SCFolder','studycourses')
     226        studycourses = getattr(academics,'studycourses')
     227        studycourses.getContent().edit(mapping={'Title':'Studycourses'})
     228    installFaculties(academics)
     229    if not hasattr(portal,'accommodation'):
     230        portal.invokeFactory('AccoFolder','accommodation')
     231        accommodation = getattr(portal,'accommodation').getContent()
     232        accommodation.edit(mapping={'Title':'Accommodation'})
     233###)
     234
    154235
    155236def exportWAeUP(context):
     
    168249    """
    169250    site = context.getSite()
     251    setupStructure(site,context)
    170252    #import pdb; pdb.set_trace()
    171     setupStructure(site)
     253    print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>p_home: ",p_home,i_home
    172254    pass
    173255    #site = context.getSite()
  • waeup_product/trunk/profiles/default/layouts.xml

    r199 r238  
    2424 <object name="student_semester" meta_type="CPS Layout"/>
    2525 <object name="study_level" meta_type="CPS Layout"/>
     26 <object name="studycourse" meta_type="CPS Layout"/>
    2627 <object name="university" meta_type="CPS Layout"/>
    2728 <object name="waeup_common" meta_type="CPS Layout"/>
  • waeup_product/trunk/profiles/default/layouts/course.xml

    r199 r238  
    3535  <property name="label_edit">Credit</property>
    3636 </widget>
    37  <widget name="heading" meta_type="String Widget">
    38   <property name="fields">
    39    <element value="heading"/>
    40   </property>
    41   <property name="is_required">True</property>
    42   <property name="label">Title</property>
    43   <property name="label_edit">Title</property>
    44   <property name="help">Course Title</property>
    45   <property name="display_width">40</property>
    46   <property name="size_max">40</property>
    47  </widget>
    4837 <widget name="level" meta_type="Select Widget">
    4938  <property name="fields">
     
    5544  <property name="vocabulary">courselevel</property>
    5645 </widget>
    57  <widget name="nr_of_seats" meta_type="Int Widget">
     46 <widget name="passmark" meta_type="Int Widget">
    5847  <property name="fields">
    59    <element value="nr_of_seats"/>
     48   <element value="passmark"/>
    6049  </property>
    6150  <property name="is_required">True</property>
    62   <property name="label">Nr. of seats</property>
    63   <property name="label_edit">Nr. of seats</property>
     51  <property name="label">Passmark</property>
     52  <property name="label_edit">Passmark</property>
     53  <property name="readonly_layout_modes"/>
     54  <property name="hidden_layout_modes"/>
     55  <property name="hidden_readonly_layout_modes"/>
    6456 </widget>
    65  <widget name="semester" meta_type="Boolean Widget">
     57 <widget name="semester" meta_type="Select Widget">
     58  <property name="title">Semester</property>
    6659  <property name="fields">
    6760   <element value="semester"/>
    6861  </property>
    69   <property name="is_required">True</property>
    7062  <property name="label">Semester</property>
    7163  <property name="label_edit">Semester</property>
    72   <property name="label_false">Second Semester</property>
    73   <property name="label_true">First Semester</property>
     64  <property name="readonly_layout_modes"/>
     65  <property name="hidden_layout_modes"/>
     66  <property name="hidden_readonly_layout_modes"/>
     67  <property name="vocabulary">semester_voc</property>
    7468 </widget>
    7569 <widget name="text" meta_type="Text Widget">
     
    108102  </row>
    109103  <row>
    110    <cell name="nr_of_seats"/>
     104   <cell name="passmark"/>
    111105  </row>
    112106 </table>
  • waeup_product/trunk/profiles/default/schemas.xml

    r199 r238  
    2121 <object name="student_schoolresults" meta_type="CPS Schema"/>
    2222 <object name="students" meta_type="CPS Schema"/>
     23 <object name="studycourse" meta_type="CPS Schema"/>
    2324 <object name="study_level" meta_type="CPS Schema"/>
    2425 <object name="university" meta_type="CPS Schema"/>
  • waeup_product/trunk/profiles/default/schemas/course.xml

    r199 r238  
    1010  <property name="default_expr">string:</property>
    1111 </field>
    12  <field name="heading" meta_type="CPS String Field">
    13   <property name="is_searchabletext">True</property>
    14  </field>
    1512 <field name="level" meta_type="CPS String Field">
    1613  <property name="is_searchabletext">True</property>
    1714 </field>
    18  <field name="nr_of_seats" meta_type="CPS Int Field"/>
    19  <field name="semester" meta_type="CPS Boolean Field">
    20   <property name="default_expr">python:True</property>
     15 <field name="passmark" meta_type="CPS Int Field">
     16  <property name="default_expr">python:40</property>
    2117 </field>
     18 <field name="semester" meta_type="CPS String Field"/>
    2219 <field name="text" meta_type="CPS String Field">
    2320  <property name="is_searchabletext">True</property>
    2421 </field>
    2522</object>
     23
  • waeup_product/trunk/profiles/default/types.xml

    r200 r238  
    1212 <object name="ScratchCard" meta_type="CPS Flexible Type Information"/>
    1313 <object name="Semester" meta_type="CPS Flexible Type Information"/>
     14 <object name="SCFolder" meta_type="CPS Flexible Type Information"/>
     15 <object name="StudyCourse" meta_type="CPS Flexible Type Information"/>
    1416 <object name="Student" meta_type="CPS Flexible Type Information"/>
    1517 <object name="StudentDocuments" meta_type="CPS Flexible Type Information"/>
  • waeup_product/trunk/profiles/default/types/AcademicsFolder.xml

    r200 r238  
    1313 <property name="allowed_content_types">
    1414  <element value="Faculty"/>
     15  <element value="SCFolder"/>
    1516 </property>
    1617 <property name="allow_discussion">False</property>
  • waeup_product/trunk/profiles/default/types/Department.xml

    r200 r238  
    1212 <property name="filter_content_types">True</property>
    1313 <property name="allowed_content_types">
     14  <element value="Course"/>
    1415  <element value="Student"/>
    15   <element value="Course"/>
    1616 </property>
    1717 <property name="allow_discussion">False</property>
    1818 <property name="cps_is_searchable">True</property>
    19  <property name="cps_proxy_type">folder</property>
     19 <property name="cps_proxy_type">btreefolderishdocument</property>
    2020 <property name="cps_display_as_document_in_listing">True</property>
    2121 <property name="schemas">
  • waeup_product/trunk/profiles/default/vocabularies.xml

    r205 r238  
    1212 <object name="range5" meta_type="CPS Vocabulary"/>
    1313 <object name="range50" meta_type="CPS Vocabulary"/>
     14 <object name="semester_voc" meta_type="CPS Vocabulary"/>
    1415 </object>
  • waeup_product/trunk/profiles/default/workflows.xml

    r209 r238  
    44 <object name="waeup_base_wf" meta_type="CPS Workflow"/>
    55 <object name="waeup_faculty_wf" meta_type="CPS Workflow"/>
     6 <object name="waeup_studycourse_wf" meta_type="CPS Workflow"/>
    67 <object name="waeup_department_wf" meta_type="CPS Workflow"/>
    78 <object name="waeup_course_wf" meta_type="CPS Workflow"/>
     
    2223   <bound-workflow workflow_id="section_folder_wf"/>
    2324  </type>
     25  <type type_id="SCFolder">
     26   <bound-workflow workflow_id="section_folder_wf"/>
     27  </type>
    2428  <type type_id="Faculty">
    2529   <bound-workflow workflow_id="waeup_faculty_wf"/>
     
    3034  <type type_id="Course">
    3135   <bound-workflow workflow_id="waeup_course_wf"/>
     36  </type>
     37  <type type_id="StudyCourse">
     38   <bound-workflow workflow_id="waeup_studycourse_wf"/>
    3239  </type>
    3340  <type type_id="StudentsFolder">
  • waeup_product/trunk/skins/waeup_default/temporary_view_all_form.pt

    r200 r238  
    2424 
    2525    <br />
    26     <span  tal:condition="python:context.portal_type != 'University'"  tal:omit-tag="">
     26    <span  tal:condition="python:context.portal_type != 'University' and doc.render()"  tal:omit-tag="">
    2727      <p>Exemplary view of the <strong>object's data fields</strong>: </p>
    28       <tal:block  tal:content="structure rendered_main|python:doc.render()" />
     28      <tal:block 
     29          tal:content="structure python:doc.render()" />
    2930    </span>
    3031    <br />     
Note: See TracChangeset for help on using the changeset viewer.