[web2py] Guarantee closing of DB connections when using PyDAL outside a request

2018-05-05 Thread Brendan Barnwell
I think this question is more about PyDAL than web2py. What I'm doing is using the web2py shell to call functions and do stuff within a web2py app, but without actually running the web server. Everything happens within a Python shell. In this environment, database transactions are not

[web2py] Re: Generate ticket "manually"

2017-12-14 Thread Brendan Barnwell
On Thursday, December 14, 2017 at 4:10:40 AM UTC-8, Anthony wrote: > > Could be a little complicated. The relevant code is in gluon.restricted -- > see > https://github.com/web2py/web2py/blob/4f51647b2f5bd68887ddd9fe139c6bbc0fa885d4/gluon/restricted.py#L115 > . > > That is unfortunate. Would be

[web2py] Generate ticket "manually"

2017-12-13 Thread Brendan Barnwell
In some situations, when my web2py code raises an exception, what I want to do is log information about what happened, but then handle it in some way that doesn't involve the default error handling. The advantage of the default error handling, though, is that it generates an error ticket. Is

[web2py] Re: Is there a way to use the DAL to specify a one-sided limit (aka offset)?

2017-12-13 Thread Brendan Barnwell
On Wednesday, December 13, 2017 at 8:40:18 AM UTC-8, Anthony wrote: > > You'll either have to first retrieve the total record count or just use a > number you know will be larger than the record count. Feel free to open an > issue in the PyDAL repo. > > Note, not all databases support "offset"

[web2py] Is there a way to use the DAL to specify a one-sided limit (aka offset)?

2017-12-13 Thread Brendan Barnwell
I would like to be able to do a query that does something like "give me the rows from the Nth row to the end, no matter how many rows there are". I can use limitby to get the first N rows, but I can't find a way to say "get all rows except for the first N rows". This seems especially perverse

[web2py] Re: Build query without DB connection

2017-09-21 Thread Brendan Barnwell
On Wednesday, September 20, 2017 at 10:31:04 PM UTC-7, Massimo Di Pierro wrote: > > In web2py, and in general in code that runs multithreaded you should not > define variables in modules at top level and then import them because they > are cached and then shared by multiple threads. That is not

[web2py] Build query without DB connection

2017-09-20 Thread Brendan Barnwell
It seems that the "db" object given by the DAL wraps up not only the database definition, but also a "live" connection to the database. This means that if the db object is stashed somewhere, it can go "stale" and attempts to use it later will lead to strange errors. Is that so? What I'm

[web2py] Storing stuff on request object

2017-09-14 Thread Brendan Barnwell
Is it considered kosher for controller functions to add their own custom data to the request object? I didn't see anything in the docs about this. For instance if a controller wants to do request.some_stuff = 123, is that "allowed"? The reason for this is that I have some library functions

[web2py] Re: Launch web2py shell from within a running interpreter session

2017-08-31 Thread Brendan Barnwell
On Thursday, August 31, 2017 at 8:05:51 AM UTC-7, Anthony wrote: > > Here is a variation of something I use in Jupyter notebook: > > import os > import gluon.shell > from gluon.settings import global_settings > from gluon.storage import Storage > > def web2py_environment(app, controller=None,

[web2py] Launch web2py shell from within a running interpreter session

2017-08-31 Thread Brendan Barnwell
I use DreamPie, a wrapper around the Python interpreter. I would like to be able to use the web2py console shell from within DreamPie. I could also imagine wanting to use it from within other alternative Python interpreters, for instance inside the IPython QT console or a console embedded in

[web2py] Re: Alias column names (akin to AS clause) in db select

2017-08-28 Thread Brendan Barnwell
On Monday, July 31, 2017 at 1:25:31 PM UTC-7, Paolo Caruccio wrote: > > Maybe the web2py book could help you: > > > http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer?search=with_alias#Self-Reference-and-aliases > > That appears to only be talking about using aliases

[web2py] Re: Alias column names (akin to AS clause) in db select

2017-07-30 Thread Brendan Barnwell
On Monday, May 29, 2017 at 11:30:53 PM UTC-7, Brendan Barnwell wrote: > > When running queries that do joins, I often find the format of the result > somewhat cumbersome, with its nested structures representing the different > tables in the join. If I were writing the query in raw

[web2py] Re: Totally app-internal routing

2017-06-30 Thread Brendan Barnwell
On Thursday, June 29, 2017 at 8:27:01 AM UTC-7, Anthony wrote: > > You need to have at least a basic routes.py in the root /web2py folder, > but for application specific routing, you can also put a routes.py file in > the application folder (i.e., in /web2py/applications/myapp/). > Okay. . .

[web2py] Totally app-internal routing

2017-06-28 Thread Brendan Barnwell
Looking at the routing discussion in the docs, it seems that any kind of custom routing has to be defined at the global level of the entire web2py install. Is that correct? This seems awkward if I want to write an app that carries with it its own knowledge of how it wants to route its

[web2py] Re: Future of web2py

2017-06-12 Thread Brendan Barnwell
> > You can put anything that would go on a full page (including any form) in > an Ajax component. Forms in components are submitted via Ajax (they are no > less "real" than forms loaded in full pages), and only the component itself > refreshes upon submission. It is not quite clear what else

[web2py] Re: Future of web2py

2017-06-11 Thread Brendan Barnwell
On Wednesday, June 7, 2017 at 8:16:38 PM UTC-7, tesser...@gmail.com wrote: > > According to github, there were semi-regular releases going back to 2013, > then they stopped about a year ago, so I guess it's only natural for people > to wonder about the status of the project. Personally, I'm

[web2py] Alias column names (akin to AS clause) in db select

2017-05-30 Thread Brendan Barnwell
When running queries that do joins, I often find the format of the result somewhat cumbersome, with its nested structures representing the different tables in the join. If I were writing the query in raw SQL, I would probably use "AS" clauses to select just the columns that I want, with

[web2py] Type conversion for args/vars?

2017-05-11 Thread Brendan Barnwell
Does web2py provide any kind of utility to convert the request args and vars "intelligently" into regular Python types? Values passed in the URL or query string will always be received as strings by web2py code, but in many cases they really need to be converted to other types. In a URL like

[web2py] Re: Call functions from other applications without network requests

2017-02-18 Thread Brendan Barnwell
On Saturday, February 18, 2017 at 6:00:23 AM UTC-8, Anthony wrote: > > Do you have a use case that cannot easily be accommodated by that pattern? >> If so, what do you imagine would be the API for doing what you want to do, >> and would it look much different from simply making an HTTP call (or

[web2py] Re: Call functions from other applications without network requests

2017-02-17 Thread Brendan Barnwell
> The simplest approach is to put shared functionality into modules. Of > course, if you don't know in what context a given bit of code will run, you > can easily check whether particular tables have been defined and then call > the table defining code if necessary. > > Maybe it would help to

[web2py] Re: Call functions from other applications without network requests

2017-02-16 Thread Brendan Barnwell
On Thursday, February 16, 2017 at 6:39:37 AM UTC-8, Anthony wrote: > > In your example above, it's one model defining tables from another model. >> But in my case, what I have is a controller function that needs access to >> the db, which is defined in the model file. But I found the hard way

[web2py] Re: Call functions from other applications without network requests

2017-02-16 Thread Brendan Barnwell
On Friday, January 13, 2017 at 8:21:48 AM UTC-8, Anthony wrote: > > > You can use the DAL from modules as well. As Niphlod suggested, you can >>> also use the scheduler to schedule and run a task in the context of another >>> app, though that might not be as fast as you'd like, as even setting

[web2py] Re: Arbitrary args/kwargs with service?

2017-01-29 Thread Brendan Barnwell
On Saturday, January 21, 2017 at 8:52:55 AM UTC-8, Anthony wrote: > > > I created an issue here: https://github.com/web2py/web2py/issues/1561 >> >> I can probably do a pull request, but wanted to see if anyone knows of a >> reason why the existing service functionality restricts the passed >>

[web2py] Re: Arbitrary args/kwargs with service?

2017-01-20 Thread Brendan Barnwell
On Thursday, January 12, 2017 at 1:17:30 AM UTC-8, Anthony wrote: > > Feel free to open a Github issue, or better yet, send a pull request. > I created an issue here: https://github.com/web2py/web2py/issues/1561 I can probably do a pull request, but wanted to see if anyone knows of a reason

[web2py] Re: Curious about history/reasoning behind find_exposed_functions mechanism

2017-01-18 Thread Brendan Barnwell
On Wednesday, January 18, 2017 at 2:12:35 PM UTC-8, Anthony wrote: > > A web2py controller is not like a Python module. It is meant to be > executed in a prepared environment to generate the response to an HTTP > request. Because the top level of the controller may include code you > wouldn't

[web2py] Curious about history/reasoning behind find_exposed_functions mechanism

2017-01-18 Thread Brendan Barnwell
I recently dug into web2py and discovered how it decides which controller functions are exposed as endpoints. I found that it does this with the find_exposed_functions function in compileapp, which uses a regex to textually search the source code of the controller file for lines of the form

[web2py] Re: Call functions from other applications without network requests

2017-01-12 Thread Brendan Barnwell
On Saturday, January 7, 2017 at 11:07:36 AM UTC-8, Anthony wrote: > > On Saturday, January 7, 2017 at 1:57:36 PM UTC-5, Brendan Barnwell wrote: >> >> The shared functionality involves DB access, so as far as I can tell it >> cannot be abstracted into modules tha

[web2py] Re: Arbitrary args/kwargs with service?

2017-01-11 Thread Brendan Barnwell
On Thursday, January 5, 2017 at 7:04:56 AM UTC-8, Anthony wrote: > > But from the other side of things, I guess the question is, if we can do >> that, is there ever any reason to use the "service" mechanism at all? Or >> can request.restful do everything service can do, and more? >> > > I

[web2py] Re: Call functions from other applications without network requests

2017-01-07 Thread Brendan Barnwell
thon modules that can be imported by multiple applications. > > Anthony > > On Thursday, January 5, 2017 at 12:54:59 AM UTC-5, Brendan Barnwell wrote: >> >> I have a situation where I have (or am going to have) multiple >> applications running on a single web2py in

[web2py] Call functions from other applications without network requests

2017-01-04 Thread Brendan Barnwell
I have a situation where I have (or am going to have) multiple applications running on a single web2py instance. Each application will do its own thing, but they are all using the same databases. Some of the applications may serve as backend API endpoints where certain kinds of data can be

[web2py] Re: Arbitrary args/kwargs with service?

2017-01-04 Thread Brendan Barnwell
It looks like I could use request.restful for that, but to be honest I find that mechanism somewhat awkward. Creating functions as local variables and then returning locals() just seems gross to me. :-) But from the other side of things, I guess the question is, if we can do that, is there

[web2py] Re: Arbitrary args/kwargs with service?

2016-12-01 Thread Brendan Barnwell
Just bumping this up to see if anyone has any ideas, as I have again run up against this limitation. The situation I'm in is that I have a number of controller functions which all accept some arguments in common (for instance, an API key that has to be checked to allow access to the resource).

[web2py] No __pow__ on pydal Expression

2016-11-15 Thread Brendan Barnwell
I notice that the pydal Expression class defines magic methods for most math operations, letting you create expression queries like `.select(db.Table.field*2)`. However, it doesn't define a __pow__ method, so I can't do something like `.select(db.Table.field**2)` to get a computed result that

[web2py] Re: Equivalent of request.args(...) for request.vars(...)

2016-11-15 Thread Brendan Barnwell
On Monday, November 14, 2016 at 1:01:26 PM UTC-8, Anthony wrote: > > On Monday, November 14, 2016 at 1:29:11 PM UTC-5, Brendan Barnwell wrote: >> >> You're right that dict.get handles the default value, but the >> functionality available for args includes substantially m

[web2py] Re: Equivalent of request.args(...) for request.vars(...)

2016-11-14 Thread Brendan Barnwell
modifications at the beginning because it's delegating to dict keys rather than list indices). Would there be interest in making this change to web2py? On Monday, November 14, 2016 at 9:50:19 AM UTC-8, Anthony wrote: > > On Monday, November 14, 2016 at 1:53:33 AM UTC-5, Brendan Barnwell

[web2py] Equivalent of request.args(...) for request.vars(...)

2016-11-13 Thread Brendan Barnwell
The request.args object has a handy callable interface that allows specification of default value, type to coerce to, etc. As far as I can tell, the request.vars object has no such interface. Is this right? Why is this? What can I do if I want to access various vars that may or may not be

[web2py] Arbitrary args/kwargs with service?

2016-11-09 Thread Brendan Barnwell
Hi, I've been experimenting the web2py services functionality. Very neat! But what I'm wondering is whether it is possible to expose a service that accepts arbitrary URL parameters and receives them as *args and/or **kwargs. That is, I'd like to have code like this: @service.json def

[web2py] Re: How to keep project separate from web2py itself?

2016-02-01 Thread Brendan Barnwell
On Friday, January 29, 2016 at 6:27:36 AM UTC-8, Anthony wrote: > > On Friday, January 29, 2016 at 3:00:47 AM UTC-5, Niphlod wrote: >> >> PS: didn't have time to read through all, but did you consider using >> web2py.py -f /path/to/applications_directory ? I just fixed a couple of >> issues in

[web2py] Re: How to keep project separate from web2py itself?

2016-01-28 Thread Brendan Barnwell
On Thursday, January 28, 2016 at 10:21:54 AM UTC-8, Anthony wrote: > > On Thursday, January 28, 2016 at 2:37:47 AM UTC-5, Brendan Barnwell wrote: >> >> Yes, I realize I can do that. The problem is that (if I understand >> right) unless I put it in the web2py folder,

[web2py] How to keep project separate from web2py itself?

2016-01-27 Thread Brendan Barnwell
I've recently begun looking at web2py. It looks very nice. However, one thing that seems strange to me is that it is apparently not set up to be installed. Rather, to "install" it you just copy the web2py files (or clone the repo) into a directory. That install then "knows" about all the

[web2py] Re: How to keep project separate from web2py itself?

2016-01-27 Thread Brendan Barnwell
Yes, I realize I can do that. The problem is that (if I understand right) unless I put it in the web2py folder, web2py won't know about it. I can symlink it (or directory-junction it, in windows), but that still seems quite awkward to me. I feel like it would make more sense if the

[web2py] Re: How to keep project separate from web2py itself?

2016-01-27 Thread Brendan Barnwell
ations folder) > > Massimo > > > > > On Wednesday, 27 January 2016 17:05:57 UTC-6, Brendan Barnwell wrote: >> >> I've recently begun looking at web2py. It looks very nice. However, one >> thing that seems strange to me is that it is apparently not se