Suppose you have a models file like this:
# -*- coding: utf-8 -*- from decimal import Decimal db.define_table('producer', Field('name','string', length=255, unique=True), ) db.define_table('product', Field('name','string', length=255,notnull=True), Field('producer', db.producer,requires=IS_IN_DB(db,db.producer,'%(name)s')),#, readable=False, writable=False), Field('description','string', length=2048), Field('price','decimal(9,2)', requires = IS_DECIMAL_IN_RANGE(-1e6,1e6,dot=',')), format='%(name)s' ) db.define_table('item', Field('product', db.product, requires = IS_IN_DB(db, db.product)), Field('user_id', db.auth_user), Field('order_date', 'date'), Field('amount', 'decimal(9,2)', requires = IS_EMPTY_OR(IS_DECIMAL_IN_RANGE(0,1e6)), default=Decimal(0)), )
then a controller like this one:
# -*- coding: utf-8 -*- def index(): from plugin_hotsheet import HOTSheet date = request.vars.date iproducer = long(request.vars.producer) producer = db.producer(iproducer) igroup = long(request.vars.group) group = db.auth_group(igroup) response.title = T('orders for group %s producer %s and date %s')%( group.role, producer.name, date ) #rows query_products = (db.product.producer==iproducer) ls_products = [(row.id, row.name) for row in db(query_products) .select(db.product.id, db.product.name, orderby=db.product.name)] row_ids = [id for id,_ in ls_products] row_headers = [nproduct for _,nproduct in ls_products] #cols people = [(row.id, row.first_name) for row in db((db.auth_user.id==db.auth_membership.user_id) & (db.auth_membership.group_id==igroup))\ .select(db.auth_user.id, db.auth_user.first_name, orderby=db.auth_user.first_name)] col_ids = [id for id,_ in people] col_headers = [m for _,m in people] #data query = ((db.item.user_id==db.auth_user.id) & (db.auth_membership.user_id==db.auth_user.id) & (db.auth_membership.group_id==igroup) & (db.item.order_date==date)) sheet = HOTSheet(query, db.item.product, db.item.user_id, db.item.amount, col_ids=col_ids, row_ids=row_ids, row_headers=row_headers, col_headers=col_headers, extra_values={'order_date':date} ) if sheet.accepts(request.vars): session.flash='Updated!' return dict(sheet=sheet)
will output the spreadsheet. This is an example of moderate complexity, in order to show you that you don't have to expose all the table db.item.
Comments (1)
0
pang 9 years ago
I noticed that if the form is submitted via ajax it doesn't work. The ultimate reason is on the behaviour of jQuery.serialize
I will fix ASAIRFMH (as soon as I return from my holidays), but if you need it now, it can be fixed using the parameter formname as in gluon.html.FORM.accepts.