[web2py] Re: OAUTH2.0 help

2018-03-07 Thread greenpoise
Hi Dave, thanks for the input. I was able to post the temporary code and get an 
authentication code. I will post tomorrow my updated code. I feel i am close. 
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: new style of welcome app

2018-03-07 Thread Anthony


On Wednesday, March 7, 2018 at 2:40:02 PM UTC-5, Andrea Fae' wrote:
>
> Thanks Anthony, but LOGIN is still in the left side...
>
>
> 
>

It's on the right for me:


What does the HTML for the login dropdown look like in the rendered page?

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.


[web2py] Re: OAUTH2.0 help

2018-03-07 Thread Dave S
I probably shouldn't be answering, because my OAUTH2 expertise comes from a 
presentation by Jim Manicore of Manicode.com,
but ...

On Wednesday, March 7, 2018 at 3:05:48 PM UTC-8, greenpoise wrote:
>
> I feel I am almost there making a connection.  So, following the steps of 
> the server side, I have to:
>
> 1. Request an Authorization and Temporary Token
> 2. Once I receive the temporary token,
> 3. I have to exchanged it for an access token which I can use to access 
> the data
>
>
> I have the first 2 i believe. Here is my code in web2py:
>
> 1. Request Authorization and Temp Token
>
> def loginview():
> params = {"response_type": "code",
>"client_id": CLIENT_ID,
>   "scope": "employee:customers_read"}
> url = "https://cloud.XXX.com/oauth/authorize.php?; + urllib.
> urlencode(params)
> return dict(url=url)
>
> which gives me the temp_code within request.env.query_string the redirect 
> which is defined in the server and goes to:
>
> 2.
> def index():
> request_uri = URL(args=request.args,vars=request.vars,host=True)
> temp_code = request.env.query_string
> 
>
>
>
> 3. Step 3 is a continuation of step 2. and this is where I dont know how 
> to exchange the temp_code above with the ACESS_TOKEN
>
> params = {"client_id":CLIENT_ID,
>  "client_secret":CLIENT_SECRET,
>  "code":temp_code,
>  "grant_type":"authorization_code"}
> url="https://cloud.XXX.com/oauth/access_token.php;
> *response = requests.request("POST", url, data=params)*
> 
> return dict(request_uri=request_uri,temp_code=temp_code,response=
> response)
>
>
> after that I have to use a session to store the access_token and start 
> querying the endpoint data.
>
> Thanks
>
>
>
I may be confused, but I suspect that you might be .. based on my alleged 
understanding of the typical OAUTH2 flow, which is something like shown in 
the attached oauth2_flow.png.

As in that diagram, the token the client gets from the OAUTH2 server goes 
to the application server, which then sends it to the OAUTH2 server to 
confirm the client has permission to access the services of the application 
server, and that the client has granted permission to the application 
server to act on the client's behalf.

(One of the examples given was an online pizza ordering experience, where 
OAUTH2 was used to post the customer's rave reviews on Yelp, with Yelp 
being the OAUTH2 server, and the pizza palace being the application server.)

Now, I may be misunderstanding a) what you're trying to do and b) OAUTH2, 
but if so you might want to post an equivalent diagram with the correct 
flow shown.

/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] OAUTH2.0 help

2018-03-07 Thread greenpoise
I feel I am almost there making a connection.  So, following the steps of 
the server side, I have to:

1. Request an Authorization and Temporary Token
2. Once I receive the temporary token,
3. I have to exchanged it for an access token which I can use to access the 
data


I have the first 2 i believe. Here is my code in web2py:

1. Request Authorization and Temp Token

def loginview():
params = {"response_type": "code",
   "client_id": CLIENT_ID,
  "scope": "employee:customers_read"}
url = "https://cloud.XXX.com/oauth/authorize.php?; + urllib.
urlencode(params)
return dict(url=url)

which gives me the temp_code within request.env.query_string the redirect 
which is defined in the server and goes to:

2.
def index():
request_uri = URL(args=request.args,vars=request.vars,host=True)
temp_code = request.env.query_string




3. Step 3 is a continuation of step 2. and this is where I dont know how to 
exchange the temp_code above with the ACESS_TOKEN

params = {"client_id":CLIENT_ID,
 "client_secret":CLIENT_SECRET,
 "code":temp_code,
 "grant_type":"authorization_code"}
url="https://cloud.XXX.com/oauth/access_token.php;
*response = requests.request("POST", url, data=params)*

return dict(request_uri=request_uri,temp_code=temp_code,response=
response)


after that I have to use a session to store the access_token and start 
querying the endpoint data.

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] Backwards compatibility

2018-03-07 Thread Mark Erbaugh
I appreciate Web2py's view towards backwards compatibility, but I think 
some of the included libraries do not share the same philosophy. I have had 
to make changes eliminate errors or have expected functionality. I would 
like to know if I'm doing this right and if I've missed something.

If you view pages using developer tools, you see an error message that 
Bootstrap tooltips require Tether. I solved this by downloading tether.min 
ad additing it to layout.html.

In the admin mode, if you try and edit a table with a list field, the + and 
- icons are missing. The buttons are there, just blank. I solved this by 
adding glyhpicons.css to layout.html which uses Glyphicons Halflings font. 
Interestingly, the glyicons-haflings files referenced were already in the 
statc\fonts directory.

Thanks,
Mark






-- 
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: please help us test trunk web2py

2018-03-07 Thread Nbush
Pluralizaiton error. (test on python 2.7.13)

 'ascii' codec can't decode byte 0xd0 
in position 0: ordinal not in range(128)
Function argument list

(self=, 
message='%{!\xd0\xb2\xd1\x8b\xd0\xb1\xd1\x80\xd0\xb0\xd0\xbd\xd0\xb0[0]} 1 
%{\xd0\xb7\xd0\xb0\xd0\xbf\xd0\xb8\xd1\x81\xd1\x8c[0]}', symbols=(1,))
Code listing

929.
930.
931.
932.
933.
934.

935.
936.
937.
938.

part = regex_plural_dict.sub(sub_dict, s)
if part == s:
return m.group(0)
return part
message = message % symbols
message = regex_plural.sub(sub_plural, message)

return message

def translate(self, message, symbols):
"""

Variables
message '%{!\xd0\xb2\xd1\x8b\xd0\xb1\xd1\x80\xd0\xb0\xd0\xbd\xd0\xb0[0]} 1 
%{\xd0\xb7\xd0\xb0\xd0\xbf\xd0\xb8\xd1\x81\xd1\x8c[0]}'
global regex_plural <_sre.SRE_Pattern object>
regex_plural.sub 
sub_plural 

-- 
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: Problem Pickling Session

2018-03-07 Thread Mark Erbaugh
I'm not sure this is the right way to answer Massimo's question as there 
appears to be no way to reply to his reply.

Web2Py is 2.16.1-stable+timestamp.2017.11.14.05.54.25

I tried deleting all the files in the application (both my application and 
admin) sessions folders, but still have the same error.

-- 
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] _href to URL()

2018-03-07 Thread 黄祥
thanks for the pointer, anthony

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.


Re: [web2py] Unit testing apis

2018-03-07 Thread Richard Vézina
I do have customized web2py.test while integrating some of welcome_enhanced
stuff like using splinter api for conducting testing + create a test
launcher to save some boiler plate initialization... I just don't have time
to exectract it form my own app and publish it... It rely on pytest... It
gear around system testing more than unit testing though...

On Wed, Mar 7, 2018 at 1:12 PM, Yoel Benítez Fonseca 
wrote:

> idk if that is the right way... i'm using this approach in on of my
> projects and at the moment the only problem i have is with the memory usage
> or the slow access with a file base sqlite database for the tests.
>
>
> On Wed, Mar 7, 2018 at 1:08 PM, António Ramos 
> wrote:
>
>> Next chapter in web2py book
>>
>> Pytest your app the right way
>>
>> 2018-03-07 18:02 GMT+00:00 Yoel Benítez Fonseca :
>>
>>> H!
>>>
>>> checkout: https://github.com/viniciusban/web2py.test
>>>
>>>
>>>
>>> On Wed, Mar 7, 2018 at 10:10 AM, Kevin Huang  wrote:
>>>

 Hi all,


 I'm relatively new to web2py, and still trying to find more resources,
 but i've hit a wall, and I'm not quite sure on this issue I'm working with:


 So working with the "guide" from http://web2py.com/AlterEgo/def
 ault/show/260, I'm trying to create a few unit tests to test some
 RESTFUL api functions. However, while testing multiple test suites, it
 seems that the request information is carrying over somehow despite my
 attempts to make sure that I start with a new request object via setUp each
 time.

 The tests will run just fine if they're alone in the suite, but running
 some of them after the other I was running into HTTP 400 errors and during
 debugging I found out that the request data carrying over.

 Some "sample" code to illustrate what I was trying to do...

 import unittest
 from gluon.globals import Request

 # import api code
 execfile("applications/appname/controllers/app_api.py", globals())class


 # Test Put api
 TestPutAPI(unittest.TestCase):

  def setUp(self):
request = Request(env=[])  # new request, env must be set.

  def test_some_function(self):
request.vars['var1'] = 1
request.vars['var2'] = 2
request.env.request_method = 'PUT'
response = api() # call api

self.assertEquals(response['result'], 'success')

   def tearDown(self):
db.table.truncate()  # clean up db (nothing request related here)


 # Test Post api
 TestPostAPI(unittest.TestCase):

  def setUp(self):
request = Request(env=[])  # new request

  def test_some_function(self):
request.vars['var5'] = "asdf"
request.vars['var6'] = 6
request.env.request_method = 'POST'
response = api() # call api

self.assertEquals(response['result'], 'success')

  def tearDown(self):
db.table.truncate()  # clean up db (nothing request related here)


 # Run tests
 suite = unittest.TestSuite()
 suite.addTest(unittest.makeSuite(TestPutAPI))
 suite.addTest(unittest.makeSuite(TestPostAPI))

 unittest.TextTestRunner(verbosity=2).run(suite)


 Is my entire approach to unit testing wrong? I know there's a lot a
 mention of doctests being recommended, also that the line request =
 Request() recommended by the original article also being wrong (or simply
 out of date), but I'm also unsure of how the request and api call is being
 processed in this scenario. Earlier I tried doing 2 calls to the same api
 in one test function and found that web2py (and this unittest) simply could
 not overwrite the request function - if that made any sense (it didn't, and
 didn't work).

 Anyone have any pointers?

 Thank you,
 KH


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

Re: [web2py] Re: new style of welcome app

2018-03-07 Thread Richard Vézina
Did you flush you browser cache??

On Wed, Mar 7, 2018 at 2:40 PM, Andrea Fae'  wrote:

> Thanks Anthony, but LOGIN is still in the left side...
>
>
> 
>
>
> Il giorno lunedì 5 marzo 2018 13:18:50 UTC+1, Anthony ha scritto:
>>
>> On Sunday, March 4, 2018 at 12:12:45 PM UTC-5, Andrea Fae' wrote:
>>>
>>> I have different apps in my web2py environments. Web2py apps built
>>> before a certain date have a stile with "login" link in the right upper
>>> side of the web page, while the new apps, for example welcome app are with
>>> another style with login link anchor in the left side, just after the
>>> menus, and after a "search" box. Why?
>>> How to delete the search box and have the login in the right part of the
>>> page?
>>>
>>
>> You can copy the layout from the old welcome app if you prefer it.
>> Otherwise, you'll have to customize the new layout to your liking. The
>> search box is just 3 lines that you can delete. Regarding the login, it is
>> already pushed to the right side of the screen.
>>
>> 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.
>

-- 
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: new style of welcome app

2018-03-07 Thread Andrea Fae'
Thanks Anthony, but LOGIN is still in the left side...




Il giorno lunedì 5 marzo 2018 13:18:50 UTC+1, Anthony ha scritto:
>
> On Sunday, March 4, 2018 at 12:12:45 PM UTC-5, Andrea Fae' wrote:
>>
>> I have different apps in my web2py environments. Web2py apps built before 
>> a certain date have a stile with "login" link in the right upper side of 
>> the web page, while the new apps, for example welcome app are with another 
>> style with login link anchor in the left side, just after the menus, and 
>> after a "search" box. Why?
>> How to delete the search box and have the login in the right part of the 
>> page?
>>
>
> You can copy the layout from the old welcome app if you prefer it. 
> Otherwise, you'll have to customize the new layout to your liking. The 
> search box is just 3 lines that you can delete. Regarding the login, it is 
> already pushed to the right side of the screen.
>
> 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: Unexpected behaviour executing a query with DAL and record versioning enabled

2018-03-07 Thread Richard Vézina
That why I think you wrongly initialize you db in the first place while
onboarding the record versioning feature...

Please try on your side to create new app drop the model and fixture I
include in one of my last email and start web2py shell and launch the
various commands of yours...

You should get the same output number of record...

If you don't it might happen that there was a bug in 2.15.4 web2py version
/ pyDAL...

Try new version...

On Wed, Mar 7, 2018 at 2:05 PM, Richard Vézina 
wrote:

> In [4]: query = (test2.type_marker=='object') | (test2.type_marker==None)
> & (test1.type_marker=='person')
>...:
>
> In [5]: db().select(db.test.ALL)
> Out[5]: 
>
> I did there...
>
> Same result...
>
> That my point...
>
> On Wed, Mar 7, 2018 at 1:47 PM, 'Awe' via web2py-users <
> web2py@googlegroups.com> wrote:
>
>> Hello Richard,
>> you are right, the use case is parent child relation.
>> All I want to point out is if you use this query:
>> "query = (test2.type_marker=='object') | (test2.type_marker==None) &
>> (test1.type_marker=='person')"
>> you do not get the same result with record versioning enabled or disabled.
>>
>> Why do I use this query definition because I want to retrieve exactly
>> this result:
>> test1.titletest2.title
>> PeterNone
>> PaulLaptop
>>
>> If you use this query instead:
>> (test2.type_marker=='object') & (test1.type_marker=='person')
>> you do not get the result I need.
>>
>> The " | (test2.type_marker==None) " is necessary, due to parent/child
>> relationship.
>>
>> Please try exactly the query mentioned using versioning enabled/disabled
>> and see what happens.
>>
>> Many thanks for your patience.
>>
>> Am Mittwoch, 7. März 2018 19:34:41 UTC+1 schrieb Richard:
>>>
>>> I don't get it, I don't understand what is the issue...
>>>
>>> I just demonstrate that with and without record versioning DAL returns
>>> the same set of result which what it should be doing no??
>>>
>>> So my understanding of the issue is that you don't get the same query
>>> output when record versioning is on and when it off which to me should is
>>> the issue you point us... I migth not understand the exact problem you have.
>>>
>>> But to me this "query = (test2.type_marker=='object') |
>>> (test2.type_marker==None) & (test1.type_marker=='person')"
>>>
>>> or this "query = (test2.type_marker=='object') &
>>> (test1.type_marker=='person')" with the set of inputs you have will lead to
>>> the same output as there is not type_marker NULL value...
>>>
>>> But I guess I miss something with related to what you try to achieve
>>> with this aliasing thing that you do...
>>>
>>> Also the use case is not obvious for me as why are you doing these
>>> aliases... I guess to retrieve some sort of genealogy/record parent-child
>>> relation...
>>>
>>> Richard
>>>
>>>
>>> On Wed, Mar 7, 2018 at 12:17 PM, 'Awe' via web2py-users <
>>> web...@googlegroups.com> wrote:
>>>
 Hello Richard,
 have read your post 3 times, but I can't find the right query result.
 Could you tell me where to find in your test the query which leads to:
 test1.titletest2.title
 PeterNone
 PaulLaptop

 Thank you.





 Am Mittwoch, 7. März 2018 17:33:33 UTC+1 schrieb Richard:

> Here some tests :
>
> *WITH record versioning*
>
> In [1]: db(db.test.id < 0).select()
> Out[1]: 
>
> In [2]: db(db.test.id > 0).select()
> Out[2]: 
>
> In [3]: test1 = db.test.with_alias('test1')
>
> In [4]: test2 = db.test.with_alias('test2')
>
> In [5]: query = (test2.type_marker=='object') |
> (test2.type_marker==None) & (test1.type_marker=='person')
>
> In [6]: db().select(current.db.test.ALL)
> 
> ---
> NameError Traceback (most recent call
> last)
> /web2py_master_trunk/web2py/applications/test_versioning_issue/models/menu.py
> in ()
> > 1 db().select(current.db.test.ALL)
>
> NameError: name 'current' is not defined
>
> In [7]: db().select(db.test.ALL)
> Out[7]: 
>
> In [8]: query = (test2.type_marker=='object') &
> (test1.type_marker=='person')
>
> In [9]: db().select(db.test.ALL)
> Out[9]: 
>
> In [10]: db(query).select(test1.title, test2.title, left=test2.on(
> test1.id==test2.granny))
> Out[10]: 
>
> In [11]: db(query)._select(test1.title, test2.title, left=test2.on(
> test1.id==test2.granny))
> Out[11]: 'SELECT "test1"."title", "test2"."title" FROM "test" AS
> "test1" LEFT JOIN "test" AS "test2" ON (("test1"."id" = "test2"."granny")
> AND (("test1"."is_active" = \'T\') AND ("test2"."is_active" = \'T\')))
> WHERE "test2"."type_marker" = \'object\') AND ("test1"."type_marker" =
> \'person\')) AND (("test1"."is_active" 

Re: [web2py] Re: Unexpected behaviour executing a query with DAL and record versioning enabled

2018-03-07 Thread Richard Vézina
In [4]: query = (test2.type_marker=='object') | (test2.type_marker==None) &
(test1.type_marker=='person')
   ...:

In [5]: db().select(db.test.ALL)
Out[5]: 

I did there...

Same result...

That my point...

On Wed, Mar 7, 2018 at 1:47 PM, 'Awe' via web2py-users <
web2py@googlegroups.com> wrote:

> Hello Richard,
> you are right, the use case is parent child relation.
> All I want to point out is if you use this query:
> "query = (test2.type_marker=='object') | (test2.type_marker==None) &
> (test1.type_marker=='person')"
> you do not get the same result with record versioning enabled or disabled.
>
> Why do I use this query definition because I want to retrieve exactly this
> result:
> test1.titletest2.title
> PeterNone
> PaulLaptop
>
> If you use this query instead:
> (test2.type_marker=='object') & (test1.type_marker=='person')
> you do not get the result I need.
>
> The " | (test2.type_marker==None) " is necessary, due to parent/child
> relationship.
>
> Please try exactly the query mentioned using versioning enabled/disabled
> and see what happens.
>
> Many thanks for your patience.
>
> Am Mittwoch, 7. März 2018 19:34:41 UTC+1 schrieb Richard:
>>
>> I don't get it, I don't understand what is the issue...
>>
>> I just demonstrate that with and without record versioning DAL returns
>> the same set of result which what it should be doing no??
>>
>> So my understanding of the issue is that you don't get the same query
>> output when record versioning is on and when it off which to me should is
>> the issue you point us... I migth not understand the exact problem you have.
>>
>> But to me this "query = (test2.type_marker=='object') |
>> (test2.type_marker==None) & (test1.type_marker=='person')"
>>
>> or this "query = (test2.type_marker=='object') &
>> (test1.type_marker=='person')" with the set of inputs you have will lead to
>> the same output as there is not type_marker NULL value...
>>
>> But I guess I miss something with related to what you try to achieve with
>> this aliasing thing that you do...
>>
>> Also the use case is not obvious for me as why are you doing these
>> aliases... I guess to retrieve some sort of genealogy/record parent-child
>> relation...
>>
>> Richard
>>
>>
>> On Wed, Mar 7, 2018 at 12:17 PM, 'Awe' via web2py-users <
>> web...@googlegroups.com> wrote:
>>
>>> Hello Richard,
>>> have read your post 3 times, but I can't find the right query result.
>>> Could you tell me where to find in your test the query which leads to:
>>> test1.titletest2.title
>>> PeterNone
>>> PaulLaptop
>>>
>>> Thank you.
>>>
>>>
>>>
>>>
>>>
>>> Am Mittwoch, 7. März 2018 17:33:33 UTC+1 schrieb Richard:
>>>
 Here some tests :

 *WITH record versioning*

 In [1]: db(db.test.id < 0).select()
 Out[1]: 

 In [2]: db(db.test.id > 0).select()
 Out[2]: 

 In [3]: test1 = db.test.with_alias('test1')

 In [4]: test2 = db.test.with_alias('test2')

 In [5]: query = (test2.type_marker=='object') |
 (test2.type_marker==None) & (test1.type_marker=='person')

 In [6]: db().select(current.db.test.ALL)
 
 ---
 NameError Traceback (most recent call
 last)
 /web2py_master_trunk/web2py/applications/test_versioning_issue/models/menu.py
 in ()
 > 1 db().select(current.db.test.ALL)

 NameError: name 'current' is not defined

 In [7]: db().select(db.test.ALL)
 Out[7]: 

 In [8]: query = (test2.type_marker=='object') &
 (test1.type_marker=='person')

 In [9]: db().select(db.test.ALL)
 Out[9]: 

 In [10]: db(query).select(test1.title, test2.title, left=test2.on(
 test1.id==test2.granny))
 Out[10]: 

 In [11]: db(query)._select(test1.title, test2.title, left=test2.on(
 test1.id==test2.granny))
 Out[11]: 'SELECT "test1"."title", "test2"."title" FROM "test" AS
 "test1" LEFT JOIN "test" AS "test2" ON (("test1"."id" = "test2"."granny")
 AND (("test1"."is_active" = \'T\') AND ("test2"."is_active" = \'T\')))
 WHERE "test2"."type_marker" = \'object\') AND ("test1"."type_marker" =
 \'person\')) AND (("test1"."is_active" = \'T\') AND ("test2"."is_active" =
 \'T\'))) AND (("test1"."is_active" = \'T\') AND ("test2"."is_active" =
 \'T\')));'

 In [12]: print db().select(db.test.ALL)
 test.id,test.title,test.granny,test.type_marker,test.is_
 active,test.created_on,test.created_by,test.modified_on,
 test.modified_by
 1,Peter,,person,True,2018-03-07 11:10:08,,2018-03-07
 11:10:08,
 2,Paul,,person,True,2018-03-07 11:10:08,,2018-03-07
 11:10:08,
 3,Laptop,2,object,True,2018-03-07 11:10:08,,2018-03-07
 11:10:08,


 *WITHOUT record versioning*

 In [1]: db(db.test.id > 0).select()
 Out[1]: 

 In [2]:  test1 = 

Re: [web2py] Re: Unexpected behaviour executing a query with DAL and record versioning enabled

2018-03-07 Thread 'Awe' via web2py-users
Hello Richard,
you are right, the use case is parent child relation.
All I want to point out is if you use this query:
"query = (test2.type_marker=='object') | (test2.type_marker==None) & 
(test1.type_marker=='person')"
you do not get the same result with record versioning enabled or disabled.

Why do I use this query definition because I want to retrieve exactly this 
result:
test1.titletest2.title
PeterNone
PaulLaptop

If you use this query instead:
(test2.type_marker=='object') & (test1.type_marker=='person')
you do not get the result I need.

The " | (test2.type_marker==None) " is necessary, due to parent/child 
relationship.

Please try exactly the query mentioned using versioning enabled/disabled 
and see what happens.

Many thanks for your patience.

Am Mittwoch, 7. März 2018 19:34:41 UTC+1 schrieb Richard:
>
> I don't get it, I don't understand what is the issue...
>
> I just demonstrate that with and without record versioning DAL returns the 
> same set of result which what it should be doing no??
>
> So my understanding of the issue is that you don't get the same query 
> output when record versioning is on and when it off which to me should is 
> the issue you point us... I migth not understand the exact problem you have.
>
> But to me this "query = (test2.type_marker=='object') | 
> (test2.type_marker==None) & (test1.type_marker=='person')"
>
> or this "query = (test2.type_marker=='object') & 
> (test1.type_marker=='person')" with the set of inputs you have will lead to 
> the same output as there is not type_marker NULL value...
>
> But I guess I miss something with related to what you try to achieve with 
> this aliasing thing that you do...
>
> Also the use case is not obvious for me as why are you doing these 
> aliases... I guess to retrieve some sort of genealogy/record parent-child 
> relation...
>
> Richard
>
>
> On Wed, Mar 7, 2018 at 12:17 PM, 'Awe' via web2py-users <
> web...@googlegroups.com > wrote:
>
>> Hello Richard,
>> have read your post 3 times, but I can't find the right query result.
>> Could you tell me where to find in your test the query which leads to:
>> test1.titletest2.title
>> PeterNone
>> PaulLaptop
>>
>> Thank you.
>>
>>
>>
>>
>>
>> Am Mittwoch, 7. März 2018 17:33:33 UTC+1 schrieb Richard:
>>
>>> Here some tests : 
>>>
>>> *WITH record versioning*
>>>
>>> In [1]: db(db.test.id < 0).select()
>>> Out[1]: 
>>>
>>> In [2]: db(db.test.id > 0).select()
>>> Out[2]: 
>>>
>>> In [3]: test1 = db.test.with_alias('test1')
>>>
>>> In [4]: test2 = db.test.with_alias('test2')
>>>
>>> In [5]: query = (test2.type_marker=='object') | 
>>> (test2.type_marker==None) & (test1.type_marker=='person')
>>>
>>> In [6]: db().select(current.db.test.ALL)
>>>
>>> ---
>>> NameError Traceback (most recent call 
>>> last)
>>> /web2py_master_trunk/web2py/applications/test_versioning_issue/models/menu.py
>>>  
>>> in ()
>>> > 1 db().select(current.db.test.ALL)
>>>
>>> NameError: name 'current' is not defined
>>>
>>> In [7]: db().select(db.test.ALL)
>>> Out[7]: 
>>>
>>> In [8]: query = (test2.type_marker=='object') & 
>>> (test1.type_marker=='person')
>>>
>>> In [9]: db().select(db.test.ALL)
>>> Out[9]: 
>>>
>>> In [10]: db(query).select(test1.title, test2.title, left=test2.on(
>>> test1.id==test2.granny))
>>> Out[10]: 
>>>
>>> In [11]: db(query)._select(test1.title, test2.title, left=test2.on(
>>> test1.id==test2.granny))
>>> Out[11]: 'SELECT "test1"."title", "test2"."title" FROM "test" AS "test1" 
>>> LEFT JOIN "test" AS "test2" ON (("test1"."id" = "test2"."granny") AND 
>>> (("test1"."is_active" = \'T\') AND ("test2"."is_active" = \'T\'))) WHERE 
>>> "test2"."type_marker" = \'object\') AND ("test1"."type_marker" = 
>>> \'person\')) AND (("test1"."is_active" = \'T\') AND ("test2"."is_active" = 
>>> \'T\'))) AND (("test1"."is_active" = \'T\') AND ("test2"."is_active" = 
>>> \'T\')));'
>>>
>>> In [12]: print db().select(db.test.ALL)
>>> test.id
>>> ,test.title,test.granny,test.type_marker,test.is_active,test.created_on,test.created_by,test.modified_on,test.modified_by
>>> 1,Peter,,person,True,2018-03-07 11:10:08,,2018-03-07 
>>> 11:10:08,
>>> 2,Paul,,person,True,2018-03-07 11:10:08,,2018-03-07 
>>> 11:10:08,
>>> 3,Laptop,2,object,True,2018-03-07 11:10:08,,2018-03-07 
>>> 11:10:08,
>>>
>>>
>>> *WITHOUT record versioning*
>>>
>>> In [1]: db(db.test.id > 0).select()
>>> Out[1]: 
>>>
>>> In [2]:  test1 = db.test.with_alias('test1')
>>>
>>> In [3]: test2 = db.test.with_alias('test2')
>>>
>>> In [4]: query = (test2.type_marker=='object') | 
>>> (test2.type_marker==None) & (test1.type_marker=='person')
>>>...: 
>>>
>>> In [5]: db().select(db.test.ALL)
>>> Out[5]: 
>>>
>>> In [6]: query = (test2.type_marker=='object') & 
>>> (test1.type_marker=='person')
>>>
>>> In [7]: db().select(db.test.ALL)
>>> Out[7]: 
>>>
>>> In [8]: 

Re: [web2py] Re: Unexpected behaviour executing a query with DAL and record versioning enabled

2018-03-07 Thread Richard Vézina
I don't get it, I don't understand what is the issue...

I just demonstrate that with and without record versioning DAL returns the
same set of result which what it should be doing no??

So my understanding of the issue is that you don't get the same query
output when record versioning is on and when it off which to me should is
the issue you point us... I migth not understand the exact problem you have.

But to me this "query = (test2.type_marker=='object') |
(test2.type_marker==None) & (test1.type_marker=='person')"

or this "query = (test2.type_marker=='object') &
(test1.type_marker=='person')" with the set of inputs you have will lead to
the same output as there is not type_marker NULL value...

But I guess I miss something with related to what you try to achieve with
this aliasing thing that you do...

Also the use case is not obvious for me as why are you doing these
aliases... I guess to retrieve some sort of genealogy/record parent-child
relation...

Richard


On Wed, Mar 7, 2018 at 12:17 PM, 'Awe' via web2py-users <
web2py@googlegroups.com> wrote:

> Hello Richard,
> have read your post 3 times, but I can't find the right query result.
> Could you tell me where to find in your test the query which leads to:
> test1.titletest2.title
> PeterNone
> PaulLaptop
>
> Thank you.
>
>
>
>
>
> Am Mittwoch, 7. März 2018 17:33:33 UTC+1 schrieb Richard:
>
>> Here some tests :
>>
>> *WITH record versioning*
>>
>> In [1]: db(db.test.id < 0).select()
>> Out[1]: 
>>
>> In [2]: db(db.test.id > 0).select()
>> Out[2]: 
>>
>> In [3]: test1 = db.test.with_alias('test1')
>>
>> In [4]: test2 = db.test.with_alias('test2')
>>
>> In [5]: query = (test2.type_marker=='object') | (test2.type_marker==None)
>> & (test1.type_marker=='person')
>>
>> In [6]: db().select(current.db.test.ALL)
>> 
>> ---
>> NameError Traceback (most recent call
>> last)
>> /web2py_master_trunk/web2py/applications/test_versioning_issue/models/menu.py
>> in ()
>> > 1 db().select(current.db.test.ALL)
>>
>> NameError: name 'current' is not defined
>>
>> In [7]: db().select(db.test.ALL)
>> Out[7]: 
>>
>> In [8]: query = (test2.type_marker=='object') &
>> (test1.type_marker=='person')
>>
>> In [9]: db().select(db.test.ALL)
>> Out[9]: 
>>
>> In [10]: db(query).select(test1.title, test2.title, left=test2.on(
>> test1.id==test2.granny))
>> Out[10]: 
>>
>> In [11]: db(query)._select(test1.title, test2.title, left=test2.on(
>> test1.id==test2.granny))
>> Out[11]: 'SELECT "test1"."title", "test2"."title" FROM "test" AS "test1"
>> LEFT JOIN "test" AS "test2" ON (("test1"."id" = "test2"."granny") AND
>> (("test1"."is_active" = \'T\') AND ("test2"."is_active" = \'T\'))) WHERE
>> "test2"."type_marker" = \'object\') AND ("test1"."type_marker" =
>> \'person\')) AND (("test1"."is_active" = \'T\') AND ("test2"."is_active" =
>> \'T\'))) AND (("test1"."is_active" = \'T\') AND ("test2"."is_active" =
>> \'T\')));'
>>
>> In [12]: print db().select(db.test.ALL)
>> test.id,test.title,test.granny,test.type_marker,test.is_
>> active,test.created_on,test.created_by,test.modified_on,test.modified_by
>> 1,Peter,,person,True,2018-03-07 11:10:08,,2018-03-07
>> 11:10:08,
>> 2,Paul,,person,True,2018-03-07 11:10:08,,2018-03-07
>> 11:10:08,
>> 3,Laptop,2,object,True,2018-03-07 11:10:08,,2018-03-07
>> 11:10:08,
>>
>>
>> *WITHOUT record versioning*
>>
>> In [1]: db(db.test.id > 0).select()
>> Out[1]: 
>>
>> In [2]:  test1 = db.test.with_alias('test1')
>>
>> In [3]: test2 = db.test.with_alias('test2')
>>
>> In [4]: query = (test2.type_marker=='object') | (test2.type_marker==None)
>> & (test1.type_marker=='person')
>>...:
>>
>> In [5]: db().select(db.test.ALL)
>> Out[5]: 
>>
>> In [6]: query = (test2.type_marker=='object') &
>> (test1.type_marker=='person')
>>
>> In [7]: db().select(db.test.ALL)
>> Out[7]: 
>>
>> In [8]: db(query).select(test1.title, test2.title, left=test2.on(test1.id
>> ==test2.granny))
>> Out[8]: 
>>
>> In [9]: db(query)._select(test1.title, test2.title, left=test2.on(
>> test1.id==test2.granny))
>> Out[9]: 'SELECT "test1"."title", "test2"."title" FROM "test" AS "test1"
>> LEFT JOIN "test" AS "test2" ON ("test1"."id" = "test2"."granny") WHERE
>> (("test2"."type_marker" = \'object\') AND ("test1"."type_marker" =
>> \'person\'));'
>>
>> In [10]: print db().select(db.test.ALL)
>> test.id,test.title,test.granny,test.type_marker,test.is_
>> active,test.created_on,test.created_by,test.modified_on,test.modified_by
>> 1,Peter,,person,True,2018-03-07 11:10:08,,2018-03-07
>> 11:10:08,
>> 2,Paul,,person,True,2018-03-07 11:10:08,,2018-03-07
>> 11:10:08,
>> 3,Laptop,2,object,True,2018-03-07 11:10:08,,2018-03-07
>> 11:10:08,
>>
>>
>>
>>
>> *I have this in db.py of a newly created app with web2py trunk/master :*
>>
>> ```python
>> db.define_table('test',
>>Field('title', 'string'),
>>Field('granny', 

Re: [web2py] Unit testing apis

2018-03-07 Thread Yoel Benítez Fonseca
idk if that is the right way... i'm using this approach in on of my 
projects and at the moment the only problem i have is with the memory 
usage or the slow access with a file base sqlite database for the tests.


On Wed, Mar 7, 2018 at 1:08 PM, António Ramos  
wrote:

Next chapter in web2py book

Pytest your app the right way

2018-03-07 18:02 GMT+00:00 Yoel Benítez Fonseca 
:

H!

checkout: https://github.com/viniciusban/web2py.test



On Wed, Mar 7, 2018 at 10:10 AM, Kevin Huang  
wrote:


Hi all,


I'm relatively new to web2py, and still trying to find more 
resources, but i've hit a wall, and I'm not quite sure on this 
issue I'm working with:



So working with the "guide" from 
http://web2py.com/AlterEgo/default/show/260, I'm trying to create a 
few unit tests to test some RESTFUL api functions. However, while 
testing multiple test suites, it seems that the request information 
is carrying over somehow despite my attempts to make sure that I 
start with a new request object via setUp each time.


The tests will run just fine if they're alone in the suite, but 
running some of them after the other I was running into HTTP 400 
errors and during debugging I found out that the request data 
carrying over.


Some "sample" code to illustrate what I was trying to do...

import unittest
from gluon.globals import Request

# import api code
execfile("applications/appname/controllers/app_api.py", 
globals())class



# Test Put api
TestPutAPI(unittest.TestCase):

 def setUp(self):
   request = Request(env=[])  # new request, env must be set.

 def test_some_function(self):
   request.vars['var1'] = 1
   request.vars['var2'] = 2
   request.env.request_method = 'PUT'
   response = api() # call api

   self.assertEquals(response['result'], 'success')

  def tearDown(self):
   db.table.truncate()  # clean up db (nothing request related here)


# Test Post api
TestPostAPI(unittest.TestCase):

 def setUp(self):
   request = Request(env=[])  # new request

 def test_some_function(self):
   request.vars['var5'] = "asdf"
   request.vars['var6'] = 6
   request.env.request_method = 'POST'
   response = api() # call api

   self.assertEquals(response['result'], 'success')

 def tearDown(self):
   db.table.truncate()  # clean up db (nothing request related here)


# Run tests
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestPutAPI))
suite.addTest(unittest.makeSuite(TestPostAPI))

unittest.TextTestRunner(verbosity=2).run(suite)


Is my entire approach to unit testing wrong? I know there's a lot a 
mention of doctests being recommended, also that the line request = 
Request() recommended by the original article also being wrong (or 
simply out of date), but I'm also unsure of how the request and api 
call is being processed in this scenario. Earlier I tried doing 2 
calls to the same api in one test function and found that web2py 
(and this unittest) simply could not overwrite the request function 
- if that made any sense (it didn't, and didn't work).


Anyone have any pointers?

Thank you,
KH


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


--
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] Unit testing apis

2018-03-07 Thread António Ramos
Next chapter in web2py book

*Pytest your app the right way*

2018-03-07 18:02 GMT+00:00 Yoel Benítez Fonseca :

> H!
>
> checkout: https://github.com/viniciusban/web2py.test
>
>
>
> On Wed, Mar 7, 2018 at 10:10 AM, Kevin Huang  wrote:
>
>>
>> Hi all,
>>
>>
>> I'm relatively new to web2py, and still trying to find more resources,
>> but i've hit a wall, and I'm not quite sure on this issue I'm working with:
>>
>>
>> So working with the "guide" from http://web2py.com/AlterEgo/def
>> ault/show/260, I'm trying to create a few unit tests to test some
>> RESTFUL api functions. However, while testing multiple test suites, it
>> seems that the request information is carrying over somehow despite my
>> attempts to make sure that I start with a new request object via setUp each
>> time.
>>
>> The tests will run just fine if they're alone in the suite, but running
>> some of them after the other I was running into HTTP 400 errors and during
>> debugging I found out that the request data carrying over.
>>
>> Some "sample" code to illustrate what I was trying to do...
>>
>> import unittest
>> from gluon.globals import Request
>>
>> # import api code
>> execfile("applications/appname/controllers/app_api.py", globals())class
>>
>>
>> # Test Put api
>> TestPutAPI(unittest.TestCase):
>>
>>  def setUp(self):
>>request = Request(env=[])  # new request, env must be set.
>>
>>  def test_some_function(self):
>>request.vars['var1'] = 1
>>request.vars['var2'] = 2
>>request.env.request_method = 'PUT'
>>response = api() # call api
>>
>>self.assertEquals(response['result'], 'success')
>>
>>   def tearDown(self):
>>db.table.truncate()  # clean up db (nothing request related here)
>>
>>
>> # Test Post api
>> TestPostAPI(unittest.TestCase):
>>
>>  def setUp(self):
>>request = Request(env=[])  # new request
>>
>>  def test_some_function(self):
>>request.vars['var5'] = "asdf"
>>request.vars['var6'] = 6
>>request.env.request_method = 'POST'
>>response = api() # call api
>>
>>self.assertEquals(response['result'], 'success')
>>
>>  def tearDown(self):
>>db.table.truncate()  # clean up db (nothing request related here)
>>
>>
>> # Run tests
>> suite = unittest.TestSuite()
>> suite.addTest(unittest.makeSuite(TestPutAPI))
>> suite.addTest(unittest.makeSuite(TestPostAPI))
>>
>> unittest.TextTestRunner(verbosity=2).run(suite)
>>
>>
>> Is my entire approach to unit testing wrong? I know there's a lot a
>> mention of doctests being recommended, also that the line request =
>> Request() recommended by the original article also being wrong (or simply
>> out of date), but I'm also unsure of how the request and api call is being
>> processed in this scenario. Earlier I tried doing 2 calls to the same api
>> in one test function and found that web2py (and this unittest) simply could
>> not overwrite the request function - if that made any sense (it didn't, and
>> didn't work).
>>
>> Anyone have any pointers?
>>
>> Thank you,
>> KH
>>
>>
>> --
>> 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.
>

-- 
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] Unit testing apis

2018-03-07 Thread Yoel Benítez Fonseca

H!

checkout: https://github.com/viniciusban/web2py.test


On Wed, Mar 7, 2018 at 10:10 AM, Kevin Huang  wrote:


Hi all,


I'm relatively new to web2py, and still trying to find more 
resources, but i've hit a wall, and I'm not quite sure on this issue 
I'm working with:



So working with the "guide" from 
http://web2py.com/AlterEgo/default/show/260, I'm trying to create a 
few unit tests to test some RESTFUL api functions. However, while 
testing multiple test suites, it seems that the request information 
is carrying over somehow despite my attempts to make sure that I 
start with a new request object via setUp each time.


The tests will run just fine if they're alone in the suite, but 
running some of them after the other I was running into HTTP 400 
errors and during debugging I found out that the request data 
carrying over.


Some "sample" code to illustrate what I was trying to do...

import unittest
from gluon.globals import Request

# import api code
execfile("applications/appname/controllers/app_api.py", 
globals())class



# Test Put api
TestPutAPI(unittest.TestCase):

 def setUp(self):
   request = Request(env=[])  # new request, env must be set.

 def test_some_function(self):
   request.vars['var1'] = 1
   request.vars['var2'] = 2
   request.env.request_method = 'PUT'
   response = api() # call api

   self.assertEquals(response['result'], 'success')

  def tearDown(self):
   db.table.truncate()  # clean up db (nothing request related here)


# Test Post api
TestPostAPI(unittest.TestCase):

 def setUp(self):
   request = Request(env=[])  # new request

 def test_some_function(self):
   request.vars['var5'] = "asdf"
   request.vars['var6'] = 6
   request.env.request_method = 'POST'
   response = api() # call api

   self.assertEquals(response['result'], 'success')

 def tearDown(self):
   db.table.truncate()  # clean up db (nothing request related here)


# Run tests
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestPutAPI))
suite.addTest(unittest.makeSuite(TestPostAPI))

unittest.TextTestRunner(verbosity=2).run(suite)


Is my entire approach to unit testing wrong? I know there's a lot a 
mention of doctests being recommended, also that the line request = 
Request() recommended by the original article also being wrong (or 
simply out of date), but I'm also unsure of how the request and api 
call is being processed in this scenario. Earlier I tried doing 2 
calls to the same api in one test function and found that web2py (and 
this unittest) simply could not overwrite the request function - if 
that made any sense (it didn't, and didn't work).


Anyone have any pointers?

Thank you,
KH


--
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: How many concurrent requests can a web2py instance handle?

2018-03-07 Thread nethugolol
Thanks 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] Unit testing apis

2018-03-07 Thread António Ramos
Some discussion here
https://groups.google.com/forum/#!topic/web2py/4HdkjbnlhBU

There should be a link in web2py docs to suggest the best way to test.

Regards

2018-03-07 15:10 GMT+00:00 Kevin Huang :

>
> Hi all,
>
>
> I'm relatively new to web2py, and still trying to find more resources, but
> i've hit a wall, and I'm not quite sure on this issue I'm working with:
>
>
> So working with the "guide" from http://web2py.com/AlterEgo/
> default/show/260, I'm trying to create a few unit tests to test some
> RESTFUL api functions. However, while testing multiple test suites, it
> seems that the request information is carrying over somehow despite my
> attempts to make sure that I start with a new request object via setUp each
> time.
>
> The tests will run just fine if they're alone in the suite, but running
> some of them after the other I was running into HTTP 400 errors and during
> debugging I found out that the request data carrying over.
>
> Some "sample" code to illustrate what I was trying to do...
>
> import unittest
> from gluon.globals import Request
>
> # import api code
> execfile("applications/appname/controllers/app_api.py", globals())class
>
>
> # Test Put api
> TestPutAPI(unittest.TestCase):
>
>  def setUp(self):
>request = Request(env=[])  # new request, env must be set.
>
>  def test_some_function(self):
>request.vars['var1'] = 1
>request.vars['var2'] = 2
>request.env.request_method = 'PUT'
>response = api() # call api
>
>self.assertEquals(response['result'], 'success')
>
>   def tearDown(self):
>db.table.truncate()  # clean up db (nothing request related here)
>
>
> # Test Post api
> TestPostAPI(unittest.TestCase):
>
>  def setUp(self):
>request = Request(env=[])  # new request
>
>  def test_some_function(self):
>request.vars['var5'] = "asdf"
>request.vars['var6'] = 6
>request.env.request_method = 'POST'
>response = api() # call api
>
>self.assertEquals(response['result'], 'success')
>
>  def tearDown(self):
>db.table.truncate()  # clean up db (nothing request related here)
>
>
> # Run tests
> suite = unittest.TestSuite()
> suite.addTest(unittest.makeSuite(TestPutAPI))
> suite.addTest(unittest.makeSuite(TestPostAPI))
>
> unittest.TextTestRunner(verbosity=2).run(suite)
>
>
> Is my entire approach to unit testing wrong? I know there's a lot a
> mention of doctests being recommended, also that the line request =
> Request() recommended by the original article also being wrong (or simply
> out of date), but I'm also unsure of how the request and api call is being
> processed in this scenario. Earlier I tried doing 2 calls to the same api
> in one test function and found that web2py (and this unittest) simply could
> not overwrite the request function - if that made any sense (it didn't, and
> didn't work).
>
> Anyone have any pointers?
>
> Thank you,
> KH
>
>
> --
> 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] Unit testing apis

2018-03-07 Thread Kevin Huang

Hi all,


I'm relatively new to web2py, and still trying to find more resources, but 
i've hit a wall, and I'm not quite sure on this issue I'm working with:


So working with the "guide" from 
http://web2py.com/AlterEgo/default/show/260, I'm trying to create a few 
unit tests to test some RESTFUL api functions. However, while testing 
multiple test suites, it seems that the request information is carrying 
over somehow despite my attempts to make sure that I start with a new 
request object via setUp each time.

The tests will run just fine if they're alone in the suite, but running 
some of them after the other I was running into HTTP 400 errors and during 
debugging I found out that the request data carrying over.

Some "sample" code to illustrate what I was trying to do...

import unittest
from gluon.globals import Request

# import api code
execfile("applications/appname/controllers/app_api.py", globals())class 


# Test Put api
TestPutAPI(unittest.TestCase):

 def setUp(self):
   request = Request(env=[])  # new request, env must be set.

 def test_some_function(self):
   request.vars['var1'] = 1
   request.vars['var2'] = 2
   request.env.request_method = 'PUT'
   response = api() # call api

   self.assertEquals(response['result'], 'success') 

  def tearDown(self):
   db.table.truncate()  # clean up db (nothing request related here)


# Test Post api
TestPostAPI(unittest.TestCase):

 def setUp(self):
   request = Request(env=[])  # new request

 def test_some_function(self):
   request.vars['var5'] = "asdf"
   request.vars['var6'] = 6
   request.env.request_method = 'POST'
   response = api() # call api

   self.assertEquals(response['result'], 'success') 

 def tearDown(self):
   db.table.truncate()  # clean up db (nothing request related here)


# Run tests
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestPutAPI))
suite.addTest(unittest.makeSuite(TestPostAPI))

unittest.TextTestRunner(verbosity=2).run(suite)


Is my entire approach to unit testing wrong? I know there's a lot a mention 
of doctests being recommended, also that the line request = Request() 
recommended by the original article also being wrong (or simply out of 
date), but I'm also unsure of how the request and api call is being 
processed in this scenario. Earlier I tried doing 2 calls to the same api 
in one test function and found that web2py (and this unittest) simply could 
not overwrite the request function - if that made any sense (it didn't, and 
didn't work).

Anyone have any pointers?

Thank you,
KH


-- 
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: Unexpected behaviour executing a query with DAL and record versioning enabled

2018-03-07 Thread 'Awe' via web2py-users
Hello Richard,
have read your post 3 times, but I can't find the right query result.
Could you tell me where to find in your test the query which leads to:
test1.titletest2.title
PeterNone
PaulLaptop

Thank you.




Am Mittwoch, 7. März 2018 17:33:33 UTC+1 schrieb Richard:
>
> Here some tests : 
>
> *WITH record versioning*
>
> In [1]: db(db.test.id < 0).select()
> Out[1]: 
>
> In [2]: db(db.test.id > 0).select()
> Out[2]: 
>
> In [3]: test1 = db.test.with_alias('test1')
>
> In [4]: test2 = db.test.with_alias('test2')
>
> In [5]: query = (test2.type_marker=='object') | (test2.type_marker==None) 
> & (test1.type_marker=='person')
>
> In [6]: db().select(current.db.test.ALL)
> ---
> NameError Traceback (most recent call last)
> /web2py_master_trunk/web2py/applications/test_versioning_issue/models/menu.py 
> in ()
> > 1 db().select(current.db.test.ALL)
>
> NameError: name 'current' is not defined
>
> In [7]: db().select(db.test.ALL)
> Out[7]: 
>
> In [8]: query = (test2.type_marker=='object') & 
> (test1.type_marker=='person')
>
> In [9]: db().select(db.test.ALL)
> Out[9]: 
>
> In [10]: db(query).select(test1.title, test2.title, left=test2.on(test1.id
> ==test2.granny))
> Out[10]: 
>
> In [11]: db(query)._select(test1.title, test2.title, left=test2.on(
> test1.id==test2.granny))
> Out[11]: 'SELECT "test1"."title", "test2"."title" FROM "test" AS "test1" 
> LEFT JOIN "test" AS "test2" ON (("test1"."id" = "test2"."granny") AND 
> (("test1"."is_active" = \'T\') AND ("test2"."is_active" = \'T\'))) WHERE 
> "test2"."type_marker" = \'object\') AND ("test1"."type_marker" = 
> \'person\')) AND (("test1"."is_active" = \'T\') AND ("test2"."is_active" = 
> \'T\'))) AND (("test1"."is_active" = \'T\') AND ("test2"."is_active" = 
> \'T\')));'
>
> In [12]: print db().select(db.test.ALL)
> test.id
> ,test.title,test.granny,test.type_marker,test.is_active,test.created_on,test.created_by,test.modified_on,test.modified_by
> 1,Peter,,person,True,2018-03-07 11:10:08,,2018-03-07 
> 11:10:08,
> 2,Paul,,person,True,2018-03-07 11:10:08,,2018-03-07 
> 11:10:08,
> 3,Laptop,2,object,True,2018-03-07 11:10:08,,2018-03-07 
> 11:10:08,
>
>
> *WITHOUT record versioning*
>
> In [1]: db(db.test.id > 0).select()
> Out[1]: 
>
> In [2]:  test1 = db.test.with_alias('test1')
>
> In [3]: test2 = db.test.with_alias('test2')
>
> In [4]: query = (test2.type_marker=='object') | (test2.type_marker==None) 
> & (test1.type_marker=='person')
>...: 
>
> In [5]: db().select(db.test.ALL)
> Out[5]: 
>
> In [6]: query = (test2.type_marker=='object') & 
> (test1.type_marker=='person')
>
> In [7]: db().select(db.test.ALL)
> Out[7]: 
>
> In [8]: db(query).select(test1.title, test2.title, left=test2.on(test1.id
> ==test2.granny))
> Out[8]: 
>
> In [9]: db(query)._select(test1.title, test2.title, left=test2.on(test1.id
> ==test2.granny))
> Out[9]: 'SELECT "test1"."title", "test2"."title" FROM "test" AS "test1" 
> LEFT JOIN "test" AS "test2" ON ("test1"."id" = "test2"."granny") WHERE 
> (("test2"."type_marker" = \'object\') AND ("test1"."type_marker" = 
> \'person\'));'
>
> In [10]: print db().select(db.test.ALL)
> test.id
> ,test.title,test.granny,test.type_marker,test.is_active,test.created_on,test.created_by,test.modified_on,test.modified_by
> 1,Peter,,person,True,2018-03-07 11:10:08,,2018-03-07 
> 11:10:08,
> 2,Paul,,person,True,2018-03-07 11:10:08,,2018-03-07 
> 11:10:08,
> 3,Laptop,2,object,True,2018-03-07 11:10:08,,2018-03-07 
> 11:10:08,
>
>
>
>
> *I have this in db.py of a newly created app with web2py trunk/master :*
>
> ```python
> db.define_table('test',
>Field('title', 'string'),
>Field('granny', 'reference test'),  # convenience - 
> topmost
>Field('type_marker', 'string'),
>auth.signature,
>)
>
> db.test._enable_record_versioning(archive_db=db,
>   archive_name='test_archive',
>   current_record='current_record',
>   is_active='is_active'
>   )
>
> if db(db.test.id > 0).count() == 0:
> db.test.insert(title='Peter', granny=None, type_marker='person')
> db.test.insert(title='Paul', granny=None, type_marker='person')
> db.test.insert(title='Laptop', granny=2, type_marker='object')
> ```
> You can start the web2py shell like this :
>
> python web2py.py -a 'DUMMYPWD' -i 127.0.0.1 -p 8001 -S 
> test_versioning_issue -M
>
>
>
> I don't notice any discrepency between both result, I mean I recover 3 
> records in both case... It makes sens that the raw query change to make 
> sure it select only active records...
>
> It mays happen that you experiment an issue with the web2py version that 
> you use 2.15.4...
>
> You may consider trying the above with a freshly 

Re: [web2py] Re: Unexpected behaviour executing a query with DAL and record versioning enabled

2018-03-07 Thread Richard Vézina
Here some tests :

*WITH record versioning*

In [1]: db(db.test.id < 0).select()
Out[1]: 

In [2]: db(db.test.id > 0).select()
Out[2]: 

In [3]: test1 = db.test.with_alias('test1')

In [4]: test2 = db.test.with_alias('test2')

In [5]: query = (test2.type_marker=='object') | (test2.type_marker==None) &
(test1.type_marker=='person')

In [6]: db().select(current.db.test.ALL)
---
NameError Traceback (most recent call last)
/web2py_master_trunk/web2py/applications/test_versioning_issue/models/menu.py
in ()
> 1 db().select(current.db.test.ALL)

NameError: name 'current' is not defined

In [7]: db().select(db.test.ALL)
Out[7]: 

In [8]: query = (test2.type_marker=='object') &
(test1.type_marker=='person')

In [9]: db().select(db.test.ALL)
Out[9]: 

In [10]: db(query).select(test1.title, test2.title, left=test2.on(test1.id
==test2.granny))
Out[10]: 

In [11]: db(query)._select(test1.title, test2.title, left=test2.on(test1.id
==test2.granny))
Out[11]: 'SELECT "test1"."title", "test2"."title" FROM "test" AS "test1"
LEFT JOIN "test" AS "test2" ON (("test1"."id" = "test2"."granny") AND
(("test1"."is_active" = \'T\') AND ("test2"."is_active" = \'T\'))) WHERE
"test2"."type_marker" = \'object\') AND ("test1"."type_marker" =
\'person\')) AND (("test1"."is_active" = \'T\') AND ("test2"."is_active" =
\'T\'))) AND (("test1"."is_active" = \'T\') AND ("test2"."is_active" =
\'T\')));'

In [12]: print db().select(db.test.ALL)
test.id
,test.title,test.granny,test.type_marker,test.is_active,test.created_on,test.created_by,test.modified_on,test.modified_by
1,Peter,,person,True,2018-03-07 11:10:08,,2018-03-07
11:10:08,
2,Paul,,person,True,2018-03-07 11:10:08,,2018-03-07
11:10:08,
3,Laptop,2,object,True,2018-03-07 11:10:08,,2018-03-07 11:10:08,


*WITHOUT record versioning*

In [1]: db(db.test.id > 0).select()
Out[1]: 

In [2]:  test1 = db.test.with_alias('test1')

In [3]: test2 = db.test.with_alias('test2')

In [4]: query = (test2.type_marker=='object') | (test2.type_marker==None) &
(test1.type_marker=='person')
   ...:

In [5]: db().select(db.test.ALL)
Out[5]: 

In [6]: query = (test2.type_marker=='object') &
(test1.type_marker=='person')

In [7]: db().select(db.test.ALL)
Out[7]: 

In [8]: db(query).select(test1.title, test2.title, left=test2.on(test1.id
==test2.granny))
Out[8]: 

In [9]: db(query)._select(test1.title, test2.title, left=test2.on(test1.id
==test2.granny))
Out[9]: 'SELECT "test1"."title", "test2"."title" FROM "test" AS "test1"
LEFT JOIN "test" AS "test2" ON ("test1"."id" = "test2"."granny") WHERE
(("test2"."type_marker" = \'object\') AND ("test1"."type_marker" =
\'person\'));'

In [10]: print db().select(db.test.ALL)
test.id
,test.title,test.granny,test.type_marker,test.is_active,test.created_on,test.created_by,test.modified_on,test.modified_by
1,Peter,,person,True,2018-03-07 11:10:08,,2018-03-07
11:10:08,
2,Paul,,person,True,2018-03-07 11:10:08,,2018-03-07
11:10:08,
3,Laptop,2,object,True,2018-03-07 11:10:08,,2018-03-07 11:10:08,




*I have this in db.py of a newly created app with web2py trunk/master :*

```python
db.define_table('test',
   Field('title', 'string'),
   Field('granny', 'reference test'),  # convenience -
topmost
   Field('type_marker', 'string'),
   auth.signature,
   )

db.test._enable_record_versioning(archive_db=db,
  archive_name='test_archive',
  current_record='current_record',
  is_active='is_active'
  )

if db(db.test.id > 0).count() == 0:
db.test.insert(title='Peter', granny=None, type_marker='person')
db.test.insert(title='Paul', granny=None, type_marker='person')
db.test.insert(title='Laptop', granny=2, type_marker='object')
```
You can start the web2py shell like this :

python web2py.py -a 'DUMMYPWD' -i 127.0.0.1 -p 8001 -S
test_versioning_issue -M



I don't notice any discrepency between both result, I mean I recover 3
records in both case... It makes sens that the raw query change to make
sure it select only active records...

It mays happen that you experiment an issue with the web2py version that
you use 2.15.4...

You may consider trying the above with a freshly create dummy app with the
db.py additions above and see by yourself... If you get the same results it
means that your own app may have been wrongly initialized in some way... If
yous till experiment the issue, try with the stable web2py version from the
web2py.com download page...

Please report here your progress...

If you determine that the issue is related to your old version of web2py,
please consider upgrade to the newer stable or wait for the next release
that Massimo's want to push soon.

Thanks

Richard

On Wed, Mar 7, 2018 at 5:35 AM, 'Awe' via web2py-users <

[web2py] Re: prevent multiple session at the same time

2018-03-07 Thread Anthony
On Wednesday, March 7, 2018 at 1:02:56 AM UTC-5, Massimo Di Pierro wrote:
>
> it is possible. 
>
> when a user first logs in, store a uuid in the session and write it in the 
> database (in a new custom field in the auth_user table). When a request 
> arrives if the uuid in the session does not match the uuid in the database 
> call auth.logout()
>

Be aware, that will require a database select on every request. If you want 
to minimize the database hits, you could also store in the session the time 
of the last database lookup, and then only check the database every X 
minutes (the tradeoff being that it could take up to X minutes to disable 
the first session after the second session has begun -- if you must ensure 
zero overlap of sessions, then you'll have to do the database check on 
every request).

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] _href to URL()

2018-03-07 Thread Anthony
On Wednesday, March 7, 2018 at 12:39:42 AM UTC-5, 黄祥 wrote:
>
> agree, so what is the best way to make a menu in web2py that can contain a 
> href with it's attribute like accesskey and title?
>

Here's the code currently used in the layout to generate the menu from 
response.menu: 
https://github.com/web2py/web2py/blob/f6d2f8a2a14bd8931fb571c9795d55fed1f4fe0d/applications/welcome/views/layout.html#L45

If you want to specify something other than just the href and the text of 
the menu item, you'll need to edit that code accordingly.

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.


[web2py] Re: SQLFORM.grid buttons

2018-03-07 Thread Esprit Garonne
Many Thanks, 
Omg! I am really enjoying to test  this framework. 

On Tuesday, March 6, 2018 at 8:33:26 PM UTC+1, Esprit Garonne wrote:
>
> Hello, 
> Does it a bug All buttons in SQLFORM have only text link. And I am working 
> on school project for carpool, Could someone help me 
> to build "etapes" like this https://www.blablacar.fr/offer-seats/1
> I need only  how to add city or remove it for a "one trajet"  Could I do 
> it with SQLFORM.factory with JQUERY?
> Many thx
> This is my model 
>  
> db.define_table('t_villes',
> Field('dep', type='string', notnull=True,
>   label=T('Département')),
> Field('nom', type='string', notnull=True,
>   label=T('ville')),
> Field('code_postal', type='string', notnull=True,
>   label=T('Code postal')),
> Field('longitude_deg', type='float', notnull=True,
>   label=T('Longitude')),
> Field('latitude_deg', type='float', notnull=True,
>   label=T('Latitude')),
> format='%(nom)s %(code_postal)s'
>)
>
>
> db.define_table(
> 't_trajets',
> Field('membre_voiture_id','reference t_voitures'),
> Field('lieu_depart_id','reference t_villes',requires=
> IS_IN_DB(db,'t_villes.id','t_villes.nom')),
> Field('lieu_arrive_id',db.t_villes),
> Field('depart_le','datetime'),
> Field('frequence',requires=IS_IN_SET(FREQUENCES),default=
> FREQUENCES[0]),
> Field('type',requires=IS_IN_SET(TYPE_TRAJETS),default=
> TYPE_TRAJETS[0]),
> Field('fumeur',requires=IS_IN_SET(FUMEUR),default=FUMEUR[1
> ]),
> Field('commentaire','text'),
>
> Field( 'place_offert','integer'),
>auth.signature
>  
> 
> )
> db.define_table('t_etapes_ville',
> Field('trajet_id','reference t_trajets',requires=IS_IN_DB(db,'
> t_trajets.id','t_trajets.lieu_depart_id')),
> Field('ville_id',db.t_villes,requires=IS_IN_DB(db,'t_villes.id',
> 't_villes.nom')),
> Field('ordre_depart','integer'),
>
>)
>
>
>
>

-- 
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] Off Topic:Pony

2018-03-07 Thread António Ramos
Nice ...
https://ponyorm.com/

-- 
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: Unexpected behaviour executing a query with DAL and record versioning enabled

2018-03-07 Thread 'Awe' via web2py-users
Great, many thanks for testing it.
Andreas

Am Dienstag, 6. März 2018 22:30:59 UTC+1 schrieb Richard:
>
> Can you make a model definition with a fixture for loading the table, I 
> will make some test with trunk and various version to determine if it a 
> regression... Nevermind I just thought you provide that in the first 
> email... Let me have a look at that...
>
> Richard
>
>
>
> On Mon, Mar 5, 2018 at 2:02 PM, 'Awe' via web2py-users <
> web...@googlegroups.com > wrote:
>
>> Hello Richard,
>> it is not a problem of deleted or changed records. As shown in the 
>> example, there is the table and versioning defined. After that 3 records 
>> are inserted and then the query is executed.
>> The defined query:
>> query = (test2.type_marker=='object') | (test2.type_marker==None) & 
>> (test1.type_marker=='person')
>> rows = current.db(query).select(test1.title, test2.title, 
>> left=test2.on(test1.id==test2.granny))
>> does not give the right result.
>> I appreciate your help, maybe the problem gets easier to understand if 
>> you try to test the given example.
>> Many thanks,
>> Andreas
>>
>>
>> Am Montag, 5. März 2018 16:05:26 UTC+1 schrieb Richard:
>>>
>>> Did you set the actual record that have been deleted to is_active = 
>>> False?? Or all the records that haven't be deleted yet to TRUE?? You have 
>>> to go in your backend and do an update there
>>>
>>> UPDATE stored_item
>>> SET is_active = TRUE
>>>   WHERE is_active IS NULL
>>>
>>> If you didn't delete any record yet...
>>>
>>> You can also do it from web2py I guess with this command :
>>>
>>> db(db.stored_item.is_active == None).update(is_active=True)
>>> db.commit()
>>>
>>> Then you both query should return the same thing... Or at least they 
>>> should...
>>>
>>> It important to initialize archive table and parent table properly when 
>>> you add audit trail table to an already existing table containing record.
>>>
>>> I encourage you to read the book about record versioning : 
>>> http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Record-versioning
>>>
>>> Richard
>>>
>>> On Sun, Mar 4, 2018 at 12:53 PM, 'Awe' via web2py-users <
>>> web...@googlegroups.com> wrote:
>>>
 Hello Richard, many thanks for analyzing. Everything you wrote is 
 completely right. But I still do not understand the behaviour explained 
 before.
 If you look at the table posted before, all is_acitve Flags are TRUE.
 to get the result I need, I have defined:
 query = (test2.type_marker=='object') | (test2.type_marker==None) & 
 (test1.type_marker=='person')
 rows = current.db(query).select(test1.title, test2.title, 
 left=test2.on(test1.id==test2.granny))

 the raw sql of this query WITHOUT record versioning is fine.
 SELECT "test1"."title", "test2"."title" FROM "test" AS "test1" LEFT 
 JOIN "test" AS "test2" ON ("test1"."id" = "test2"."granny") WHERE 
 (("test2"."type_marker" = 'object') OR (("test2"."type_marker" IS NULL) 
 AND 
 ("test1"."type_marker" = 'person')));
 And the result is the way it suposed to be:

 test1.titletest2.title
 PeterNone
 PaulLaptop

 The result with record versioning enabled is different:
 test1.titletest2.title
 PaulLaptop

 Even when the is_acitve Field is defined like that:

 Field('is_active', 'boolean', writable=False, readable=False, 
 default=True,required=True, requires=IS_NOT_EMPTY()),

 So maybe I miss something? At the moment I still wonder why the identical 
 query comes to different results.


 Best regards, an many thanks for your help!
 Andreas





 Am Freitag, 2. März 2018 16:59:35 UTC+1 schrieb Richard:
>
> Hmmm... I think that if you have record versioning activated there 
> shouldn't be any is_active row(s) with NULL value... I mean is_active 
> flag 
> is used to determine if the record in the "parent" table has been deleted 
> or not, since you can truely deleted in case you use record versioning 
> feature as all the previous record stated records contained in the 
> versioning table reference the parent record in the parent table...
>
> And you see in the second example here :
>
>
> http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer?search=record+versioning#Record-versioning
>
> That is_active is set to default=True and there is this note :
>
> Notice the hidden boolean field called is_active and defaulting to 
> True.
>
> So if you have activated record versioning feature over an already 
> existing table you need to set is_active to TRUE for all the existing 
> record once you start using the versioning feature and set the is_active 
> to 
> be mandatory...
>
> I guess it would make sens to change seconde book example in 

Re: [web2py] Re: prevent multiple session at the same time

2018-03-07 Thread Manuele Pesenti

Thanks a lot Massimo! As precious as ever.
:)

    M.


On 07/03/2018 07:02, Massimo Di Pierro wrote:

it is possible.

when a user first logs in, store a uuid in the session and write it in 
the database (in a new custom field in the auth_user table). When a 
request arrives if the uuid in the session does not match the uuid in 
the database call auth.logout()


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