Skip to content

Commit

Permalink
Implementing new event on ObjectValue: on_expression_error
Browse files Browse the repository at this point in the history
  • Loading branch information
marinho committed Jun 24, 2010
1 parent 0448346 commit 22af69a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
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, 5, 'stable')
VERSION = (0, 4, 6, 'stable')

def get_version():
return '%d.%d.%d-%s'%VERSION
Expand Down
1 change: 0 additions & 1 deletion geraldo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,6 @@ def generate_by(self, generator_class, *args, **kwargs):
if not self.print_if_empty and not self.queryset:
raise EmptyQueryset("This report doesn't accept empty queryset")

# TODO: use multiprocessing
# Initialize generator instance
generator = generator_class(self, *args, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion geraldo/generators/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def generate_pages(self):

# Multiple canvas support (closes current and creates a new
# once if reaches the max pages for temp file)
if num and self.multiple_canvas and num%self.temp_files_max_pages == 0:
if num and self.multiple_canvas and num % self.temp_files_max_pages == 0:
self.close_current_canvas()
del self.canvas
self.start_canvas()
Expand Down
14 changes: 13 additions & 1 deletion geraldo/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ class ObjectValue(Label):
converts_decimal_to_float = False
converts_float_to_decimal = True
_cached_text = None
on_expression_error = None # Expected arguments:
# - widget
# - instance
# - exception
# - expression

def __init__(self, *args, **kwargs):
super(ObjectValue, self).__init__(*args, **kwargs)
Expand Down Expand Up @@ -254,6 +259,7 @@ def clone(self):
new.objects = self.objects
new.stores_text_in_cache = self.stores_text_in_cache
new.expression = self.expression
new.on_expression_error = self.on_expression_error

return new

Expand Down Expand Up @@ -286,7 +292,13 @@ def get_value_by_expression(self, expression=None):
'p': self.report.parent_object, # Just a short alias
})

return eval(expression, global_vars)
try:
return eval(expression, global_vars)
except Exception, e:
if not callable(self.on_expression_error):
raise

return on_expression_error(self, e, expression, self.instance)

class SystemField(Label):
"""This shows system informations, like the report title, current date/time,
Expand Down

0 comments on commit 22af69a

Please sign in to comment.