Ignore:
Timestamp:
20 Jun 2013, 19:41:56 (11 years ago)
Author:
Henrik Bettermann
Message:

Render two-column table of tables (not yet tested in custom packages).

Location:
main/waeup.kofa/trunk/src/waeup/kofa
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/pdf.py

    r10317 r10319  
    5353    column_two_fields = ('applicant_id', 'reg_number',
    5454        'firstname', 'middlename', 'lastname')
     55    two_columns_design_fields = []
    5556
    5657    @property
     
    132133
    133134        # create two-column header table
    134         data_left = []
    135         data_right = []
    136135        # append photograph to the left
    137136        img_path = getattr(
    138137            getUtility(IExtFileStore).getFileByContext(self.context),
    139138            'name', DEFAULT_PASSPORT_IMAGE_PATH)
    140         data_left.append([creator.getImage(img_path)])
     139        data_left = [[creator.getImage(img_path)]]
    141140        table_left = Table(data_left,style=SLIP_STYLE)
     141
    142142        # append column-two fields to the right
    143143        fields = [
     
    150150        data.append(header_table)
    151151
     152        # append two-column table of widgets of those fields defined in
     153        # two_columns_design_fields
     154        fields = [
     155            field for field in self.form_fields
     156                if not field.__name__ in self.column_two_fields and
     157                field.__name__ in self.two_columns_design_fields]
     158        if fields:
     159            data.append(creator.getWidgetsTable(
     160                fields, self.context, view, lang=portal_language,
     161                domain='waeup.kofa', twoDataCols=True))
     162
    152163        # append widgets except those already added in column two
    153164        dept, faculty = self._getDeptAndFaculty()
    154165        fields = [
    155166            field for field in self.form_fields
    156                 if not field.__name__ in self.column_two_fields]
     167                if not field.__name__ in self.column_two_fields and
     168                not field.__name__ in self.two_columns_design_fields]
    157169        data.append(creator.getWidgetsTable(
    158170            fields, self.context, view, lang=portal_language,
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/pdf.py

    r10318 r10319  
    622622        return img
    623623
    624     def _getWidgetsTableData(self, widgets,
    625                              separators, domain, lang, table_style):
     624    def _getWidgetsTableData(self, widgets, separators, domain,
     625                             lang, table_style, twoDataCols):
    626626        row_num = 0
    627627        table_data = []
    628628        for widget in widgets:
    629             if separators and separators.get(widget.name):
     629            # We do not render headlines in multi-column design
     630            if twoDataCols is False and separators and separators.get(widget.name):
    630631                f_headline = translate(
    631632                    separators[widget.name], domain, target_language=lang)
    632633                f_headline = Paragraph(f_headline, HEADLINE1_STYLE)
    633                 table_data.append([f_headline ])
     634                table_data.append([f_headline])
    634635                table_style.append(('SPAN', (0,row_num), (-1,row_num)),)
    635636                table_style.append(
     
    676677           if these are given, we render extra rows with faculty and
    677678           department.
     679        - `colWidths`
     680           defines the the column widths of the data in the right column
     681           of base data (right to the passport image).
    678682        - `twoDataCols`
    679            render widgets in a parent table with two columns.
    680         """
    681         table_style = [#('LEFTPADDING', (0,0), (0,-1), 0), # indentation
    682                        ('VALIGN', (0,0), (-1,-1), 'TOP'),
     683           renders data widgets in a parent table with two columns.
     684        """
     685        table_style = [('VALIGN', (0,0), (-1,-1), 'TOP'),
    683686                       ]
    684687        widgets = self._setUpWidgets(form_fields, context)
     
    686689        # Determine table data
    687690        table_data, row_num, table_style = self._getWidgetsTableData(
    688             widgets, separators, domain, lang, table_style)
     691            widgets, separators, domain, lang, table_style, twoDataCols)
    689692
    690693        # Add course (admitted, etc.) if applicable
     
    696699            table_data, row_num, dept, faculty, lang, domain)
    697700
    698         # Create table
     701        # render two-column table of tables
     702        lines = len(table_data)
     703        middle = lines/2
     704        if twoDataCols is True and lines > 2:
     705            table_left = Table(table_data[:middle+1],
     706                               style=table_style, colWidths=[5*cm, 4*cm])
     707            table_right = Table(table_data[middle+1:],
     708                                style=table_style, colWidths=[5*cm, 4*cm])
     709            table_style.append(('LEFTPADDING', (0,0), (0,-1), 3*cm),)
     710            table = Table([[table_left, table_right],],style=table_style)
     711            return table
     712
     713        # render single table
    699714        table = Table(
    700715            table_data,style=table_style, colWidths=colWidths) #, rowHeights=14)
Note: See TracChangeset for help on using the changeset viewer.