I'm getting a 404 NOT FOUND error whenever I try to use a smartgrid which 
is linked to from a grid. I just started using web2py about two days ago, 
so I might be totally missing something here.

I currently have an SQLFORM.grid on one page with a link to another 
smartgrid. The link is defined in the controller below on line 33.

@auth.requires_login()
> def index():
>     # our manage product page controller
>     
>     # first we define our query so that we can include UOM, BOH and 
> Min/Max Target Qtys
>     query = (
>                 (db.product.id == db.balanceonhand.product_id) & 
>                 (db.product.id == db.targetquantities.product_id) & 
>                 (db.product.uom_id == db.uom.id)
>             )
>             
>     # select which fields we want to display
>     fields = [
>                 db.product.internal_code, 
>                 db.product.internal_name, 
>                 db.product.description, 
>                 db.balanceonhand.amount_on_hand, 
>                 db.uom.unit_of_measure,  
>                 db.targetquantities.minimum_quantity, 
>                 db.targetquantities.maximum_quantity
>              ]
>     
>     # How to display the column names (e.g. UOM instead of Unit of 
> Measure)
>     headers = {
>                 'uom.unit_of_measure':'UOM', 
>                 'balanceonhand.amount_on_hand':'BOH', 
>                 'targetquantities.minimum_quantity':'Min Qty', 
>                 'targetquantities.maximum_quantity':'Max Qty'
>               }
>     
>     # only "hyperlink" boh, qtys if we're on the main manage product page 
> (i.e. no request.args passed)
>     if len(request.args) == 0:
>         links = [lambda row: A('BOM', _href=URL("manage_product", 
> "billofmaterials", args=row.product.id, user_signature=True))] # link for 
> BOM
>         
>         #link for BOH -- clicking link allows BOH to be updated
>         db.balanceonhand.amount_on_hand.represent = \
>             lambda id, row: A(str(id), _href=URL("manage_product", 
> "update_balanceonhand", args=str(row.product.id)))
>         db.targetquantities.minimum_quantity.represent = \
>             lambda id, row: A(str(id), _href=URL("manage_product", 
> "update_targetquantities", args = str(row.product.id)))
>         db.targetquantities.maximum_quantity.represent = \
>             lambda id, row: A(str(id), _href=URL("manage_product", 
> "update_targetquantities", args = str(row.product.id)))
>     else:
>         if request.args[0] == "view":
>             response.flash = "In view page" + str(request.args)
>         links = None
>     
>     # create our grid
>     grid = SQLFORM.grid(query, field_id=db.product.id, fields=fields,headers
> =headers, deletable=False, create=False, links=links)
>     
>     return dict(grid=grid)
>
>>
>>
And this is SQLFORM.smartgrid to which the above links:

> @auth.requires_login()
> def billofmaterials():
>     # our manage BOM page
>     
>     # get our product_id so we know what we're working with
>     product_id = request.args(0, cast=int) or redirect(URL('index'))
>     
>     # get our product code so we can display which product we're updating
>     product_code = db.product[product_id].internal_code
>     
>     query = (db.billofmaterials.product_id == product_id)
>
>
>     # create our grid
>     grid=SQLFORM.grid(query)
>     
>     return dict(grid=grid, product_code=product_code)
>
>>
>> Whenever I click on a "BOM" link in the grid on /manage_product/index, 
the /manage_product/billofmaterials page with the smartgrid opens fine, but 
if I try to Add/View/Edit/Delete on that smartgrid I get a "404 NOT FOUND" 
error. 

I think it is due to the signed URL not being passed correctly, but I could 
be wrong. I originally tried using this without user_signature=True when 
creating the link, but then I would get a "Not authorized"/"ACCESS DENIED" 
error.

Also, I know that smartgrid allows linked_tables, but since my "manage 
product" grid is composed of a query, I'm stuck with using that for the 
main grid.

Is there somewhere in the billofmaterials controller where I should capture 
the key, or am I totally off?

P.S. My database model is attached if needed.

-- 

--- 
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/groups/opt_out.


# -*- coding: utf-8 -*-

#########################################################################
## This scaffolding model makes your app work on Google App Engine too
## File is released under public domain and you can use without limitations
#########################################################################

## if SSL/HTTPS is properly configured and you want all HTTP requests to
## be redirected to HTTPS, uncomment the line below:
# request.requires_https()

if not request.env.web2py_runtime_gae:
    ## if NOT running on Google App Engine use SQLite or other DB
    db = DAL('sqlite://storage.sqlite',pool_size=1,check_reserved=['all'])
else:
    ## connect to Google BigTable (optional 'google:datastore://namespace')
    db = DAL('google:datastore')
    ## store sessions and tickets there
    session.connect(request, response, db=db)
    ## or store session in Memcache, Redis, etc.
    ## from gluon.contrib.memdb import MEMDB
    ## from google.appengine.api.memcache import Client
    ## session.connect(request, response, db = MEMDB(Client()))

## by default give a view/generic.extension to all actions from localhost
## none otherwise. a pattern can be 'controller/function.extension'
response.generic_patterns = ['*'] if request.is_local else []
## (optional) optimize handling of static files
# response.optimize_css = 'concat,minify,inline'
# response.optimize_js = 'concat,minify,inline'

#########################################################################
## Here is sample code if you need for
## - email capabilities
## - authentication (registration, login, logout, ... )
## - authorization (role based authorization)
## - services (xml, csv, json, xmlrpc, jsonrpc, amf, rss)
## - old style crud actions
## (more options discussed in gluon/tools.py)
#########################################################################

from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
auth = Auth(db)
crud, service, plugins = Crud(db), Service(), PluginManager()

## create all tables needed by auth if not custom tables
auth.define_tables(username=False, signature=False)

## configure email
mail = auth.settings.mailer
mail.settings.server = 'logging' or 'smtp.gmail.com:587'
mail.settings.sender = '[email protected]'
mail.settings.login = 'username:password'

## configure auth policy
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True

## if you need to use OpenID, Facebook, MySpace, Twitter, Linkedin, etc.
## register with janrain.com, write your domain:api_key in private/janrain.key
from gluon.contrib.login_methods.rpx_account import use_janrain
use_janrain(auth, filename='private/janrain.key')

#########################################################################
## Define your tables below (or better in another model file) for example
##
## >>> db.define_table('mytable',Field('myfield','string'))
##
## Fields can be 'string','text','password','integer','double','boolean'
##       'date','time','datetime','blob','upload', 'reference TABLENAME'
## There is an implicit 'id integer autoincrement' field
## Consult manual for more options, validators, etc.
##
## More API examples for controllers:
##
## >>> db.mytable.insert(myfield='value')
## >>> rows=db(db.mytable.myfield=='value').select(db.mytable.ALL)
## >>> for row in rows: print row.id, row.myfield
#########################################################################

##  UOM  ################################################################
db.define_table('uom',
    Field('unit_of_measure', 'string', required=True),
    Field('created_by', 'reference auth_user', default=auth.user_id),
    format = '%(unit_of_measure)s'
    )

db.uom.unit_of_measure.requires = [IS_NOT_EMPTY()]


## Product ##############################################################
db.define_table('product', Field('internal_code', 'string'),
    Field('internal_name', 'string', unique=True, required=True),
    Field('description', 'string', required=True),
    #Field('uom_id', 'reference uom', default=1, label="UOM"),
    Field('uom_id', db.uom, label="UOM"),
    Field('can_be_bought', 'boolean'),
    Field('can_be_sold', 'boolean'),
    Field('is_valid', 'boolean'),
    Field('notes', 'string'),
    Field('created_on', 'datetime', default=request.now),
    Field('created_by', 'reference auth_user', default=auth.user_id),
    format = '%(internal_name)s')
    
db.product.internal_name.requires = [IS_NOT_EMPTY(), IS_ALPHANUMERIC(), IS_NOT_IN_DB(db, 'product.internal_name')]
db.product.description.requires = [IS_NOT_EMPTY()]
db.product.uom_id.requires = IS_IN_DB(db, 'uom.id', '%(unit_of_measure)s')
db.product.id.writable = db.product.id.readable = False

   
##  BOH  ################################################################    
db.define_table('balanceonhand',
    #####Field('product_id', 'reference product', writable=False, readable=False),
    Field('product_id', db.product),
    Field('amount_on_hand', 'integer', default=0),
    singular = "BOH",
    plural = "BOH"
    )

db.balanceonhand.product_id.requires = [IS_NOT_EMPTY(), IS_NOT_IN_DB(db, 'balanceonhand.product_id')]
db.balanceonhand.amount_on_hand.requires = [IS_NOT_EMPTY()]
db.balanceonhand.id.writable = db.balanceonhand.id.readable = False
db.balanceonhand.product_id.writable = db.balanceonhand.product_id.readable = False

##  Conversions  ########################################################        
db.define_table('conversions',
    #####Field('from_uom_id', 'reference uom'),
    #####Field('to_uom_id', 'reference uom'),
    Field('from_uom_id', db.uom),
    Field('to_uom_id', db.uom),
    Field('ratio', 'double', default=0.0)
    )

db.conversions.from_uom_id.requires = IS_EXPR('value!=request.vars.from_uom_id', error_message="From and to units of measure cannot be the same.")

##  TargetQuantities  ###################################################        
db.define_table('targetquantities',
    #####Field('product_id', 'reference product', writable=False, readable=False),
    Field('product_id', db.product, writable=False, readable=False),
    Field('minimum_quantity', 'integer'),
    Field('maximum_quantity', 'integer'),
    singular = "Target Quantities",
    plural = "Target Quantities"
    )

db.targetquantities.minimum_quantity.requires = IS_NOT_EMPTY()
db.targetquantities.maximum_quantity.requires = IS_NOT_EMPTY()
db.targetquantities.id.writable = db.targetquantities.id.readable = False

##  BillOfMaterials #####################################################        
db.define_table('billofmaterials',
    #####Field('product_id', 'reference product'),
    Field('product_id', db.product),
    #####Field('child_product_id', 'reference product'),
    Field('child_product_id', db.product),
    Field('amount', 'double', default=0.0),
    #####Field('amount_uom_id', 'reference uom')
    Field('amount_uom_id', db.uom)
    )

#db.billofmaterials.child_product_id.requires = IS_EXPR('value!=request.vars.product_id', error_message="Child product cannot equal parent product")    
   
## after defining tables, uncomment below to enable auditing
# auth.enable_record_versioning(db)

Reply via email to