1.1.2.2. gnr.core.gnrbaghtml

Last page update: November 23, 2011

Classes:

Complete reference:

1.1.2.2.2. BagToHtml - webpage variables

With the term webpages variables we mean that there are some defined variables that you can use to customize the class to which they belong (in this case, the BagToHtml class).

Note

the unit of measurement of all the numerical variables are in millimeters (e.g: print_width = 200 means 200 millimeters)

Note

the three levels in which is divided the print zone are:

Most of the following webpage variables are related to these three print zones; please check the Layout print regions section for more information about them

The webpage variables are:

1.1.2.2.2.1. copies_per_page

TODO. Default value is 1

1.1.2.2.2.2. copy_extra_height

TODO. Default value is 0

1.1.2.2.2.3. css_requires

Set the css files to import. Default value is '' (empty string)

Example:

css_requires = 'my_style'

This line implies that you have created a CSS file called my_style.css

Note

The CSS files you want to use must be placed into your “resources” folder

  • For more information about Genro CSS, please check the CSS page.
  • For more information about their location in a Genro project, please check the resources page.

1.1.2.2.2.4. currencyFormat

Set the format of the numerical columns of the print. Default value is u'#,###.00'

1.1.2.2.2.5. doc_header_height

Set the height of the doc header in millimeters. Default value is 0.

Note

you can call the docHeader() method only if you give a different dimension respect to 0 to this attribute

1.1.2.2.2.7. encoding

Set the encoding of your data. Default value is 'utf-8'

1.1.2.2.2.8. grid_header_height

Set the height of the grid header in millimeters. Default value is 0

1.1.2.2.2.10. grid_col_headers

String. Set the header names of the print columns. Default value is None

1.1.2.2.2.11. grid_col_widths

List. Set the width of the grid columns in millimeters. Default value is [0, 0, 0]

Note

Every column you set equal to 0 takes the remaining place divided equally

Example:

grid_col_widths = [0,0,0]

in this example we have 3 columns that get the current grid width divided equally in 3

Example:

grid_col_widths = [17,12,0,0,20,15,15,20]

in this example we have 8 columns; the first one measures 17 mm, the second one 12 mm and so on. The total millimeters specified are 99 (17+12+20+15+15+20), so if we suppose that the total width of the grid is 149 millimeters, then the remaining space (that is: 149 - 99 = 50 millimeters) will be taken from the third and the fourth columns divided equally (both the third and the fourth columns have a width of 50:2 = 25 millimeters)

1.1.2.2.2.12. grid_row_height

Set the height of the grid rows in millimeters. Default value is 5

Example:

grid_row_height = 5.3

1.1.2.2.2.13. page_debug

boolean. TODO Default value is False

1.1.2.2.2.15. page_header_height

Set the page header height in millimeters. Default value is 0

Note

you can call the pageHeader() method only if you give a different dimension respect to 0 to this attribute

1.1.2.2.2.16. page_height

Set the page height in millimeters. Default value is 280

1.1.2.2.2.17. page_leftbar_width

Set the width of the page left bar in millimeters Default value is 0

1.1.2.2.2.18. page_margin_bottom

Set the page bottom margin in millimeters. Default value is 0

1.1.2.2.2.19. page_margin_left

Set the page left margin in millimeters. Default value is 0

1.1.2.2.2.20. page_margin_right

Set the page right margin in millimeters. Default value is 0

1.1.2.2.2.21. page_margin_top

Set the page top margin in millimeters. Default value is 0

1.1.2.2.2.22. page_rightbar_width

Set the width of the page right bar in millimeters. Default value is 0

1.1.2.2.2.23. page_width

Set the page width in millimeters. Default value is 200

1.1.2.2.2.25. row_mode

TODO. You can set it to:

  • 'value': (default value) TODO
  • 'attribute': TODO

1.1.2.2.2.26. rows_path

TODO. Default value is 'rows'

1.1.2.2.2.27. starting_page_number

Set the starting page number. Default value is 0. It is used in the pageCounter() method to choose the starting number for the page enumeration

1.1.2.2.2.28. templates

A string with the names of the html templates separated by a comma. More information in the TODO section of the html template page

1.1.2.2.3. gnr.core.gnrbaghtml - The complete reference list

class gnr.core.gnrbaghtml.BagToHtml(locale='en', encoding='utf-8', templates=None, templateLoader=None, **kwargs)

A class that transforms a Bag into HTML. It can be used to make a print

calcDocFooterHeight()

override for special needs

calcDocHeaderHeight()

override for special needs

calcGridFooterHeight()

override for special needs

calcGridHeaderHeight()

override for special needs

calcRowHeight()

override for special needs

copyHeight()

TODO

copyValue(valuename)

TODO

Parameters:valuename – the name of the value to copy
copyWidth()

TODO

createHtml(filepath=None)

TODO

Parameters:filepath – the path where html will be saved
defineCustomStyles()

override this for custom styles

defineStandardStyles()

TODO

docFooter(footer, lastPage=None)

Hook method. Define the footer of the doc in the print layout file

Parameters:
  • footer – the footer object
  • lastPage – boolean. More information in the lastPage section

Note

the method is called only if the doc_footer_height has a value different from 0

docHeader(header)

Hook method. Define the header of the doc in the print layout file

Parameters:header – the header object

The docHeader() method allows to receive an object called header to which you can append a layout structure made by layouts, rows, and cells

Note

the method is called only if the doc_header_height has a value different from 0

field(path, default=None, locale=None, format=None, mask=None, root=None, **kwargs)

TODO

Parameters:
  • path – TODO
  • default – TODO
  • locale – the current locale (e.g: en, en_us, it)
  • format – TODO
  • mask – TODO
  • root – the root of the page. For more information, check the main documentation section
fillBodyGrid()

TODO

getData(path, default=None)

Make a getItem() on data if ... TODO

Parameters:
  • path – the path of data (e.g: 'period.from')
  • default – the default return value for a not found item
getTemplates(templates)

TODO

Parameters:templates – TODO
get_css_requires()

Get the “css_requires” webpage variable in its string format and return it as a list

gridFooter(row)

It can be overridden

Parameters:row – the grid row
gridHeader(row)

It can be overridden

Parameters:row – the grid row
gridLayout(grid)

Hook method. MANDATORY if you define a grid in your print. Through this method you receive the center of the page and you can define the layout of the grid

Parameters:grid – the grid
init(*args, **kwargs)

A init hook method

initializeBuilder()

TODO

main()

It can be overridden

mainLayout(page)

Hook method that must be overridden. It gives the page object to which you have to append a layout

Parameters:page – the page object
mainLoop()

TODO

onRecordExit(recordBag)

Hook method.

Parameters:recordBag – a Bag that contains the result of the batch
onRecordLoaded()

Hook method. Allow to define the query to be executed for the print

Example:

def onRecordLoaded(self):
    where = '$date >= :begin_date AND $date <= :end_date AND doctor_id=:d_id'
    columns ='''$doctor,$date,$hour,$patient,$performance,
                @convention_id.code AS convention_code,
                $amount,$cost,@invoice_id.number AS invoice'''
    query = self.db.table(self.rows_table).query(columns=columns, where=where, 
                                                 begin_data = self.getData('period.from'),
                                                 end_data = self.getData('period.to'),
                                                 d_id=self.record['id'])
    selection = query.selection()
    if not selection:
        return False
    self.setData('rows',selection.output('grid'))
orientation()

Set the page orientation to ‘Landscape’ if the page_width is greater than the page_height, else set the orientation to ‘Portrait’

outputDocName(ext='')

Set the filename extension and return it

Parameters:ext – the filename extension
pageCounter(mask=None)

Allow to automatically number the pages created in a print. You can choose the format output with the mask parameter

Parameters:mask

format output of the pageCounter method. By default is '%s/%s'

Example: if you print three pages then they will be numbered as 1/3, 2/3 and 3/3

Syntax: You can alternatively set it as '%s of %s', '%s - %s' and so on

pageFooter(footer, lastPage=None)

Hook method. Define the footer of the page in the print layout file

Parameters:
  • footer – the footer object
  • lastPage – boolean. More information in the lastPage section

Note

the method is called only if the page_footer_height has a value different from 0

pageHeader(header)

Hook method. Define the header of the page in the print layout file

Parameters:header – the header object

Note

the method is called only if the page_header_height has a value different from 0

prepareTemplates()

Set the correct value of every measure of the page: height, width, header, footer, margins

rowCell(field=None, value=None, default=None, locale=None, format=None, mask=None, currency=None, **kwargs)

Allow to get data from record. You can use it in the prepareRow() method

Parameters:
  • field – the name of the table column
  • value – TODO
  • default – TODO
  • locale – the current locale (e.g: en, en_us, it)
  • format – the format of the cell (e.g: use HH:mm)
  • mask – TODO
  • currency – TODO
rowField(path=None, **kwargs)

TODO

Parameters:path – TODO
setData(path, value, **kwargs)

Make a setItem() on data

Parameters:
  • path – the path of data (e.g: 'period.from')
  • default – the default return value for a not found item
setTemplates(templates)

Set a template.

Parameters:templates – TODO
showTemplate(value)

TODO

Parameters:value – TODO
toText(obj, locale=None, format=None, mask=None, encoding=None, **kwargs)

TODO

Parameters:
  • obj – TODO
  • locale – the current locale (e.g: en, en_us, it)
  • format – TODO
  • mask – TODO
  • encoding – the multibyte character encoding you choose