Ignore:
Timestamp:
15 May 2013, 06:47:52 (12 years ago)
Author:
Henrik Bettermann
Message:

Add view for displaying cumulative transcript data.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/students
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py

    r10155 r10178  
    10441044        return
    10451045
     1046class StudyCourseTranscriptPage(KofaDisplayFormPage):
     1047    """ Page to display the student's transcript.
     1048    """
     1049    grok.context(IStudentStudyCourse)
     1050    grok.name('transcript')
     1051    grok.require('waeup.viewStudent')
     1052    grok.template('transcript')
     1053    pnav = 4
     1054
     1055    def update(self):
     1056        super(StudyCourseTranscriptPage, self).update()
     1057        self.semester_dict = getUtility(IKofaUtils).SEMESTER_DICT
     1058        self.session_dict = dict(
     1059            [(item[1], item[0]) for item in academic_sessions()])
     1060        self.studymode_dict = getUtility(IKofaUtils).STUDY_MODES_DICT
     1061        return
     1062
     1063    @property
     1064    def label(self):
     1065        # Here we know that the cookie has been set
     1066        lang = self.request.cookies.get('kofa.language')
     1067        return _('${a}: Transcript Data', mapping = {
     1068            'a':self.context.student.display_fullname})
     1069
    10461070class StudentTransferFormPage(KofaAddFormPage):
    10471071    """Page to transfer the student.
  • main/waeup.kofa/trunk/src/waeup/kofa/students/studycourse.py

    r10155 r10178  
    118118        return
    119119
     120    def getTranscriptData(self):
     121        """Get a sorted list of dicts with level and course ticket data.
     122
     123        This method is used for transcripts.
     124        """
     125        levels = []
     126        gpa = 0.0
     127        credits_counted = 0
     128        for level_key, level_val in self.items():
     129            tickets_1 = []
     130            tickets_2 = []
     131            tickets_3 = []
     132            for ticket in level_val.values():
     133                if ticket.semester == 1:
     134                    tickets_1.append(ticket)
     135                elif ticket.semester == 2:
     136                    tickets_2.append(ticket)
     137                elif ticket.semester == 3:
     138                    tickets_3.append(ticket)
     139                if ticket.score:
     140                    credits_counted += ticket.credits
     141                    gpa += ticket.credits * ticket.weight
     142            levels.append(
     143                dict(level_key=level_key,
     144                     level=level_val,
     145                     tickets_1=tickets_1,
     146                     tickets_2=tickets_2,
     147                     tickets_3=tickets_3))
     148        if credits_counted:
     149            gpa = round(gpa/credits_counted, 2)
     150        return sorted(levels, key=lambda level: level['level_key']), gpa
     151
    120152StudentStudyCourse = attrs_to_fields(StudentStudyCourse)
    121153
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r10060 r10178  
    18111811            'temp_password generated: %s' % temp_password in logcontent)
    18121812
     1813    def test_transcrtipts(self):
     1814        studylevel = createObject(u'waeup.StudentStudyLevel')
     1815        studylevel.level = 100
     1816        studylevel.level_session = 2005
     1817        self.student['studycourse'].addStudentStudyLevel(
     1818            self.certificate, studylevel)
     1819        # Add second course
     1820        courseticket = createObject('waeup.CourseTicket')
     1821        courseticket.code = 'ANYCODE'
     1822        courseticket.title = u'Any TITLE'
     1823        courseticket.credits = 13
     1824        courseticket.score = 66
     1825        courseticket.semester = 1
     1826        courseticket.dcode = u'ANYDCODE'
     1827        courseticket.fcode = u'ANYFCODE'
     1828        self.student['studycourse']['100']['COURSE2'] = courseticket
     1829        self.student['studycourse']['100']['COURSE1'].score = 55
     1830        self.assertEqual(self.student['studycourse']['100'].gpa, 3.57)
     1831        # Get transcript data
     1832        td = self.student['studycourse'].getTranscriptData()
     1833        self.assertEqual(td[0][0]['level_key'], '100')
     1834        self.assertEqual(td[0][0]['level'].level, 100)
     1835        self.assertEqual(td[0][0]['level'].level_session, 2005)
     1836        self.assertEqual(td[0][0]['tickets_1'][0].code, 'COURSE1')
     1837        self.assertEqual(td[0][0]['tickets_1'][1].code, 'ANYCODE')
     1838        self.assertEqual(td[1], 3.57)
     1839        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     1840        self.browser.open(self.student_path + '/studycourse/transcript')
     1841        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     1842        self.assertTrue('Transcript' in self.browser.contents)
     1843
    18131844class StudentUITests(StudentsFullSetup):
    18141845    # Tests for Student class views and pages
Note: See TracChangeset for help on using the changeset viewer.