[web2py] Re: Use length of list:reference field in query

2017-04-17 Thread Sharjeel Ali Shaukat
Its help me alot Thanks

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Use length of list:reference field in query

2017-04-17 Thread Mujeeb Farees
Thank you for answering, this worked for me. I want to avoid loops after 
query, so I used *users_gt_2* approach.

On Monday, April 17, 2017 at 7:10:38 PM UTC+5, Anthony wrote:
>
> list:-type fields are stored as strings with items being delimited by the 
> "|" character, so you can do a query that counts the number of pipe 
> characters (minus 1, because the string starts with a "|" character), and 
> select records with a count greater than two. The functions to use may vary 
> depending on the RDBMS, but in SQLite, it would be:
>
> users_gt_2 = "(length(users) - length(replace(users, '|', '')) - 1) > 2"
> rows = db((db.company.id > 0) & users_gt_2).select()
>
> The trick in the users_gt_2 query is to get the length of the "users" 
> field, and then subtract the length after replacing the "|" characters with 
> empty strings (the difference therefore being the number of "|" characters 
> in the original string).
>
> The other alternative would be to select all the records and then use 
> Python to do the filtering (you can use rows.find() for that -- 
> http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#find--exclude--sort
> ).
>
> Anthony
>
> On Monday, April 17, 2017 at 5:26:33 AM UTC-4, Mujeeb Farees wrote:
>>
>> I know the auth_user table should have a company field for the case 
>> below. But this is just a sample data, the actual data is different.
>>
>> *Company Table*
>> |  *id*  |  *name*  |  *users*  |
>> |  1   |  Com1  |  |1|2| |
>> |  2   |  Com2  |  |3|4|5|  |
>>
>> The users field is of list:reference type that refers to auth_user table.
>> I need to write a query that will return the names of all companies that 
>> have more than 2 users. Your help will be appreciated.
>> Thanks! 
>>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Password Recovery Not Sending (lazyT object being passed to GAE?)

2017-04-17 Thread webmaster
Please mark this as "Best Answer".  It uses web2py's internal password 
reset mechanism.  Just gave it a fairly thorough testing.  I really 
appreciate the people who gave help in this thread and a couple others 
about resetting passwords.  This should mostly suffice until we get a real 
solution (though I make no strong statement about security).

*views/default/reset_password.html*

{{=form}}

*default.py [Include this somewhere under def user()]*

if request.args[0] == 'request_reset_password':
redirect(URL('default','reset_password'))

*default.py*

def reset_password():
# EXP: Import UUID module from gluon.
from gluon.utils import web2py_uuid



# EXP: Define variables.
# NOTE: No idea how long this is... and any shorter number breaks it, I 
think...
max_time = 1000



# EXP: Create a form that will return "E-mail Address Unknown" if the email 
can't be found.
form = SQLFORM.factory(
Field('email', requires = [IS_EMAIL(error_message='Email Address Unknown'),
IS_IN_DB(db, 'auth_user.email', error_message='Email Address Unknown')]))

# EXP: If the email address is valid, process a password reset email.
if form.process().accepted:

# EXP: Find the user whose email matches the request.
user = db(db.auth_user.email == form.vars.email).select().first()


# EXP: Generate a one-time key to allow password reset. Web2py's uuid 
method allows duplication across instances.
reset_password_key = str(int(max_time)) + '-' + web2py_uuid()

# TODO: Find a way to encrypt the key before uploading it to DB that works 
with web2py's internal password reset system.
user.update_record(reset_password_key = reset_password_key)

# EXP: Send an email with a password reset link to the entered email 
address.
message = ' Retrieve your password for Trytha.com Please 
use the link below to reset your password.  Reset Password If you did not 
initiate this password reset, please ignore this email. '

mail.send(to = [user.email],
subject = 'Reset your password at Trytha.com',
message = message)

session.flash = 'Email sent'


# # TODO: Forward to login page with forward_page variable.
redirect(URL('default','index'))


elif form.errors:
response.flash = 'Wrong E-mail Address'


return dict(form=form)




On Friday, April 14, 2017 at 12:13:10 AM UTC-7, Jacinto Parga wrote:
>
> Yes it is easy to change anyone password, but you still have to access to 
> his/hers email to set the final password. Anyway it is not the right 
> solution. There was no problem with 2.13 versions.
>
>  
>
> El viernes, 14 de abril de 2017, 0:55:50 (UTC+2), webm...@trytha.com 
> escribió:
>>
>> Can we not get a real solution to this?  I was gonna try the posted hack, 
>> but it can be too easily abused (it changes the user's password instead of 
>> using a password_reset token, so anyone could change your password just by 
>> knowing your email address).
>>
>> On Friday, April 7, 2017 at 7:28:48 PM UTC-7, webm...@trytha.com wrote:
>>>
>>> Thanks for bringing this issue back up and posting a workaround.  
>>>
>>> The worst part is the way to fix this is probably about as easy as 
>>> wrapping something in "str()", just need to know how the web2py internals 
>>> all link together.
>>>
>>> On Thursday, April 6, 2017 at 4:51:17 AM UTC-7, Karoly Kantor wrote:

 Thanks, this helped, i am now using my own function to send the 
 password reset email.

 On Friday, March 31, 2017 at 2:51:03 PM UTC+2, Jacinto Parga wrote:
>
> Yes, still unresolved.
>
> I did a workaround for the request_reset_password: 
>
> def user(): 
> if request.args(0)=='request_reset_password':
> redirect(URL('default','myrequestpass'))
> return dict(form=auth())
>
> def myrequestpass():
> form = SQLFORM.factory(
> Field('u_email', requires =[IS_EMAIL(error_message='Wrong 
> email'), IS_IN_DB(db, 'auth_user.email', error_message='Address not in 
> DB')]),
>   table_name='solicitar_pass')
> if form.process().accepted:
> user = 
> db(db.auth_user.email==form.vars.u_email).select().first()
> session.flash = 'Comprueba tu correo '+str(user.first_name)
> u_passwd = str(hex(int(time.time([2:]
> 
> user.update_record(password=CRYPT()(u_passwd.encode('utf8'))[0])
> mensaje=' Retrieve your password Temporal 
> password :  '+ u_passwd   +'   Login with the 
> temporal 
> password and set your new password in this link :https://yoursite.com/user/login?_next=/user/change_password;>Change 
> Password''
> mail.send(to=[form.vars.u_email],
> subject='Change your password, follow this link',
> message=mensaje)
> redirect(URL('default','index'))
> elif form.errors:
> response.flash = 'Wrong Email address'
> return dict(form=form)
>
>
> But anyway the lazyT found is an annoying error width, for instance: 

[web2py] Using validate_and_insert with a computed field

2017-04-17 Thread Chris
Hello,

I've got a users table with a computed field:

db.define_table(
auth.settings.table_user_name,
[...]
Field('calculated_field', requires=IS_NOT_EMPTY(),
  compute=lambda(r): calculate_field(r)),

And a bit of code that uses validate_and_insert() to insert a row:

dct_new_user = {...}

new_user = db.auth_user.validate_and_insert(**dct_new_user)

This code always fails, returning 


Is this a bug? If not, what should I do to get around it?

Thanks!

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: table already exists; 'Rows' object has no attribute 'fields'

2017-04-17 Thread Dave S


On Monday, April 17, 2017 at 3:58:38 PM UTC-7, pbreit wrote:
>
> Sqlite. These are fresh installs with just a table defined and no other 
> edits.
>
> I've noticed that I can get it to work if I quickcreate the new app, call 
> it up in a browser so the initial tables get created, add my own models and 
> the call it up again.
>

What did you name your model files?

/dps
 

>
>
> On Monday, April 17, 2017 at 1:29:09 PM UTC-7, Dave S wrote:
>>
>> On Sunday, April 16, 2017 at 12:31:04 AM UTC-7, pbreit wrote:
>>>
>>> I'm a long time web2py user running into some problems I haven't seen 
>>> before and cannot resolve.
>>>
>>> First, I am getting this error a lot even when I create a brand new 
>>> project from scratch:
>>>
>>> OperationalError: table "auth_user" already exists
>>>
>>>
>>> Another error I am getting consistently is:
>>>
>>> AttributeError: 'Rows' object has no attribute 'fields'
>>>
>>>
>>
>> What database?  What does your connection string look like?
>>  
>>
>>> All I am doing is going to /appadmin and trying to view a simple table:
>>>
>>> http://127.0.0.1:8000/payouts/appadmin/select/db?query=db.contact.id>0
>>>
>>>
>>> db.define_table('contact',
>>> Field('user_id', 'reference auth_user', default=auth.user_id),
>>> Field('name'),
>>> Field('address'),
>>> Field('city'),
>>> Field('province'),
>>> Field('zip'),
>>> Field('country'),
>>> Field('status', default='new'),
>>> Field('tax_id'),
>>> Field('phone'),
>>> Field('entity'),
>>> Field('business_type'),
>>> Field('bank_name'),
>>> Field('bank_id'),
>>> Field('bank_account_id'),
>>> Field('bank_currency'),
>>> auth.signature)
>>>
>>>
>>>
>>
>> /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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: table already exists; 'Rows' object has no attribute 'fields'

2017-04-17 Thread pbreit
Sqlite. These are fresh installs with just a table defined and no other 
edits.

I've noticed that I can get it to work if I quickcreate the new app, call 
it up in a browser so the initial tables get created, add my own models and 
the call it up again.


On Monday, April 17, 2017 at 1:29:09 PM UTC-7, Dave S wrote:
>
> On Sunday, April 16, 2017 at 12:31:04 AM UTC-7, pbreit wrote:
>>
>> I'm a long time web2py user running into some problems I haven't seen 
>> before and cannot resolve.
>>
>> First, I am getting this error a lot even when I create a brand new 
>> project from scratch:
>>
>> OperationalError: table "auth_user" already exists
>>
>>
>> Another error I am getting consistently is:
>>
>> AttributeError: 'Rows' object has no attribute 'fields'
>>
>>
>
> What database?  What does your connection string look like?
>  
>
>> All I am doing is going to /appadmin and trying to view a simple table:
>>
>> http://127.0.0.1:8000/payouts/appadmin/select/db?query=db.contact.id>0
>>
>>
>> db.define_table('contact',
>> Field('user_id', 'reference auth_user', default=auth.user_id),
>> Field('name'),
>> Field('address'),
>> Field('city'),
>> Field('province'),
>> Field('zip'),
>> Field('country'),
>> Field('status', default='new'),
>> Field('tax_id'),
>> Field('phone'),
>> Field('entity'),
>> Field('business_type'),
>> Field('bank_name'),
>> Field('bank_id'),
>> Field('bank_account_id'),
>> Field('bank_currency'),
>> auth.signature)
>>
>>
>>
>
> /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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: use case: user login on android

2017-04-17 Thread Dave S


On Monday, April 17, 2017 at 1:20:20 PM UTC-7, Oasis Agano wrote:
>
> No extra modifications inside the web2py controller? I want to 
> authenticate users available in a web2py application through an android app
>
>
I don't know of anything particularly unusual, but I haven't done android 
apps since JellyBean.  There's a package that seems to be popular around 
here to run Javascript in a framework on the phone, but the normal 
server-side tools should be fine.  Maybe returning JSON.  Web2py supports 
that out of the box, and also supports REST apis, and as mentioned in the 
other thread has support for JWT.  The web2py auth mechanisms are fairly 
flexible.

/dps

 

> On Monday, April 17, 2017 at 10:07:24 PM UTC+2, Dave S wrote:
>>
>>
>>
>> On Monday, April 17, 2017 at 4:08:29 AM UTC-7, Oasis Agano wrote:
>>>
>>> Can Someone write a slice on how to connect an android app to a web2py 
>>> server, using java and py
>>>
>>
>>
>> Android end just has to do GET and POST, innit?
>>
>> /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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Returning a token for Android app authentication

2017-04-17 Thread Dave S


On Monday, April 17, 2017 at 1:16:49 PM UTC-7, Oasis Agano wrote:
>
> You mean that it doesnt require modifying core Web2py code? or adding 
> other codes inside your controller? because what i want is actually logging 
> in and storing a token returned by w2p.
>
>
It is already part of web2py core, in all 2.14.x versions (and maybe some 
2.13.y versions).
I haven't actually used it, but the doc comment in tools.py seems to be a 
very good explanation.
(I've done some other reading on JWT -- Niphlod posted the link to the RFC, 
for instance -- and
know of its use for helping to secure OAuth2.)

I think a couple of other users have posted here that they used  it now 
that it's built-in.

/dps

 

> On Monday, April 17, 2017 at 10:05:53 PM UTC+2, Dave S wrote:
>>
>>
>>
>> On Monday, April 17, 2017 at 4:18:48 AM UTC-7, Oasis Agano wrote:
>>>
>>> Hello,
>>> Can someone create a web2pyslice explaining how to do it and what to 
>>> change in web2py gluon in order to connect an android native app to it.
>>> 4 years later people(e.g: me, my colleagues...) are still facing the 
>>> same issue and i think it can be helpful to the community.
>>>
>>
>> Have you looked at using JWT?  Documentation is mainly gluon/tools.py, 
>> although Niphlod wrote here a little about its use when he coded it a 
>> couple of years ago.
>>
>> /dps
>>
>>  
>>
>>> On Wednesday, October 15, 2014 at 3:48:02 AM UTC+2, Mark Li wrote:

 Hey Mark,

 I did finish this, although it's been some time since I've looked into 
 the code for the mobile-related stuff. Most of it still makes sense to me

 On Friday, October 10, 2014 1:31:09 PM UTC-7, Mark Graves wrote:
>
> Did you ever finish this?
>
> I implemented something similar.
>
> I'd love to collaborate and get a repo up for working with mobile 
> devices with web2py as an app back end.
>
> On Sunday, January 6, 2013 11:43:05 AM UTC-6, dlypka wrote:
>>
>> If you mimic the same http traffic that a browser would generate, 
>> then of course you will get all the normal web2py functionality such as 
>> the 
>> session.
>>
>> The web2py session is usually stored in the database which means it 
>> can store a large amount of data without the size limits of cookie 
>> storage. 
>> And it will persist between requests.
>>
>> [...]
>>
>  
>>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: table already exists; 'Rows' object has no attribute 'fields'

2017-04-17 Thread Dave S
On Sunday, April 16, 2017 at 12:31:04 AM UTC-7, pbreit wrote:
>
> I'm a long time web2py user running into some problems I haven't seen 
> before and cannot resolve.
>
> First, I am getting this error a lot even when I create a brand new 
> project from scratch:
>
> OperationalError: table "auth_user" already exists
>
>
> Another error I am getting consistently is:
>
> AttributeError: 'Rows' object has no attribute 'fields'
>
>

What database?  What does your connection string look like?
 

> All I am doing is going to /appadmin and trying to view a simple table:
>
> http://127.0.0.1:8000/payouts/appadmin/select/db?query=db.contact.id>0
>
>
> db.define_table('contact',
> Field('user_id', 'reference auth_user', default=auth.user_id),
> Field('name'),
> Field('address'),
> Field('city'),
> Field('province'),
> Field('zip'),
> Field('country'),
> Field('status', default='new'),
> Field('tax_id'),
> Field('phone'),
> Field('entity'),
> Field('business_type'),
> Field('bank_name'),
> Field('bank_id'),
> Field('bank_account_id'),
> Field('bank_currency'),
> auth.signature)
>
>
>

/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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: CKEditor CDN

2017-04-17 Thread Dave S


On Sunday, April 16, 2017 at 7:19:53 PM UTC-7, Alex Glaros wrote:
>
> "basic" works to fix sanitation problem
>
> https://cdn.ckeditor.com/4.6.2/basic/ckeditor.js";>
>

Glad you got it working.

/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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Select filled with years

2017-04-17 Thread Dave S


On Sunday, April 16, 2017 at 9:11:37 PM UTC-7, Winter Kryz wrote:
>
> Thanks, but how can I do the loop thing. I'm new on web2py so I don't know 
> how to do that.
>
> Can you explain me please?
>
>

I have a models/mymodel.py that has something like:

db.define_table('mytable',
   Field('issueYr','integer', requires=IS_IN_RANGE(1965, 
2017)),
   otherfields,etc)



and in a controller, I do
  
  form=SQLFORM('mytable', etc)



That should do it, although I usually enter a date by hand, and then use 
browser suggestions.



El domingo, 16 de abril de 2017, 21:09:55 (UTC-3), 黄祥 escribió:
>>
>> you can use requires = IS_IN_SET() validators for that :
>> ref:
>>
>> http://web2py.com/books/default/chapter/29/07/forms-and-validators#Range--set-and-equality-validators
>>
>> perhaps you can use for loop for that, so that you dont define the years 
>> by yourself
>>
>> best regards,
>> stifan
>>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: use case: user login on android

2017-04-17 Thread Oasis Agano
No extra modifications inside the web2py controller? I want to authenticate 
users available in a web2py application through an android app

On Monday, April 17, 2017 at 10:07:24 PM UTC+2, Dave S wrote:
>
>
>
> On Monday, April 17, 2017 at 4:08:29 AM UTC-7, Oasis Agano wrote:
>>
>> Can Someone write a slice on how to connect an android app to a web2py 
>> server, using java and py
>>
>
>
> Android end just has to do GET and POST, innit?
>
> /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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Returning a token for Android app authentication

2017-04-17 Thread Oasis Agano
You mean that it doesnt require modifying core Web2py code? or adding other 
codes inside your controller? because what i want is actually logging in 
and storing a token returned by w2p.

On Monday, April 17, 2017 at 10:05:53 PM UTC+2, Dave S wrote:
>
>
>
> On Monday, April 17, 2017 at 4:18:48 AM UTC-7, Oasis Agano wrote:
>>
>> Hello,
>> Can someone create a web2pyslice explaining how to do it and what to 
>> change in web2py gluon in order to connect an android native app to it.
>> 4 years later people(e.g: me, my colleagues...) are still facing the same 
>> issue and i think it can be helpful to the community.
>>
>
> Have you looked at using JWT?  Documentation is mainly gluon/tools.py, 
> although Niphlod wrote here a little about its use when he coded it a 
> couple of years ago.
>
> /dps
>
>  
>
>> On Wednesday, October 15, 2014 at 3:48:02 AM UTC+2, Mark Li wrote:
>>>
>>> Hey Mark,
>>>
>>> I did finish this, although it's been some time since I've looked into 
>>> the code for the mobile-related stuff. Most of it still makes sense to me
>>>
>>> On Friday, October 10, 2014 1:31:09 PM UTC-7, Mark Graves wrote:

 Did you ever finish this?

 I implemented something similar.

 I'd love to collaborate and get a repo up for working with mobile 
 devices with web2py as an app back end.

 On Sunday, January 6, 2013 11:43:05 AM UTC-6, dlypka wrote:
>
> If you mimic the same http traffic that a browser would generate, then 
> of course you will get all the normal web2py functionality such as the 
> session.
>
> The web2py session is usually stored in the database which means it 
> can store a large amount of data without the size limits of cookie 
> storage. 
> And it will persist between requests.
>
> [...]
>
  
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: use case: user login on android

2017-04-17 Thread Dave S


On Monday, April 17, 2017 at 4:08:29 AM UTC-7, Oasis Agano wrote:
>
> Can Someone write a slice on how to connect an android app to a web2py 
> server, using java and py
>


Android end just has to do GET and POST, innit?

/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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Returning a token for Android app authentication

2017-04-17 Thread Dave S


On Monday, April 17, 2017 at 4:18:48 AM UTC-7, Oasis Agano wrote:
>
> Hello,
> Can someone create a web2pyslice explaining how to do it and what to 
> change in web2py gluon in order to connect an android native app to it.
> 4 years later people(e.g: me, my colleagues...) are still facing the same 
> issue and i think it can be helpful to the community.
>

Have you looked at using JWT?  Documentation is mainly gluon/tools.py, 
although Niphlod wrote here a little about its use when he coded it a 
couple of years ago.

/dps

 

> On Wednesday, October 15, 2014 at 3:48:02 AM UTC+2, Mark Li wrote:
>>
>> Hey Mark,
>>
>> I did finish this, although it's been some time since I've looked into 
>> the code for the mobile-related stuff. Most of it still makes sense to me
>>
>> On Friday, October 10, 2014 1:31:09 PM UTC-7, Mark Graves wrote:
>>>
>>> Did you ever finish this?
>>>
>>> I implemented something similar.
>>>
>>> I'd love to collaborate and get a repo up for working with mobile 
>>> devices with web2py as an app back end.
>>>
>>> On Sunday, January 6, 2013 11:43:05 AM UTC-6, dlypka wrote:

 If you mimic the same http traffic that a browser would generate, then 
 of course you will get all the normal web2py functionality such as the 
 session.

 The web2py session is usually stored in the database which means it can 
 store a large amount of data without the size limits of cookie storage. 
 And 
 it will persist between requests.

 [...]

>>>  

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Highlighting the fields that user can't leave blank

2017-04-17 Thread Dave S


On Monday, April 17, 2017 at 11:02:46 AM UTC-7, Marcelo Huerta wrote:
>
> El miércoles, 12 de abril de 2017, 9:51:25 (UTC-3), Anthony escribió:
>>
>> First, don't use Crud, as it has been deprecated. Just use SQLFORM.
>>
>
> I guess the book should reflect this, then.
> It still says «One of the recent additions to web2py is the 
> Create/Read/Update/Delete (CRUD) API on top of SQLFORM...»
>
> This confuses people into believing this is the modern and preferred way 
> to do CRUD operations...
>

A pull request recently got that change into master (so if you pull web2py, 
check the book source in applications/examples).  It doesn't seem to have 
reached the online copy at web2py.com, quite yet.

/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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Highlighting the fields that user can't leave blank

2017-04-17 Thread Marcelo Huerta
El miércoles, 12 de abril de 2017, 9:51:25 (UTC-3), Anthony escribió:
>
> First, don't use Crud, as it has been deprecated. Just use SQLFORM.
>

I guess the book should reflect this, then.
It still says «One of the recent additions to web2py is the 
Create/Read/Update/Delete (CRUD) API on top of SQLFORM...»

This confuses people into believing this is the modern and preferred way to 
do CRUD operations...

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Could I use SQLFORM.factory to update 2 tables in a single form

2017-04-17 Thread Rudy
Hi there,

I am building an accounting system. When I create a quotation, if the item 
is in 'subscription' category, i want to use SQLFORM.factory(db.item, 
db.subscription_item) to generate a create form for submitting the 
necessary values. Now i want to edit these 2 tables(item and 
subscription_item have 1-1 relationship), does SQLFORM.factory() takes any 
constraint or query to specify which item I want to edit?  If not, what's 
the best way to do it? Thanks in advance!

Below is the simplified database tables:
db.define_table('company',
Field('company_name', requires=IS_NOT_EMPTY()), # 
unique=True
format='%(company_name)s')

db.define_table('quotation',
Field('company', 'reference company'),
Field('project_name', requires=IS_NOT_EMPTY()),
Field('quote_amount', 'double', default=0, writable=False),
auth.signature)

db.define_table('category',
Field('category_name', ondelete='NO ACTION'), # eg. project 
or subscription
format='%(category_name)s')

db.define_table('item',
Field('quotation', 'reference quotation',  writable=False, 
label='Quote Id'),
Field('category', 'reference category', 
requires=IS_IN_DB(db, 'category.id', '%(category_name)s')),
Field('description'),
Field('amount', 'double', default=0),
auth.signature)

db.define_table('subscription_item',
Field('item', 'reference item',  writable=False, 
label='Item Id'),
Field('start_date', 'date'),
Field('end_date', 'date'),
auth.signature)

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[web2py] best way to disable "Save Password" alert in browser

2017-04-17 Thread lucas
hello one and all,

related to this other post:

https://groups.google.com/forum/#!topic/web2py/FFKTOAzz59E

which I was able to get working cross-browser great.  

however, I am trying to also massage the html/javascript of the page to 
disable the "Save Password" alert/notice in the browser.  the only way I 
seem to get it to work is by changing the type of the input field from 
password to text for the password input field.  this disables the alert, 
but then I have to massage the validation of the password, which works if 
the user types in a new password, but revalidates it to a wrong password if 
the user doesn't type in a new password.

any ideas on how to either keep the password input to type="password" and 
still disable the alert, or how to process the input with type="text" in 
either javascript or onvalidation of the form.process?

thanx in advance, lucas

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Use length of list:reference field in query

2017-04-17 Thread Anthony
list:-type fields are stored as strings with items being delimited by the 
"|" character, so you can do a query that counts the number of pipe 
characters (minus 1, because the string starts with a "|" character), and 
select records with a count greater than two. The functions to use may vary 
depending on the RDBMS, but in SQLite, it would be:

users_gt_2 = "(length(users) - length(replace(users, '|', '')) - 1) > 2"
rows = db((db.company.id > 0) & users_gt_2).select()

The trick in the users_gt_2 query is to get the length of the "users" 
field, and then subtract the length after replacing the "|" characters with 
empty strings (the difference therefore being the number of "|" characters 
in the original string).

The other alternative would be to select all the records and then use 
Python to do the filtering (you can use rows.find() for that -- 
http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#find--exclude--sort).

Anthony

On Monday, April 17, 2017 at 5:26:33 AM UTC-4, Mujeeb Farees wrote:
>
> I know the auth_user table should have a company field for the case below. 
> But this is just a sample data, the actual data is different.
>
> *Company Table*
> |  *id*  |  *name*  |  *users*  |
> |  1   |  Com1  |  |1|2| |
> |  2   |  Com2  |  |3|4|5|  |
>
> The users field is of list:reference type that refers to auth_user table.
> I need to write a query that will return the names of all companies that 
> have more than 2 users. Your help will be appreciated.
> Thanks! 
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Should I modify response.headers in order to get nginx's uwsgi_cache work properly?

2017-04-17 Thread Lisandro
I've been dealing with this problem for some time now.
Some weeks ago I posted a question in stackoverflow, but I didn't find a 
solution yet:
http://stackoverflow.com/questions/43052276/nginx-why-isnt-uwsgi-cache-working-with-this-headers

Also I've been working with a sysop who knows better than me, but still 
couldn't solve the problem. 

I don't think web2py has anything to do with it, so I'll mark this thread 
as "no action required".
Still, any comment or suggestion will be appreciated.

Best regards,
Lisandro

El viernes, 24 de marzo de 2017, 10:00:06 (UTC-3), Lisandro escribió:
>
> I'm running a web2py website with public articles, and there are ocasional 
> peaks in traffic. 
> I use Nginx as a webserver, and uWsgi to run my web2py application.
>
> Considering the articles are public (the HTML page of an article is the 
> same for every visitor), I'm already doing some caching in order to improve 
> performance (I'm using @cache.action decorator with Redis model).
> However, and please correct me if I'm wrong, for every request made to the 
> URL of an article, before the caching can be done, the models need to be 
> executed.
> So I thought I could improve performance even more, caching the HTML 
> directly from Nginx, that way I would save resources in my server.
>
> However I'm having a hard time getting it, and I wanted to know if I 
> should modify the response.headers.
> I've read that they come set by default:
> http://web2py.com/books/default/chapter/29/04/the-core#response
>
> To do some tests, I have this simple web2py function:
>
> def test():
> from datetime import datetime
>
> return datetime.now().strftime('%H:%M:%S')
>
>
>
> In the ngin'x side, the server block configuration is this:
>
> uwsgi_cache_path /tmp/nginx_cache/ levels=1:2 keys_zone=mycache:10m 
> max_size=10g inactive=10m use_temp_path=off;
>
> server {
> ...
>
> location / {
> # response header to check if cache is a HIT or a MISS
> add_header  X-uWSGI-Cache $upstream_cache_status;
>
> # server cache
> uwsgi_cache  mycache;
> uwsgi_cache_valid  15m;
> uwsgi_cache_key  $request_uri;
>
> # client cache
> expires 3m;
>
> uwsgi_pass  unix:///tmp/web2py.socket;
> include uwsgi_params;
> uwsgi_param UWSGI_SCHEME $scheme;
> }
> }
>
>
> But every time I hit the test page, I check the response headers and I see 
> always a MISS.
> In other words, nginx still sends the requests to uwsgi, and the page is 
> generated in every request.
> I've found this forum post where someone says this:
>
> *"...it looks to me like the issue is that the upstream server is just not 
> sending response that contain an expiration date (Expires:) or a cache 
> validator (for instance, Last-Modified:). (The cookie expiration time has 
> nothing to do with caching.)*
> *The HTTP 1.1 spec 
>  says: 'If 
> there is neither a cache validator nor an explicit expiration time 
> associated with a response, we do not expect it to be cached, but certain 
> caches MAY violate this expectation (for example, when little or no network 
> connectivity is available).'"*
>
>
> So I thought I would still needed to use the @cache.action decorator (with 
> model=None in order to only set response headers to allow client caching):
>
> @cache.action(time_expire=222, cache_model=None, session=False, vars=False
> , public=True)
> def test():
> from datetime import datetime
>
> return datetime.now().strftime('%H:%M:%S')
>
>
> However I sill can't get it to work.
> I set up time_expire=222 to check if the directive "expires 3m;" in 
> nginx's configuration would overwrite it, and yes it does, the responses 
> have a Cache-Control: max-age=180 (that is 3 minutes, not 222 seconds).
>
> *I don't intend to talk about nginx's configuration variables, but I'm 
> tempted to ask: am I missing something on the web2py's side?* 
> Do I need to modify response.headers in another way to let nginx cache the 
> response from uwsgi?
>
>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Returning a token for Android app authentication

2017-04-17 Thread Oasis Agano
Hello,
Can someone create a web2pyslice explaining how to do it and what to change 
in web2py gluon in order to connect an android native app to it.
4 years later people(e.g: me, my colleagues...) are still facing the same 
issue and i think it can be helpful to the community.

kr,
Oasis

On Wednesday, October 15, 2014 at 3:48:02 AM UTC+2, Mark Li wrote:
>
> Hey Mark,
>
> I did finish this, although it's been some time since I've looked into the 
> code for the mobile-related stuff. Most of it still makes sense to me
>
> On Friday, October 10, 2014 1:31:09 PM UTC-7, Mark Graves wrote:
>>
>> Did you ever finish this?
>>
>> I implemented something similar.
>>
>> I'd love to collaborate and get a repo up for working with mobile devices 
>> with web2py as an app back end.
>>
>> On Sunday, January 6, 2013 11:43:05 AM UTC-6, dlypka wrote:
>>>
>>> If you mimic the same http traffic that a browser would generate, then 
>>> of course you will get all the normal web2py functionality such as the 
>>> session.
>>>
>>> The web2py session is usually stored in the database which means it can 
>>> store a large amount of data without the size limits of cookie storage. And 
>>> it will persist between requests.
>>>
>>> On Friday, January 4, 2013 6:19:14 PM UTC-6, Mark Li wrote:

 Would it be necessary to connect to the same web2py session?

 To my understanding, connecting to the same session would be necessary 
 if the session contained Auth information indicating whether or not a user 
 was logged in. However, using auth.login_bare(), I only return a token on 
 login success, and the Auth information is never stored in session. Only 
 the token would be used to check whether or not a user was authenticated, 
 as this info is not stored in session.

 The login/authentication from Android would only be used for API calls, 
 and not for browsing the site. In the 'tokens' table, there would be 
 information about the user that would be similar to the Auth info stored 
 in 
 session. When the token is passed to web2py, it would return the same 
 information that would normally be stored in session about the user.

 Thanks again for your help and checking my logic, I'm still pretty new 
 to this!

 On Thursday, January 3, 2013 7:57:45 PM UTC-8, dlypka wrote:
>
> But are you reconnecting to the same web2py session on each request?
>
> On Thursday, January 3, 2013 3:20:01 PM UTC-6, Mark Li wrote:
>>
>> I reviewed your code again and looked into the source code for web2py 
>> to see how web2py deals with session login cookies.
>>
>> For what I want to accomplish, I believe I have found a method which 
>> does not involved changing web2py source code. It's simpler and more 
>> straight forward for me to wrap my head around (also not having to worry 
>> about storing cookies in the app). Please let me know if there's 
>> anything 
>> important I am missing or security flaws that I should consider.
>>
>>
>> 1. Embed webview into native Android app, using auth.login_bare to 
>> authenticate.
>> 2. On login success, return a token of similar format to web2py's 
>> session cookies.
>> 3. Store this token in the database (in a table named 'tokens'), and 
>> send back to Android app as a cookie
>> 4. For every request to my web service that requires authentication, 
>> send the token as a cookie and have the receiving API controller 
>> function 
>> extract the cookie/token. If the token is currently in the db.tokens, 
>> then 
>> the user has been authenticated and the request returns the appropriate 
>> data.
>> 5. On logout/password change, delete the issued tokens for this user 
>> from db.tokens, so the same token can't be used to authenticate for 
>> future 
>> api calls.
>>
>> On Tuesday, January 1, 2013 10:33:26 PM UTC-8, dlypka wrote:
>>>
>>> I was not precisely calling from a native Android or native IOS app.
>>> I was using a PhoneGap client, which is different. It is looks like 
>>> a web browser but is not a browser client.
>>> PhoneGap can only use HTML5 storage unless you write a native 
>>> Android / IOS PhoneGap extension/plugin.
>>> So my technique will work from almost any client platform, even from 
>>> a Windows native client app for example
>>> as long as it uses HTTP.
>>>
>>> Also, in my tracing of how web2py handles the client connection, I 
>>> believe I found a few wrinkles in the sequence of events
>>> which needed to be handled specially in this case where the client 
>>> is not a web browser.
>>>
>>> In your particular case, if you have cookies in the native client, 
>>> then that is one less problem to solve,
>>> You probably just have to mimic the HTTP messages that a browser 
>>> would send.
>>>
>>> On 

[web2py] Re: use case: user login on android

2017-04-17 Thread Oasis Agano
Can Someone write a slice on how to connect an android app to a web2py 
server, using java and py

On Wednesday, December 9, 2015 at 12:47:19 PM UTC+2, noam cohen wrote:
>
>
> 
>
> Hi
> I need help implementing this scenario:
>
> user opens the android app. 
> app checks if he is currently logged in. 
> if not, open the login web page ( in a webview - as seen in the screenshot)
> from here, new users can register.
> user enter credentials.
> login result (pass/fail) is used by the app logic to decide how to 
> continue. 
> The user SHOULD not have to see web pages outside the application (i.e. 
> opening the browser)
> Once the user is logged in, he updates the web2py server with the 
> equivalent of c -> s :  foo(user_id, data1,data2)
>
>
>1. how can I check if user is currently logged in? I saw the session 
>cookie but not sure how to infer from it the status. Also, a user could 
>have logged in long time ago, have the cookie but the session will expire. 
>I guess something like this is needed in controllers/hello.py: ( i.e. 
> start 
>by sending GET http://mysite/my_app/hello/logged
>@auth.requires_login()
>def logged(): return dict(message="hello logged user")
>2. I guess I don't really need the user_id field in the client side. 
>What is the proper way to get actions associated with this user? in other 
>words, each user has database updates relevant only for him.
>
>
>
> This is similar to 
> https://groups.google.com/forum/?fromgroups#!searchin/web2py/login/web2py/22hXvhMF-ws/gEb62ZJMabEJ
>  but 
> not exactly.
>
> Once I have it working, I will upload the java class to the web2py splices.
>
> thanks!
> Noam
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Use length of list:reference field in query

2017-04-17 Thread Mujeeb Farees
I know the auth_user table should have a company field for the case below. 
But this is just a sample data, the actual data is different.

*Company Table*
|  *id*  |  *name*  |  *users*  |
|  1   |  Com1  |  |1|2| |
|  2   |  Com2  |  |3|4|5|  |

The users field is of list:reference type that refers to auth_user table.
I need to write a query that will return the names of all companies that 
have more than 2 users. Your help will be appreciated.
Thanks! 

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: pdf output of web2py-book app

2017-04-17 Thread Al Ex
Yes, I saw them.

At the end I am trying to get along with convert_book.py (which is in
web2py_book/private).

Thank you



From: Marlysson Silva  
Reply: web2py@googlegroups.com 

Date: April 10, 2017 at 22:57:04
To: web2py-users  
Subject:  [web2py] Re: pdf output of web2py-book app

Here have some files to do that

https://github.com/web2py/web2py/tree/master/gluon/contrib/markmin

Do you tried use them ?

Em sábado, 8 de abril de 2017 11:49:11 UTC-3, alex escreveu:
>
> I have downloaded and used the book app https://github.com/web2py/
> web2py-book to write some documentation.
>
> The document's markmins and images are in the folder /sources/xx-doc-lang,
> together with updated chapters.txt, info.txt and latex_template.tex
> mimicking the original web2py documentations folders.
>
> Now, which command should I use to create the pdf version of this
> documentation, including content and indexes?
>
> --
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.
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.
For more options, visit https://groups.google.com/d/optout.