[web2py] Re: list of usernames

2011-11-02 Thread Archibald Linx
Dear Anthony,

I know, you explained me they were supposed to be identical.

In both cases, I can fill in the form the same way, but when you
submit the form and that a row in the database is added, the "title"
column is filled in, but not the "tosomeone" column.

Archibald


On 2 nov, 03:39, Anthony  wrote:
> On Tuesday, November 1, 2011 7:15:32 PM UTC-4, Archibald Linx wrote:
>
> > @auth.requires_login()
> > def write_message():
> >     form = SQLFORM(db.message)
> >     if form.process().accepted:
> >         response.flash = 'Got it'
> >     return dict(form=form)
>
> > then although the "title" field is filled, the "tosomeone" field is
> > not. The "tosomeone" field remains empty. So the problem came from
> > "form.process().accepted", without me noticing it at first.
>
> > By keeping "if form.accepts(request.vars, session):", I solved my
> > problem.
>
> if form.process().accepted and if form.accepts(request.vars, session) are
> supposed to be identical. Can you better explain how the behavior differs.
> You say the "tosomeone" field "remains empty" -- what does that mean? It's
> a create form, so it should start out empty, no? Are you saying you can't
> fill it in? Or it doesn't show the multi-select widget?
>
> Anthony


[web2py] Re: list of usernames

2011-11-01 Thread Anthony
On Tuesday, November 1, 2011 7:15:32 PM UTC-4, Archibald Linx wrote:
>
> @auth.requires_login() 
> def write_message(): 
> form = SQLFORM(db.message) 
> if form.process().accepted: 
> response.flash = 'Got it' 
> return dict(form=form) 
>
> then although the "title" field is filled, the "tosomeone" field is 
> not. The "tosomeone" field remains empty. So the problem came from 
> "form.process().accepted", without me noticing it at first. 
>
> By keeping "if form.accepts(request.vars, session):", I solved my 
> problem.
>

if form.process().accepted and if form.accepts(request.vars, session) are 
supposed to be identical. Can you better explain how the behavior differs. 
You say the "tosomeone" field "remains empty" -- what does that mean? It's 
a create form, so it should start out empty, no? Are you saying you can't 
fill it in? Or it doesn't show the multi-select widget?

Anthony



[web2py] Re: list of usernames

2011-11-01 Thread Archibald Linx
I have discovered where my problem came from.

If you try this model :

db.define_table('message',
Field('title'),
Field('tosomeone', 'list:reference auth_user'))

and this controller :

@auth.requires_login()
def write_message():
form = SQLFORM(db.message)
if form.accepts(request.vars, session):
response.flash = 'Got it'
return dict(form=form)

while still using the same web2pyslice*, everything works.

* http://www.web2pyslices.com/slices/take_slice/70

Now change "form.accepts(request.vars, session)" into
"form.process().accepted" :

@auth.requires_login()
def write_message():
form = SQLFORM(db.message)
if form.process().accepted:
response.flash = 'Got it'
return dict(form=form)

then although the "title" field is filled, the "tosomeone" field is
not. The "tosomeone" field remains empty. So the problem came from
"form.process().accepted", without me noticing it at first.

By keeping "if form.accepts(request.vars, session):", I solved my
problem.

Archibald


On 29 oct, 13:20, Archibald Linx  wrote:
> I was wondering if the problem could come from
> "multiselect_widget(f,v)", a function that I took from this Web2py
> slices page :http://www.web2pyslices.com/slices/take_slice/70
>
> In this function you can find the following line : "inp =
> SQLFORM.widgets.options.widget(f,v)"
>
> But now I am using "SQLFORM.factory", not exclusively "SQLFORM". Could
> the problem lie there ?
>
> Thanks for your help,
> Archibald
>
> On 28 oct, 19:18, Archibald Linx  wrote:
>
>
>
>
>
>
>
> > Thank you Anthony, I have given it a thought and I will create another
> > table called "status".
>
> > The "message" table contains the fields : "id" and "to" among others.
> > The "status" table contains the fields : "id", "message_id", "person"
> > and "status" among others.
> > "to" is readable and writable.
> > "message_id", "person" and "status" are non readable and non writable
> > fields.
>
> > I think that what I need is one form for multiple tables 
> > :http://web2py.com/book/default/chapter/07#One-form-for-multiple-tables
>
> > Here are two rows of the "message" table (without all the fields) :
> > id / to
> > 1  / steve,jimmy
> > 2  / julia
>
> > Here are the corresponding rows of the "status" table (without all the
> > fields) :
> > id / message_id / person / status
> > 1  /   1        / steve  /  0
> > 2  /   1        / jimmy  /  0
> > 3  /   2        / julia  /  0
>
> > The "message_id" field in the "status" table refers to the "id" in the
> > "message" table.
>
> > Here is what I have tried in the controller :
>
> >     form = SQLFORM.factory(db.message,db.status)
> >      if form.process().accepted:
> >         id = db.message.insert(**db.message._filter_fields(form.vars))
> >         form.vars.message_id = id
> >         for to in form.vars.to:
> >             form.vars.person = to
> >             id =
> > db.status.insert(**db.status._filter_fields(form.vars))
>
> > Unfortunately the "to" field of the "message" table remains empty. And
> > an empty row is inserted in the "status" table.
>
> > Where does the problem come from ? Could there be a problem with the
> > "_filter_fields" method when it deals with a "list:reference" field ?
> > I am just giving it a go ;)
>
> > Thanks a lot,
> > Archibald
>
> > On 26 oct, 23:57, Anthony  wrote:
>
> > > That's what I was thinking.list: type fields are good if you just need to
> > > store alistof things associated with a given record and retrieve thelist
> > > when the record is retrieved, but they aren't necessarily easy or 
> > > efficient
> > > for querying the data (depending on the application). If you really want 
> > > to
> > > stick with thelist: fields, I suppose you could do a select to get the
> > > Julia records, and then use some Python code to further filter the records
> > > based on status. You might also be able to create either a computed or
> > > virtual field that concatenates name and status into a newlist, and query
> > > that. Depending on how many records you're dealing with, though, it might
> > > be more efficient to go with a more normalized data structure.
>
> > > Anthony
>
> > > On Wednesday, October 26, 2011 5:38:41 PM UTC-4, Archibald Linx wrote:
>
> > > > Dear Anthony,
>
> > > > I have asked the question on Stackoverflow and it seems it is a bad
> > > > database structure ;) Sorry.
>
> > > > See :http://stackoverflow.com/questions/7908024/sql-query-list-fields
>
> > > > I will put the status information somewhere else. Maybe in a separate
> > > > database. I don't know yet.
>
> > > > Thanks for the help you gave me,
> > > > Archibald
>
> > > > On 26 oct, 20:35, Archibald Linx  wrote:
> > > > > Thank you Anthony.
>
> > > > > I don't know about the raw SQL query. I will ask on Stackoverflow and
> > > > > post the link here.
>
> > > > > Best,
> > > > > Archibald
>
> > > > > On 26 oct, 19:07, Anthony  wrote:
>
> > > > > > On Wednesday, October 26, 2011 12:21:33 PM UTC-4, Archibald Linx
> > > > wrote

[web2py] Re: list of usernames

2011-10-29 Thread Archibald Linx
I was wondering if the problem could come from
"multiselect_widget(f,v)", a function that I took from this Web2py
slices page : http://www.web2pyslices.com/slices/take_slice/70

In this function you can find the following line : "inp =
SQLFORM.widgets.options.widget(f,v)"

But now I am using "SQLFORM.factory", not exclusively "SQLFORM". Could
the problem lie there ?

Thanks for your help,
Archibald



On 28 oct, 19:18, Archibald Linx  wrote:
> Thank you Anthony, I have given it a thought and I will create another
> table called "status".
>
> The "message" table contains the fields : "id" and "to" among others.
> The "status" table contains the fields : "id", "message_id", "person"
> and "status" among others.
> "to" is readable and writable.
> "message_id", "person" and "status" are non readable and non writable
> fields.
>
> I think that what I need is one form for multiple tables 
> :http://web2py.com/book/default/chapter/07#One-form-for-multiple-tables
>
> Here are two rows of the "message" table (without all the fields) :
> id / to
> 1  / steve,jimmy
> 2  / julia
>
> Here are the corresponding rows of the "status" table (without all the
> fields) :
> id / message_id / person / status
> 1  /   1        / steve  /  0
> 2  /   1        / jimmy  /  0
> 3  /   2        / julia  /  0
>
> The "message_id" field in the "status" table refers to the "id" in the
> "message" table.
>
> Here is what I have tried in the controller :
>
>     form = SQLFORM.factory(db.message,db.status)
>      if form.process().accepted:
>         id = db.message.insert(**db.message._filter_fields(form.vars))
>         form.vars.message_id = id
>         for to in form.vars.to:
>             form.vars.person = to
>             id =
> db.status.insert(**db.status._filter_fields(form.vars))
>
> Unfortunately the "to" field of the "message" table remains empty. And
> an empty row is inserted in the "status" table.
>
> Where does the problem come from ? Could there be a problem with the
> "_filter_fields" method when it deals with a "list:reference" field ?
> I am just giving it a go ;)
>
> Thanks a lot,
> Archibald
>
> On 26 oct, 23:57, Anthony  wrote:
>
>
>
>
>
>
>
> > That's what I was thinking.list: type fields are good if you just need to
> > store alistof things associated with a given record and retrieve thelist
> > when the record is retrieved, but they aren't necessarily easy or efficient
> > for querying the data (depending on the application). If you really want to
> > stick with thelist: fields, I suppose you could do a select to get the
> > Julia records, and then use some Python code to further filter the records
> > based on status. You might also be able to create either a computed or
> > virtual field that concatenates name and status into a newlist, and query
> > that. Depending on how many records you're dealing with, though, it might
> > be more efficient to go with a more normalized data structure.
>
> > Anthony
>
> > On Wednesday, October 26, 2011 5:38:41 PM UTC-4, Archibald Linx wrote:
>
> > > Dear Anthony,
>
> > > I have asked the question on Stackoverflow and it seems it is a bad
> > > database structure ;) Sorry.
>
> > > See :http://stackoverflow.com/questions/7908024/sql-query-list-fields
>
> > > I will put the status information somewhere else. Maybe in a separate
> > > database. I don't know yet.
>
> > > Thanks for the help you gave me,
> > > Archibald
>
> > > On 26 oct, 20:35, Archibald Linx  wrote:
> > > > Thank you Anthony.
>
> > > > I don't know about the raw SQL query. I will ask on Stackoverflow and
> > > > post the link here.
>
> > > > Best,
> > > > Archibald
>
> > > > On 26 oct, 19:07, Anthony  wrote:
>
> > > > > On Wednesday, October 26, 2011 12:21:33 PM UTC-4, Archibald Linx
> > > wrote:
>
> > > > > > Thank you Anthony !
>
> > > > > > Is the length "len" always defined in Python ?
>
> > > > > No, I think the len() function will fail if you pass None to it, so if
> > > you
> > > > > were using request.vars, you'd want something like:
>
> > > > > default=len(request.vars.to) if request.vars.to is not None else
> > > [whatever
> > > > > you want the default to be otherwise]
>
> > > > > > I couldn't find much tools in the documentation to query lists of
> > > > > > references apart from the "contains" operator.
>
> > > > > > For example, let's have the following "message" table :
> > > > > > id / to          / status
> > > > > > 1  / steve,jimmy / 0,2
> > > > > > 2  / john,julia  / 1,2
> > > > > > 3  / julia,peggy / 0,1
>
> > > > > > I want to get the rows where "Julia" is in "to" and where her status
> > > > > > is "0" (in this particular case, that is row n°3).
> > > > > > With the "contains" operator I only know how to get the rows where
> > > > > > "Julia" is in "to" (that is row n°2 and n°3).
>
> > > > > > Should I write raw SQL ?
>
> > > > > How would you write it in raw SQL?- Masquer le texte des messages 
> > > > > précédents -
>
> > - Afficher le texte des messages précédents -


[web2py] Re: list of usernames

2011-10-28 Thread Archibald Linx
Thank you Anthony, I have given it a thought and I will create another
table called "status".

The "message" table contains the fields : "id" and "to" among others.
The "status" table contains the fields : "id", "message_id", "person"
and "status" among others.
"to" is readable and writable.
"message_id", "person" and "status" are non readable and non writable
fields.

I think that what I need is one form for multiple tables :
http://web2py.com/book/default/chapter/07#One-form-for-multiple-tables

Here are two rows of the "message" table (without all the fields) :
id / to
1  / steve,jimmy
2  / julia

Here are the corresponding rows of the "status" table (without all the
fields) :
id / message_id / person / status
1  /   1/ steve  /  0
2  /   1/ jimmy  /  0
3  /   2/ julia  /  0

The "message_id" field in the "status" table refers to the "id" in the
"message" table.

Here is what I have tried in the controller :

form = SQLFORM.factory(db.message,db.status)
 if form.process().accepted:
id = db.message.insert(**db.message._filter_fields(form.vars))
form.vars.message_id = id
for to in form.vars.to:
form.vars.person = to
id =
db.status.insert(**db.status._filter_fields(form.vars))

Unfortunately the "to" field of the "message" table remains empty. And
an empty row is inserted in the "status" table.

Where does the problem come from ? Could there be a problem with the
"_filter_fields" method when it deals with a "list:reference" field ?
I am just giving it a go ;)

Thanks a lot,
Archibald


On 26 oct, 23:57, Anthony  wrote:
> That's what I was thinking. list: type fields are good if you just need to
> store a list of things associated with a given record and retrieve the list
> when the record is retrieved, but they aren't necessarily easy or efficient
> for querying the data (depending on the application). If you really want to
> stick with the list: fields, I suppose you could do a select to get the
> Julia records, and then use some Python code to further filter the records
> based on status. You might also be able to create either a computed or
> virtual field that concatenates name and status into a new list, and query
> that. Depending on how many records you're dealing with, though, it might
> be more efficient to go with a more normalized data structure.
>
> Anthony
>
>
>
> On Wednesday, October 26, 2011 5:38:41 PM UTC-4, Archibald Linx wrote:
>
> > Dear Anthony,
>
> > I have asked the question on Stackoverflow and it seems it is a bad
> > database structure ;) Sorry.
>
> > See :http://stackoverflow.com/questions/7908024/sql-query-list-fields
>
> > I will put the status information somewhere else. Maybe in a separate
> > database. I don't know yet.
>
> > Thanks for the help you gave me,
> > Archibald
>
> > On 26 oct, 20:35, Archibald Linx  wrote:
> > > Thank you Anthony.
>
> > > I don't know about the raw SQL query. I will ask on Stackoverflow and
> > > post the link here.
>
> > > Best,
> > > Archibald
>
> > > On 26 oct, 19:07, Anthony  wrote:
>
> > > > On Wednesday, October 26, 2011 12:21:33 PM UTC-4, Archibald Linx
> > wrote:
>
> > > > > Thank you Anthony !
>
> > > > > Is the length "len" always defined in Python ?
>
> > > > No, I think the len() function will fail if you pass None to it, so if
> > you
> > > > were using request.vars, you'd want something like:
>
> > > > default=len(request.vars.to) if request.vars.to is not None else
> > [whatever
> > > > you want the default to be otherwise]
>
> > > > > I couldn't find much tools in the documentation to query lists of
> > > > > references apart from the "contains" operator.
>
> > > > > For example, let's have the following "message" table :
> > > > > id / to          / status
> > > > > 1  / steve,jimmy / 0,2
> > > > > 2  / john,julia  / 1,2
> > > > > 3  / julia,peggy / 0,1
>
> > > > > I want to get the rows where "Julia" is in "to" and where her status
> > > > > is "0" (in this particular case, that is row n°3).
> > > > > With the "contains" operator I only know how to get the rows where
> > > > > "Julia" is in "to" (that is row n°2 and n°3).
>
> > > > > Should I write raw SQL ?
>
> > > > How would you write it in raw SQL?- Masquer le texte des messages 
> > > > précédents -
>
> - Afficher le texte des messages précédents -


[web2py] Re: list of usernames

2011-10-26 Thread Anthony
That's what I was thinking. list: type fields are good if you just need to 
store a list of things associated with a given record and retrieve the list 
when the record is retrieved, but they aren't necessarily easy or efficient 
for querying the data (depending on the application). If you really want to 
stick with the list: fields, I suppose you could do a select to get the 
Julia records, and then use some Python code to further filter the records 
based on status. You might also be able to create either a computed or 
virtual field that concatenates name and status into a new list, and query 
that. Depending on how many records you're dealing with, though, it might 
be more efficient to go with a more normalized data structure.

Anthony

On Wednesday, October 26, 2011 5:38:41 PM UTC-4, Archibald Linx wrote:
>
> Dear Anthony, 
>
> I have asked the question on Stackoverflow and it seems it is a bad 
> database structure ;) Sorry. 
>
> See : http://stackoverflow.com/questions/7908024/sql-query-list-fields 
>
> I will put the status information somewhere else. Maybe in a separate 
> database. I don't know yet. 
>
> Thanks for the help you gave me, 
> Archibald 
>
>
> On 26 oct, 20:35, Archibald Linx  wrote: 
> > Thank you Anthony. 
> > 
> > I don't know about the raw SQL query. I will ask on Stackoverflow and 
> > post the link here. 
> > 
> > Best, 
> > Archibald 
> > 
> > On 26 oct, 19:07, Anthony  wrote: 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > > On Wednesday, October 26, 2011 12:21:33 PM UTC-4, Archibald Linx 
> wrote: 
> > 
> > > > Thank you Anthony ! 
> > 
> > > > Is the length "len" always defined in Python ? 
> > 
> > > No, I think the len() function will fail if you pass None to it, so if 
> you 
> > > were using request.vars, you'd want something like: 
> > 
> > > default=len(request.vars.to) if request.vars.to is not None else 
> [whatever 
> > > you want the default to be otherwise] 
> > 
> > > > I couldn't find much tools in the documentation to query lists of 
> > > > references apart from the "contains" operator. 
> > 
> > > > For example, let's have the following "message" table : 
> > > > id / to  / status 
> > > > 1  / steve,jimmy / 0,2 
> > > > 2  / john,julia  / 1,2 
> > > > 3  / julia,peggy / 0,1 
> > 
> > > > I want to get the rows where "Julia" is in "to" and where her status 
> > > > is "0" (in this particular case, that is row n°3). 
> > > > With the "contains" operator I only know how to get the rows where 
> > > > "Julia" is in "to" (that is row n°2 and n°3). 
> > 
> > > > Should I write raw SQL ? 
> > 
> > > How would you write it in raw SQL?



[web2py] Re: list of usernames

2011-10-26 Thread Archibald Linx
Dear Anthony,

I have asked the question on Stackoverflow and it seems it is a bad
database structure ;) Sorry.

See : http://stackoverflow.com/questions/7908024/sql-query-list-fields

I will put the status information somewhere else. Maybe in a separate
database. I don't know yet.

Thanks for the help you gave me,
Archibald


On 26 oct, 20:35, Archibald Linx  wrote:
> Thank you Anthony.
>
> I don't know about the raw SQL query. I will ask on Stackoverflow and
> post the link here.
>
> Best,
> Archibald
>
> On 26 oct, 19:07, Anthony  wrote:
>
>
>
>
>
>
>
> > On Wednesday, October 26, 2011 12:21:33 PM UTC-4, Archibald Linx wrote:
>
> > > Thank you Anthony !
>
> > > Is the length "len" always defined in Python ?
>
> > No, I think the len() function will fail if you pass None to it, so if you
> > were using request.vars, you'd want something like:
>
> > default=len(request.vars.to) if request.vars.to is not None else [whatever
> > you want the default to be otherwise]
>
> > > I couldn't find much tools in the documentation to query lists of
> > > references apart from the "contains" operator.
>
> > > For example, let's have the following "message" table :
> > > id / to          / status
> > > 1  / steve,jimmy / 0,2
> > > 2  / john,julia  / 1,2
> > > 3  / julia,peggy / 0,1
>
> > > I want to get the rows where "Julia" is in "to" and where her status
> > > is "0" (in this particular case, that is row n°3).
> > > With the "contains" operator I only know how to get the rows where
> > > "Julia" is in "to" (that is row n°2 and n°3).
>
> > > Should I write raw SQL ?
>
> > How would you write it in raw SQL?


[web2py] Re: list of usernames

2011-10-26 Thread Archibald Linx
Thank you Anthony.

I don't know about the raw SQL query. I will ask on Stackoverflow and
post the link here.

Best,
Archibald

On 26 oct, 19:07, Anthony  wrote:
> On Wednesday, October 26, 2011 12:21:33 PM UTC-4, Archibald Linx wrote:
>
> > Thank you Anthony !
>
> > Is the length "len" always defined in Python ?
>
> No, I think the len() function will fail if you pass None to it, so if you
> were using request.vars, you'd want something like:
>
> default=len(request.vars.to) if request.vars.to is not None else [whatever
> you want the default to be otherwise]
>
>
>
>
>
>
>
>
>
>
>
> > I couldn't find much tools in the documentation to query lists of
> > references apart from the "contains" operator.
>
> > For example, let's have the following "message" table :
> > id / to          / status
> > 1  / steve,jimmy / 0,2
> > 2  / john,julia  / 1,2
> > 3  / julia,peggy / 0,1
>
> > I want to get the rows where "Julia" is in "to" and where her status
> > is "0" (in this particular case, that is row n°3).
> > With the "contains" operator I only know how to get the rows where
> > "Julia" is in "to" (that is row n°2 and n°3).
>
> > Should I write raw SQL ?
>
> How would you write it in raw SQL?


[web2py] Re: list of usernames

2011-10-26 Thread Anthony
On Wednesday, October 26, 2011 12:21:33 PM UTC-4, Archibald Linx wrote:
>
> Thank you Anthony ! 
>
> Is the length "len" always defined in Python ? 
>

No, I think the len() function will fail if you pass None to it, so if you 
were using request.vars, you'd want something like:

default=len(request.vars.to) if request.vars.to is not None else [whatever 
you want the default to be otherwise]
 

>
> I couldn't find much tools in the documentation to query lists of 
> references apart from the "contains" operator. 
>
> For example, let's have the following "message" table : 
> id / to  / status 
> 1  / steve,jimmy / 0,2 
> 2  / john,julia  / 1,2 
> 3  / julia,peggy / 0,1 
>
> I want to get the rows where "Julia" is in "to" and where her status 
> is "0" (in this particular case, that is row n°3). 
> With the "contains" operator I only know how to get the rows where 
> "Julia" is in "to" (that is row n°2 and n°3). 
>
> Should I write raw SQL ? 
>

How would you write it in raw SQL?



[web2py] Re: list of usernames

2011-10-26 Thread Archibald Linx
Thank you Anthony !

Is the length "len" always defined in Python ?

I couldn't find much tools in the documentation to query lists of
references apart from the "contains" operator.

For example, let's have the following "message" table :
id / to  / status
1  / steve,jimmy / 0,2
2  / john,julia  / 1,2
3  / julia,peggy / 0,1

I want to get the rows where "Julia" is in "to" and where her status
is "0" (in this particular case, that is row n°3).
With the "contains" operator I only know how to get the rows where
"Julia" is in "to" (that is row n°2 and n°3).

Should I write raw SQL ?

Thanks,
Archibald


On 26 oct, 15:03, Anthony  wrote:
> This is probably the easiest way to go. You could use a computed field, but
> then if you want the computed field to appear in an update form, you have
> to explicitly list it (along with all fields you want to appear). Note, if
> you instead used request.vars.to to set the field default, that wouldn't
> present any danger in terms of the contents of request.vars.to not being
> validated, because you're only using the length of request.vars.to. It
> would only be an issue if the validation of request.vars.to could result in
> it passing validation but its length changing as a result of that.
>
> Anthony
>
>
>
>
>
>
>
> On Wednesday, October 26, 2011 6:39:29 AM UTC-4, Archibald Linx wrote:
>
> > Thank you Anthony.
>
> > I will need to exclusively modify the variable "status" on other
> > occasions. So I am not sure I really want "computed fields". Is that
> > true ?
>
> > So I decided to try an onvalidation function and I ended up with :
>
> > def status(form):
> >     form.vars.status = [0]*len(form.vars.to)
>
> > def write():
> >     form = SQLFORM(db.message)
> >         if form.accepts(request.vars, session, onvalidation=status):
> >             response.flash = 'Got it'
>
> > It seems to work.
>
> > Is it ok ? If I have understood correctly, onvalidation is called
> > after validation and before insert. Like this I am sure
> > "forms.vars.to" does not contain anything fishy or dangerous.
>
> > Thanks,
> > Archibald
>
> > On 25 oct, 18:30, Anthony  wrote:
> > > On Tuesday, October 25, 2011 11:45:41 AM UTC-4, Archibald Linx wrote:
>
> > > > Thank you Anthony.
>
> > > > All this works very nicely.
> > > > Maybe the default format for auth_user should also be documented.
>
> > > > Let's say I have the following table :
> > > > db.define_table('message',
> > > >     Field('to', 'list:reference auth_user'),
> > > >     Field('status', 'list:integer'))
>
> > > > I want "status" to be a list of 0 as long as "to", but
> > > > "db.message.status.default = [0]*len(db.message.to.default)" does not
> > > > work.
>
> > > db.message.to.default represents the default value for the 'to' field
> > (which
> > > you have not set), not the actually values being inserted. Anyway, I
> > don't
> > > think the default for one field can reference the values of another.
>
> > > There are a few other options. You could use a computed field (though by
> > > default that won't display in a form, if you need that). If
> > inserts/updates
> > > will always be handled via form submissions, you could us a form
> > > onvalidation function or a custom validator. You could also just do
> > > default=[0]*len(request.vars.to), since upon form submission, the
> > values
> > > submitted to the 'to' field will be stored in request.vars.to (note,
> > the
> > > values stored in request.vars will be the unvalidated values). See here
> > for
> > > more
> > > details:
> >http://stackoverflow.com/questions/7325776/using-a-lambda-for-a-model...
>
> > > Anthony


[web2py] Re: list of usernames

2011-10-26 Thread Anthony
This is probably the easiest way to go. You could use a computed field, but 
then if you want the computed field to appear in an update form, you have 
to explicitly list it (along with all fields you want to appear). Note, if 
you instead used request.vars.to to set the field default, that wouldn't 
present any danger in terms of the contents of request.vars.to not being 
validated, because you're only using the length of request.vars.to. It 
would only be an issue if the validation of request.vars.to could result in 
it passing validation but its length changing as a result of that.

Anthony

On Wednesday, October 26, 2011 6:39:29 AM UTC-4, Archibald Linx wrote:
>
> Thank you Anthony. 
>
> I will need to exclusively modify the variable "status" on other 
> occasions. So I am not sure I really want "computed fields". Is that 
> true ? 
>
> So I decided to try an onvalidation function and I ended up with : 
>
> def status(form): 
> form.vars.status = [0]*len(form.vars.to) 
>
> def write(): 
> form = SQLFORM(db.message) 
> if form.accepts(request.vars, session, onvalidation=status): 
> response.flash = 'Got it' 
>
> It seems to work. 
>
> Is it ok ? If I have understood correctly, onvalidation is called 
> after validation and before insert. Like this I am sure 
> "forms.vars.to" does not contain anything fishy or dangerous. 
>
> Thanks, 
> Archibald 
>
>
> On 25 oct, 18:30, Anthony  wrote: 
> > On Tuesday, October 25, 2011 11:45:41 AM UTC-4, Archibald Linx wrote: 
> > 
> > > Thank you Anthony. 
> > 
> > > All this works very nicely. 
> > > Maybe the default format for auth_user should also be documented. 
> > 
> > > Let's say I have the following table : 
> > > db.define_table('message', 
> > > Field('to', 'list:reference auth_user'), 
> > > Field('status', 'list:integer')) 
> > 
> > > I want "status" to be a list of 0 as long as "to", but 
> > > "db.message.status.default = [0]*len(db.message.to.default)" does not 
> > > work. 
> > 
> > db.message.to.default represents the default value for the 'to' field 
> (which 
> > you have not set), not the actually values being inserted. Anyway, I 
> don't 
> > think the default for one field can reference the values of another. 
> > 
> > There are a few other options. You could use a computed field (though by 
> > default that won't display in a form, if you need that). If 
> inserts/updates 
> > will always be handled via form submissions, you could us a form 
> > onvalidation function or a custom validator. You could also just do 
> > default=[0]*len(request.vars.to), since upon form submission, the 
> values 
> > submitted to the 'to' field will be stored in request.vars.to (note, 
> the 
> > values stored in request.vars will be the unvalidated values). See here 
> for 
> > more 
> > details:
> http://stackoverflow.com/questions/7325776/using-a-lambda-for-a-model... 
> > 
> > Anthony



[web2py] Re: list of usernames

2011-10-26 Thread Archibald Linx
Thank you Anthony.

I will need to exclusively modify the variable "status" on other
occasions. So I am not sure I really want "computed fields". Is that
true ?

So I decided to try an onvalidation function and I ended up with :

def status(form):
form.vars.status = [0]*len(form.vars.to)

def write():
form = SQLFORM(db.message)
if form.accepts(request.vars, session, onvalidation=status):
response.flash = 'Got it'

It seems to work.

Is it ok ? If I have understood correctly, onvalidation is called
after validation and before insert. Like this I am sure
"forms.vars.to" does not contain anything fishy or dangerous.

Thanks,
Archibald


On 25 oct, 18:30, Anthony  wrote:
> On Tuesday, October 25, 2011 11:45:41 AM UTC-4, Archibald Linx wrote:
>
> > Thank you Anthony.
>
> > All this works very nicely.
> > Maybe the default format for auth_user should also be documented.
>
> > Let's say I have the following table :
> > db.define_table('message',
> >     Field('to', 'list:reference auth_user'),
> >     Field('status', 'list:integer'))
>
> > I want "status" to be a list of 0 as long as "to", but
> > "db.message.status.default = [0]*len(db.message.to.default)" does not
> > work.
>
> db.message.to.default represents the default value for the 'to' field (which
> you have not set), not the actually values being inserted. Anyway, I don't
> think the default for one field can reference the values of another.
>
> There are a few other options. You could use a computed field (though by
> default that won't display in a form, if you need that). If inserts/updates
> will always be handled via form submissions, you could us a form
> onvalidation function or a custom validator. You could also just do
> default=[0]*len(request.vars.to), since upon form submission, the values
> submitted to the 'to' field will be stored in request.vars.to (note, the
> values stored in request.vars will be the unvalidated values). See here for
> more
> details:http://stackoverflow.com/questions/7325776/using-a-lambda-for-a-model...
>
> Anthony


[web2py] Re: list of usernames

2011-10-25 Thread Anthony
On Tuesday, October 25, 2011 11:45:41 AM UTC-4, Archibald Linx wrote:
>
> Thank you Anthony. 
>
> All this works very nicely. 
> Maybe the default format for auth_user should also be documented. 
>
> Let's say I have the following table : 
> db.define_table('message', 
> Field('to', 'list:reference auth_user'), 
> Field('status', 'list:integer')) 
>
> I want "status" to be a list of 0 as long as "to", but 
> "db.message.status.default = [0]*len(db.message.to.default)" does not 
> work.
>

db.message.to.default represents the default value for the 'to' field (which 
you have not set), not the actually values being inserted. Anyway, I don't 
think the default for one field can reference the values of another.

There are a few other options. You could use a computed field (though by 
default that won't display in a form, if you need that). If inserts/updates 
will always be handled via form submissions, you could us a form 
onvalidation function or a custom validator. You could also just do 
default=[0]*len(request.vars.to), since upon form submission, the values 
submitted to the 'to' field will be stored in request.vars.to (note, the 
values stored in request.vars will be the unvalidated values). See here for 
more 
details: 
http://stackoverflow.com/questions/7325776/using-a-lambda-for-a-model-default-in-web2py/7328407#7328407

Anthony


[web2py] Re: list of usernames

2011-10-25 Thread Archibald Linx
Thank you Anthony.

All this works very nicely.
Maybe the default format for auth_user should also be documented.

Let's say I have the following table :
db.define_table('message',
Field('to', 'list:reference auth_user'),
Field('status', 'list:integer'))

I want "status" to be a list of 0 as long as "to", but
"db.message.status.default = [0]*len(db.message.to.default)" does not
work.

Do you have any suggestion ?

Thanks,
Archibald

On 25 oct, 17:04, Anthony  wrote:
> On Tuesday, October 25, 2011 10:38:38 AM UTC-4, Archibald Linx wrote:
>
> > Thank you Anthony.
>
> > Do you mean "multiple=(0,9)" ? I cannot find this possibility in the
> > documentation.
>
> Oops, yes, that's what I meant. Apparently, this is undocumented.
>
>
>
> > How can I specify that the format of auth_user be auth_user.username ?
>
> Should be something like IS_IN_DB(db, 'auth_user.id', db.auth_user._format,
> multiple=(0,9))
>
> Note, db.auth_user._format is the default format for auth_user, which is
> '%(username)s', which is what you want.
>
> Anthony


[web2py] Re: list of usernames

2011-10-25 Thread Anthony
On Tuesday, October 25, 2011 10:38:38 AM UTC-4, Archibald Linx wrote:
>
> Thank you Anthony. 
>
> Do you mean "multiple=(0,9)" ? I cannot find this possibility in the 
> documentation. 
>

Oops, yes, that's what I meant. Apparently, this is undocumented.
 

>
> How can I specify that the format of auth_user be auth_user.username ? 
>

Should be something like IS_IN_DB(db, 'auth_user.id', db.auth_user._format, 
multiple=(0,9))

Note, db.auth_user._format is the default format for auth_user, which is 
'%(username)s', which is what you want.

Anthony



[web2py] Re: list of usernames

2011-10-25 Thread Archibald Linx
Thank you Anthony.

Do you mean "multiple=(0,9)" ? I cannot find this possibility in the
documentation.

How can I specify that the format of auth_user be auth_user.username ?

Thanks in advance,
Archibald


On 25 oct, 15:32, Anthony  wrote:
> On Tuesday, October 25, 2011 8:34:16 AM UTC-4, Archibald Linx wrote:
>
> > It works great !
>
> > Because a "list:reference" field gets a default constraint, I
> > deleted :
> > "IS_IN_SET(['Apples','Oranges','Bananas','Kiwis','Lemons'],multiple=True)"
> > I put no requirement.
>
> The default validator for list:reference should be IS_IN_DB, which you
> probably do want to keep to ensure the references are valid.
>
>
>
> > How can I limit the size of a "list:reference" field ? I don't want
> > more than 8 people for example.
>
> I think the 'multiple' argument to IS_IN_DB can be a list/tuple like (min,
> max), so maybe IS_IN_DB(..., (0,9)). Note, I think the max is exclusive,
> hence then 9 to ensure no more than 8.
>
> Anthony


[web2py] Re: list of usernames

2011-10-25 Thread Anthony
On Tuesday, October 25, 2011 8:34:16 AM UTC-4, Archibald Linx wrote:
>
> It works great ! 
>
> Because a "list:reference" field gets a default constraint, I 
> deleted : 
> "IS_IN_SET(['Apples','Oranges','Bananas','Kiwis','Lemons'],multiple=True)" 
> I put no requirement. 
>

The default validator for list:reference should be IS_IN_DB, which you 
probably do want to keep to ensure the references are valid.
 

>
> How can I limit the size of a "list:reference" field ? I don't want 
> more than 8 people for example.
>

I think the 'multiple' argument to IS_IN_DB can be a list/tuple like (min, 
max), so maybe IS_IN_DB(..., (0,9)). Note, I think the max is exclusive, 
hence then 9 to ensure no more than 8.

Anthony



[web2py] Re: list of usernames

2011-10-25 Thread Archibald Linx
It works great !

Because a "list:reference" field gets a default constraint, I
deleted :
"IS_IN_SET(['Apples','Oranges','Bananas','Kiwis','Lemons'],multiple=True)"
I put no requirement.

How can I limit the size of a "list:reference" field ? I don't want
more than 8 people for example.

Thanks a lot,
Archibald

On 25 oct, 02:23, Archibald Linx  wrote:
> The documentation recommands the multiple select plug-in.
>
> http://www.web2pyslices.com/slices/take_slice/70
>
> Sorry,
> Archibald
>
> On 25 oct, 01:18, Archibald Linx  wrote:
>
>
>
>
>
>
>
> > Thank you very much Richard and Anthony !
>
> > What's the easiest way to use these fields in the controller and the view ?
>
> > Archibald
>
> > 2011/10/25 Anthony 
>
> > > Even better, use auth.settings.table_user_name instead of 'auth_user', in
> > > case the user table has a name other than 'auth_user'.
>
> > > On Monday, October 24, 2011 5:25:39 PM UTC-4, Richard wrote:
>
> > >> I think you have mistake :
>
> > >> Field 
> > >> ('tags','list:reference 
> > >> tag'))
>
> > >> In that case "tag" is you table...
>
> > >> So when uselist:reference you don't use the db.auth_user just "auth_user"
>
> > >> Also you don't specified the db.auth_user.username since username is not 
> > >> a
> > >> default field of auth_user and you maybe want to specified the
> > >> representation of thelist:reference field since it is a integer and 
> > >> replace
> > >> it by the name or email of the user...
>
> > >> To do that you need to user .represent()
>
> > >> I let you read futher in the book..
>
> > >> Richard
>
> > >> On Mon, Oct 24, 2011 at 5:19 PM, Archibald Linx 
> > >> wrote:
>
> > >>> Dear Web2py users,
>
> > >>> Do you sometimes use fields which are lists ofusernames?
>
> > >>> How would you write that : Field('usernames','list:**reference
> > >>> db.auth_user.username')) ?
>
> > >>> Thanks a lot,
> > >>> Archibald


[web2py] Re: list of usernames

2011-10-24 Thread Archibald Linx
The documentation recommands the multiple select plug-in.

http://www.web2pyslices.com/slices/take_slice/70

Sorry,
Archibald

On 25 oct, 01:18, Archibald Linx  wrote:
> Thank you very much Richard and Anthony !
>
> What's the easiest way to use these fields in the controller and the view ?
>
> Archibald
>
> 2011/10/25 Anthony 
>
>
>
>
>
>
>
> > Even better, use auth.settings.table_user_name instead of 'auth_user', in
> > case the user table has a name other than 'auth_user'.
>
> > On Monday, October 24, 2011 5:25:39 PM UTC-4, Richard wrote:
>
> >> I think you have mistake :
>
> >> Field 
> >> ('tags','list:reference 
> >> tag'))
>
> >> In that case "tag" is you table...
>
> >> So when use list:reference you don't use the db.auth_user just "auth_user"
>
> >> Also you don't specified the db.auth_user.username since username is not a
> >> default field of auth_user and you maybe want to specified the
> >> representation of the list:reference field since it is a integer and 
> >> replace
> >> it by the name or email of the user...
>
> >> To do that you need to user .represent()
>
> >> I let you read futher in the book..
>
> >> Richard
>
> >> On Mon, Oct 24, 2011 at 5:19 PM, Archibald Linx wrote:
>
> >>> Dear Web2py users,
>
> >>> Do you sometimes use fields which are lists of usernames ?
>
> >>> How would you write that : Field('usernames','list:**reference
> >>> db.auth_user.username')) ?
>
> >>> Thanks a lot,
> >>> Archibald