how to use a user specific form input

33 views
Skip to first unread message

Maurice Waka

unread,
Mar 6, 2019, 9:38:48 AM3/6/19
to web2py-users
I'm trying to make a tracker that users input data. 

So far its successful with this code:

form = SQLFORM(db.weight, submit_button=T('Submit')).process()

How ever, I need an author specific data, but can't get around this code:

form = SQLFORM((db.weight.author == auth.user.id).select(db.weight), submit_button=T('Submit')).process()

This is the error that comes:

Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
Traceback (most recent call last):
File "/home/mauricewaka/web2py/gluon/restricted.py", line 219, in restricted
exec(ccode, environment)
File "/home/mauricewaka/web2py/applications/Hestque_Wellness/controllers/e_default.py", line 667, in <module>
File "/home/mauricewaka/web2py/gluon/globals.py", line 421, in <lambda>
self._caller = lambda f: f()
File "/home/mauricewaka/web2py/applications/Hestque_Wellness/controllers/e_default.py", line 510, in myWeight
form = SQLFORM(db.weight.author == auth.user.id, submit_button=T('Submit')).process()
File "/home/mauricewaka/web2py/gluon/sqlhtml.py", line 1354, in __init__
fields = [f.name for f in table if (ignore_rw or f.writable or (f.readable and f.default)) and not f.compute]
TypeError: 'Query' object is not iterable


This is because I'll need a chart in the view with this code:
chart = pygal.StackedLine(fill=True, interpolate='cubic', style=BlueStyle) 
data = db(db.weight).select() 
chart.add('W', [i.weight for i in data]) 
return chart.render()

Leonel Câmara

unread,
Mar 6, 2019, 9:49:14 AM3/6/19
to web2py-users
Do you mean you want to store the author automatically? Or do you want to edit a specific record of weight from a given user?

Lovedie JC

unread,
Mar 6, 2019, 10:58:05 AM3/6/19
to web...@googlegroups.com
Ok. I the first example after I logged in several users, I noticed that they share the same table result. Meaning that when one user updates, everyone else sees the data. I want the privacy of a user having his/her own result. 

On Wed, 6 Mar 2019, 17:49 Leonel Câmara <leonel...@gmail.com> wrote:
Do you mean you want to store the author automatically? Or do you want to edit a specific record of weight from a given user?

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
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 web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Leonel Câmara

unread,
Mar 6, 2019, 12:05:31 PM3/6/19
to web2py-users
Ok that problem is easily solved by adding common_filter to the weight table

db.weight._common_filter = lambda query: db.weight.author == auth.user_id

You can also set the common filter in your define_table call if you want to keep the weight table lazy.

Maurice Waka

unread,
Mar 6, 2019, 12:26:47 PM3/6/19
to web...@googlegroups.com
getting an error:
Syntaxerror:(keyword can't an expression)

--
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/tpYcuBypMZk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.

Maurice Waka

unread,
Mar 6, 2019, 12:37:54 PM3/6/19
to web...@googlegroups.com
More,
this works some how:
db.define_table('weight',
                Field('author', 'reference auth_user', default=auth.user_id, writable=False, readable=False),
                Field('weight','double',),
                Field('created_by','reference auth_user',default = auth.user_id, readable = False, writable = False),
                common_filter = lambda query: db.weight.author == auth.user_id)

On Wed, Mar 6, 2019 at 8:05 PM Leonel Câmara <leonel...@gmail.com> wrote:
--

Maurice Waka

unread,
Mar 6, 2019, 12:47:47 PM3/6/19
to web...@googlegroups.com
Thanks a lot @Leonel
Regards 
Reply all
Reply to author
Forward
0 new messages