Changeset 12897


Ignore:
Timestamp:
1 May 2015, 14:32:09 (10 years ago)
Author:
Henrik Bettermann
Message:

Filter students by current level in reports.

Location:
main/waeup.kofa/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/CHANGES.txt

    r12896 r12897  
    441.3.2.dev0 (unreleased)
    55=======================
     6
     7* Filter students by current level in reports.
    68
    79* Add `StudentsUtils.increaseMatricInteger` method which allows to use various
  • main/waeup.kofa/trunk/src/waeup/kofa/students/reports/browser_templates/studentstatisticsreportgeneratorpage.pt

    r12515 r12897  
    4040  </select>
    4141  <br />
     42  <label for="level">Current Level</label>
     43  <select name="level" i18n:translate="" class="form-control half">
     44    <span tal:repeat="items view/levels" tal:omit-tag="">
     45      <option
     46          tal:define="name python: items[1]; title python: items[0]"
     47          tal:attributes="value name">
     48        <span tal:replace="title">TITLE</span>
     49      </option>
     50    </span>
     51  </select>
     52  <br />
    4253  <input i18n:translate="" type="submit" class="btn btn-primary"
    4354         name="CREATE" value="Create" />
  • main/waeup.kofa/trunk/src/waeup/kofa/students/reports/level_report.py

    r11254 r12897  
    1717##
    1818import grok
     19from zope.i18n import translate
    1920from zope.catalog.interfaces import ICatalog
    2021from zope.component import queryUtility, getUtility
     
    2627from waeup.kofa.reports import IReport
    2728from waeup.kofa.browser.pdf import get_signature_tables
     29from waeup.kofa.students.vocabularies import StudyLevelSource
    2830from waeup.kofa.students.reports.student_statistics import (
    2931    StudentStatisticsReportPDFView)
     
    174176        pdf_data += [
    175177            Table(table_data, style=TABLE_STYLE, colWidths=col_widths)]
    176         doc_title = 'Level Report'
     178        doc_title = translate(_('Level Report'))
    177179
    178180        pdf_data.append(Spacer(1, 40))
     
    183185        pdf = creator.create_pdf(
    184186            pdf_data, None, doc_title, self.author,
    185             'Level Report %s/%s/%s/%s' % (
     187            doc_title + ' %s/%s/%s/%s' % (
    186188            self.faccode, self.depcode, self.levelcode, self.sessioncode)
    187189            )
     
    262264        return
    263265
     266    #def _set_level_values(self):
     267    #    vocab_terms = course_levels.by_value.values()
     268    #    self.levels = sorted([(x.title, x.token) for x in vocab_terms])
     269    #    return
     270
    264271    def _set_level_values(self):
    265         vocab_terms = course_levels.by_value.values()
    266         self.levels = sorted([(x.title, x.token) for x in vocab_terms])
     272        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
     273        studylevelsource = StudyLevelSource().factory
     274        self.levels = []
     275        for code in studylevelsource.getValues(None):
     276            title = translate(studylevelsource.getTitle(None, code),
     277                'waeup.kofa', target_language=portal_language)
     278            self.levels.append((title, code))
    267279        return
    268280
  • main/waeup.kofa/trunk/src/waeup/kofa/students/reports/student_payment_statistics.py

    r12619 r12897  
    1717##
    1818import grok
     19from zope.i18n import translate
    1920from zope.catalog.interfaces import ICatalog
    2021from zope.component import queryUtility, getUtility
     
    2324    IKofaUtils,
    2425    academic_sessions_vocab, registration_states_vocab)
     26from waeup.kofa.students.vocabularies import StudyLevelSource
    2527from waeup.kofa.interfaces import MessageFactory as _
    2628from waeup.kofa.reports import IReport
     
    3133    session = Attribute('Session to report')
    3234    mode = Attribute('Study modes group to report')
     35    level = Attribute('Level to report')
    3336    creation_dt_string = Attribute('Human readable report creation datetime')
    3437
    3538
    36 def get_student_payment_stats(session, mode, breakdown):
    37     """Get students in a certain session and study mode.
     39def get_student_payment_stats(session, mode, level, breakdown):
     40    """Get payment amounts of students in a certain session, study mode
     41    and current level.
    3842
    3943    Returns a table ordered by code (faculty or department, one per row) and
     
    8387        if mode != 'All' and stud.current_mode not in mode_groups[mode]:
    8488            continue
     89        if level != 0 and stud.current_level != level:
     90            continue
    8591        if getattr(stud, breakdown) not in codes:
    8692            # studs can have a faccode ``None``
     
    176182    mode = None
    177183
    178     def __init__(self, session, mode, breakdown, author='System'):
     184    def __init__(self, session, mode, level, breakdown, author='System'):
    179185        super(StudentPaymentStatisticsReport, self).__init__(
    180186            args=[session, mode, breakdown], kwargs={'author':author})
     187        self.studylevelsource = StudyLevelSource().factory
     188        self.portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
    181189        self.session = academic_sessions_vocab.getTerm(session).title
    182190        self.mode = mode
     191        if level == 0:
     192            self.level = ''
     193        else:
     194            self.level = translate(self.studylevelsource.getTitle(None, int(level)),
     195                'waeup.kofa', target_language=self.portal_language)
    183196        self.breakdown = breakdown
    184197        self.author = author
    185198        self.creation_dt_string = self.creation_dt.astimezone(
    186199            getUtility(IKofaUtils).tzinfo).strftime("%Y-%m-%d %H:%M:%S %Z")
    187         self.data = get_student_payment_stats(session, mode, breakdown)
     200        self.data = get_student_payment_stats(session, mode, level, breakdown)
    188201
    189202    def create_pdf(self):
     
    196209        pdf_data += [
    197210            Table(table_data, style=TABLE_STYLE, colWidths=col_widths)]
    198         doc_title = '%s Student Payments in Session %s' % (self.mode, self.session)
    199         pdf = creator.create_pdf(
    200             pdf_data, None, doc_title, self.author,
    201             'Student Payments in Session %s' % self.session
    202             )
     211        if not self.level:
     212            doc_title = translate(
     213                _('${a} Student Payments - ${b}',
     214                mapping = {'a':self.mode, 'b':self.session}))
     215            pdf = creator.create_pdf(
     216                pdf_data, None, doc_title, self.author, doc_title + '-'
     217                )
     218        else:
     219            doc_title = translate(
     220                _('${a} Student Payments - ${b} - ${c}',
     221                mapping = {'a':self.mode, 'b': self.level, 'c':self.session}))
     222            pdf = creator.create_pdf(
     223                pdf_data, None, doc_title, self.author, doc_title + '-'
     224                )
    203225        return pdf
    204226
     
    210232    grok.name('student_payment_stats')
    211233
    212     def generate(self, site, session=None,
    213                  mode=None, breakdown=None, author=None):
     234    def generate(
     235        self, site, session=None, mode=None,
     236        level=None, breakdown=None, author=None):
    214237        result = StudentPaymentStatisticsReport(
    215             session=session, mode=mode, breakdown=breakdown, author=author)
     238            session=session, mode=mode, level=level,
     239            breakdown=breakdown, author=author)
    216240        return result
    217241
     
    245269
    246270    def _filename(self):
    247         return 'StudentPaymentStatisticsReport_%s_%s_%s.pdf' % (
    248             self.context.session, self.context.mode,
     271        return 'StudentPaymentStatisticsReport_%s_%s_%s_%s.pdf' % (
     272            self.context.session, self.context.mode, self.context.level,
    249273            self.context.creation_dt_string)
    250274
  • main/waeup.kofa/trunk/src/waeup/kofa/students/reports/student_statistics.py

    r12619 r12897  
    1717##
    1818import grok
     19from zope.i18n import translate
    1920from zope.catalog.interfaces import ICatalog
    2021from zope.component import queryUtility, getUtility
     
    2324    IKofaUtils,
    2425    academic_sessions_vocab, registration_states_vocab)
     26from waeup.kofa.students.vocabularies import StudyLevelSource
    2527from waeup.kofa.interfaces import MessageFactory as _
    2628from waeup.kofa.reports import IReport
     
    2931
    3032    session = Attribute('Session to report')
     33    level = Attribute('Level to report')
    3134    mode = Attribute('Study modes group to report')
    3235    creation_dt_string = Attribute('Human readable report creation datetime')
    3336
    34 def get_student_stats(session, mode, breakdown):
    35     """Get students in a certain session and study mode.
     37def get_student_stats(session, mode, level, breakdown):
     38    """Get students in a certain session, study mode and current level.
    3639
    3740    Returns a table ordered by code (faculty or department, one per row) and
     
    8184        if mode != 'All' and stud.current_mode not in mode_groups[mode]:
    8285            continue
     86        if level != 0 and stud.current_level != level:
     87            continue
    8388        if getattr(stud, breakdown) not in codes:
    8489            # studs can have a faccode ``None``
     
    139144    mode = None
    140145
    141     def __init__(self, session, mode, breakdown, author='System'):
     146    def __init__(self, session, mode, level, breakdown, author='System'):
    142147        super(StudentStatisticsReport, self).__init__(
    143148            args=[session, mode, breakdown], kwargs={'author':author})
     149        self.studylevelsource = StudyLevelSource().factory
     150        self.portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
    144151        self.session = academic_sessions_vocab.getTerm(session).title
    145152        self.mode = mode
     153        if level == 0:
     154            self.level = ''
     155        else:
     156            self.level = translate(self.studylevelsource.getTitle(None, int(level)),
     157                'waeup.kofa', target_language=self.portal_language)
    146158        self.breakdown = breakdown
    147159        self.author = author
    148160        self.creation_dt_string = self.creation_dt.astimezone(
    149161            getUtility(IKofaUtils).tzinfo).strftime("%Y-%m-%d %H:%M:%S %Z")
    150         self.data = get_student_stats(session, mode, breakdown)
     162        self.data = get_student_stats(session, mode, level, breakdown)
    151163
    152164    def create_pdf(self):
     
    159171        pdf_data += [
    160172            Table(table_data, style=TABLE_STYLE, colWidths=col_widths)]
    161         doc_title = '%s Students in Session %s' % (self.mode, self.session)
    162         pdf = creator.create_pdf(
    163             pdf_data, None, doc_title, self.author,
    164             'Students in Session %s' % self.session
    165             )
     173        if not self.level:
     174            doc_title = translate(
     175                _('${a} Students - ${b}',
     176                mapping = {'a':self.mode, 'b':self.session}))
     177            pdf = creator.create_pdf(
     178                pdf_data, None, doc_title, self.author, doc_title + '-'
     179                )
     180        else:
     181            doc_title = translate(
     182                _('${a} Students - ${b} - ${c}',
     183                mapping = {'a':self.mode, 'b': self.level, 'c':self.session}))
     184            pdf = creator.create_pdf(
     185                pdf_data, None, doc_title, self.author, doc_title + '-'
     186                )
    166187        return pdf
    167188
     
    172193    grok.name('student_stats')
    173194
    174     def generate(self, site, session=None, mode=None, breakdown=None, author=None):
     195    def generate(
     196        self, site, session=None, mode=None,
     197        level=None, breakdown=None, author=None):
    175198        result = StudentStatisticsReport(
    176             session=session, mode=mode, breakdown=breakdown, author=author)
     199            session=session, mode=mode, level=level,
     200            breakdown=breakdown, author=author)
    177201        return result
    178202
     
    202226        return None
    203227
    204     def update(self, CREATE=None, session=None, mode=None, breakdown=None):
     228    def update(
     229        self, CREATE=None, session=None, mode=None, level=None, breakdown=None):
    205230        self.parent_url = self.url(self.context.__parent__)
    206231        self._set_session_values()
    207232        self._set_mode_values()
     233        self._set_level_values()
    208234        self._set_breakdown_values()
    209235        if CREATE and session:
    210             # create a new report job for students by session
     236            # create a new report job for students by session and level
    211237            container = self.context.__parent__
    212238            user_id = self.request.principal.id
     
    214240                session=int(session),
    215241                mode=mode,
     242                level=int(level),
    216243                breakdown=breakdown)
    217244            self.flash(_('New report is being created in background'))
     
    220247            ob_class = self.__implemented__.__name__.replace('waeup.kofa.','')
    221248            grok.getSite().logger.info(
    222                 '%s - report %s created: %s (session=%s, mode=%s, breakdown=%s)' % (
    223                 ob_class, job_id, self.context.title, session, mode, breakdown))
     249                '%s - report %s created: %s (session=%s, mode=%s, level=%s, breakdown=%s)' % (
     250                ob_class, job_id, self.context.title,
     251                session, mode, level, breakdown))
    224252            self.redirect(self.parent_url)
    225253            return
     
    234262        mode_groups = getUtility(IKofaUtils).MODE_GROUPS
    235263        self.modes = sorted([(key, key) for key in mode_groups.keys()])
     264        return
     265
     266    def _set_level_values(self):
     267        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
     268        studylevelsource = StudyLevelSource().factory
     269        self.levels = [(u'All levels', 0)]
     270        for code in studylevelsource.getValues(None):
     271            title = translate(studylevelsource.getTitle(None, code),
     272                'waeup.kofa', target_language=portal_language)
     273            self.levels.append((title, code))
    236274        return
    237275
     
    248286
    249287    def _filename(self):
    250         return 'StudentStatisticsReport_%s_%s_%s.pdf' % (
    251             self.context.session, self.context.mode,
     288        return 'StudentStatisticsReport_%s_%s_%s_%s.pdf' % (
     289            self.context.session, self.context.mode, self.context.level,
    252290            self.context.creation_dt_string)
    253291
  • main/waeup.kofa/trunk/src/waeup/kofa/students/reports/tests/test_student_payment_statistics.py

    r12564 r12897  
    2222        # ensure we fullfill interface contracts
    2323        obj = StudentPaymentStatisticsReport(
    24             2010, 'Undergraduate Full-Time', 'faccode')
     24            2010, 'Undergraduate Full-Time', 0, 'faccode')
    2525        verifyClass(IStudentPaymentStatisticsReport, StudentPaymentStatisticsReport)
    2626        verifyObject(IStudentPaymentStatisticsReport, obj)
     
    2929    def test_get_student_payment_stats_session_simple(self):
    3030        # we can get a table with one student
    31         result1 = get_student_payment_stats(2010, 'Undergraduate Full-Time', 'faccode')
    32         result2 = get_student_payment_stats(2009, 'Undergraduate Full-Time', 'faccode')
     31        result1 = get_student_payment_stats(
     32            2010, 'Undergraduate Full-Time', 0, 'faccode')
     33        result2 = get_student_payment_stats(
     34            2009, 'Undergraduate Full-Time', 0, 'faccode')
    3335        self.assertEqual(
    3436            result1,
     
    5355    def test_create_pdf(self):
    5456        report = StudentPaymentStatisticsReport(
    55             2010, 'Undergraduate Full-Time', 'faccode')
     57            2010, 'Undergraduate Full-Time', 0,  'faccode')
    5658        result = report.create_pdf()
    5759        self.assertTrue(result.startswith('%PDF-'))
     
    104106                         'application/pdf')
    105107        self.assertTrue(
    106             'filename="StudentPaymentStatisticsReport_2004_2005_All_' in
     108            'filename="StudentPaymentStatisticsReport_2004_2005_All__' in
    107109            self.browser.headers['content-disposition'])
    108110        self.assertEqual(len(self.app['reports'].running_report_jobs), 1)
     
    118120        self.assertTrue(
    119121            'INFO - zope.mgr - students.reports.student_payment_statistics.StudentPaymentStatisticsReportGeneratorPage - '
    120             'report %s created: Student Payment Statistics (session=2004, mode=All, breakdown=depcode)'
     122            'report %s created: Student Payment Statistics (session=2004, mode=All, level=0, breakdown=depcode)'
    121123            % job_id in logcontent
    122124            )
    123125        self.assertTrue(
    124126            'INFO - zope.mgr - students.reports.student_payment_statistics.StudentPaymentStatisticsReportPDFView - '
    125             'report %s downloaded: StudentPaymentStatisticsReport_2004_2005_All_'
     127            'report %s downloaded: StudentPaymentStatisticsReport_2004_2005_All__'
    126128            % job_id in logcontent
    127129            )
  • main/waeup.kofa/trunk/src/waeup/kofa/students/reports/tests/test_student_statistics.py

    r12619 r12897  
    2525        # ensure we fullfill interface contracts
    2626        obj = StudentStatisticsReport(
    27             2010, 'Undergraduate Full-Time', 'faccode')
     27            2010, 'Undergraduate Full-Time', 0, 'faccode')
    2828        verifyClass(IStudentStatisticsReport, StudentStatisticsReport)
    2929        verifyObject(IStudentStatisticsReport, obj)
     
    3232    def test_get_student_stats_session_simple(self):
    3333        # we can get a table with one student
    34         result1 = get_student_stats(2010, 'Undergraduate Full-Time', 'faccode')
    35         result2 = get_student_stats(2009, 'Undergraduate Full-Time', 'faccode')
     34        result1 = get_student_stats(
     35            2010, 'Undergraduate Full-Time', 0, 'faccode')
     36        result2 = get_student_stats(
     37            2009, 'Undergraduate Full-Time', 0, 'faccode')
    3638        self.assertEqual(
    3739            result1,
     
    5153        # we can get a table with several students
    5254        self.create_cert(u'fac2', u'dep2', u'CERT2')
    53         result1 = get_student_stats(2010, 'Undergraduate Full-Time', 'faccode')
    54         result2 = get_student_stats(2009, 'Undergraduate Full-Time', 'faccode')
     55        result1 = get_student_stats(
     56            2010, 'Undergraduate Full-Time', 0, 'faccode')
     57        result2 = get_student_stats(
     58            2009, 'Undergraduate Full-Time', 0, 'faccode')
    5559        self.assertEqual(
    5660            result1,
     
    7276        # we can get a table with several students
    7377        self.create_cert(u'fac2', u'dep2', u'CERT2')
    74         result1 = get_student_stats(2010, 'Undergraduate Full-Time', 'depcode')
    75         result2 = get_student_stats(2009, 'Undergraduate Full-Time', 'depcode')
     78        result1 = get_student_stats(2010, 'Undergraduate Full-Time', 0, 'depcode')
     79        result2 = get_student_stats(2009, 'Undergraduate Full-Time', 0, 'depcode')
     80        self.assertEqual(
     81            result1,
     82            ((u'fac1/dep1', u'fac2/dep2', u'Total'),
     83             self.states,
     84             ((1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1),
     85              (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
     86              (1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1),)))
     87        self.assertEqual(
     88            result2,
     89            ((u'fac1/dep1', u'fac2/dep2', u'Total'),
     90             self.states,
     91             ((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
     92              (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
     93              (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),)))
     94        return
     95
     96    def test_get_student_stats_session_multiple_dep_breakdown_level_100(self):
     97        # we can get a table with several students
     98        self.create_cert(u'fac2', u'dep2', u'CERT2')
     99        result1 = get_student_stats(2010, 'Undergraduate Full-Time', 0, 'depcode')
     100        result2 = get_student_stats(2009, 'Undergraduate Full-Time', 0, 'depcode')
    76101        self.assertEqual(
    77102            result1,
     
    93118        self.create_cert(u'FAC2', u'dept2', u'CERT2')
    94119        report = StudentStatisticsReport(
    95             2010, 'Undergraduate Full-Time', 'faccode')
     120            2010, 'Undergraduate Full-Time', 0, 'faccode')
    96121        result = report.create_pdf()
    97122        self.assertTrue(result.startswith('%PDF-'))
     
    99124        open(path, 'wb').write(result)
    100125        print "Sample PDF student_statistics.pdf written to %s" % path
     126        return
     127
     128    def test_create_100level_pdf(self):
     129        self.create_cert(u'FAC2', u'dept2', u'CERT2')
     130        report = StudentStatisticsReport(
     131            2010, 'Undergraduate Full-Time', 100, 'faccode')
     132        result = report.create_pdf()
     133        self.assertTrue(result.startswith('%PDF-'))
     134        path = os.path.join(samples_dir(), 'student_statistics_100.pdf')
     135        open(path, 'wb').write(result)
     136        print "Sample PDF student_statistics_100.pdf written to %s" % path
    101137        return
    102138
     
    158194        self.assertTrue(
    159195            'INFO - zope.mgr - students.reports.student_statistics.StudentStatisticsReportGeneratorPage - '
    160             'report %s created: Student Statistics (session=2004, mode=All, breakdown=depcode)'
     196            'report %s created: Student Statistics (session=2004, mode=All, level=0, breakdown=depcode)'
    161197            % job_id in logcontent
    162198            )
    163199        self.assertTrue(
    164200            'INFO - zope.mgr - students.reports.student_statistics.StudentStatisticsReportPDFView - '
    165             'report %s downloaded: StudentStatisticsReport_2004_2005_All_'
     201            'report %s downloaded: StudentStatisticsReport_2004_2005_All__'
    166202            % job_id in logcontent
    167203            )
Note: See TracChangeset for help on using the changeset viewer.