Skip to content

Commit

Permalink
* Implementing ReportGroup to support 'force_new_page' to force a new…
Browse files Browse the repository at this point in the history
… page for each new item on the groupper.

* Implementing new function for expression 'coalesce' to set a default value.
  • Loading branch information
marinho committed Apr 27, 2010
1 parent b7b8aec commit ca19b5e
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGES
@@ -1,3 +1,9 @@
2010-04-27: Version 0.4.1-stable
--------------------------------
* Implementing ReportGroup to support 'force_new_page' to force a new page for each new
item on the groupper.
* Implementing new function for expression 'coalesce' to set a default value.

2010-04-18: Version 0.4-beta
--------------------------------
* Just releasing 0.4-beta
Expand Down
1 change: 1 addition & 0 deletions docs/source/basic.txt
Expand Up @@ -293,6 +293,7 @@ values.

- **name** - Default: None
- **attribute_name** - Default: None
- **force_new_page** - Default: False

**Report bands**

Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Expand Up @@ -47,7 +47,7 @@
# The short X.Y version.
version = '0.4'
# The full version, including alpha/beta/rc tags.
release = '0.4-final'
release = '0.4.1-stable'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
6 changes: 6 additions & 0 deletions docs/source/widgets.txt
Expand Up @@ -257,4 +257,10 @@ number, page count, etc.
going to use two standards, this wouldn't be nice. If you want
to use Django's template filter, you can override the method
**Report.format_date(date, expression)** and use it.
- %(var:VARIABLE_NAME)s - you can inform a variable here and declare it when
call generator, like the example below:

SystemField(expression='%(var:filter)s')
...
report.generate_by(PDFGenerator, variables={'filter': 'My Filter'})

4 changes: 2 additions & 2 deletions geraldo/__init__.py
Expand Up @@ -43,10 +43,10 @@
- tests - a package with automated doc tests.
"""

VERSION = (0, 4, 'final')
VERSION = (0, 4, 1, 'stable')

def get_version():
return '%d.%d-%s'%VERSION
return '%d.%d.%d-%s'%VERSION

__author__ = 'Marinho Brandao'
__license__ = 'GNU Lesser General Public License (LGPL)'
Expand Down
1 change: 1 addition & 0 deletions geraldo/base.py
Expand Up @@ -749,6 +749,7 @@ class ReportGroup(GeraldoObject):
attribute_name = None
band_header = None
band_footer = None
force_new_page = False

def __init__(self, **kwargs):
for k,v in kwargs.items():
Expand Down
21 changes: 16 additions & 5 deletions geraldo/generators/base.py
Expand Up @@ -408,6 +408,9 @@ def force_blank_page_by_height(self, height):
makes a new page if necessary"""
if self.get_available_height() < height:
self.force_new_page()
return True

return False

def append_new_page(self):
self._rendered_pages.append(ReportPage())
Expand Down Expand Up @@ -753,12 +756,20 @@ def render_groups_headers(self):
self._groups_working_values = self._groups_values

# Loops on groups to render changed ones
new_page = False
for group in self.report.groups:
if self._groups_changed.get(group, None) and\
group.band_header and\
group.band_header.visible:
self.force_blank_page_by_height(self.calculate_size(group.band_header.height))
self.render_band(group.band_header)
if self._groups_changed.get(group, None):
# If there is no space for group header band, forces a new page
if group.band_header and group.band_header.visible:
new_page = self.force_blank_page_by_height(self.calculate_size(group.band_header.height))

# 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:
self.force_new_page(insert_new_page=False)

# Renders the group header band
if group.band_header and group.band_header.visible:
self.render_band(group.band_header)

def render_groups_footers(self, force=False):
"""Renders the report footers using previous 'changed' definition calculated by
Expand Down
9 changes: 7 additions & 2 deletions geraldo/tests/07-groupping.txt
Expand Up @@ -81,7 +81,10 @@ Report class
... ]
...
... groups = [
... ReportGroup(attribute_name='is_superuser',
... ReportGroup(
... attribute_name='is_superuser',
... force_new_page=True,
... name='first-group',
... band_header=ReportBand(
... height=0.7*cm,
... elements=[
Expand All @@ -108,7 +111,8 @@ Report class
... borders={'top': True},
... ),
... ),
... ReportGroup(attribute_name='is_staff',
... ReportGroup(
... attribute_name='is_staff',
... band_header=ReportBand(
... height=0.7*cm,
... elements=[
Expand Down Expand Up @@ -151,6 +155,7 @@ PDF common generation with users

Page with half height

>>> report.find_by_name('first-group').force_new_page = False
>>> report.page_size = (A4[0], A4[1] / 2)
>>> report.generate_by(PDFGenerator, filename=os.path.join(cur_dir, 'output/groupping-report-half-height.pdf'))

Expand Down
9 changes: 7 additions & 2 deletions geraldo/widgets.py
Expand Up @@ -80,7 +80,7 @@ def clone(self):

return new

EXP_QUOTED = re.compile('\(([^\'"].+?[^\'"])\)')
EXP_QUOTED = re.compile('\(([^\'"].+?[^\'"])(|,.*?)\)')
EXP_TOKENS = re.compile('([\w\._]+|\*\*|\+|\-|\*|\/)')

class ObjectValue(Label):
Expand Down Expand Up @@ -129,7 +129,7 @@ def prepare_expression(self):
self.expression = 'value("%s")' % self.expression
break

self.expression = EXP_QUOTED.sub('("%s")'%(f[0]), self.expression, 1)
self.expression = EXP_QUOTED.sub('("%s"%s)'%(f[0][0], f[0][1]), self.expression, 1)

def get_object_value(self, instance=None, attribute_name=None):
"""Return the attribute value for just an object"""
Expand Down Expand Up @@ -220,6 +220,10 @@ def action_distinct_count(self, attribute_name=None):
values = filter(lambda v: v is not None, self.get_queryset_values(attribute_name))
return len(set(values))

def action_coalesce(self, attribute_name=None, default=''):
value = self.get_object_value(attribute_name=attribute_name)
return value or unicode(default)

def _text(self):
if not self.stores_text_in_cache or self._cached_text is None:
try: # Before all, tries to get the value using parent object
Expand Down Expand Up @@ -269,6 +273,7 @@ def get_value_by_expression(self, expression=None):
'max': self.action_max,
'sum': self.action_sum,
'distinct_count': self.action_distinct_count,
'coalesce': self.action_coalesce,
})

if isinstance(self.report, SubReport):
Expand Down
1 change: 1 addition & 0 deletions pypi_upload.sh
@@ -1,2 +1,3 @@
#!/bin/bash
python setup.py sdist upload
python setup.py bdist upload
5 changes: 0 additions & 5 deletions site/newsite/site-geraldo/local_settings.py

This file was deleted.

12 changes: 12 additions & 0 deletions site/newsite/site-geraldo/media/css/layout.css
Expand Up @@ -152,4 +152,16 @@ dd {
margin-bottom: 10px;
}

pre {
margin: 0.5em;
}

pre code {
background-color: white;
display: block;
border: 1px solid silver;
font-size: 0.8em;
overflow-x: scroll;
padding: 5px;
}

0 comments on commit ca19b5e

Please sign in to comment.