Ignore:
Timestamp:
3 Aug 2016, 09:07:57 (8 years ago)
Author:
Henrik Bettermann
Message:

Implement alternative get_courses method.

Location:
main/waeup.aaue/trunk/src/waeup/aaue/students/reports
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.aaue/trunk/src/waeup/aaue/students/reports/raw_score_report.py

    r14043 r14048  
    4040    creation_dt_string = Attribute('Human readable report creation datetime')
    4141
    42 def get_courses(faccode, depcode, level):
    43     """Get certificate courses of a certain department at a certain level.
     42def get_courses_1(faccode, depcode, session, level):
     43    """Method 1: Get certificate courses of a
     44    certain department at a certain level.
    4445    """
    4546    site = grok.getSite()
     
    5051            if certcourse.level == level:
    5152                course_codes.append(certcourse.getCourseCode())
     53    return course_codes
     54
     55def get_courses_2(faccode, depcode, session, level):
     56    """Method 2: Get all courses students of a certain
     57    department have registered at a certain level.
     58    """
     59    cat = queryUtility(ICatalog, name="students_catalog")
     60    result = cat.searchResults(
     61        depcode = (depcode, depcode), faccode = (faccode, faccode)
     62        )
     63    course_codes = []
     64    for stud in result:
     65        if not stud['studycourse'].has_key(str(level)):
     66            continue
     67        level_obj = stud['studycourse'][str(level)]
     68        if level_obj.level_session != session:
     69            continue
     70        for ticket in level_obj.values():
     71            course_codes.append(ticket.code)
     72    course_codes = sorted(list(set(course_codes)))
    5273    return course_codes
    5374
     
    104125    def draw(self):
    105126        canvas = self.canv
    106         canvas.rotate(45)
     127        canvas.rotate(60)
    107128        canvas.drawString( 0, -1, self.text)
    108129
     
    121142    for code in course_codes:
    122143        course = list(catalog.searchResults(code=(code, code)))[0]
    123         col_names += (TTR('%s (%s)' % (course.title, code)),)
     144        col_names += (TTR('%s - %s' % (code, course.title)),)
    124145    table = [col_names]
    125146    sn = 1
     
    177198        self.creation_dt_string = self.creation_dt.astimezone(
    178199            getUtility(IKofaUtils).tzinfo).strftime("%Y-%m-%d %H:%M:%S %Z")
    179         self.course_codes = get_courses(faccode, depcode, level)
     200        self.course_codes = get_courses_2(faccode, depcode, session, level)
    180201        self.data = get_students(
    181202            faccode, depcode, session, level, self.course_codes)
  • main/waeup.aaue/trunk/src/waeup/aaue/students/reports/tests/test_raw_score_report.py

    r14041 r14048  
    1010
    1111from waeup.aaue.students.reports.raw_score_report import (
    12     get_students, get_courses, RawScoreReport, IRawScoreReport)
     12    get_students, RawScoreReport, IRawScoreReport,
     13    get_courses_2 as get_courses)
    1314from waeup.aaue.testing import FunctionalLayer
    1415
     
    3536    def test_get_courses(self):
    3637        # we can get a list with one course code
    37         result = get_courses('fac1', 'dep1', 100)
     38        result = get_courses('fac1', 'dep1', 2010, 100)
    3839        self.assertEqual(result, [(u'Course1')])
    3940        return
     
    4142    def test_get_students(self):
    4243        # we can get a table with one student
    43         course_codes = get_courses('fac1', 'dep1', 100)
     44        course_codes = get_courses('fac1', 'dep1', 2010, 100)
    4445        result = get_students('fac1', 'dep1', 2010, 100, course_codes)
    4546        self.assertEqual(result,
Note: See TracChangeset for help on using the changeset viewer.