Changeset 2460


Ignore:
Timestamp:
28 Oct 2007, 14:46:29 (17 years ago)
Author:
joachim
Message:

fix refreshlevel + add_course_result

Location:
WAeUP_SRP/base
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/base/WAeUPTables.py

    r2454 r2460  
    13731373            else:
    13741374                normal.append(d)
    1375         normal.sort(cmp=lambda x,y: cmp(x['semester'], y['semester']))
    1376         carry_overs.sort(cmp=lambda x,y: cmp(x['semester'], y['semester']))
     1375        normal.sort(cmp=lambda x,y: cmp("%(semester)s%(code)s" % x,
     1376                                        "%(semester)s%(code)s" % y))
     1377        carry_overs.sort(cmp=lambda x,y: cmp("%(semester)s%(code)s" % x,
     1378                                             "%(semester)s%(code)s" % y))
    13771379        return credits,carry_overs,normal
    13781380    ###)
  • WAeUP_SRP/base/skins/waeup_student/add_course_result.py

    r2451 r2460  
    3333member = mtool.getAuthenticatedMember()
    3434
    35 
    3635d = context.getCourseInfo(course_id)
    3736args = {}
     
    4443    if d['title'] == 'unknown':
    4544        err = "No such course!"
    46         #logger.info('%s tried to add StudentCourseResult object %s for non-existing course' % (member,course_id))
    4745        break
    48     if context.hasObject(course_id):
     46    d['course_id'] = course_id
     47    d['student_id'] = student_id = context.getStudentId()
     48    d['level_id'] = level_id = context.getId()
     49    session_id = context.getLevelSession(context.getContent(),student_id,level_id)
     50    d['session_id'] = session_id
     51    d['key'] = "%s|%s|%s" % (student_id,level_id,course_id)
     52    try:
     53        context.course_results.addRecord(**d)
     54        break
     55    except ValueError:
    4956        err = "Course already exists!"
    50         #logger.info('%s tried to add StudentCourseResult object %s which is already in course list' % (member,course_id))
    51         break
    52     if context.hasObject("%s_co" % course_id):
    53         err = "Course already exists as carryover course!"
    54         #logger.info('%s tried to add StudentCourseResult object %s which already exists as carryover course' % (member,course_id))
    5557        break
    5658    break
     
    5860if err:
    5961    args['course_id'] = course_id
    60     #args['error'] = err
    6162    args['portal_status_message'] = err
    6263    url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args)
    6364    return request.RESPONSE.redirect(url)
    6465
    65 
    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)
    70 d['course_id'] = course_id
    71 d['student_id'] = student_id = context.getStudentId()
    72 d['level_id'] = level_id = context.getId()
    73 session_id = context.getLevelSession(context.getContent(),student_id,level_id)
    74 d['session_id'] = session_id
    75 d['key'] = "%s|%s|%s" % (student_id,level_id,course_id)
    76 
    77 context.course_results.addRecord(**d)
    78 #context.portal_workflow.doActionFor(cr,'close')
    79 #args['course_id'] = course_id
    8066
    8167logger.info('%s added StudentCourseResult object %s at level %s for %s' % (member,
  • WAeUP_SRP/base/skins/waeup_student/refresh_level.py

    r2451 r2460  
    4242student = context.students_catalog(id=context.getStudentId())[0]
    4343cert_id = student.course
    44 current_level = student.level
     44student_id = context.getStudentId()
    4545level = context
    46 #results = context.results_import(matric_no = student.matric_no)
    47 # results = False #skip carry overs
    48 # if results:
    49 #     #carry_overs = [brain for brain in results if brain.GRADE in ('D','E','F')]
    50 #     l = []
    51 #     carry_overs = results
    52 #     for co in carry_overs:
    53 #         carry_over = False
    54 #         query = Eq('code',co.CosCode)
    55 #         c_res = aq_courses(query)
    56 #         if not c_res:
    57 #             logger.info('%s, course %s not found in courses_catalog' % (student.id,co.CosCode))
    58 #             continue
    59 #         course_cat_entry = c_res[0]
    60 #         if not course_cat_entry.passmark:
    61 #             carry_over = co.GRADE in ('D','E','F')
    62 #         else:
    63 #             try:
    64 #                 score = int(co.Score)
    65 #             except:
    66 #                 logger.info('%s, course %s has invalid score %s' % (student.id,
    67 #                                                                     co.CosCode,
    68 #                                                                     co.Score))
    69 #                 continue
    70 #             if int(c_res[0].passmark) <= score:
    71 #                 continue
    72 #             carry_over = True
    73 #         if not carry_over:
    74 #             continue
    75 #         d = context.getCourseInfo(co.CosCode)
    76 #         d['grade'] = co.GRADE
    77 #         d['carry_level'] = co.CarryLevel
    78 #         course_id = "%s_co" % co.CosCode
    79 #         if not context.hasObject(course_id):
    80 #             cr_id = level.invokeFactory('StudentCourseResult',course_id)
    81 #             course_result = getattr(level,cr_id)
    82 #             context.portal_workflow.doActionFor(course_result,'open')
    83 #             course_result.getContent().edit(mapping=d)
     46level_id = context.getId()
    8447res = context.portal_catalog(portal_type="Certificate", id = cert_id)
     48query = Eq('student_id',student_id) & Eq('level_id', level_id)
     49existing_courses = [course.code for course in
     50                    context.course_results.evalAdvancedQuery(query)]
    8551l = []
     52records = []
    8653if res:
    8754    cert = res[0]
     
    9057            Eq('portal_type','CertificateCourse')
    9158    courses = aq_portal(query)
    92     course_ids = [c.getId  for c in courses if c.getId not in level.objectIds()]
     59    course_ids = [c.getId  for c in courses if c.getId not in existing_courses]
    9360    for course_id in course_ids:
    9461        #set_trace()
     62        if course_id in l:
     63            # don't add twice
     64            continue
     65        l += course_id,
    9566        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()
    10167        d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective')
    102         #d['core_or_elective'] = True
    10368        d['course_id'] = course_id
    104         d['student_id'] = student_id = context.getStudentId()
    105         d['level_id'] = level_id = context.getId()
     69        d['student_id'] = student_id
     70        d['level_id'] = level_id
    10671        d['key'] = "%s|%s|%s" % (student_id,level_id,course_id)
    107         context.course_results.addRecord(**d)
     72        records.append(d)
     73if records:
     74    context.course_results.addMultipleRecords(records)
     75
    10876#session.set('in_progress','finished')
    10977logger.info('%s updated course list' % member)
Note: See TracChangeset for help on using the changeset viewer.