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

new course registration module

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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)
Note: See TracChangeset for help on using the changeset viewer.