Skip to content

Commit

Permalink
added default mask
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolajbaer committed Jun 21, 2010
1 parent ddd8e6c commit 71b7e55
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions reportengine/base.py
Expand Up @@ -30,10 +30,19 @@ class Report(object):
output_formats=[AdminOutputFormat(),CSVOutputFormat()]
allow_unspecified_filters = False
date_field = None # if specified will lookup for this date field. .this is currently limited to queryset based lookups
default_mask = {} # a dict of filter default values. Can be callable

# TODO add charts = [ {'name','type e.g. bar','data':(0,1,3) cols in table}]
# then i can auto embed the charts at the top of the report based upon that data..

def get_default_mask(self):
"""Builds default mask. The filter is merged with this to create the filter for the report. Items can be callable and will be resolved when called here (which should be at view time)."""
m={}
for k in self.default_mask.keys():
v=self.default_mask[k]
m[k] = callable(v) and v() or v
return m

def get_filter_form(self,request):
form = forms.Form(data=request.REQUEST)
return form
Expand Down
7 changes: 6 additions & 1 deletion reportengine/views.py
Expand Up @@ -55,8 +55,13 @@ def view_report(request, namespace, slug, output=None):
if filters[k] == '':
del filters[k]

# Merge filters with default mask
mask = report.get_default_mask()
mask.update(filters)


# pull the rows and aggregates
rows,aggregates = report.get_rows(filters,order_by=order_by)
rows,aggregates = report.get_rows(mask,order_by=order_by)

# Determine output format, as it can squash paging if it wants
outputformat=None
Expand Down

0 comments on commit 71b7e55

Please sign in to comment.