db.product.category.widget = suggest_widget(db.category.name, id_field=db.category.id, 
                                          limitby=(0,10), min_length=1)
     
from gluon.storage import Storage
session.auth = Storage(hmac_key='test')
                                        
################################ The core ######################################
# The lazy_options_widget receives js events
# called "product_category__selected" and "product_category__unselected"
# which will be triggered by the above suggest_widget.]
# You can also pass user_signature and hmac_key arguments for authorization in ajax 
db.product.color.widget = lazy_options_widget(
                  'product_category__selected', 'product_category__unselected',
                  lambda category_id: (db.color.category==category_id), 
                  request.vars.category,
                  orderby=db.color.id,
                  user_signature=True,
                  # If you want to process ajax requests at the time of the object construction (not at the form rendered),
                  # specify your target field in the following:
                  field=db.product.color, 
                  )
################################################################################
     
def index():
    form = SQLFORM(db.product)
    if form.accepts(request.vars, session):
        session.flash = 'submitted %s' % form.vars
        redirect(URL('index'))
    return dict(form=form, 
                categories=SQLTABLE(db().select(db.category.ALL)),
                colors=SQLTABLE(db(db.color.id>0)(db.color.category==db.category.id
                                ).select(db.color.id, db.category.name, db.color.name)))
                                            min_length=1)

from gluon.storage import Storage
session.auth = Storage(hmac_key='test')

################################ The core ######################################
# The lazy_options_widget receives js events
# called "product_category__selected" and "product_category__unselected"
# which will be triggered by the above suggest_widget.]
# You can also pass user_signature and hmac_key arguments for authorization in ajax
db.product.color.widget = lazy_options_widget(
    'product_category__selected',
    'product_category__unselected',
    lambda category_id: (db.color.category == category_id),
    request.vars.category,
    orderby=db.color.id,
    user_signature=True,
    # If you want to process ajax requests at the time of the object construction (not at the form rendered),
    # specify your target field in the following:
    field=db.product.color,
)
################################################################################


def index():
    form = SQLFORM(db.product)
    if form.accepts(request.vars, session):
        session.flash = 'submitted %s' % form.vars
        redirect(URL('index'))
    return dict(
        form=form,
Exemple #3
0
        db.color.bulk_insert([{'category': _id, 'name':'green'}])
     
db.product.category.widget = suggest_widget(db.category.name, id_field=db.category.id, 
                                          limitby=(0,10), min_length=1)
     
from gluon.storage import Storage
session.auth = Storage(hmac_key='test')
                                        
################################ The core ######################################
# The lazy_options_widget receives js events
# called "product_category__selected" and "product_category__unselected"
# which will be triggered by the above suggest_widget.]
# You can also pass user_signature and hmac_key arguments for authorization in ajax 
db.product.color.widget = lazy_options_widget(
                  'product_category__selected', 'product_category__unselected',
                  lambda category_id: (db.color.category==category_id), 
                  request.vars.category,
                  orderby=db.color.id,
                  user_signature=True)
################################################################################
     
def index():
    form = SQLFORM(db.product)
    if form.accepts(request.vars, session):
        session.flash = 'submitted %s' % form.vars
        redirect(URL('index'))
    return dict(form=form, 
                categories=SQLTABLE(db().select(db.category.ALL)),
                colors=SQLTABLE(db(db.color.id>0)(db.color.category==db.category.id
                                ).select(db.color.id, db.category.name, db.color.name)))