| Revision 543,
1.2 KB
checked in by jdalbey, 6 years ago
(diff) |
|
Add branch for web2py example application: Highways
|
| Line | |
|---|
| 1 | def index(): |
|---|
| 2 | return dict() |
|---|
| 3 | # List all the current records in the database |
|---|
| 4 | def list(): |
|---|
| 5 | highways = db().select(db.highways.ALL, orderby=db.highways.lognum) |
|---|
| 6 | return dict(highways = highways) |
|---|
| 7 | # Show details of a single record |
|---|
| 8 | def show(): |
|---|
| 9 | # Retrieve the requested log entry from the database |
|---|
| 10 | # Assumes the requested entry exists in the db (no error handling yet) |
|---|
| 11 | hwy = db(db.highways.lognum == request.args(0)).select().first() |
|---|
| 12 | return dict(hwy=hwy) |
|---|
| 13 | # Display a search form |
|---|
| 14 | def search(): |
|---|
| 15 | form = FORM(INPUT(_name='log_number', requires=IS_NOT_EMPTY()), |
|---|
| 16 | INPUT(_type='submit')) |
|---|
| 17 | if form.process().accepted: |
|---|
| 18 | session.log_number = form.vars.log_number |
|---|
| 19 | redirect(URL('results')) |
|---|
| 20 | return dict(form=form) |
|---|
| 21 | # Show the item that was found in the search |
|---|
| 22 | def results(): |
|---|
| 23 | hwy = db(db.highways.lognum == session.log_number).select().first() |
|---|
| 24 | return dict(hwy=hwy) |
|---|
| 25 | # Create a new record |
|---|
| 26 | def submit(): |
|---|
| 27 | # Don't name this function 'request' because it creates a name conflict with http.request |
|---|
| 28 | form = SQLFORM(db.highways) |
|---|
| 29 | if form.process().accepted: |
|---|
| 30 | response.flash = 'your submission is accepted' |
|---|
| 31 | redirect(URL('list')) |
|---|
| 32 | return dict(form=form) |
|---|
Note: See
TracBrowser
for help on using the repository browser.