Re: [web2py] orderby=['alias'] - works in sqlite, but not in postgres

2019-06-17 Thread Eliezer (Vlad) Tseytkin
Thank you!

On Tue, Jun 18, 2019, 1:19 AM Val K  wrote:

> Try [~db.cart_sharing.stats.sum()]
>
> --
> 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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/87RAPjGI0_k/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/web2py/026bdb99-f659-4d35-849c-3df119671f9e%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/CABZ%2BKCDdah1JRM%3D-3F0AmGaZ_7LHR7Q7Xx5Ujywp%2BsUHPZogMw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] orderby=['alias'] - works in sqlite, but not in postgres

2019-06-17 Thread Val K
Try [~db.cart_sharing.stats.sum()]

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/026bdb99-f659-4d35-849c-3df119671f9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] orderby=['alias'] - works in sqlite, but not in postgres

2019-06-17 Thread Vlad
This works perfect in SQLite:

   rows = db(query).select(db.cart_sharing.created_by.with_alias('sharer'),
   db.cart_sharing.stats.count().with_alias('carts'
),
   db.cart_sharing.stats.sum().with_alias('shares'),
   groupby=db.cart_sharing.created_by,
   orderby=['~shares'])


'shares' is alias to sum(), and sqlite understands exactly what's needed - 
sorts by the number of shares. 

Posgres doesn't like it: 
   column "shares" does not exist 
LINE 1: ...NULL) GROUP BY "cart_sharing"."created_by" ORDER BY ~shares; ^

What's the proper DAL syntax for such a thing compatible with Postgres? 


-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/c3bfb0ea-6c29-48d8-85a3-3e4e21242b9d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: web2py dynamic queries

2019-06-17 Thread Jim Steil
I think you need to check the web2py errors that are being generated. That
should tell you what is going on.

Jim


On Mon, Jun 17, 2019, 5:04 PM Cristina Sig  wrote:

> I'm having the same datatables warning: ajax error so I guess it might be
> the referenced field that is causing the error because even the table is
> not being field with data.
>
> El lunes, 17 de junio de 2019, 18:55:02 (UTC-3), Jim S escribió:
>>
>> Are you getting an error on the referenced field (Nationality) or is it
>> just not returning the results you're expecting?
>>
>> -Jim
>>
>> On Monday, June 17, 2019 at 4:46:14 PM UTC-5, Cristina Sig wrote:
>>>
>>> thanks!
>>> I solved the integer field but it seems that the referenced fields are
>>> not working.
>>> I will try to see what is the issue with them
>>>
>>> El lunes, 17 de junio de 2019, 18:05:18 (UTC-3), Jim S escribió:

 I'm guessing it's the phone number field.  You can't use 'contains' on
 a numeric field.  So, try this:

 if search_value and search_value != '' and search_value != 0:
 try:
 int_search_value = int(search_value)
 queries.append((db.Student.firstname.contains(search_value)) |
(db.Student.lastname.contains(search_value)) |
(db.Student.phone == int_search_value) |
(db.Nationality.descripcion.contains(
 search_value))

 except:
 queries.append((db.Student.firstname.contains(search_value)) |
(db.Student.lastname.contains(search_value)) |
(db.Nationality.descripcion.contains(
 search_value))

 query = reduce(lambda a, b: (a & b), queries)
 query.select(left=db.Nationality.on(db.Student.nationality == db.
 Nationality.id))

 Basically, if you can convert the search_value to an int, you want to
 check the phone number against the int as well.  If you can't convert to an
 int, then don't include phone number in the search.

 The datatables error is not very helpful.  What you want to look at is
 the error that web2py is generating to confirm that it is the phone number
 like I think it is.

 -Jim

 On Monday, June 17, 2019 at 3:44:27 PM UTC-5, Cristina Sig wrote:
>
> Hello Jim,
>
> I tried the code and it shows me an error
>
> *DataTables warning: table id=tableStudent - Ajax error. For more
> information about this error, please see http://datatables.net/tn/7
> *
>
> I think it is not recognising the numeric field or the referenced ones
>
>
> El lunes, 17 de junio de 2019, 11:30:45 (UTC-3), Jim S escribió:
>>
>> Cristina
>>
>> I'd look at adding a 'left' argument on my query.select().
>>
>> if search_value and search_value != '' and search_value != 0:
>> queries.append((db.Student.firstname.contains(search_value)) |
>>(db.Student.lastname.contains(search_value)) |
>>(db.Student.phone.contains(search_value)) |
>>(db.Nationality.descripcion.contains(search_value
>> ))
>>
>> query = reduce(lambda a, b: (a & b), queries)
>> query.select(left=db.Nationality.on(db.Student.nationality == db.
>> Nationality.id))
>>
>> The above should give you the rows where the search text matches
>> firstname or lastname or phone or nationality description.  You may want 
>> to
>> change that to 'and' instead of 'or' depending on your requirements.
>>
>> Make sense?
>>
>> -Jim
>>
>>
>>
>> On Sunday, June 16, 2019 at 8:36:09 PM UTC-5, Cristina Sig wrote:
>>>
>>> Hello,
>>>
>>> I'm a newbie on python language so I'm struggling to do some queries.
>>> I have a table Student which I use to fill a table on view, above
>>> that table, I have a search box, where I would like to provide the 
>>> option
>>> to search in multiple columns (phone, last name, first name, or
>>> nationality).
>>> I don't know how exactly do a dynamic query in this case because I
>>> have some fields which are references from other tables.
>>>
>>> This is my Db
>>> db.define_table('Nationality',
>>> Field('descripcion', 'string'),
>>>)
>>>
>>> db.define_table('Grade',
>>> Field('level', 'string'),
>>>)
>>>
>>> db.define_table('Student',
>>> Field('lastname', 'string'),
>>> Field('firstname', 'string'),
>>> Field('nationality','reference Nationality'),
>>> Field('phone', 'integer'),
>>> Field('email', 'string'),
>>> Field('gradelevel','reference Grade'),
>>>)
>>>
>>> and this is my try so far

[web2py] Re: web2py dynamic queries

2019-06-17 Thread Cristina Sig
I'm having the same datatables warning: ajax error so I guess it might be 
the referenced field that is causing the error because even the table is 
not being field with data.

El lunes, 17 de junio de 2019, 18:55:02 (UTC-3), Jim S escribió:
>
> Are you getting an error on the referenced field (Nationality) or is it 
> just not returning the results you're expecting?
>
> -Jim
>
> On Monday, June 17, 2019 at 4:46:14 PM UTC-5, Cristina Sig wrote:
>>
>> thanks!
>> I solved the integer field but it seems that the referenced fields are 
>> not working.
>> I will try to see what is the issue with them 
>>
>> El lunes, 17 de junio de 2019, 18:05:18 (UTC-3), Jim S escribió:
>>>
>>> I'm guessing it's the phone number field.  You can't use 'contains' on a 
>>> numeric field.  So, try this:
>>>
>>> if search_value and search_value != '' and search_value != 0:
>>> try:
>>> int_search_value = int(search_value)
>>> queries.append((db.Student.firstname.contains(search_value)) | 
>>>(db.Student.lastname.contains(search_value)) |
>>>(db.Student.phone == int_search_value) |
>>>(db.Nationality.descripcion.contains(search_value
>>> ))
>>>
>>> except:
>>> queries.append((db.Student.firstname.contains(search_value)) | 
>>>(db.Student.lastname.contains(search_value)) |
>>>(db.Nationality.descripcion.contains(search_value
>>> ))
>>> 
>>> query = reduce(lambda a, b: (a & b), queries)
>>> query.select(left=db.Nationality.on(db.Student.nationality == db.
>>> Nationality.id))
>>>
>>> Basically, if you can convert the search_value to an int, you want to 
>>> check the phone number against the int as well.  If you can't convert to an 
>>> int, then don't include phone number in the search.
>>>
>>> The datatables error is not very helpful.  What you want to look at is 
>>> the error that web2py is generating to confirm that it is the phone number 
>>> like I think it is.
>>>
>>> -Jim
>>>
>>> On Monday, June 17, 2019 at 3:44:27 PM UTC-5, Cristina Sig wrote:

 Hello Jim,

 I tried the code and it shows me an error

 *DataTables warning: table id=tableStudent - Ajax error. For more 
 information about this error, please see http://datatables.net/tn/7 
 *

 I think it is not recognising the numeric field or the referenced ones


 El lunes, 17 de junio de 2019, 11:30:45 (UTC-3), Jim S escribió:
>
> Cristina
>
> I'd look at adding a 'left' argument on my query.select().
>
> if search_value and search_value != '' and search_value != 0:
> queries.append((db.Student.firstname.contains(search_value)) | 
>(db.Student.lastname.contains(search_value)) |
>(db.Student.phone.contains(search_value)) |
>(db.Nationality.descripcion.contains(search_value))
>
> query = reduce(lambda a, b: (a & b), queries)
> query.select(left=db.Nationality.on(db.Student.nationality == db.
> Nationality.id))
>
> The above should give you the rows where the search text matches 
> firstname or lastname or phone or nationality description.  You may want 
> to 
> change that to 'and' instead of 'or' depending on your requirements.
>
> Make sense?
>
> -Jim
>
>
>
> On Sunday, June 16, 2019 at 8:36:09 PM UTC-5, Cristina Sig wrote:
>>
>> Hello,
>>
>> I'm a newbie on python language so I'm struggling to do some queries.
>> I have a table Student which I use to fill a table on view, above 
>> that table, I have a search box, where I would like to provide the 
>> option 
>> to search in multiple columns (phone, last name, first name, or 
>> nationality).
>> I don't know how exactly do a dynamic query in this case because I 
>> have some fields which are references from other tables.
>>
>> This is my Db
>> db.define_table('Nationality',
>> Field('descripcion', 'string'),
>>)
>>
>> db.define_table('Grade',
>> Field('level', 'string'),
>>)
>>
>> db.define_table('Student',
>> Field('lastname', 'string'),
>> Field('firstname', 'string'),
>> Field('nationality','reference Nationality'),
>> Field('phone', 'integer'),
>> Field('email', 'string'),
>> Field('gradelevel','reference Grade'),
>>)
>>
>> and this is my try so far
>> queries = [(db.Student.id > 0)]
>> if search_value and search_value != '' and search_value != 0:
>> queries.append(db.Student(search_value))  
>> query = reduce(lambda a,b:(a),queries) 
>>
>> query.select()
>>
>>

[web2py] Re: web2py dynamic queries

2019-06-17 Thread Jim S
Are you getting an error on the referenced field (Nationality) or is it 
just not returning the results you're expecting?

-Jim

On Monday, June 17, 2019 at 4:46:14 PM UTC-5, Cristina Sig wrote:
>
> thanks!
> I solved the integer field but it seems that the referenced fields are not 
> working.
> I will try to see what is the issue with them 
>
> El lunes, 17 de junio de 2019, 18:05:18 (UTC-3), Jim S escribió:
>>
>> I'm guessing it's the phone number field.  You can't use 'contains' on a 
>> numeric field.  So, try this:
>>
>> if search_value and search_value != '' and search_value != 0:
>> try:
>> int_search_value = int(search_value)
>> queries.append((db.Student.firstname.contains(search_value)) | 
>>(db.Student.lastname.contains(search_value)) |
>>(db.Student.phone == int_search_value) |
>>(db.Nationality.descripcion.contains(search_value
>> ))
>>
>> except:
>> queries.append((db.Student.firstname.contains(search_value)) | 
>>(db.Student.lastname.contains(search_value)) |
>>(db.Nationality.descripcion.contains(search_value
>> ))
>> 
>> query = reduce(lambda a, b: (a & b), queries)
>> query.select(left=db.Nationality.on(db.Student.nationality == db.
>> Nationality.id))
>>
>> Basically, if you can convert the search_value to an int, you want to 
>> check the phone number against the int as well.  If you can't convert to an 
>> int, then don't include phone number in the search.
>>
>> The datatables error is not very helpful.  What you want to look at is 
>> the error that web2py is generating to confirm that it is the phone number 
>> like I think it is.
>>
>> -Jim
>>
>> On Monday, June 17, 2019 at 3:44:27 PM UTC-5, Cristina Sig wrote:
>>>
>>> Hello Jim,
>>>
>>> I tried the code and it shows me an error
>>>
>>> *DataTables warning: table id=tableStudent - Ajax error. For more 
>>> information about this error, please see http://datatables.net/tn/7 
>>> *
>>>
>>> I think it is not recognising the numeric field or the referenced ones
>>>
>>>
>>> El lunes, 17 de junio de 2019, 11:30:45 (UTC-3), Jim S escribió:

 Cristina

 I'd look at adding a 'left' argument on my query.select().

 if search_value and search_value != '' and search_value != 0:
 queries.append((db.Student.firstname.contains(search_value)) | 
(db.Student.lastname.contains(search_value)) |
(db.Student.phone.contains(search_value)) |
(db.Nationality.descripcion.contains(search_value))

 query = reduce(lambda a, b: (a & b), queries)
 query.select(left=db.Nationality.on(db.Student.nationality == db.
 Nationality.id))

 The above should give you the rows where the search text matches 
 firstname or lastname or phone or nationality description.  You may want 
 to 
 change that to 'and' instead of 'or' depending on your requirements.

 Make sense?

 -Jim



 On Sunday, June 16, 2019 at 8:36:09 PM UTC-5, Cristina Sig wrote:
>
> Hello,
>
> I'm a newbie on python language so I'm struggling to do some queries.
> I have a table Student which I use to fill a table on view, above that 
> table, I have a search box, where I would like to provide the option to 
> search in multiple columns (phone, last name, first name, or nationality).
> I don't know how exactly do a dynamic query in this case because I 
> have some fields which are references from other tables.
>
> This is my Db
> db.define_table('Nationality',
> Field('descripcion', 'string'),
>)
>
> db.define_table('Grade',
> Field('level', 'string'),
>)
>
> db.define_table('Student',
> Field('lastname', 'string'),
> Field('firstname', 'string'),
> Field('nationality','reference Nationality'),
> Field('phone', 'integer'),
> Field('email', 'string'),
> Field('gradelevel','reference Grade'),
>)
>
> and this is my try so far
> queries = [(db.Student.id > 0)]
> if search_value and search_value != '' and search_value != 0:
> queries.append(db.Student(search_value))  
> query = reduce(lambda a,b:(a),queries) 
>
> query.select()
>
>
>
> I found a generic way to do it but still don't know how to deal with 
> references.
> Any suggestion/idea would be very appreciated :)
>
> queries=[]if arg1 == "xyz": queries.append(db.abc.id > 0)if arg2 == 
> "xyz": queries.append(db.def.id > 0)query = reduce(lambda 
> a,b:(a),queries)query.select()
>
>
>
>
>

-- 
Resources:
- 

[web2py] Re: web2py dynamic queries

2019-06-17 Thread Cristina Sig
thanks!
I solved the integer field but it seems that the referenced fields are not 
working.
I will try to see what is the issue with them 

El lunes, 17 de junio de 2019, 18:05:18 (UTC-3), Jim S escribió:
>
> I'm guessing it's the phone number field.  You can't use 'contains' on a 
> numeric field.  So, try this:
>
> if search_value and search_value != '' and search_value != 0:
> try:
> int_search_value = int(search_value)
> queries.append((db.Student.firstname.contains(search_value)) | 
>(db.Student.lastname.contains(search_value)) |
>(db.Student.phone == int_search_value) |
>(db.Nationality.descripcion.contains(search_value))
>
> except:
> queries.append((db.Student.firstname.contains(search_value)) | 
>(db.Student.lastname.contains(search_value)) |
>(db.Nationality.descripcion.contains(search_value))
> 
> query = reduce(lambda a, b: (a & b), queries)
> query.select(left=db.Nationality.on(db.Student.nationality == db.
> Nationality.id))
>
> Basically, if you can convert the search_value to an int, you want to 
> check the phone number against the int as well.  If you can't convert to an 
> int, then don't include phone number in the search.
>
> The datatables error is not very helpful.  What you want to look at is the 
> error that web2py is generating to confirm that it is the phone number like 
> I think it is.
>
> -Jim
>
> On Monday, June 17, 2019 at 3:44:27 PM UTC-5, Cristina Sig wrote:
>>
>> Hello Jim,
>>
>> I tried the code and it shows me an error
>>
>> *DataTables warning: table id=tableStudent - Ajax error. For more 
>> information about this error, please see http://datatables.net/tn/7 
>> *
>>
>> I think it is not recognising the numeric field or the referenced ones
>>
>>
>> El lunes, 17 de junio de 2019, 11:30:45 (UTC-3), Jim S escribió:
>>>
>>> Cristina
>>>
>>> I'd look at adding a 'left' argument on my query.select().
>>>
>>> if search_value and search_value != '' and search_value != 0:
>>> queries.append((db.Student.firstname.contains(search_value)) | 
>>>(db.Student.lastname.contains(search_value)) |
>>>(db.Student.phone.contains(search_value)) |
>>>(db.Nationality.descripcion.contains(search_value))
>>>
>>> query = reduce(lambda a, b: (a & b), queries)
>>> query.select(left=db.Nationality.on(db.Student.nationality == db.
>>> Nationality.id))
>>>
>>> The above should give you the rows where the search text matches 
>>> firstname or lastname or phone or nationality description.  You may want to 
>>> change that to 'and' instead of 'or' depending on your requirements.
>>>
>>> Make sense?
>>>
>>> -Jim
>>>
>>>
>>>
>>> On Sunday, June 16, 2019 at 8:36:09 PM UTC-5, Cristina Sig wrote:

 Hello,

 I'm a newbie on python language so I'm struggling to do some queries.
 I have a table Student which I use to fill a table on view, above that 
 table, I have a search box, where I would like to provide the option to 
 search in multiple columns (phone, last name, first name, or nationality).
 I don't know how exactly do a dynamic query in this case because I have 
 some fields which are references from other tables.

 This is my Db
 db.define_table('Nationality',
 Field('descripcion', 'string'),
)

 db.define_table('Grade',
 Field('level', 'string'),
)

 db.define_table('Student',
 Field('lastname', 'string'),
 Field('firstname', 'string'),
 Field('nationality','reference Nationality'),
 Field('phone', 'integer'),
 Field('email', 'string'),
 Field('gradelevel','reference Grade'),
)

 and this is my try so far
 queries = [(db.Student.id > 0)]
 if search_value and search_value != '' and search_value != 0:
 queries.append(db.Student(search_value))  
 query = reduce(lambda a,b:(a),queries) 

 query.select()



 I found a generic way to do it but still don't know how to deal with 
 references.
 Any suggestion/idea would be very appreciated :)

 queries=[]if arg1 == "xyz": queries.append(db.abc.id > 0)if arg2 == "xyz": 
 queries.append(db.def.id > 0)query = reduce(lambda 
 a,b:(a),queries)query.select()






-- 
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 

[web2py] Re: web2py dynamic queries

2019-06-17 Thread Jim S
I'm guessing it's the phone number field.  You can't use 'contains' on a 
numeric field.  So, try this:

if search_value and search_value != '' and search_value != 0:
try:
int_search_value = int(search_value)
queries.append((db.Student.firstname.contains(search_value)) | 
   (db.Student.lastname.contains(search_value)) |
   (db.Student.phone == int_search_value) |
   (db.Nationality.descripcion.contains(search_value))

except:
queries.append((db.Student.firstname.contains(search_value)) | 
   (db.Student.lastname.contains(search_value)) |
   (db.Nationality.descripcion.contains(search_value))

query = reduce(lambda a, b: (a & b), queries)
query.select(left=db.Nationality.on(db.Student.nationality == db.Nationality
.id))

Basically, if you can convert the search_value to an int, you want to check 
the phone number against the int as well.  If you can't convert to an int, 
then don't include phone number in the search.

The datatables error is not very helpful.  What you want to look at is the 
error that web2py is generating to confirm that it is the phone number like 
I think it is.

-Jim

On Monday, June 17, 2019 at 3:44:27 PM UTC-5, Cristina Sig wrote:
>
> Hello Jim,
>
> I tried the code and it shows me an error
>
> *DataTables warning: table id=tableStudent - Ajax error. For more 
> information about this error, please see http://datatables.net/tn/7 
> *
>
> I think it is not recognising the numeric field or the referenced ones
>
>
> El lunes, 17 de junio de 2019, 11:30:45 (UTC-3), Jim S escribió:
>>
>> Cristina
>>
>> I'd look at adding a 'left' argument on my query.select().
>>
>> if search_value and search_value != '' and search_value != 0:
>> queries.append((db.Student.firstname.contains(search_value)) | 
>>(db.Student.lastname.contains(search_value)) |
>>(db.Student.phone.contains(search_value)) |
>>(db.Nationality.descripcion.contains(search_value))
>>
>> query = reduce(lambda a, b: (a & b), queries)
>> query.select(left=db.Nationality.on(db.Student.nationality == db.
>> Nationality.id))
>>
>> The above should give you the rows where the search text matches 
>> firstname or lastname or phone or nationality description.  You may want to 
>> change that to 'and' instead of 'or' depending on your requirements.
>>
>> Make sense?
>>
>> -Jim
>>
>>
>>
>> On Sunday, June 16, 2019 at 8:36:09 PM UTC-5, Cristina Sig wrote:
>>>
>>> Hello,
>>>
>>> I'm a newbie on python language so I'm struggling to do some queries.
>>> I have a table Student which I use to fill a table on view, above that 
>>> table, I have a search box, where I would like to provide the option to 
>>> search in multiple columns (phone, last name, first name, or nationality).
>>> I don't know how exactly do a dynamic query in this case because I have 
>>> some fields which are references from other tables.
>>>
>>> This is my Db
>>> db.define_table('Nationality',
>>> Field('descripcion', 'string'),
>>>)
>>>
>>> db.define_table('Grade',
>>> Field('level', 'string'),
>>>)
>>>
>>> db.define_table('Student',
>>> Field('lastname', 'string'),
>>> Field('firstname', 'string'),
>>> Field('nationality','reference Nationality'),
>>> Field('phone', 'integer'),
>>> Field('email', 'string'),
>>> Field('gradelevel','reference Grade'),
>>>)
>>>
>>> and this is my try so far
>>> queries = [(db.Student.id > 0)]
>>> if search_value and search_value != '' and search_value != 0:
>>> queries.append(db.Student(search_value))  
>>> query = reduce(lambda a,b:(a),queries) 
>>>
>>> query.select()
>>>
>>>
>>>
>>> I found a generic way to do it but still don't know how to deal with 
>>> references.
>>> Any suggestion/idea would be very appreciated :)
>>>
>>> queries=[]if arg1 == "xyz": queries.append(db.abc.id > 0)if arg2 == "xyz": 
>>> queries.append(db.def.id > 0)query = reduce(lambda 
>>> a,b:(a),queries)query.select()
>>>
>>>
>>>
>>>
>>>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/c03ab8ff-cad1-479e-ba22-2404ac55a0c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: web2py dynamic queries

2019-06-17 Thread Cristina Sig
Hello Jim,

I tried the code and it shows me an error

*DataTables warning: table id=tableStudent - Ajax error. For more 
information about this error, please see http://datatables.net/tn/7*

I think it is not recognising the numeric field or the referenced ones


El lunes, 17 de junio de 2019, 11:30:45 (UTC-3), Jim S escribió:
>
> Cristina
>
> I'd look at adding a 'left' argument on my query.select().
>
> if search_value and search_value != '' and search_value != 0:
> queries.append((db.Student.firstname.contains(search_value)) | 
>(db.Student.lastname.contains(search_value)) |
>(db.Student.phone.contains(search_value)) |
>(db.Nationality.descripcion.contains(search_value))
>
> query = reduce(lambda a, b: (a & b), queries)
> query.select(left=db.Nationality.on(db.Student.nationality == db.
> Nationality.id))
>
> The above should give you the rows where the search text matches firstname 
> or lastname or phone or nationality description.  You may want to change 
> that to 'and' instead of 'or' depending on your requirements.
>
> Make sense?
>
> -Jim
>
>
>
> On Sunday, June 16, 2019 at 8:36:09 PM UTC-5, Cristina Sig wrote:
>>
>> Hello,
>>
>> I'm a newbie on python language so I'm struggling to do some queries.
>> I have a table Student which I use to fill a table on view, above that 
>> table, I have a search box, where I would like to provide the option to 
>> search in multiple columns (phone, last name, first name, or nationality).
>> I don't know how exactly do a dynamic query in this case because I have 
>> some fields which are references from other tables.
>>
>> This is my Db
>> db.define_table('Nationality',
>> Field('descripcion', 'string'),
>>)
>>
>> db.define_table('Grade',
>> Field('level', 'string'),
>>)
>>
>> db.define_table('Student',
>> Field('lastname', 'string'),
>> Field('firstname', 'string'),
>> Field('nationality','reference Nationality'),
>> Field('phone', 'integer'),
>> Field('email', 'string'),
>> Field('gradelevel','reference Grade'),
>>)
>>
>> and this is my try so far
>> queries = [(db.Student.id > 0)]
>> if search_value and search_value != '' and search_value != 0:
>> queries.append(db.Student(search_value))  
>> query = reduce(lambda a,b:(a),queries) 
>>
>> query.select()
>>
>>
>>
>> I found a generic way to do it but still don't know how to deal with 
>> references.
>> Any suggestion/idea would be very appreciated :)
>>
>> queries=[]if arg1 == "xyz": queries.append(db.abc.id > 0)if arg2 == "xyz": 
>> queries.append(db.def.id > 0)query = reduce(lambda 
>> a,b:(a),queries)query.select()
>>
>>
>>
>>
>>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/8a5444bd-3b22-4e14-959b-263a841e143d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] intercepting login & logout events

2019-06-17 Thread Vlad
thank you ! 

On Monday, June 17, 2019 at 11:02:13 AM UTC-4, Yoel Benitez Fonseca wrote:
>
> Vlad, in the book:
>
>
> http://www.web2py.com/books/default/chapter/29/04/the-core#HTTP-and-redirect
>
> And i can comment out +/- the code:
>
> def user():
>
> # just a way to ensure form allways have a value
> form = CAT()
> 
> try:
>
> # the call to auth can return a lot of things
>
> # it can be a form (a login form for example or a registration form)
>
> # it can raise a redirect - for exple if the login is correct
>
> # it can be the login form with erros if the password is incorrect
>
> # etc
> form = auth()
> except HTTP as e:
> if e.status == 303'login' in request.args:
> if ('login' in request.args) and auth.user:
> # probably a success, the user has logged in
> do_your_loging_event_here() 
>
> # ensuere u do the redirect, for example a raise shoul do it
> elif 'logout' if request.args:
> do_your_logout_event_here()
> 
> # give the form to the view, can be register form, login form, etc
> return dict(form=form)
>
>
>
> El lun., 17 jun. 2019 a las 10:31, Vlad ( >) escribió:
>
>> Yoel, where could I look up how this works about the exception 303? 
>> Because I don't understand that part at all - I am not aware of exception 
>> being raised, why, and how it works in the flow - could you please point me 
>> to the direction where it's explained? 
>>
>> On Monday, June 17, 2019 at 10:16:58 AM UTC-4, Yoel Benitez Fonseca wrote:
>>>
>>> no, it is not.
>>>
>>> The first time the default/user is called - in the login process for 
>>> example - there not a HTTP(303) (redirect) exception, and the user get the 
>>> form.
>>> The second time, in this scenery, the call to auth() will cause a 
>>> redirect (HTTP exception) and the user is effectively logged into the 
>>> system.
>>>
>>> The same goes for the logout, but there is not a form in the middle.
>>>
>>> El lun., 17 jun. 2019 a las 9:57, Vlad () escribió:
>>>
 but isn't such a scenario catching a user in a process of logging in or 
 logging out, but before actual login/logout?

 On Monday, June 17, 2019 at 9:44:10 AM UTC-4, Yoel Benitez Fonseca 
 wrote:
>
> I think you can do it in the default/user function. Having in account 
> that the call to auth() probably raises a HTTP exceptiong in case of a 
> success. This example is only a proof of concept:
>
> def user():
> form = CAT()
> 
> try:
> form = auth()
> except HTTP as e:
> if e.status == 303'login' in request.args:
> if ('login' in request.args) and auth.user:
> # probably a success, u can test if auth.user is o not 
> None
> do_your_loging_event_here() 
> elif 'logout' if request.args:
> do_your_logout_event_here()
> 
> return dict(form=form)
>
>
>
> El lun., 17 jun. 2019 a las 9:19, Vlad () 
> escribió:
>
>> What would be the simplest way to intercept login and logout? 
>> (i.e. I'd like to perform some additional tasks when a user is logged 
>> in, and when a user is logged out.)
>> web2py elegantly hides the functionality in default.user under 
>> form=auth() and {{=form}} and somehow I can't think of a simple way to 
>> be 
>> notified about successful login and logout actions... 
>>
>> -- 
>> 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 web...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/web2py/b9dbb7bb-4500-48b2-82fd-cd8ea644f1fe%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> -- 
> Msc. Yoel Benítez Fonseca
>
>
>
>
>
>
> -- 
 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 web...@googlegroups.com.
 To 

Re: [web2py] intercepting login & logout events

2019-06-17 Thread Yoel Benitez Fonseca
Vlad, in the book:

http://www.web2py.com/books/default/chapter/29/04/the-core#HTTP-and-redirect

And i can comment out +/- the code:

def user():

# just a way to ensure form allways have a value
form = CAT()

try:

# the call to auth can return a lot of things

# it can be a form (a login form for example or a registration form)

# it can raise a redirect - for exple if the login is correct

# it can be the login form with erros if the password is incorrect

# etc
form = auth()
except HTTP as e:
if e.status == 303'login' in request.args:
if ('login' in request.args) and auth.user:
# probably a success, the user has logged in
do_your_loging_event_here()

# ensuere u do the redirect, for example a raise shoul do it
elif 'logout' if request.args:
do_your_logout_event_here()

# give the form to the view, can be register form, login form, etc
return dict(form=form)



El lun., 17 jun. 2019 a las 10:31, Vlad () escribió:

> Yoel, where could I look up how this works about the exception 303?
> Because I don't understand that part at all - I am not aware of exception
> being raised, why, and how it works in the flow - could you please point me
> to the direction where it's explained?
>
> On Monday, June 17, 2019 at 10:16:58 AM UTC-4, Yoel Benitez Fonseca wrote:
>>
>> no, it is not.
>>
>> The first time the default/user is called - in the login process for
>> example - there not a HTTP(303) (redirect) exception, and the user get the
>> form.
>> The second time, in this scenery, the call to auth() will cause a
>> redirect (HTTP exception) and the user is effectively logged into the
>> system.
>>
>> The same goes for the logout, but there is not a form in the middle.
>>
>> El lun., 17 jun. 2019 a las 9:57, Vlad () escribió:
>>
>>> but isn't such a scenario catching a user in a process of logging in or
>>> logging out, but before actual login/logout?
>>>
>>> On Monday, June 17, 2019 at 9:44:10 AM UTC-4, Yoel Benitez Fonseca wrote:

 I think you can do it in the default/user function. Having in account
 that the call to auth() probably raises a HTTP exceptiong in case of a
 success. This example is only a proof of concept:

 def user():
 form = CAT()

 try:
 form = auth()
 except HTTP as e:
 if e.status == 303'login' in request.args:
 if ('login' in request.args) and auth.user:
 # probably a success, u can test if auth.user is o not None
 do_your_loging_event_here()
 elif 'logout' if request.args:
 do_your_logout_event_here()

 return dict(form=form)



 El lun., 17 jun. 2019 a las 9:19, Vlad ()
 escribió:

> What would be the simplest way to intercept login and logout?
> (i.e. I'd like to perform some additional tasks when a user is logged
> in, and when a user is logged out.)
> web2py elegantly hides the functionality in default.user under
> form=auth() and {{=form}} and somehow I can't think of a simple way to be
> notified about successful login and logout actions...
>
> --
> 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 web...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/web2py/b9dbb7bb-4500-48b2-82fd-cd8ea644f1fe%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


 --
 Msc. Yoel Benítez Fonseca






 --
>>> 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 web...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/web2py/ee8abe78-346c-44dd-b8a6-e9b243e4eb90%40googlegroups.com
>>> 
>>> .
>>> For more options, visit 

Re: [web2py] intercepting login & logout events

2019-06-17 Thread Vlad
Yoel, where could I look up how this works about the exception 303? Because 
I don't understand that part at all - I am not aware of exception being 
raised, why, and how it works in the flow - could you please point me to 
the direction where it's explained? 

On Monday, June 17, 2019 at 10:16:58 AM UTC-4, Yoel Benitez Fonseca wrote:
>
> no, it is not.
>
> The first time the default/user is called - in the login process for 
> example - there not a HTTP(303) (redirect) exception, and the user get the 
> form.
> The second time, in this scenery, the call to auth() will cause a redirect 
> (HTTP exception) and the user is effectively logged into the system.
>
> The same goes for the logout, but there is not a form in the middle.
>
> El lun., 17 jun. 2019 a las 9:57, Vlad (>) 
> escribió:
>
>> but isn't such a scenario catching a user in a process of logging in or 
>> logging out, but before actual login/logout?
>>
>> On Monday, June 17, 2019 at 9:44:10 AM UTC-4, Yoel Benitez Fonseca wrote:
>>>
>>> I think you can do it in the default/user function. Having in account 
>>> that the call to auth() probably raises a HTTP exceptiong in case of a 
>>> success. This example is only a proof of concept:
>>>
>>> def user():
>>> form = CAT()
>>> 
>>> try:
>>> form = auth()
>>> except HTTP as e:
>>> if e.status == 303'login' in request.args:
>>> if ('login' in request.args) and auth.user:
>>> # probably a success, u can test if auth.user is o not None
>>> do_your_loging_event_here() 
>>> elif 'logout' if request.args:
>>> do_your_logout_event_here()
>>> 
>>> return dict(form=form)
>>>
>>>
>>>
>>> El lun., 17 jun. 2019 a las 9:19, Vlad () escribió:
>>>
 What would be the simplest way to intercept login and logout? 
 (i.e. I'd like to perform some additional tasks when a user is logged 
 in, and when a user is logged out.)
 web2py elegantly hides the functionality in default.user under 
 form=auth() and {{=form}} and somehow I can't think of a simple way to be 
 notified about successful login and logout actions... 

 -- 
 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 web...@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/web2py/b9dbb7bb-4500-48b2-82fd-cd8ea644f1fe%40googlegroups.com
  
 
 .
 For more options, visit https://groups.google.com/d/optout.

>>>
>>>
>>> -- 
>>> Msc. Yoel Benítez Fonseca
>>>
>>>
>>>
>>>
>>>
>>>
>>> -- 
>> 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 web...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/web2py/ee8abe78-346c-44dd-b8a6-e9b243e4eb90%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> -- 
> Msc. Yoel Benítez Fonseca
>
>
>
>
>
>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/237c7ee1-72d9-4f3b-a3f5-f09fd34459ad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: web2py dynamic queries

2019-06-17 Thread Jim S
Cristina

I'd look at adding a 'left' argument on my query.select().

if search_value and search_value != '' and search_value != 0:
queries.append((db.Student.firstname.contains(search_value)) | 
   (db.Student.lastname.contains(search_value)) |
   (db.Student.phone.contains(search_value)) |
   (db.Nationality.descripcion.contains(search_value))

query = reduce(lambda a, b: (a & b), queries)
query.select(left=db.Nationality.on(db.Student.nationality == db.Nationality
.id))

The above should give you the rows where the search text matches firstname 
or lastname or phone or nationality description.  You may want to change 
that to 'and' instead of 'or' depending on your requirements.

Make sense?

-Jim



On Sunday, June 16, 2019 at 8:36:09 PM UTC-5, Cristina Sig wrote:
>
> Hello,
>
> I'm a newbie on python language so I'm struggling to do some queries.
> I have a table Student which I use to fill a table on view, above that 
> table, I have a search box, where I would like to provide the option to 
> search in multiple columns (phone, last name, first name, or nationality).
> I don't know how exactly do a dynamic query in this case because I have 
> some fields which are references from other tables.
>
> This is my Db
> db.define_table('Nationality',
> Field('descripcion', 'string'),
>)
>
> db.define_table('Grade',
> Field('level', 'string'),
>)
>
> db.define_table('Student',
> Field('lastname', 'string'),
> Field('firstname', 'string'),
> Field('nationality','reference Nationality'),
> Field('phone', 'integer'),
> Field('email', 'string'),
> Field('gradelevel','reference Grade'),
>)
>
> and this is my try so far
> queries = [(db.Student.id > 0)]
> if search_value and search_value != '' and search_value != 0:
> queries.append(db.Student(search_value))  
> query = reduce(lambda a,b:(a),queries) 
>
> query.select()
>
>
>
> I found a generic way to do it but still don't know how to deal with 
> references.
> Any suggestion/idea would be very appreciated :)
>
> queries=[]if arg1 == "xyz": queries.append(db.abc.id > 0)if arg2 == "xyz": 
> queries.append(db.def.id > 0)query = reduce(lambda 
> a,b:(a),queries)query.select()
>
>
>
>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/df34641b-50b8-425d-b845-59b77c9c7710%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] intercepting login & logout events

2019-06-17 Thread Yoel Benitez Fonseca
no, it is not.

The first time the default/user is called - in the login process for
example - there not a HTTP(303) (redirect) exception, and the user get the
form.
The second time, in this scenery, the call to auth() will cause a redirect
(HTTP exception) and the user is effectively logged into the system.

The same goes for the logout, but there is not a form in the middle.

El lun., 17 jun. 2019 a las 9:57, Vlad () escribió:

> but isn't such a scenario catching a user in a process of logging in or
> logging out, but before actual login/logout?
>
> On Monday, June 17, 2019 at 9:44:10 AM UTC-4, Yoel Benitez Fonseca wrote:
>>
>> I think you can do it in the default/user function. Having in account
>> that the call to auth() probably raises a HTTP exceptiong in case of a
>> success. This example is only a proof of concept:
>>
>> def user():
>> form = CAT()
>>
>> try:
>> form = auth()
>> except HTTP as e:
>> if e.status == 303'login' in request.args:
>> if ('login' in request.args) and auth.user:
>> # probably a success, u can test if auth.user is o not None
>> do_your_loging_event_here()
>> elif 'logout' if request.args:
>> do_your_logout_event_here()
>>
>> return dict(form=form)
>>
>>
>>
>> El lun., 17 jun. 2019 a las 9:19, Vlad () escribió:
>>
>>> What would be the simplest way to intercept login and logout?
>>> (i.e. I'd like to perform some additional tasks when a user is logged
>>> in, and when a user is logged out.)
>>> web2py elegantly hides the functionality in default.user under
>>> form=auth() and {{=form}} and somehow I can't think of a simple way to be
>>> notified about successful login and logout actions...
>>>
>>> --
>>> 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 web...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/web2py/b9dbb7bb-4500-48b2-82fd-cd8ea644f1fe%40googlegroups.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>> --
>> Msc. Yoel Benítez Fonseca
>>
>>
>>
>>
>>
>>
>> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/web2py/ee8abe78-346c-44dd-b8a6-e9b243e4eb90%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Msc. Yoel Benítez Fonseca

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/CAFDb1rUYzrXURyuVquS1n3Mgk%2B4T-2aVd%3DkV9c4cTveOigAh_A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] intercepting login & logout events

2019-06-17 Thread Vlad
but isn't such a scenario catching a user in a process of logging in or 
logging out, but before actual login/logout?

On Monday, June 17, 2019 at 9:44:10 AM UTC-4, Yoel Benitez Fonseca wrote:
>
> I think you can do it in the default/user function. Having in account that 
> the call to auth() probably raises a HTTP exceptiong in case of a success. 
> This example is only a proof of concept:
>
> def user():
> form = CAT()
> 
> try:
> form = auth()
> except HTTP as e:
> if e.status == 303'login' in request.args:
> if ('login' in request.args) and auth.user:
> # probably a success, u can test if auth.user is o not None
> do_your_loging_event_here() 
> elif 'logout' if request.args:
> do_your_logout_event_here()
> 
> return dict(form=form)
>
>
>
> El lun., 17 jun. 2019 a las 9:19, Vlad (>) 
> escribió:
>
>> What would be the simplest way to intercept login and logout? 
>> (i.e. I'd like to perform some additional tasks when a user is logged in, 
>> and when a user is logged out.)
>> web2py elegantly hides the functionality in default.user under 
>> form=auth() and {{=form}} and somehow I can't think of a simple way to be 
>> notified about successful login and logout actions... 
>>
>> -- 
>> 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 web...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/web2py/b9dbb7bb-4500-48b2-82fd-cd8ea644f1fe%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> -- 
> Msc. Yoel Benítez Fonseca
>
>
>
>
>
>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/ee8abe78-346c-44dd-b8a6-e9b243e4eb90%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] intercepting login & logout events

2019-06-17 Thread Yoel Benitez Fonseca
Got a syntax error there, sorry:

El lunes, 17 de junio de 2019, 9:44:10 (UTC-4), Yoel Benitez Fonseca 
escribió:
>
> I think you can do it in the default/user function. Having in account that 
> the call to auth() probably raises a HTTP exceptiong in case of a success. 
> This example is only a proof of concept:
>
> def user():
> form = CAT()
> 
> try:
> form = auth()
> except HTTP as e:
> if e.status == 303:
> if ('login' in request.args) and auth.user:
> # probably a success, u can test if auth.user is o not None
> do_your_loging_event_here() 
> elif 'logout' if request.args:
> do_your_logout_event_here()
> 
> return dict(form=form)
>
>
>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/a9e81732-268c-43d4-b860-390f016d4de5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] intercepting login & logout events

2019-06-17 Thread Yoel Benitez Fonseca
I think you can do it in the default/user function. Having in account that
the call to auth() probably raises a HTTP exceptiong in case of a success.
This example is only a proof of concept:

def user():
form = CAT()

try:
form = auth()
except HTTP as e:
if e.status == 303'login' in request.args:
if ('login' in request.args) and auth.user:
# probably a success, u can test if auth.user is o not None
do_your_loging_event_here()
elif 'logout' if request.args:
do_your_logout_event_here()

return dict(form=form)



El lun., 17 jun. 2019 a las 9:19, Vlad () escribió:

> What would be the simplest way to intercept login and logout?
> (i.e. I'd like to perform some additional tasks when a user is logged in,
> and when a user is logged out.)
> web2py elegantly hides the functionality in default.user under form=auth()
> and {{=form}} and somehow I can't think of a simple way to be notified
> about successful login and logout actions...
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/web2py/b9dbb7bb-4500-48b2-82fd-cd8ea644f1fe%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Msc. Yoel Benítez Fonseca

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/CAFDb1rWHRtiJE3x0Puedo8tP5Wjhz59e-%2BJ7%3D4UH1sXT7V0WiQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] intercepting login & logout events

2019-06-17 Thread Vlad
What would be the simplest way to intercept login and logout? 
(i.e. I'd like to perform some additional tasks when a user is logged in, 
and when a user is logged out.)
web2py elegantly hides the functionality in default.user under form=auth() 
and {{=form}} and somehow I can't think of a simple way to be notified 
about successful login and logout actions... 

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/b9dbb7bb-4500-48b2-82fd-cd8ea644f1fe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: How to create wrapper / decorator functions

2019-06-17 Thread Gilad Hoshmand
This is the answer:
Call /controller/wrapper_func1/arg1/arg2

def wrapper_func1():
get args...
response.view  =  "path/to/main_page.html"
return generalFunc(..args..)

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/f4bf1e10-0f4c-47a6-b7b8-c9b70a512f85%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] How to create wrapper / decorator functions

2019-06-17 Thread Gilad Hoshmand
Hi
I'm trying to create wrapper/decorator functions like so:

The view to load is the same html file every time, the args need to be 
different. 
I can pass arguments using request.args[0] etc. but it seems dirty and I 
prefer to separate and handle pre-processing the data (according to args) 
in the wrapping functions & then call the generalFunc.

def func1():
var1 = ... 
var2 = ... 
return genralFunc(var1 , var2 )

def func2():
var1 = ... 
var2 = ...
var3 = ... 
return genralFunc(var1 , var2 , var3)

def generalFunc(a , b , c):
...dostuff...
return (dict( .. all page data .))

user calls controller/func1 => main_page.html
user calls controller/func2 => main_page.html

Each time with different data

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/c137f204-c84b-4658-9d67-e622f7564477%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Generating graph with chartjs

2019-06-17 Thread Christian Varas
Sorry the delay, the second chart is a radar chart

Cheers.
Chris.

El mar., 11 de jun. de 2019 18:25, Dave S  escribió:

>
>
> On Sunday, June 9, 2019 at 3:06:01 PM UTC-7, Christian Varas wrote:
>>
>> II have this site www.climbersoul.cl using AdminLTE, and I with graphics
>> too.
>> https://imgur.com/HQTI1u7
>> [image: image.png]
>>
>>
>> you need to include the libraries first:
>>
>> https://www.chartjs.org/samples/latest/utils.js";>
>> https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js
>> ">
>>
>> This is the code for the bar chart, for other chart is similar, you just
>> need to set the values in the array (are marked)
>>
>>>
>>>
> Nice!   What type of chart is the 2nd one, some sort of polar display?
>
> /dps
>
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/web2py/1b1bc784-149a-4886-9bc2-e4182ca58d8e%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/CA%2Bs%2BuJurhgUz3TNrTDGHHwASkJox4fPpN%2BqJbG9sEGSqeej3RA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Generating graph with chartjs

2019-06-17 Thread António Ramos
I guess that having vue as a default frontend we shoud try to use vue
charts

Em sáb, 15 de jun de 2019 às 18:53, Massimo Di Pierro <
massimo.dipie...@gmail.com> escreveu:

> mind highcharts is not free
>
> On Tuesday, 11 June 2019 09:33:37 UTC-7, Lovedie JC wrote:
>>
>> I'm following this discussion. Does the chart have a print to image(jpg,
>> png, svg) or pdf?
>> Hicharts does a nice job.
>> Regards
>>
>> On Tue, 11 Jun 2019, 19:25 Dave S  wrote:
>>
>>>
>>>
>>> On Sunday, June 9, 2019 at 3:06:01 PM UTC-7, Christian Varas wrote:

 II have this site www.climbersoul.cl using AdminLTE, and I with
 graphics too.
 https://imgur.com/HQTI1u7
 [image: image.png]


 you need to include the libraries first:

 https://www.chartjs.org/samples/latest/utils.js";>
 https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js
 ">

 This is the code for the bar chart, for other chart is similar, you
 just need to set the values in the array (are marked)

>
>
>>> Nice!   What type of chart is the 2nd one, some sort of polar display?
>>>
>>> /dps
>>>
>>>
>>> --
>>> 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+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/web2py/1b1bc784-149a-4886-9bc2-e4182ca58d8e%40googlegroups.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/web2py/92223ec4-fd55-4e7a-a244-e4580df84d91%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/CAEM0BxP8prhW48sDrU-Ak2%2BO2QiVz4F7KRTV3gcPmKjR_BnB0g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


RE: [web2py] web2py dynamic queries

2019-06-17 Thread John Bannister
Hi Cristina,

 

Can you show us your view code as well?

 

Assuming you are trying to use datatables instead of web2py Grid or Smartgrid 
(which gives you ability to build dynamic queries), you will probably need to 
loop through all the fields in the table (server side) and build your query 
based on the value entered in the serach box.

 

Referenced fields will generally be displayed as the id of the referencing 
field depending on how you pass the information back to your view (i.e rendered 
or not) so you will only be able to search on the value in the view.

 

Alternatively you can look at the individual field.type (which will tell you 
the type of field you are dealing with) and treat each field type accordingly.

 

Hope this helps

John

 

 

From: web2py@googlegroups.com [mailto:web2py@googlegroups.com] On Behalf Of 
Cristina Sig
Sent: 17 June 2019 03:36
To: web2py-users
Subject: [web2py] web2py dynamic queries

 

Hello,

 

I'm a newbie on python language so I'm struggling to do some queries.

I have a table Student which I use to fill a table on view, above that table, I 
have a search box, where I would like to provide the option to search in 
multiple columns (phone, last name, first name, or nationality).

I don't know how exactly do a dynamic query in this case because I have some 
fields which are references from other tables.

 

This is my Db

db.define_table('Nationality',
Field('descripcion', 'string'),
   )

db.define_table('Grade',
Field('level', 'string'),
   )

db.define_table('Student',
Field('lastname', 'string'),
Field('firstname', 'string'),
Field('nationality','reference Nationality'),
Field('phone', 'integer'),
Field('email', 'string'),
Field('gradelevel','reference Grade'),
   )

 

and this is my try so far

queries = [(db.Student.id > 0)]
if search_value and search_value != '' and search_value != 0:
queries.append(db.Student(search_value))  
query = reduce(lambda a,b:(a),queries) 

query.select()

 

 

I found a generic way to do it but still don't know how to deal with references.
Any suggestion/idea would be very appreciated :)

 

queries=[]
if arg1 == "xyz": queries.append(db.abc.id > 0)
if arg2 == "xyz": queries.append(db.def.id > 0)
query = reduce(lambda a,b:(a),queries)
query.select()

 

 

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/54dc8ca8-bebe-4604-8e4e-a89c254ed944%40googlegroups.com
 

 .
For more options, visit https://groups.google.com/d/optout.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/050901d524e4%24075852f0%241608f8d0%24%40gmail.com.
For more options, visit https://groups.google.com/d/optout.