-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontacts.py
51 lines (41 loc) · 1.5 KB
/
contacts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-
# try something like
def add():
form = SQLFORM(db.contacts.process)
return locals()
def view():
if request.args(0) is None:
rows = db(db.contacts).select(orderby=db.contacts.last_name\
| db.contacts.first_name)
else:
letter = request.args(0)
rows = \
db(db.contacts.last_name.startswith(letter)).select(orderby=db.contacts.last_name |\
db.contacts.first_name)
return locals()
def update():
record = db.contacts(request.args(0)) or redirect(URL('view'))
form = SQLFORM(db.contacts, record)
if form.process().accepted:
response.flash = T('Record Updated')
else:
response.flash = T('Please complete the form.')
return locals()
def index(): return dict(message="hello from contacts.py")
def data():
rows = db(db.contacts).select()
return locals()
def filter():
# get count
rows_count = db(db.contacts).count()
# get all records. sorted by name
rows2_all_sorted_by_name = \
db(db.contacts.select(orderby=~db.contacts.last_name | \
db.contacts.first_name)
# filter, show only those whose last_name starts with M
rows3_startswith = \
db(db.contacts.last_name.startswith('M')).select(orderby=db.contacts.state_name | \
db.contacts.last_name)
# filter only those in California
rows4_by_state = db(~(db.contacts.state_name=='CA')).select(orderby=db.contacts.last_name | \
db.contacts.first_name)