If you want to show the book's category in the heading, then you need to 
look up the corresponding category's record from the DB and pass it into 
your view.

As far as the default, maybe just put it in the else clause of the 
form.accepts.  Something like this (not tested):


form = SQLFORM.factory(Field("category",label="Book Category", 
requires=IS_IN_DB(db(db.category.id>0), 'category.id', 'category.name', 
error_message="Please pick a category from the list")))

if form.accepts(request.vars, session, keepvalues=True):
    #search by the category selected in the form
    search_category = request.vars.category
else:
    #go with user's default category
    search_category = auth.category

powerTable = plugins.powerTable
powerTable.datasource = 
db(db.book.category==search_category).select(db.category.ALL) 
#this time with our search_category var
powerTable.headers = 'labels' #Add a label="some text" to your fields in the 
model & it'll be used else it'll try to use the field's name
powerTable.columns=['book.name', 'book.code']
books = powerTable.create()

#lets look up the category itself so we can display it in a heading
book_category = db.category[search_category]
return dict(form = form, books = books, book_category = book_category)

Then in your view:

{{extend 'layout.html'}}

<center><h3>You are currently seeing {{=book_category.name}} 
books.</h3></center>

{{=form}}
{{=table}}

Reply via email to