Re: [web2py] Re: Unable to update database entry after compute=lambda r: calculation of some field values in the DB

2018-10-26 Thread mostwanted
Hey SP, i dont think the problem was the code itself, there must have been 
something wrong with the version of web2py i had implemented my application 
on because when i switched to version 2.17.2 that problem disappeard, so i 
just assumed the problem was with the previous version of web2py i was 
using.

Regards

Mostwanted

On Friday, October 26, 2018 at 7:20:22 AM UTC+2, sandeep patel wrote:
>
> I think there is a problem in field type in Days because the default is a 
> string so days have a string value, you are multiplying string with an 
> integer in the computed field.
>
> # 1
> db.define_table('ClientDetails', 
> Field('CheckIn', 'date', label=SPAN('Check-In Date',
>  _style="font-weight: bold;")),
> Field('CheckOut', 'date', label=SPAN('Check-Out Date',
>  _style="font-weight: bold;")),
> Field('Days', compute=lambda r: (r['CheckOut']-r['CheckIn'
> ]).days),
> Field('Amount', compute=lambda r: int(r['Days'])*int(r[
> 'Number_of_Guests'])*650))  
>
> # 2
> db.define_table('ClientDetails', 
> Field('CheckIn', 'date', label=SPAN('Check-In Date',
>  _style="font-weight: bold;")),
> Field('CheckOut', 'date', label=SPAN('Check-Out Date',
>  _style="font-weight: bold;")),
> Field('Days', compute=lambda r: (r['CheckOut']-r['CheckIn'
> ]).days),
> Field('Amount', compute=lambda r: ((r['CheckOut']-r[
> 'CheckIn']).days)*int(r['Number_of_Guests'])*650))  
>
> Let me know this will work for you.
>
> Thanks
> SP
>
> On Fri, Oct 26, 2018 at 10:27 AM mostwanted  > wrote:
>
>> With this one there was no error traceback, the form just failed to 
>> submit showed a message that read *Error in form, please check it out *and 
>> i do have a field Number_of_Guests i just didnt include it coz i thought i 
>> was minimizing the whole code to show what could the root cause of the 
>> problem. When i remove the *Days *and* Amount *fields I am able to 
>> update the form but when put them back it gives an error!
>>
>> On Friday, October 26, 2018 at 12:13:55 AM UTC+2, 黄祥 wrote:
>>>
>>> pls show the error traceback, it's hard to know what the root cause.
>>> just a quick analyze (guess), perhaps it's no Number_of_Guests field in 
>>> your table definition, so it can't be calculated
>>>
>>> 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+un...@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.


[web2py] Re: Issue between 2.14.5 and 2.17.2

2018-10-26 Thread Anthony
Nothing changed. It has always been necessary to explicitly import any external 
libraries. The web2py environment only includes some of the core API objects.

Anthony

-- 
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: No module named states

2018-10-26 Thread Lovedie JC
That is python 2.7, web2py 2.17.2

On Sat, 27 Oct 2018, 00:36 Lovedie JC  wrote:

> Latest of both.
>
> On Fri, 26 Oct 2018, 23:31 Dave S  wrote:
>
>>
>>
>> On Friday, October 26, 2018 at 6:05:03 AM UTC-7, lbjc...@gmail.com wrote:
>>>
>>> I have a module with this: from gluon.contrib.states import *
>>>
>>> Getting the above error.
>>>
>>> Regards
>>>
>>
>> Which version of web2py and of python?
>>
>> /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.
>>
>

-- 
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: No module named states

2018-10-26 Thread Lovedie JC
Latest of both.

On Fri, 26 Oct 2018, 23:31 Dave S  wrote:

>
>
> On Friday, October 26, 2018 at 6:05:03 AM UTC-7, lbjc...@gmail.com wrote:
>>
>> I have a module with this: from gluon.contrib.states import *
>>
>> Getting the above error.
>>
>> Regards
>>
>
> Which version of web2py and of python?
>
> /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.
>

-- 
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: UPDATE with limit

2018-10-26 Thread Dave S


On Friday, October 26, 2018 at 11:28:48 AM UTC-7, Artem wrote:
>
> Dear All , 
> 1. How to make DAL query with update only one/first record :
> 'UPDATE itft SET task_status = "S", w_id="w_id" WHERE task_status = "N" 
> LIMIT 1;'
> When i try something like:
> db(db['itft']['task_status']=="N").update(task_status = "S",w_id= "w_id",
> limitby=(0,1))
> all rows with task_status == N get updated 
> 2. Is anyway to return updated row ID ? or how to update and select 
> updated in one query ? 
>
>  
Maybe try

You are using a curious query string; I don't know if that is part of the 
problem or not, but perhaps the more conventional style will help.  And the 
update() method automatically returns the ROWS object that was updated, 
doesn't it?  Ooops, no, it returns a count.

Maybe it's better to use update_record():
row = db(db.itfttask_status =="N").select().first()
row.update_record(task_status = "S",w_id= "w_id")

Good luck!

/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: No module named states

2018-10-26 Thread Dave S


On Friday, October 26, 2018 at 6:05:03 AM UTC-7, lbjc...@gmail.com wrote:
>
> I have a module with this: from gluon.contrib.states import *
>
> Getting the above error.
>
> Regards
>

Which version of web2py and of python?

/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] UPDATE with limit

2018-10-26 Thread Artem
Dear All , 
1. How to make DAL query with update only one/first record :
'UPDATE itft SET task_status = "S", w_id="w_id" WHERE task_status = "N" 
LIMIT 1;'
When i try something like:
db(db['itft']['task_status']=="N").update(task_status = "S",w_id= "w_id",
limitby=(0,1))
all rows with task_status == N get updated 
2. Is anyway to return updated row ID ? or how to update and select updated 
in one query ? 


-- 
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: Issue between 2.14.5 and 2.17.2

2018-10-26 Thread 'Annet' via web2py-users
Thank you both for your replies.

Are you on the same filesystem/OS? Is it possible your OS sort order is now 
> different, so "_" sorts after the digits instead of before? Try changing 
> 0_imports.py to 00_imports.py.
>

I tried, but it did not solve the issue.

Like Carlos said I had add the import os statement to my own model file. 
This was not the case in web2py version 2.14.5 (I checked all my model 
files), so I guess something must have changed between 2.14.5 and 2.17.2.

Best,

Annet

-- 
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] Auth issues when using ldap

2018-10-26 Thread lbjc1978
I am trying out the ldap authentication from an app but encountered this 
error:

 File "/home/mau/web2py/gluon/globals.py", line 421, in 
 self._caller = lambda f: f()
 File "/home/mau/web2py/applications/schoop/controllers/default.py" 
, 
line 43, in user
 if con_parameters[0] != request.vars["host"] or request.vars["username"] != 
'admin':
TypeError: 'Auth' object does not support indexing

Here is the code:

if "host" in request.vars:
session.server=request.vars["host"]
session.username=request.vars["username"]
session.password=request.vars["password"]
con_parameters=auth.settings.login_methods[0]#.__defaults__)


"""session.secureAuth = "off"
if request.vars["secureAuth"]=="on":
session.secureAuth= request.vars["secureAuth"]"""


if con_parameters[0] != request.vars["host"] or request.vars[
"username"] != 'admin':
new_parameters=list(con_parameters)
new_parameters[0]=request.vars["host"]



-- 
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] No module named states

2018-10-26 Thread lbjc1978
I have a module with this: from gluon.contrib.states import *

Getting the above error.

Regards

-- 
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: Auth question

2018-10-26 Thread Jim Steil
Can you show the entire db.py, default py and index.html?

Jim


On Fri, Oct 26, 2018, 1:44 AM Rahul  wrote:

> Nope - doesnt help. I commented out all the user functions defined in the
> controller and
>
>
> #  User functions ---
> '''def login(): return dict(form=auth.login())
> def register(): return dict(form=auth.register())
> def retrieve_password(): return dict(form=auth.reset_password())
> def logout(): return dict(form=auth.logout())
> def profile(): return dict(form=auth.profile())
> '''
>
> I even decorated index - It does take me to the login screen but from
> there nothing happens. It just wont log me in like it did before. Also,  I
> have two users in database but none work now.  Again, register seems to
> fail (It did work earlier) but now it doesnt. See screenshot of both
> screens. Looks like I must be really doing something weird. If this wont
> work by this Sunday. I may go back to my old style of coding and do it all
> by myself. I've seriously lost 10 days reading and experimenting with Auth
> to make it work . Not too much coded.
>
> @auth.requires_login()
> def index():
> response.flash = T("Hello User")
> #redirect(URL(r=request, c='default/user', f='login')) # Redirects
> user to login page
> return dict(message=T('Welcome to web2py!'))
>
>
>
> Thanks,
>
> Rahul
>
>
>
> On Thursday, October 25, 2018 at 6:02:45 PM UTC+5:30, Jim S wrote:
>>
>> Having the default user() functions is all you need.  I'd try commenting
>> out your 'user' functions.
>>
>> -Jim
>>
>> On Wednesday, October 24, 2018 at 10:59:45 PM UTC-5, Rahul wrote:
>>>
>>> Yes this is in default.py. Please excuse me for my bad code as I am
>>> still experimenting with Auth and not totally familiar with the
>>> implementation. Is this the right way that I am doing it? or only having
>>> user() function is enough ?
>>>
>>> Thanks, Rahul
>>>
>>> On Wednesday, October 24, 2018 at 9:45:21 PM UTC+5:30, Jim S wrote:

 I'm confused.  Is this code in your controller somewhere?

 #  User functions ---
 def login(): return dict(form=auth.login())
 def register(): return dict(form=auth.register())
 def retrieve_password(): return dict(form=auth.reset_password())
 def logout(): return dict(form=auth.logout())
 def profile(): return dict(form=auth.profile())

 You shouldn't need it.  To override the default login stuff I've just
 modified the one in default.py.

 -Jim



 On Tuesday, October 23, 2018 at 11:26:45 PM UTC-5, Rahul wrote:
>
> The user function remains as-is - No modifications done.
>
> def user():
> """
> exposes:
> http:///[app]/default/user/login
> http:///[app]/default/user/logout
> http:///[app]/default/user/register
> http:///[app]/default/user/profile
> http:///[app]/default/user/retrieve_password
> http:///[app]/default/user/change_password
> http:///[app]/default/user/bulk_register
> use @auth.requires_login()
> @auth.requires_membership('group name')
> @auth.requires_permission('read','table name',record_id)
> to decorate functions that need access control
> also notice there is http:///[app]/appadmin/manage/auth to
> allow administrator to manage users
> """
> return dict(form=auth())
>
> I am using the specified functions to expose methods as below -
> #  User functions ---
> def login(): return dict(form=auth.login())
> def register(): return dict(form=auth.register())
> def retrieve_password(): return dict(form=auth.reset_password())
> def logout(): return dict(form=auth.logout())
> def profile(): return dict(form=auth.profile())
>
>
>
> and the corresponding files reside in \views\  *not in*
> \views\default - I am not sure if the application is even picking up these
> files.
>
> Note - I have extended the Auth (auth_user) table and added workspace
> and other fields - This will be specified everytime I add a new user. I
> would filter out the results as you mentioned but only after all the login
> stuff works properly.
>
> auth.settings.extra_fields['auth_user'] = [
> Field ('workspace', length=128),
>
> Sincerely,
>
> Rahul
>
> On Tuesday, October 23, 2018 at 7:49:48 PM UTC+5:30, Jim S wrote:
>>
>> Did you modify the user() function in default.py?  Or, are you using
>> your own custom login functions?
>>
>> -Jim
>>
>> On Tuesday, October 23, 2018 at 7:59:21 AM UTC-5, Rahul wrote:
>>>
>>> Hi Jim, All,
>>>  Okay I tried this - And I also decorated index() function
>>> in controller like below as I want to redirect the user to login page
>>> rather than directly jumping to index.html
>>>
>>> #  example index page 
>>> @auth.requires_login()

Re: [web2py] Re: Auth question

2018-10-26 Thread Dave S


On Thursday, October 25, 2018 at 11:44:18 PM UTC-7, Rahul wrote:
[...] 

> I even decorated index - It does take me to the login screen but from 
> there nothing happens. It just wont log me in like it did before. Also,  I 
> have two users in database but none work now.  Again, register seems to 
> fail (It did work earlier) but now it doesnt. See screenshot of both 
> screens. Looks like I must be really doing something weird. If this wont 
> work by this Sunday. I may go back to my old style of coding and do it all 
> by myself. I've seriously lost 10 days reading and experimenting with Auth 
> to make it work . Not too much coded. 
>
>  
Perhaps you should show your changes to the Auth tables.  I haven't used 
'extra' fields myself, but the discussions I've seen in this group over the 
years make it seem a much smaller effort than you seem to be going 
through.  Most people just go from the discussion in the book, from what 
I've seen.

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


Re: [web2py] Re: Auth question

2018-10-26 Thread Rahul
Nope - doesnt help. I commented out all the user functions defined in the 
controller and 


#  User functions ---
'''def login(): return dict(form=auth.login())
def register(): return dict(form=auth.register())
def retrieve_password(): return dict(form=auth.reset_password())
def logout(): return dict(form=auth.logout())
def profile(): return dict(form=auth.profile())
'''

I even decorated index - It does take me to the login screen but from there 
nothing happens. It just wont log me in like it did before. Also,  I have 
two users in database but none work now.  Again, register seems to fail (It 
did work earlier) but now it doesnt. See screenshot of both screens. Looks 
like I must be really doing something weird. If this wont work by this 
Sunday. I may go back to my old style of coding and do it all by myself. 
I've seriously lost 10 days reading and experimenting with Auth to make it 
work . Not too much coded. 

@auth.requires_login()
def index():
response.flash = T("Hello User")
#redirect(URL(r=request, c='default/user', f='login')) # Redirects user 
to login page
return dict(message=T('Welcome to web2py!'))



Thanks,

Rahul



On Thursday, October 25, 2018 at 6:02:45 PM UTC+5:30, Jim S wrote:
>
> Having the default user() functions is all you need.  I'd try commenting 
> out your 'user' functions.
>
> -Jim
>
> On Wednesday, October 24, 2018 at 10:59:45 PM UTC-5, Rahul wrote:
>>
>> Yes this is in default.py. Please excuse me for my bad code as I am still 
>> experimenting with Auth and not totally familiar with the implementation. 
>> Is this the right way that I am doing it? or only having user() function is 
>> enough ? 
>>
>> Thanks, Rahul
>>
>> On Wednesday, October 24, 2018 at 9:45:21 PM UTC+5:30, Jim S wrote:
>>>
>>> I'm confused.  Is this code in your controller somewhere?
>>>
>>> #  User functions ---
>>> def login(): return dict(form=auth.login())
>>> def register(): return dict(form=auth.register())
>>> def retrieve_password(): return dict(form=auth.reset_password())
>>> def logout(): return dict(form=auth.logout())
>>> def profile(): return dict(form=auth.profile())
>>>
>>> You shouldn't need it.  To override the default login stuff I've just 
>>> modified the one in default.py.
>>>
>>> -Jim
>>>
>>>
>>>
>>> On Tuesday, October 23, 2018 at 11:26:45 PM UTC-5, Rahul wrote:

 The user function remains as-is - No modifications done. 

 def user():
 """
 exposes:
 http:///[app]/default/user/login
 http:///[app]/default/user/logout
 http:///[app]/default/user/register
 http:///[app]/default/user/profile
 http:///[app]/default/user/retrieve_password
 http:///[app]/default/user/change_password
 http:///[app]/default/user/bulk_register
 use @auth.requires_login()
 @auth.requires_membership('group name')
 @auth.requires_permission('read','table name',record_id)
 to decorate functions that need access control
 also notice there is http:///[app]/appadmin/manage/auth to 
 allow administrator to manage users
 """
 return dict(form=auth())

 I am using the specified functions to expose methods as below - 
 #  User functions ---
 def login(): return dict(form=auth.login())
 def register(): return dict(form=auth.register())
 def retrieve_password(): return dict(form=auth.reset_password())
 def logout(): return dict(form=auth.logout())
 def profile(): return dict(form=auth.profile())



 and the corresponding files reside in \views\  *not in* \views\default 
 - I am not sure if the application is even picking up these files. 

 Note - I have extended the Auth (auth_user) table and added workspace 
 and other fields - This will be specified everytime I add a new user. I 
 would filter out the results as you mentioned but only after all the login 
 stuff works properly.

 auth.settings.extra_fields['auth_user'] = [
 Field ('workspace', length=128),

 Sincerely,

 Rahul 

 On Tuesday, October 23, 2018 at 7:49:48 PM UTC+5:30, Jim S wrote:
>
> Did you modify the user() function in default.py?  Or, are you using 
> your own custom login functions?
>
> -Jim
>
> On Tuesday, October 23, 2018 at 7:59:21 AM UTC-5, Rahul wrote:
>>
>> Hi Jim, All,
>>  Okay I tried this - And I also decorated index() function in 
>> controller like below as I want to redirect the user to login page 
>> rather 
>> than directly jumping to index.html 
>>
>> #  example index page 
>> @auth.requires_login()
>> def index():
>> response.flash= T("Hello World")
>> return dict(message=T('Welcome to web2py!'))
>>
>> However, now when I put the credentials username and password, it 
>> doesnt log me in - I generates