Below is something similar I've been playing with.  The interface is utter 
garbage, but it shows the general idea.  A form that allows you to select 
fields and aggregation per field:
Manage a list of queries fields, adding in the field or its .sum() or 
.count() method as necessary.  Where you're not using an aggregate, append 
the field to the groupby list.

def test():
    table = idb.student

    options = []
    for field in table.fields:
        options.append(Field(field, 'boolean'))
        options.append(Field('%s_group' % field, 'string', 
requires=IS_EMPTY_OR(IS_IN_SET(['group', 'count', 'sum']))))


    form = SQLFORM.factory(
        *options,
        keepvalues=True
    )

    if form.process().accepted:
        fields = []
        groupby = []
        for field in form.vars:
            if '_group' not in field and form.vars[field]:
                if form.vars['%s_group' % field] == 'sum':
                    fields.append(table[field].sum())
                if form.vars['%s_group' % field] == 'count':
                    fields.append(table[field].count())
                if form.vars['%s_group' % field] == 'group':
                    fields.append(table[field])
                    groupby.append(table[field])

        results = idb().select(*fields, groupby=groupby, limitby=(0, 10))

    return dict(form=form, results=results)


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to