[web2py] Re: firebird error when tries to execute auth.defines_tables()

2017-10-27 Thread 黄祥
thanks villas, after modified the dal parameter DAL(..., ignore_field_case 
= True, entity_quoting = False, ...), theres a lot of thing deal with 
auth_user in firebird:
e.g.
1. deal with auth_user password field (already posted above)
auth.settings.password_field = 'password2'
auth.define_tables(username = True, signature = True, migrate = False)
custom_auth_table.password2.label = T('Password')
custom_auth_table.password2.widget = lambda field, value: \
SQLFORM.widgets.password.widget(field, value, 
_class = "form-control password", 
_placeholder = T('Should be filled') )
2. query auth_user  
auth_user_customer = db(db.customer.auth_user == 
auth.user_id).iterselect().first()
3. event log when user insert, update or delete
for table in db.tables:
if '_archive' not in table and '_queue' not in table and table != 
'auth_event':
db[table]._after_insert.append(partial(test_event.after_insert_event, table 
= table) )
db[table]._after_update.append(partial(test_event.after_update_event, table 
= table) )
db[table]._before_delete.insert(0, partial(test_event.before_delete_event, 
table = table) )
4. record versioning 
auth.enable_record_versioning(db)

*traceback error:*
ProgrammingError: (-607, 'isc_dsql_execute: \n  unsuccessful metadata 
update\n  Table AUTH_USER not found')

*Solution:*
- Comment the code in no 2 till 4 (assuming you put the code no 2 till 4 in 
models)
- Hit the app once, if you need the code in no 2 till 4, remove the comment 
after you hit the app

thanks and 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: How to get the last few records except the last record

2017-10-27 Thread Dave S


On Thursday, October 26, 2017 at 7:26:48 AM UTC-7, Anthony wrote:
>
> There's no need to select the extra record and then drop it via Python. 
> Instead you can just change the range of the limitby tuple to get exactly 
> the records you want.
>
>  
Perhaps the issue is not knowing how many records there are.  Solvable by 
doing a count(), but then you're making two queries (to get the count, and 
then to get the records).

/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] cache.redis differs from cache.ram

2017-10-27 Thread Pierre
here book description from
http://web2py.com/books/default/chapter/29/04/the-core#cache :

Note, time_expire is used to compare the current time with the time the 
requested object was last saved in the cache. It does not affect future 
requests. This enables time_expire to be set dynamically when an object is 
requested rather than being fixed when the object is saved. For example:



message = cache.ram('message', lambda: 'Hello', time_expire=5)
 

Now, suppose the following call is made 10 seconds after the above call:



message = cache.ram('message', lambda: 'Goodbye', time_expire=20)
 

*Because time_expire is set to 20 seconds in the second call and only 10 
seconds has elapsed since the message was first saved, the value "Hello" 
will be retrieved from the cache, and it will not be updated with 
"Goodbye". The time_expire value of 5 seconds in the first call has no 
impact on the second call.*

Setting time_expire=0 (or a negative value) forces the cached item to be 
refreshed (because the elapsed time since the last save will always be > 
0), *and setting time_expire=None forces retrieval of the cached value*, 
*regardless 
of the time elapsed since it was saved* (if time_expire is always None, the 
cached item will effectively never expire).


now with cache.redis:


def acache():
cache.redis('message', None)
message = cache.redis('message', lambda: 'Hello', time_expire=5)
sleep(10)
v = cache.redis('message', lambda: 'Goodbye', time_expire=20)
return locals()


result:

v=*'Goodbye'*



using *time_expire=None* to retrieve cached value:


def bcache():
cache.redis('message', None)
message = cache.redis('message', lambda: 'Hello', time_expire=5)
sleep(10)
v = cache.redis('message', lambda: 'Goodbye', time_expire=None)
return locals()

result:

v=*'Goodbye'*


I'd like to cache user specific values for the user session period:


message = cache.redis('avalue', lambda: value, time_expire= 
auth.settings.expiration)


how do I make sure value can be retrieved ?

-- 
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: Help with python classes...

2017-10-27 Thread António Ramos
my second  shotsmaller code i omitted the 3rd function "init"
as in the first shot...

class Group1_disabled:
def f1(self):
print "f1 disabled"
def f2(self):
print "f2 disabled"

class Group1_visible:
def f1(self):
print "f1 visible"
def f2(self):
print "f2 visible"

class Load_fields(object):
def __init__(self,fields):
self.fields=fields

MyGroup1=Load_fields([Load_visible(),Load_disabled()])


Results in smaller code but still not very clever is it???

Regards

2017-10-27 16:48 GMT+01:00 António Ramos :

> This is my best shot...
> It works but as it can have for example 30 groups of fields it may not be
> the simplest/smartest code
>
> class Group1_fields(object):
> def __init__(self, fields):
> print "calling init"
> self.fields = fields
>
> class f1(object):
> def __init__(self, visible,disabled) :
> print "calling f1"
> self.visible=oc_visible
> self.disabled=oc_disabled
>
> class f1_visible(object):
> def __init__(self):
> print "calling f1 visible"
>
> class f1_disabled(object):
> def __init__(self):
> print "calling f1 disabled"
>
> class f2(object):
> def __init__(self, visible,disabled) :
> print "calling f2"
> self.visible=oc_visible
> self.disabled=oc_disabled
>
> class f2_visible(object):
> def __init__(self):
> print "calling f2 visible"
>
> class f2_disabled(object):
> def __init__(self):
> print "calling f2 disabled"
>
>
> MyGroup1=Group1_fields([
> f1(f1_visible(),f1_disabled()),
> f2(f2_visible(),f2_disabled())
> ]
> )
>
> 2017-10-27 16:06 GMT+01:00 António Ramos :
>
>> Hello i'm blocked so i need your opinion
>>
>> I have many groups of  Objects.
>> Each group has some fields.
>> Each field has 3 functions: visible,init and disabled.
>>
>>
>> I'm coding something like
>>
>> main.py
>> from all_fields import *
>>
>>
>> all_fields.py
>>
>> Class Load_fields:
>> def f1():
>> this field should have inside 3 functions like explained above
>> def f2():
>> etc..
>>
>> Class Another_group:
>> def f3():
>>this field should have inside 3 functions like explained above
>>
>>
>> I know i´m doing something wrong but can "unlock" my mind...
>> I need 3 functions inside each fx function but this is not the way...
>>
>> Any ideas?
>>
>> 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: Legacy table with reserved keyword in column name

2017-10-27 Thread Fabiano Almeida
Wow, thanks!

The rname parameter of Field solved the problem.

2017-10-27 6:14 GMT-02:00 Nico de Groot :

> No, that just changes how the DAL checks for conflicts with reserved SQL
> words. It depends on the backend which words are problematic. See the book.
> If you really want to use a reserved word check out the rname parameter of
> Field.
>
> Nico de Groot
>
> --
> 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: firebird error when tries to execute auth.defines_tables()

2017-10-27 Thread villas
Hi Stifan

Earlier this year web2py started to quote all SQL entities and this caused 
a problem for Firebird because this DB creates entities in uppercase by 
default.

Anyhow,  it may help if you change your DAL declaration to use switches: 
ignore_field_case, 
entity_quoting

DAL('firebird://SYSDBA:password@',   ... 
   ignore_field_case=True, entity_quoting=False,
    )

I hope it helps.  D

-- 
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: Help with python classes...

2017-10-27 Thread António Ramos
This is my best shot...
It works but as it can have for example 30 groups of fields it may not be
the simplest/smartest code

class Group1_fields(object):
def __init__(self, fields):
print "calling init"
self.fields = fields

class f1(object):
def __init__(self, visible,disabled) :
print "calling f1"
self.visible=oc_visible
self.disabled=oc_disabled

class f1_visible(object):
def __init__(self):
print "calling f1 visible"

class f1_disabled(object):
def __init__(self):
print "calling f1 disabled"

class f2(object):
def __init__(self, visible,disabled) :
print "calling f2"
self.visible=oc_visible
self.disabled=oc_disabled

class f2_visible(object):
def __init__(self):
print "calling f2 visible"

class f2_disabled(object):
def __init__(self):
print "calling f2 disabled"


MyGroup1=Group1_fields([
f1(f1_visible(),f1_disabled()),
f2(f2_visible(),f2_disabled())
]
)

2017-10-27 16:06 GMT+01:00 António Ramos :

> Hello i'm blocked so i need your opinion
>
> I have many groups of  Objects.
> Each group has some fields.
> Each field has 3 functions: visible,init and disabled.
>
>
> I'm coding something like
>
> main.py
> from all_fields import *
>
>
> all_fields.py
>
> Class Load_fields:
> def f1():
> this field should have inside 3 functions like explained above
> def f2():
> etc..
>
> Class Another_group:
> def f3():
>this field should have inside 3 functions like explained above
>
>
> I know i´m doing something wrong but can "unlock" my mind...
> I need 3 functions inside each fx function but this is not the way...
>
> Any ideas?
>
> 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.


[web2py] Help with python classes...

2017-10-27 Thread António Ramos
Hello i'm blocked so i need your opinion

I have many groups of  Objects.
Each group has some fields.
Each field has 3 functions: visible,init and disabled.


I'm coding something like

main.py
from all_fields import *


all_fields.py

Class Load_fields:
def f1():
this field should have inside 3 functions like explained above
def f2():
etc..

Class Another_group:
def f3():
   this field should have inside 3 functions like explained above


I know i´m doing something wrong but can "unlock" my mind...
I need 3 functions inside each fx function but this is not the way...

Any ideas?

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.


[web2py] Re: _next-Parameter to become an array during login

2017-10-27 Thread 'Silvan Marco Fin' via web2py-users
I think I misunderstood your answer the first time I read it.

Am Freitag, 27. Oktober 2017 15:39:33 UTC+2 schrieb Anthony:
>
> The Auth login method adds _next as a hidden input in the login form, so 
> _next ends up in both request.get_vars and request.post_vars. Because 
> request.vars combines get_vars and post_vars and each of those includes a 
> "_next" key, request.vars ends up with _next being a list including the 
> values from both get_vars and post_vars (which should be the same).
>
> So, if you just want _next from the URL query string, you can use 
> request.get_vars._next. But why do you need that -- the auth.login() action 
> already handles redirecting to the _next URL after successful login?
>

The authentication is done via ldap. The application is kind of a self 
service tool for our users. There are two kind of users, the ones already 
managed with the new tool and the ones that are not yet managed with the 
new tool (don't ask why).
First type of users shall log in and work with the front end, second type 
shall enter a registration process, that is handled in the back end. To 
distinguish the two of them, I introduced a function as login_onaccept hook 
that checks some ldap membership property, which is automatically handled 
by the back end. If they are not yet member of the "managed" group, the 
application redirects to the registration process.

Somehow I thought I would have to manually redirect the ordinary users, 
that's where I discovered, that the _next key was an array. Your answer 
made it clear, that I do not need to handle this case, but simply let the 
hook pass without doing anything and only redirect to the specific 
registration process in the second case.

Many thanks again,
Silvan
 

-- 
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: _next-Parameter to become an array during login

2017-10-27 Thread 'Silvan Marco Fin' via web2py-users
Reading your answer I realize, that I'm not doing it "the right way" :)
I don't know when I added the next-parameter to the return value, but that 
was clearly a mistake. I'll remove it and try again!

Many thanks for your answer,
Silvan

-- 
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: _next-Parameter to become an array during login

2017-10-27 Thread Anthony
The Auth login method adds _next as a hidden input in the login form, so 
_next ends up in both request.get_vars and request.post_vars. Because 
request.vars combines get_vars and post_vars and each of those includes a 
"_next" key, request.vars ends up with _next being a list including the 
values from both get_vars and post_vars (which should be the same).

So, if you just want _next from the URL query string, you can use 
request.get_vars._next. But why do you need that -- the auth.login() action 
already handles redirecting to the _next URL after successful login?

Anthony

On Friday, October 27, 2017 at 4:46:14 AM UTC-4, Silvan Marco Fin wrote:
>
> Hi!
>
> I found the _next-parameter to become an array during login and I wonder 
> if this is a feature and if I'm using it "the right way(tm)".
>
> Situation is as follows:
>
> def user():
> import logging
> logging.warn('default/user _next={}'.format(request.vars._next))
> return dict(form=auth(), next=request.vars._next)
>
> Browser displays page 'myapp/customer/accounts', the user is not logged in.
> There is a login button pointing to 
> 'myapp/default/user/login?_next=/myapp/customer/accounts'.
> The user presses the login-button, gives credentials, everything fine so 
> far.
>
> The user method is run twice as I understand, first to generate the form 
> and then to handle the submission.
>
> I get the following output: 
> WARNING:root:default/user _next=/myapp/customer/accounts
> WARNING:root:default/user _next=['/myapp/customer/accounts', 
> '/myapp/customer/accounts']
>
> Next thing I do is something like
> auth.settings.login_onaccept.append(my_login_hook)
> and I expected a single valued parameter _next and I get a multi valued 
> array. 
>
> Is this intentional?
>
> Are the values always the same or may the values in the array differ? 
> Which one is the "right one"?
>
> Kind regards,
> Silvan
>

-- 
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: _next-Parameter to become an array during login

2017-10-27 Thread 'Silvan Marco Fin' via web2py-users

Sry, forgot to mention: Ubuntu Linux Ubuntu 14.04.5 LTS with 
web2py 2.15.2-stable

-- 
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] _next-Parameter to become an array during login

2017-10-27 Thread 'Silvan Marco Fin' via web2py-users
Hi!

I found the _next-parameter to become an array during login and I wonder if 
this is a feature and if I'm using it "the right way(tm)".

Situation is as follows:

def user():
import logging
logging.warn('default/user _next={}'.format(request.vars._next))
return dict(form=auth(), next=request.vars._next)

Browser displays page 'myapp/customer/accounts', the user is not logged in.
There is a login button pointing to 
'myapp/default/user/login?_next=/myapp/customer/accounts'.
The user presses the login-button, gives credentials, everything fine so 
far.

The user method is run twice as I understand, first to generate the form 
and then to handle the submission.

I get the following output: 
WARNING:root:default/user _next=/myapp/customer/accounts
WARNING:root:default/user _next=['/myapp/customer/accounts', 
'/myapp/customer/accounts']

Next thing I do is something like
auth.settings.login_onaccept.append(my_login_hook)
and I expected a single valued parameter _next and I get a multi valued 
array. 

Is this intentional?

Are the values always the same or may the values in the array differ? Which 
one is the "right one"?

Kind regards,
Silvan

-- 
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: Legacy table with reserved keyword in column name

2017-10-27 Thread Nico de Groot
No, that just changes how the DAL checks for conflicts with reserved SQL words. 
It depends on the backend which words are problematic. See the book. If you 
really want to use a reserved word check out the rname parameter of Field.

Nico de Groot 

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