Ignore:
Timestamp:
16 Nov 2012, 21:43:29 (12 years ago)
Author:
Henrik Bettermann
Message:

Generate reports for students in a certain session and for groups of study modes.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/students
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/studentreportgeneratorpage.pt

    r9643 r9647  
    1919      </select>
    2020      <div class="help-inline" i18n:translate="">
    21         Academic session to report
     21        Select academic session to report
    2222      </div>
    2323    </div>
     24    <br />
     25    <label for="session">Study Mode Group:</label>
     26    <div class="input">
     27      <select name="mode">
     28        <span tal:repeat="items view/modes" tal:omit-tag="">
     29          <option
     30              tal:define="name python: items[1]; title python: items[0]"
     31              tal:attributes="value name">
     32            <span tal:replace="title">TITLE</span>
     33          </option>
     34        </span>
     35      </select>
     36      <div class="help-inline" i18n:translate="">
     37        Set study modes filter
     38      </div>
     39    </div>
     40
    2441  </div>
    2542  <div class="input">
  • main/waeup.kofa/trunk/src/waeup/kofa/students/reports.py

    r9637 r9647  
    2525from waeup.kofa.reports import IReport
    2626
     27MODE_GROUPS = {
     28    'All':('all',),
     29    'Undergraduate Full-Time':('ug_ft',),
     30    'Undergraduate Part-Time':('ug_pt',),
     31    'Postgraduate Full-Time':('pg_ft',),
     32    'Postgraduate Part-Time':('pg_pt',),
     33    }
     34
    2735class IStudentReport(IReport):
    2836    pass
    2937
    30 def get_students_by_session(session):
    31     """Get students of a certain session.
     38def get_students_by(session, mode):
     39    """Get students in a certain session and study mode.
    3240
    3341    Returns a table ordered by faculty code (one per row) and
     
    5260    fac_codes = tuple(sorted([x for x in site['faculties'].keys()],
    5361                             key=lambda x: x.lower()))
    54     fac_codes = fac_codes + ('Total',)
     62    fac_codes = fac_codes + (u'Total',)
    5563    # XXX: Here we do _one_ query and then examine the single
    5664    #   students. One could also do multiple queries and just look for
     
    6169    table = [[0 for x in xrange(len(states))] for y in xrange(len(fac_codes))]
    6270    for stud in result:
     71        if mode != 'All' and stud.current_mode not in MODE_GROUPS[mode]:
     72            continue
    6373        row = fac_codes.index(stud.faccode)
    6474        col = states.index(stud.state)
     
    112122    data = None
    113123    session = None
    114 
    115     def __init__(self, session, author='System'):
     124    mode = None
     125
     126    def __init__(self, session, mode, author='System'):
    116127        super(StudentReport, self).__init__(
    117             args=[session], kwargs={'author':author})
    118         self.session = session
     128            args=[session, mode], kwargs={'author':author})
     129        self.session = academic_sessions_vocab.getTerm(session).title
     130        self.mode = mode
    119131        self.author = author
    120         self.data = get_students_by_session(session)
     132        self.data = get_students_by(session, mode)
    121133
    122134    def __repr__(self):
    123         return 'StudentReport(session=%s, author=%r)' % (
    124             self.session, self.author)
     135        return 'StudentReport(session=%s, mode=%s, author=%r)' % (
     136            self.session, self.mode, self.author)
    125137
    126138    def get_data(self):
    127         self.data = get_students_by_session(self.session)
     139        self.data = get_students_by(self.session, self.mode)
    128140
    129141    def create_pdf(self):
     
    131143        table_data = tbl_data_to_table(*self.data)
    132144        col_widths = [None,] + [1.6*cm] * len(self.data[1]) + [None,]
    133         pdf_data = [Paragraph('<b>Session:</b> %s' % self.session,
    134                               STYLE["Normal"]),
    135                     Spacer(1, 12),]
    136         pdf_data += [
     145        #pdf_data = [Paragraph('<b>Study mode:</b> %s' % self.mode,
     146        #                      STYLE["Normal"]),
     147        #            Spacer(1, 12),]
     148        pdf_data = [
    137149            Table(table_data, style=TABLE_STYLE, colWidths=col_widths)]
    138         doc_title = 'Report: Students of Session %s\nby faculty and status' % (
     150        doc_title = '%s Students in Session %s' % (
     151            self.mode,
    139152            self.session,)
    140153        pdf = creator.create_pdf(
    141154            pdf_data, None, doc_title, self.author,
    142             'Session %s Students,' % self.session)
     155            'Students in Session %s,' % self.session)
    143156        open('/tmp/result.pdf', 'wb').write(pdf)
    144157        return pdf
     
    154167        return self.title
    155168
    156     def generate(self, site, session=None, author=None):
    157         result = StudentReport(session=session, author=author)
     169    def generate(self, site, session=None, mode=None, author=None):
     170        result = StudentReport(session=session, mode=mode, author=author)
    158171        return result
    159172
     
    182195        return None
    183196
    184     def update(self, CREATE=None, session=None):
     197    def update(self, CREATE=None, session=None, mode=None):
    185198        self.parent_url = self.url(self.context.__parent__)
    186199        self._set_session_values()
     200        self._set_mode_values()
    187201        if CREATE and session:
    188202            # create a new report job for students by session
    189203            container = self.context.__parent__
    190204            user_id = self.request.principal.id
    191             kw = dict(session=self._value_dict[session])
     205            kw = dict(
     206                #session=self._session_value_dict[session],
     207                session=int(session),
     208                mode=mode)
    192209            self.flash(_('New report is being created in background'))
    193210            container.start_report_job(
     
    200217        vocab_terms = academic_sessions_vocab.by_value.values()
    201218        self.sessions = [(x.title, x.token) for x in vocab_terms]
    202         self._value_dict = dict([(x.token, x.value) for x in vocab_terms])
     219        #self._session_value_dict = dict([(x.token, x.value) for x in vocab_terms])
    203220        return
    204221
     222    def _set_mode_values(self):
     223        self.modes = sorted([(key, key) for key in MODE_GROUPS.keys()])
     224        return
    205225
    206226class StudentReportPDFView(grok.View):
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_catalog.py

    r9264 r9647  
    5959        setSite(self.app)
    6060        self.certificate = self.create_cert(u'fac1', u'dep1', u'CERT1')
     61        self.certificate.study_mode = u'ug_ft'
    6162
    6263        # Create student with subobjects
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_reports.py

    r9633 r9647  
    11# Tests for student related reports
    2 from waeup.kofa.students.reports import get_students_by_session, StudentReport
     2from waeup.kofa.students.reports import (
     3    get_students_by, StudentReport)
    34from waeup.kofa.students.tests.test_catalog import CatalogTestSetup
    45from waeup.kofa.testing import FunctionalLayer
     
    1415    def test_get_students_by_session_simple(self):
    1516        # we can get a table with one student
    16         result1 = get_students_by_session(2010)
    17         result2 = get_students_by_session(2009)
     17        result1 = get_students_by(2010, 'Undergraduate Full-Time')
     18        result2 = get_students_by(2009, 'Undergraduate Full-Time')
    1819        self.assertEqual(
    1920            result1,
     
    3334        # we can get a table with several students
    3435        self.create_cert('fac2', 'dept2', 'CERT2')
    35         result1 = get_students_by_session(2010)
    36         result2 = get_students_by_session(2009)
     36        result1 = get_students_by(2010, 'Undergraduate Full-Time')
     37        result2 = get_students_by(2009, 'Undergraduate Full-Time')
    3738        self.assertEqual(
    3839            result1,
     
    5354    def test_create_pdf(self):
    5455        self.create_cert('FAC2', 'dept2', 'CERT2')
    55         report = StudentReport(2010)
     56        report = StudentReport(2010, 'Undergraduate Full-Time')
    5657        result = report.create_pdf()
    5758        self.assertTrue(result.startswith('%PDF-'))
Note: See TracChangeset for help on using the changeset viewer.