Changeset 9668 for main/waeup.kofa


Ignore:
Timestamp:
17 Nov 2012, 12:35:46 (12 years ago)
Author:
uli
Message:

Add a str for StudentsReport? and add a local creation_dt string.

File:
1 edited

Legend:

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

    r9664 r9668  
    124124        self.mode = mode
    125125        self.author = author
     126        self._creation_dt_string = self.creation_dt.astimezone(
     127            getUtility(IKofaUtils).tzinfo).strftime("%Y-%m-%d %H:%M:%S %Z")
    126128        self.data = get_students_by(session, mode)
    127129
    128130    def __repr__(self):
     131        """Creates an executable representation of a StudentsReport object.
     132        """
    129133        return 'StudentsReport(%r, %r, author=%r)' % (
    130134            self.args[0], self.mode, self.author)
     135
     136    def __str__(self):
     137        """A nice human readable representation of a StudentsReport.
     138
     139        Includes infos about session, mode and creation datetime.
     140        """
     141        return 'Students Report [session=%s, mode=%s] of %s ' % (
     142            self.session, self.mode, self._creation_dt_string)
    131143
    132144    def create_pdf(self):
     
    134146        table_data = tbl_data_to_table(*self.data)
    135147        col_widths = [None,] + [1.6*cm] * len(self.data[1]) + [None,]
    136         creation_dt = self.creation_dt.astimezone(getUtility(IKofaUtils).tzinfo)
    137         creation_dt = creation_dt.strftime("%Y-%m-%d %H:%M:%S %Z")
    138         pdf_data = [Paragraph('<b>%s</b>' % creation_dt,
     148        pdf_data = [Paragraph('<b>%s</b>' % self._creation_dt_string,
    139149                              STYLE["Normal"]),
    140150                    Spacer(1, 12),]
     
    145155            pdf_data, None, doc_title, self.author,
    146156            'Students in Session %s' % self.session)
    147         open('/tmp/result.pdf', 'wb').write(pdf)
    148157        return pdf
    149158
Note: See TracChangeset for help on using the changeset viewer.