Changeset 2448 for WAeUP_SRP


Ignore:
Timestamp:
27 Oct 2007, 12:03:25 (17 years ago)
Author:
Henrik Bettermann
Message:

new course registration module

Location:
WAeUP_SRP
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/base/WAeUPTables.py

    r2442 r2448  
    13661366                d['coe'] = 'Core'
    13671367            id = code = d['id'] = brain.code
    1368             is_carry_over = False
    1369             if brain.carry_over:
    1370                 is_carry_over = True
    1371                 #code = code[:-3]
    13721368            d['code'] = code
    13731369            d['title'] = self.courses_catalog.evalAdvancedQuery(Eq('code',code))[0].title
    1374             if is_carry_over:
    1375                 d['coe'] = 'Core'
     1370            if brain.carry_over:
     1371                d['coe'] = 'Carry-Over'
    13761372                carry_overs.append(d)
    13771373            else:
  • WAeUP_SRP/base/skins/waeup_student/add_course_result.py

    r2033 r2448  
    6464
    6565
    66 cr_id = context.invokeFactory('StudentCourseResult',course_id)
    67 cr = getattr(context,cr_id)
    68 context.portal_workflow.doActionFor(cr,'open')
    69 cr.getContent().edit(mapping=d)
     66# cr_id = context.invokeFactory('StudentCourseResult',course_id)
     67# cr = getattr(context,cr_id)
     68# context.portal_workflow.doActionFor(cr,'open')
     69# cr.getContent().edit(mapping=d)
     70d['course_id'] = course_id
     71d['student_id'] = student_id = context.getStudentId()
     72d['level_id'] = level_id = context.getId()
     73d['session_id'] = context.session
     74d['key'] = "%s|%s|%s" % (student_id,level_id,course_id)
     75
     76context.course_results.addRecord(**d)
    7077#context.portal_workflow.doActionFor(cr,'close')
    7178#args['course_id'] = course_id
     
    7380logger.info('%s added StudentCourseResult object %s at level %s for %s' % (member,
    7481                                                                           course_id,
    75                                                                            context.getId(),
    76                                                                            context.getStudentId()))
     82                                                                           level_id,
     83                                                                           student_id))
    7784
    7885psm = "You successfully added course %s!" % course_id
     
    8390    url = context.absolute_url() + '?' + urlencode(args)
    8491return REQUEST.RESPONSE.redirect(url)
    85 
  • WAeUP_SRP/base/skins/waeup_student/course_edit.py

    r2053 r2448  
    1010"""
    1111"""
    12 wf = context.portal_workflow
     12try:
     13    from Products.zdb import set_trace
     14except:
     15    def set_trace():
     16        pass
    1317from urllib import urlencode
    1418from Products.CPSDocument.utils import getFormUidUrlArg
     19from Products.AdvancedQuery import Eq, Between, Le,In
    1520import DateTime
    1621current = DateTime.DateTime()
    1722import logging
    1823logger = logging.getLogger('Skins.course_edit')
     24wf = context.portal_workflow
     25request = REQUEST
     26edit = "edit" in request.form.keys()
     27mtool = context.portal_membership
     28member = mtool.getAuthenticatedMember()
     29member_id = str(member)
     30requested_id = context.getStudentId()
     31if requested_id and not context.isStaff() and member_id != requested_id:
     32    logger.info('%s tried to access personal object of %s' % (member_id,requested_id))
     33    student_id = requested_id
     34    return REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
     35elif context.isStaff():
     36    student_id = requested_id
     37else:
     38    student_id = member_id
     39   
     40level_id = context.getId()
     41course_id = traverse_subpath[0]
     42query = Eq('student_id',student_id) &\
     43        Eq('level_id', level_id) &\
     44        Eq('code', course_id)
    1945
    20 info = context.getCourseResultInfo()
     46course_results = context.course_results.evalAdvancedQuery(query)
     47mode = 'edit'
     48object = {}
     49course = course_results[0]
     50for field in context.course_results.schema():
     51    object[field] = getattr(course,field)
     52lt = context.portal_layouts
     53res,psm, ds = lt.renderLayout(schema_id = 'student_course_result',
     54                               layout_id = 'student_course_result_fe',
     55                               layout_mode = mode,
     56                               context=context,
     57                               mapping=edit and REQUEST,
     58                               ob=object,
     59                               commit = False)
    2160
    22 if info is None:
    23     logger.info('Anonymous user tried to access %s' % REQUEST.get('URL0'))
    24     return REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
     61while True:
     62    if psm == 'invalid':
     63        psm = "Please correct your input"
     64        break
     65    elif psm == '':
     66        break
     67    if edit:
     68        data = {}
     69        dm = ds.getDataModel()
     70        for field in context.course_results.schema():
     71            if dm.has_key("%s" % field):
     72                data[field] = dm.get(field)
     73        data['key'] = object['key']
     74        context.course_results.modifyRecord(**data)
     75        logger.info('%s edited course result data %s' % (student_id, course_id))
     76        psm = 'psm_content_changed'
     77        break
    2578
    26 student = info['student']
    27 #per = info['per']
    28 course_doc = info['course_doc']
    29 state = info['review_state']
    30 result_state = wf.getInfoFor(context,'review_state',None)
    31 if result_state == "closed":
    32     try:
    33         context.portal_workflow.doActionFor(context,'open')
    34     except:
    35         pass
     79return context.course_edit_form(rendered = res,
     80                                psm = psm,
     81                                mode = mode,
     82                                ds = ds,
     83                               )
    3684
    37 is_valid, ds = course_doc.validate(request=REQUEST,
    38                                 schema_id = 'student_course_result',
    39                                 layout_id = 'student_course_result_fe',
    40                                 proxy=context,
    41                                 use_session=True)
    42 
    43 psm = ""
    44 args = {}
    45 action = "/course_edit_form"
    46 base_url = context.absolute_url()
    47 
    48 if is_valid:
    49     if cpsdocument_edit_button:
    50         #name = "%(firstname)s %(middlename)s %(lastname)s" % ds
    51         #name = name.strip()
    52         #name = name.replace('  ',' ')
    53         #email = ds.get('email')
    54         #phone = ds.get('phone')
    55         #student_id = context.getStudentId()
    56         #context.students_catalog.modifyRecord(id = student_id,
    57         #                                      name = name,
    58         #                                      email = email,
    59         #                                      phone = phone,
    60         #                                      sex = ds.get('sex'),
    61         #                                     )
    62         logger.info('%s (%s) edited course result data %s' % (info['id'],info['review_state'],context.id))
    63         #action = ""
    64         #base_url = student.absolute_url()
    65         #url = base_url + action
    66         psm = 'psm_content_changed'
    67 else:
    68     psm = 'psm_content_error'
    69     args = getFormUidUrlArg(REQUEST)
    70 
    71 args['portal_status_message'] = psm
    72 url = base_url + action + '?' + urlencode(args)
    73 REQUEST.RESPONSE.redirect(url)
  • WAeUP_SRP/base/skins/waeup_student/course_edit_form.pt

    r1861 r2448  
    1 <metal:body use-macro="here/slip_template/macros/master">
     1<tal:block define="rendered_main options/rendered;
     2           portal_status_message options/psm;
     3           ds options/ds;
     4           mode options/mode;
     5           course_id python:traverse_subpath[0];
     6           "
     7           >
     8  <metal:block define-macro="edit_form">
     9    <metal:block use-macro="here/slip_template/macros/master">
     10      <metal:block fill-slot="main">
     11        <h3>Update Your Course <span tal:content="course_id" /> </h3>
     12        <br />           
     13       
     14        <form action="ACTION" method="post" id="editForm"
     15              enctype="multipart/form-data" class="workflow"
     16              tal:attributes="action string:${context/absolute_url}/course_edit/${course_id}">
     17          <span tal:omit-tag="" tal:replace="structure rendered_main"/>
     18          <br/>
     19          <input type="submit" class="standalone"
     20                 name="edit"
     21                 value="Save"
     22                 id="edit"/>
     23        </form>
     24      </metal:block>
     25    </metal:block>
     26  </metal:block>
     27</tal:block>
    228
    3     <metal:main fill-slot="main"
    4                   tal:define="info context/getCourseResultInfo;">
    5       <metal:block tal:condition="not: info">
    6         <span tal:content="here/illegal_view" />
    7       </metal:block>
    8       <metal:block tal:condition="info">
    9       <metal:block tal:define="rendered_main python:info['course_doc'].render(
    10                               layout_mode='edit',
    11                               schema_id = 'student_course_result',
    12                               layout_id = 'student_course_result_fe',
    13                               request=request,
    14                               use_session=True,);
    15            form_action string:course_edit;
    16            edition python:True;
    17            metadata nothing;
    18             ">
    19     <h3>Update Your Course <span tal:content='here/id' /> </h3>
    20     <br />           
    21            
    22     <form action="ACTION" method="post" id="editForm"
    23           enctype="multipart/form-data" class="workflow"
    24           tal:attributes="action form_action">
    25       <span tal:condition="not: info">
    26         <metal:block use-macro="here/error_not_found/macros/not_found" />
    27       </span>
    28       <span tal:condition="info">
    29         <span tal:omit-tag="" tal:replace="structure rendered_main"/>
    30       </span>
    31       <br/>
    32       <input type="submit" class="standalone"
    33              name="cpsdocument_edit_button"
    34              value="Save"
    35              id="cpsdocument_edit_button"/>
    36     </form>
    37     </metal:block>
    38     </metal:block>   
    39     </metal:main>
    40 </metal:body>
    41 
  • WAeUP_SRP/base/skins/waeup_student/create_level.py

    r2033 r2448  
    6464    level.getContent().edit(mapping={'session': current_session})
    6565    context.portal_workflow.doActionFor(level,'close_for_edit')
    66     context.waeup_tool.doCommit()
    67 results = []
     66    #context.waeup_tool.doCommit()
     67level_id = level.getId()
     68student_id = context.getStudentId()
     69session_id = context.getLevelSession(level.getContent(),student_id,level_id)
     70
    6871if student.matric_no:
    6972    results = context.results_import(matric_no = student.matric_no)
     73records = []
    7074if results:
    71     #carry_overs = [brain for brain in results if brain.GRADE in ('D','E','F')]
    7275    l = []
    7376    carry_overs = results
    74 
    75     # carry_overs for probation students: yes or not, that is the question
    76     #if student.verdict == "C": # on probation
    77     #    carry_overs = []
    78 
    7977    for co in carry_overs:
    80         cr_id = "%s_co" % co.CosCode
    81         if level.hasObject(cr_id):    #already created
     78        course_id = co.CosCode
     79        if level.hasObject(course_id):    #already created
    8280            continue
    8381        carry_over = False
     
    9694            except:
    9795                # logger.info('%s, course %s has invalid score %s"' % (student.id,
    98                 #                                                     co.CosCode,
     96                #                                                     course_id,
    9997                #                                                     co.Score))
    10098                continue
     
    104102        if not carry_over:
    105103            continue
     104        if course_id in l:
     105            # don't add twice
     106            continue
     107        l += course_id,
    106108        d = context.getCourseInfo(co.CosCode)
     109        d['course_id'] = course_id
    107110        d['grade'] = co.GRADE
    108         d['carry_level'] = co.CarryLevel
    109         cr_id = level.invokeFactory('StudentCourseResult',"%s_co" % co.CosCode)
    110         course_result = getattr(level,cr_id)
    111         context.portal_workflow.doActionFor(course_result,'open')
    112         course_result.getContent().edit(mapping=d)
    113         context.waeup_tool.doCommit()
     111        d['carry_over'] = carry_over
     112        # course_id = level.invokeFactory('StudentCourseResult',"%s_co" % course_id)
     113        # course_result = getattr(level,course_id)
     114        # context.portal_workflow.doActionFor(course_result,'open')
     115        # course_result.getContent().edit(mapping=d)
     116        # context.waeup_tool.doCommit()
     117        d['code'] = course_id
     118        d['student_id'] = student_id
     119        d['level_id'] = level_id
     120        d['session_id'] = session_id
     121        records.append(d)
     122
    114123#level['create_course_results'](cert_id,current_level)
    115124res = context.portal_catalog(portal_type="Certificate", id = cert_id)
    116 l = []
    117125if res:
    118126    cert = res[0]
    119127    path = cert.getPath()
    120     #set_trace()
    121128    query = Eq("path","%s/%s" % (path,current_level)) &\
    122129            Eq('portal_type','CertificateCourse')
    123130    courses = aq_portal(query)
    124131    for c in courses:
    125         cr_id = "%s" % c.getId
    126         if level.hasObject(cr_id):    #already created
     132        course_id = "%s" % c.getId
     133        if course_id in l:
     134            # don't add twice
    127135            continue
     136        l += course_id,
    128137        d = context.getCourseInfo(c.getId)
    129         cr_id = level.invokeFactory('StudentCourseResult',c.getId)
    130         course_result = getattr(level,cr_id)
    131         context.portal_workflow.doActionFor(course_result,'open')
    132         #d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective')
    133         d['core_or_elective'] = True
    134         course_result.getContent().edit(mapping=d)
    135         context.waeup_tool.doCommit()
     138        # course_id = level.invokeFactory('StudentCourseResult',c.getId)
     139        # course_result = getattr(level,course_id)
     140        # context.portal_workflow.doActionFor(course_result,'open')
     141        # d['core_or_elective'] = True
     142        # course_result.getContent().edit(mapping=d)
     143        # context.waeup_tool.doCommit()
     144        d['carry_over'] = False
     145        d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective')
     146        d['course_id'] = course_id
     147        d['student_id'] = student_id = context.getStudentId()
     148        d['level_id'] = level_id
     149        d['session_id'] = session_id
     150        #context.course_results.addRecord(**d)
     151        records.append(d)
     152if records:
     153    context.course_results.addMultipleRecords(records)
    136154logger.info('%s finished to create level %s' % (student.id,current_level))
    137155
     
    147165
    148166return response.redirect("%s/%s" % (context.absolute_url(),current_level))
    149 
  • WAeUP_SRP/base/skins/waeup_student/delete_course_result.py

    r1865 r2448  
    2727
    2828message = ''
     29student_id = context.getStudentId()
    2930if ids:
    30     real_ids = []
    31     for id in ids:
    32         if context.hasObject(id):
    33             real_ids.append(id)
    34     for cr_id in real_ids:
    35         cr = getattr(context,cr_id)
    36         if wf.getInfoFor(cr,'review_state',None) == "closed":
    37             context.portal_workflow.doActionFor(cr,'open')
    38     if real_ids:
    39         try:
    40             context.manage_delObjects(real_ids)
    41             logger.info('%s deleted StudentCourseResult object %s for %s' % (member,id,context.getStudentId()))
    42             message = 'psm_item(s)_deleted'
    43         except Unauthorized:
    44             logger.info('%s has no permission to delete StudentCourseResult objects for %s' % (member,context.getStudentId()))
    45             message = 'no item(s) deleted'
     31    sid_level = "%s|%s" % (student_id,context.getId())
     32    for key in ['%s|%s' % (sid_level,id) for id in ids]:
     33        context.course_results.deleteRecord(key)
     34    logger.info('%s deleted CourseResults  %s for %s' % (member,ids,student_id))
     35    message = 'psm_item(s)_deleted'
    4636else:
    4737    message = 'psm_select_at_least_one_document'
  • WAeUP_SRP/base/skins/waeup_student/getStudyLevelInfo.py

    r2286 r2448  
    2525
    2626
    27 from Products.AdvancedQuery import Eq, Between, Le,In
    28 try:
    29     aq_portal = context.portal_catalog.evalAdvancedQuery
    30 except:
    31     aq_portal = context.portal_catalog_real.evalAdvancedQuery
     27# from Products.AdvancedQuery import Eq, Between, Le,In
     28# try:
     29#     aq_portal = context.portal_catalog.evalAdvancedQuery
     30# except:
     31#     aq_portal = context.portal_catalog_real.evalAdvancedQuery
     32course_results = context.course_results
    3233request = context.REQUEST
    3334#session = request.SESSION
    3435response = request.RESPONSE
     36import logging
     37logger = logging.getLogger('Skins.getStudyLevelInfo')
    3538
    3639def calculateGPA():
     
    6164
    6265student_id = context.getStudentId()
     66level_id = context.getId()
    6367
    6468info = {}
     
    8589        info['status_info'] = "Courses validated"
    8690info['doc'] = context.getContent()
    87 ##study_course = context.aq_parent.getContent()
    88 ##cert_id = study_course.study_course
    8991cert_id = student.course
    9092info['cert_id'] = cert_id
    91 normal = []
    92 carry_overs = []
    93 credits_total = 0
    94 for id,obj in context.objectItems():
    95     #try:
    96     #    credit = int(obj.getContent().credits)
    97     #except ValueError:
    98     #    credit = 3
    99     #credits_total += credit
    100     if not id:
    101         continue
    102     if id.endswith('_co'):
    103         d = context.getCourseInfo(id[:-3])
    104         try:
    105             credits_total += int(d['credits'])
    106         except ValueError:
    107             credits_total += 0
    108         d['id'] = id
    109         d['grade'] = obj.getContent().grade
    110         carry_overs.append(d)
    111     else:
    112         d = context.getCourseInfo(id)
    113         d['id'] = id
    114         coe = getattr(obj.getContent(),'core_or_elective',True)
    115         d['coe'] = 'Core'
    116         try:
    117             credits_total += int(d['credits'])
    118         except ValueError:
    119             credits_total += 0
    120         if not coe:
    121             d['coe'] = 'Elective'
    122         normal.append(d)
     93if context.objectIds():
     94    course_results.moveResultsHere(context,student_id)
     95    logger.info("%s moved courseresults and deleted objects in level %s" % (student_id,level_id))
     96credits_total,carry_overs,normal = course_results.getCourses(student_id,level_id)
    12397info['credits_total'] = credits_total
    124 max_credits = 50
    125 if context.getId() == student.end_level:
    126     max_credits = 51
    127 info['max_credits'] = max_credits
    128 info['credits_exceeded'] = credits_total > max_credits
     98info['credits_exceeded'] = credits_total > 51
    12999current_session = student.session
    130100info['submission_allowed']= not info['credits_exceeded'] and current_session == context.getSessionId()[-2:]
    131 carry_overs.sort(cmp_semester_id)
     101# carry_overs.sort(cmp_semester_id)
    132102info['carry_overs'] = carry_overs
    133 normal.sort(cmp_semester_id)
     103# normal.sort(cmp_semester_id)
    134104info['normal'] = normal
    135105
  • WAeUP_SRP/base/skins/waeup_student/level_delete.py

    r2306 r2448  
    4747    #     evtool = getPublicEventService(here)
    4848    #     evtool.notifyEvent('workflow_delete', ob, {})
     49    for level_id in ids:
     50        context.course_results.deleteResultsHere(level_id,student_id)
    4951    here.manage_delObjects(ids)
     52   
    5053    message = 'portal_status_message=psm_item(s)_deleted'
    5154else:
  • WAeUP_SRP/base/skins/waeup_student/refresh_level.py

    r2040 r2448  
    9191    courses = aq_portal(query)
    9292    course_ids = [c.getId  for c in courses if c.getId not in level.objectIds()]
    93     for c_id in course_ids:
     93    for course_id in course_ids:
    9494        #set_trace()
    95         d = context.getCourseInfo(c_id)
    96         cr_id = level.invokeFactory('StudentCourseResult',c_id)
    97         course_result = getattr(level,cr_id)
    98         context.portal_workflow.doActionFor(course_result,'open')
     95        d = context.getCourseInfo(course_id)
     96        # cr_id = level.invokeFactory('StudentCourseResult',c_id)
     97        # course_result = getattr(level,cr_id)
     98        # context.portal_workflow.doActionFor(course_result,'open')
     99        # course_result.getContent().edit(mapping=d)
     100        # context.waeup_tool.doCommit()
    99101        d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective')
    100         course_result.getContent().edit(mapping=d)
    101         context.waeup_tool.doCommit()
     102        #d['core_or_elective'] = True
     103        d['course_id'] = course_id
     104        d['student_id'] = student_id = context.getStudentId()
     105        d['level_id'] = level_id = context.getId()
     106        d['key'] = "%s|%s|%s" % (student_id,level_id,course_id)
     107        context.course_results.addRecord(**d)
    102108#session.set('in_progress','finished')
    103109logger.info('%s updated course list' % member)
  • WAeUP_SRP/base/skins/waeup_student/study_level_view.pt

    r2279 r2448  
    5555                   />
    5656          </td>
    57           <td width="78%" tal:content="row/title"></td>
     57          <td width="66%" tal:content="row/title"></td>
    5858          <td align="center" width="10%" tal:content="row/code"></td>
    5959          <td align="center" width="2%">S<span tal:content="row/semester" /></td>
    6060          <td align="center" width="2%" tal:content="row/credits"></td>
    61           <td align="center" width="8%" tal:content="row/grade|string:"></td>
     61          <td align="center" width="10%"> <span tal:content="row/coe|nothing" /></td>
     62          <td tal:condition="python:review_state == 'school_fee_paid'" align="center" width="5%">&nbsp;</td>
     63       
    6264        </tr>
    6365      </table>
     
    8385                   />
    8486          </td>
    85           <td width="78%" tal:content="row/title"></td>
     87          <td width="66%" tal:content="row/title"></td>
    8688          <td align="center" width="10%" tal:content="row/code"></td>
    8789          <td align="center" width="2%">S<span tal:content="row/semester" /></td>
    8890          <td align="center" width="2%" tal:content="row/credits"></td>
    89           <td align="center" width="8%" tal:content="row/coe|nothing"></td>
    90          
    91          
    92 
    93 
    94           <td>
    95           <a tal:condition="python:review_state == 'school_fee_paid'" href="edit" tal:attributes="href string:${row/code}/course_edit_form"
     91          <td align="center" width="10%" tal:content="row/coe|nothing"></td>
     92         
     93         
     94
     95
     96          <td tal:condition="python:review_state == 'school_fee_paid'" width="5%" align="center">
     97          <a href="edit" tal:attributes="href string:course_edit/${row/code}"
    9698          target="edit"
    9799          onclick="javascript:window.open('','edit','width=600, height=350, directories=no, toolbar=no, location=no, menubar=no, scrollbars=yes, status=no, resizable=no, dependent=no')">
  • WAeUP_SRP/fceokene/profiles/default/layouts/student_course_result.xml

    r1861 r2448  
    134134   <cell name="core_or_elective "/>
    135135  </row>
    136   <row>
    137    <cell name="carry_level"/>
    138   </row>
    139136 </table>
    140137</object>
Note: See TracChangeset for help on using the changeset viewer.