Skip to content

Commit

Permalink
* Refactored force_new_page and start_new_page to be the same.
Browse files Browse the repository at this point in the history
* Fixed documentation about auto_expand_height
  • Loading branch information
marinho committed Feb 16, 2011
1 parent 7fd7ba7 commit e97feff
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 46 deletions.
6 changes: 6 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2011-02-16: Version 0.4.11-alpha
--------------------------------

* Refactored force_new_page and start_new_page to be the same.
* Fixed documentation about auto_expand_height

2010-09-23: Version 0.4.10-stable
--------------------------------
* Fixed ReportGroup.force_new_page when works with child bands (with secondary detail pages)
Expand Down
4 changes: 2 additions & 2 deletions docs/source/basic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ queryset.
- **default_style** - Default: None
- **margin_top** - Default: 0
- **margin_bottom** - Default: 0
- **auto_expanded_height** - Default: False
- **auto_expand_height** - Default: False

Use 'auto_expanded_height' to make flexible bands to fit their heights to
Use 'auto_expand_height' to make flexible bands to fit their heights to
their elements.

DetailBand
Expand Down
2 changes: 1 addition & 1 deletion geraldo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
- tests - a package with automated doc tests.
"""

VERSION = (0, 4, 10, 'stable')
VERSION = (0, 4, 11, 'alpha')

def get_version():
return '%d.%d.%d-%s'%VERSION
Expand Down
68 changes: 32 additions & 36 deletions geraldo/generators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def render_band(self, band, top_position=None, left_position=None,
temp_height = band.height + getattr(band, 'margin_top', 0) + getattr(band, 'margin_bottom', 0)
self.update_top_pos(decrease=self.calculate_size(temp_height))
else:
self.update_left_pos(set=0)
self.update_left_pos(set_position=0)
left_position = self.get_left_pos()

temp_top = top_position = top_position or self.get_top_pos()
Expand Down Expand Up @@ -388,7 +388,7 @@ def render_band(self, band, top_position=None, left_position=None,
if getattr(band, 'display_inline', False):
self.update_left_pos(band.width + self.calculate_size(getattr(band, 'margin_right', 0)))
else:
self.update_left_pos(set=0)
self.update_left_pos(set_position=0)

# Child bands
for child_band in band.child_bands or []: # TODO This "or []" here is a quickfix
Expand All @@ -410,21 +410,39 @@ def force_blank_page_by_height(self, height):
"""Check if the height is in client available report height and
makes a new page if necessary"""
if Decimal(str(self.get_available_height())) < Decimal(str(height)):
self.force_new_page()
self.start_new_page()
return True

return False

def append_new_page(self):
self._rendered_pages.append(ReportPage())

def force_new_page(self):
def start_new_page(self, with_header=True):
"""Starts a new blank page"""
# Ends the current page
self._current_top_position = 0

# Starts a new one
self.start_new_page()
self.append_new_page()

self.report.do_on_new_page(
page=self._rendered_pages[-1],
page_number=len(self._rendered_pages) + self.first_page_number - 1,
generator=self,
)

if with_header:
self.render_page_header()

# Page borders
if self.report.borders:
if not self._page_rect:
self._page_rect = self.report.get_page_rect()
self._page_rect['top'] = self.calculate_size(self.report.page_size[1]) - self._page_rect['top']
self._page_rect['bottom'] = self.calculate_size(self.report.page_size[1]) - self._page_rect['bottom']

self.render_border(self.report.borders, self._page_rect)

# Page footer
self.render_page_footer()
Expand Down Expand Up @@ -505,7 +523,7 @@ def render_end_current_page(self):

self._current_page_number += 1
self._is_first_page = False
self.update_top_pos(set=0) # <---- update top position
self.update_top_pos(set_position=0) # <---- update top position

def render_bands(self):
"""Loops into the objects list to create the report pages until the end"""
Expand Down Expand Up @@ -606,28 +624,6 @@ def render_bands(self):
# Increment page number
self._current_page_number += 1

def start_new_page(self, with_header=True):
"""Do everything necessary to be done to start a new page"""
self.append_new_page()

self.report.do_on_new_page(
page=self._rendered_pages[-1],
page_number=len(self._rendered_pages) + self.first_page_number - 1,
generator=self,
)

if with_header:
self.render_page_header()

# Page borders
if self.report.borders:
if not self._page_rect:
self._page_rect = self.report.get_page_rect()
self._page_rect['top'] = self.calculate_size(self.report.page_size[1]) - self._page_rect['top']
self._page_rect['bottom'] = self.calculate_size(self.report.page_size[1]) - self._page_rect['bottom']

self.render_border(self.report.borders, self._page_rect)

def calculate_size(self, size):
"""Uses the function 'calculate_size' to calculate a size"""
return calculate_size(size)
Expand Down Expand Up @@ -667,22 +663,22 @@ def get_available_height(self):

return ret

def update_top_pos(self, increase=0, decrease=0, set=None):
def update_top_pos(self, increase=0, decrease=0, set_position=None):
"""Updates the current top position controller, increasing (by default),
decreasing or setting it with a new value."""
if set is not None:
self._current_top_position = set
if set_position is not None:
self._current_top_position = set_position
else:
self._current_top_position += increase
self._current_top_position -= decrease

return self._current_top_position

def update_left_pos(self, increase=0, decrease=0, set=None):
def update_left_pos(self, increase=0, decrease=0, set_position=None):
"""Updates the current left position controller, increasing (by default),
decreasing or setting it with a new value."""
if set is not None:
self._current_left_position = set
if set_position is not None:
self._current_left_position = set_position
else:
self._current_left_position += increase
self._current_left_position -= decrease
Expand Down Expand Up @@ -765,7 +761,7 @@ def render_groups_headers(self, first_object_on_page=False):
# Forces a new page if this group is defined to do it
if not new_page and group.force_new_page and self._current_object_index > 0 and not first_object_on_page:
self.render_page_footer()
self.force_new_page()
self.start_new_page()

# Renders the group header band
if group.band_header and group.band_header.visible:
Expand Down Expand Up @@ -832,7 +828,7 @@ def force_new_page(height):
# Forces new page if there is no available space
if self.get_available_height() < self.calculate_size(height):
self.render_page_footer()
self.force_new_page()
self.start_new_page()

for subreport in self.report.subreports:
# Subreports must have detail band
Expand Down
4 changes: 2 additions & 2 deletions site/newsite/site-geraldo/docs/_sources/basic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ queryset.
- **default_style** - Default: None
- **margin_top** - Default: 0
- **margin_bottom** - Default: 0
- **auto_expanded_height** - Default: False
- **auto_expand_height** - Default: False

Use 'auto_expanded_height' to make flexible bands to fit their heights to
Use 'auto_expand_height' to make flexible bands to fit their heights to
their elements.

DetailBand
Expand Down
4 changes: 2 additions & 2 deletions site/newsite/site-geraldo/docs/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ <h2>ReportBand<a class="headerlink" href="#reportband" title="Permalink to this
</li>
<li><p class="first"><strong>margin_bottom</strong> - Default: 0</p>
</li>
<li><p class="first"><strong>auto_expanded_height</strong> - Default: False</p>
<li><p class="first"><strong>auto_expand_height</strong> - Default: False</p>
<blockquote>
<p>Use &#8216;auto_expanded_height&#8217; to make flexible bands to fit their heights to
<p>Use &#8216;auto_expand_height&#8217; to make flexible bands to fit their heights to
their elements.</p>
</blockquote>
</li>
Expand Down
4 changes: 2 additions & 2 deletions site/newsite/site-geraldo/docs/objects.inv
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ geraldo.base.Report class basic.html
geraldo.graphics.Arc class graphics.html
geraldo.graphics.Circle class graphics.html
geraldo.graphics.Fixed class graphics.html
geraldo.graphics.Image class graphics.html
geraldo.cross_reference.CrossReferenceMatrix class cross-reference.html
geraldo.widgets.Widget class widgets.html
geraldo.barcodes.BarCode class barcodes.html
geraldo.generators.TextGenerator class generators.html
geraldo.utils.BAND_WIDTH data utils.html
geraldo.graphics.Line class graphics.html
geraldo.generators.CSVGenerator class generators.html
geraldo.base.ManyElements class basic.html
geraldo.utils.DISABLE_MULTIPROCESSING data utils.html
geraldo.utils.memoize function utils.html
geraldo.graphics.Ellipse class graphics.html
geraldo.generators.PDFGenerator class generators.html
geraldo.utils.landscape function utils.html
geraldo.base.DetailBand class basic.html
geraldo.widgets.Label class widgets.html
geraldo.graphics.Image class graphics.html
geraldo.base.ManyElements class basic.html
geraldo.base.SubReport class basic.html
geraldo.widgets.SystemField class widgets.html
2 changes: 1 addition & 1 deletion site/newsite/site-geraldo/docs/searchindex.js

Large diffs are not rendered by default.

0 comments on commit e97feff

Please sign in to comment.