[web2py] long running rpc call
Hi, We're making a number of rpc calls to other services using jsonrpc, and a few of them are particularly long running. I'd rather not use the scheduler, but instead was wondering if I could associate a jsonrpc httpclient in python to the current context so that longer tasks wouldn't block other incoming requests. I tried initially to just do a setattr on current (it's thread local storage as far as I understand), but that doesn't seem to work. Anyone have better ideas? Or am I just doing this completely wrong. Cheers, Matt -- 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] controller return list instead of string or dict
On Tue, Jul 30, 2013 at 2:11 PM, Matt mbroa...@gmail.com wrote: On Tuesday, July 30, 2013 11:51:08 AM UTC-4, Jonathan Lundell wrote: On 30 Jul 2013, at 8:34 AM, Anthony abas...@gmail.com wrote: Can you show your code? You say you return locals(), but locals() produces a dictionary, so it should ultimately execute a view. Or are you just returning the list directly? Here is a snippit of what we are trying to do: import simplejson @request.restful() def jsonlisttest(): response.view = 'generic.json' def GET(*args, **vars): sample_raw_rpc_response = '[one, two, three]' sample_rpc_response = simplejson.loads(sample_raw_rpc_response) return sample_rpc_response def POST(*args, **vars): return dict() def PUT(*args, **vars): return dict() def DELETE(*args, **vars): return dict() return locals() Ack, that will teach me for using the google groups interface instead of email.. anyway, assume that snippit was actually formatted properly. You'll see that I've added the basic json loading in there, but that is not the actual issue. The issue is that a python list is returned, instead of a dict or just a string, therefore bypassing any of the generic views and auto-concatenating the list into a single string when accessed. Matt A list directly (see the code fragment below). Since generic.json serializes response._vars, it doesn't care about anything in env. You *could* write a view that accepts a dict with a list (or dict) as a well-known name and serialize that, but it's not what generic.json does. Anthony On Tuesday, July 30, 2013 10:28:53 AM UTC-4, Matt wrote: On Tuesday, July 30, 2013 10:26:45 AM UTC-4, Jonathan Lundell wrote: On 30 Jul 2013, at 12:22 AM, Niphlod nip...@gmail.com wrote: can you explain better what's going on ? the generic json view (as any other view) is made to serialize a python object to something (in json's case, a json string). If you already return a string because your code encodes it already, than you don't need any view, because the job the view usually does has been done already by your code. The explanation isn't quite clear. I believe he's returning a list, intending that to be serialized as JSON. But web2py serializes anything that's not a dict as a string, so generic.json (for example) is never used. The question is: what should happen when a controller returns a list? The JSON serializer is happy to serialize a list. Is there any downside in doing it? Does it make any sense right now for a controller to return a list? Exactly. Apologies for lack of clarity. Matt On Monday, July 29, 2013 11:07:35 PM UTC+2, Matt wrote: Hi, We're running into an issue with our restful api where a certain method is returning a json string (eg: ['one', 'two', 'three'] ), however web2py wants to render this as a string even when the request.extension is forced to json, and the response.view is forced to generic.json. I've tracked the issue down to gluon/main.py:231 where it checks if page is a dict, and what seems to be happening is that the valid json string above is instead being concatenated as a string representation. Adding this below the check for dict seems to fix it, but I'm not sure how well it fixes the problem: elif isinstance(page, list): response._vars = page run_view_in(response._view_**environment) page = response.body.getvalue() Any suggestions for other ways to go about fixing this? Thanks, Matt -- --- 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/groups/opt_out. -- --- 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/groups/opt_out.
Re: [web2py] controller return list instead of string or dict
On Tue, Jul 30, 2013 at 2:14 PM, Alan Etkin spame...@gmail.com wrote: The question is: what should happen when a controller returns a list? The JSON serializer is happy to serialize a list. Is there any downside in doing it? Does it make any sense right now for a controller to return a list? It would be inconsistent with this documented part of the workflow ... If the action returns an iterable, this is used to loop and stream the data to the client. ... I suppose that the expected way to return json arrays is to add them to a dictionary and then process them with a custom view (customize the generic view). So the advice is to make generic-list.json, and force that view, expecting that the input is in some format we decide upon. e.g. instead of returning sample_rpc_response, we return dict(result=sample_rpc_response)? Matt -- --- 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/groups/opt_out. -- --- 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/groups/opt_out.
Re: [web2py] controller return list instead of string or dict
On Tue, Jul 30, 2013 at 2:26 PM, Anthony abasta...@gmail.com wrote: @request.restful() def jsonlisttest(): response.view = 'generic.json' def GET(*args, **vars): sample_raw_rpc_response = '[one, two, three]' sample_rpc_response = simplejson.loads(sample_raw_rpc_response) return sample_rpc_response Looks like you're starting with what is already JSON (sample_raw_rpc_response), then converting to a Python list (with simplejson.loads), and then wanting to send it to the generic.json view to be converted back to a JSON string. Why not just deliver the original string: def GET(*args, **vars): sample_raw_rpc_response = '[one, two, three]' return sample_raw_rpc_response Because in between there is a whole lot of other processing.. I was just trying to put together a small test case to show that returning a python list caused a problem. Matt Anthony -- --- 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/groups/opt_out. -- --- 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/groups/opt_out.
Re: [web2py] controller return list instead of string or dict
On Tue, Jul 30, 2013 at 2:31 PM, Anthony abasta...@gmail.com wrote: So the advice is to make generic-list.json, and force that view, expecting that the input is in some format we decide upon. e.g. instead of returning sample_rpc_response, we return dict(result=sample_rpc_**response)? You could do that, but see my other response. Anthony think of it this way: import simplejson @request.restful() def jsonlisttest(): response.view = 'generic.json' def GET(*args, **vars): sample_raw_rpc_response = '[one, two, three]' sample_rpc_response = simplejson.loads(sample_raw_rpc_response) result = someOtherOperationThatCanPOTENTIALLYReturnAList(sample_rpc_response) return result def POST(*args, **vars): return dict() def PUT(*args, **vars): return dict() def DELETE(*args, **vars): return dict() return locals() The problem is that we can't be sure if the operation returns a list or a dict, but we want to render the result as json. So, the solution where we create a generic-list.json doesn't work for us in this case either. We rather unavoidably end up with a list result sometimes, and if that's the case then it just iterates over it and returns a concatenated string. Matt -- --- 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/groups/opt_out. -- --- 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/groups/opt_out.
Re: [web2py] Re: nginx + uwsgi + web2py + PAM
Man, we're still using web2py 2.0.9 so that was definitely not in the script before! That would have saved me a day of work :) Matt On Tue, Apr 2, 2013 at 3:41 AM, Niphlod niph...@gmail.com wrote: nice. The script shipped with web2py installs uwsgi from pip, so we're covered! On Monday, April 1, 2013 4:48:59 PM UTC+2, Matt wrote: On Fri, Mar 29, 2013 at 12:15 PM, Matt Broadstone mbro...@gmail.com wrote: On Fri, Mar 29, 2013 at 12:05 PM, Niphlod nip...@gmail.com wrote: uhm. Before smashing heads against the wall, there are 3 different available methods here. 1) rely on nginx to authenticate users through pam (kinda of a basic auth, but checked against PAM) 2) rely on uwsgi to authenticate users through pam (kinda of a basic auth, but checked against PAM) 3) rely on web2py module to authenticate users through pam Yes, this is my understanding as well. You want the users to reach web2py no matter what, and let the authentication happen using web2py's logic assuming that the only thing you want is not having the username/password combos checked against a table in web2py's database but against PAM's database. Yes, this is what we are trying to do. To reiterate: we always want to provide access to web2py, and through web2py's auth (using a username and password form) we want to authenticate using PAM in the backend. Unless I understood it wrong, apache and rocket work. This means (if you didn't mess with apache configs) that 3) works out of the box What it seems by your config is that you're trying to do 2), i.e. stopping users one step before, letting uwsgi interact deal pam authentication..that is a different thing. Do you want 1), 2) or 3) ? My config is not doing 1 or 2, you may be confused by the fact that I provided an /etc/pam.d/uwsgi configuration, and specified pam in the uwsgi configuration. Here's what I _think_ is going on (though my understanding is spotty at best). * nginx is serving a python application using uwsgi * nginx is properly configured, I can access the site and the web2py app shows up * web2py is running in the context of uwsgi (and thus inherits its permissions) * web2py has a pam auth module that loads a pam library, attempts to connect to pam and authenticate with the credentials provided after all of those steps, I get the messages in my auth.log that I posted above, indicating to me that whatever user is trying to authenticate with pam doesn't actually have the rights to authenticate against the /etc/shadow file. That was my intention with playing around with /etc/pam.d/uwsgi config file, etc. Matt -- --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. Hey all, Just wanted to let you know I figured out what was wrong here. The problem was that ubuntu ships with a quite out-of-date version of uwsgi (1.0.3 in 12.04, and in recent releases only up to 1.2.x), which confuses PAM. If you're trying to do something similar, you need to run a version of uwsgi = 1.4 Matt -- --- 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/groups/opt_out. -- --- 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/groups/opt_out.
Re: [web2py] Re: nginx + uwsgi + web2py + PAM
On Fri, Mar 29, 2013 at 12:15 PM, Matt Broadstone mbroa...@gmail.com wrote: On Fri, Mar 29, 2013 at 12:05 PM, Niphlod niph...@gmail.com wrote: uhm. Before smashing heads against the wall, there are 3 different available methods here. 1) rely on nginx to authenticate users through pam (kinda of a basic auth, but checked against PAM) 2) rely on uwsgi to authenticate users through pam (kinda of a basic auth, but checked against PAM) 3) rely on web2py module to authenticate users through pam Yes, this is my understanding as well. You want the users to reach web2py no matter what, and let the authentication happen using web2py's logic assuming that the only thing you want is not having the username/password combos checked against a table in web2py's database but against PAM's database. Yes, this is what we are trying to do. To reiterate: we always want to provide access to web2py, and through web2py's auth (using a username and password form) we want to authenticate using PAM in the backend. Unless I understood it wrong, apache and rocket work. This means (if you didn't mess with apache configs) that 3) works out of the box What it seems by your config is that you're trying to do 2), i.e. stopping users one step before, letting uwsgi interact deal pam authentication..that is a different thing. Do you want 1), 2) or 3) ? My config is not doing 1 or 2, you may be confused by the fact that I provided an /etc/pam.d/uwsgi configuration, and specified pam in the uwsgi configuration. Here's what I _think_ is going on (though my understanding is spotty at best). * nginx is serving a python application using uwsgi * nginx is properly configured, I can access the site and the web2py app shows up * web2py is running in the context of uwsgi (and thus inherits its permissions) * web2py has a pam auth module that loads a pam library, attempts to connect to pam and authenticate with the credentials provided after all of those steps, I get the messages in my auth.log that I posted above, indicating to me that whatever user is trying to authenticate with pam doesn't actually have the rights to authenticate against the /etc/shadow file. That was my intention with playing around with /etc/pam.d/uwsgi config file, etc. Matt -- --- 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/groups/opt_out. Hey all, Just wanted to let you know I figured out what was wrong here. The problem was that ubuntu ships with a quite out-of-date version of uwsgi (1.0.3 in 12.04, and in recent releases only up to 1.2.x), which confuses PAM. If you're trying to do something similar, you need to run a version of uwsgi = 1.4 Matt -- --- 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/groups/opt_out.
[web2py] Re: nginx + uwsgi + web2py + PAM
For further info, these are relevant configuration files: /etc/nginx/sites-enabled/site: server { listen 80; server_name $hostname; rewrite ^ https://$server_name$request_uri? permanent; } server { listen 443; server_name $hostname; ssl on; ssl_certificate /etc/nginx/ssl/certificate.crt; ssl_certificate_key /etc/nginx/ssl/certificate.key; location / { uwsgi_pass 127.0.0.1:9001; include uwsgi_params; uwsgi_param UWSGI_SCHEME $scheme; uwsgi_param SERVER_SOFTWAREnginx/$nginx_version; } } /etc/uwsgi/apps-enabled/site.xml uwsgi pluginpython/plugin socket127.0.0.1:9001/socket pythonpath/opt/web/site//pythonpath pamuwsgi/pam app mountpoint=/ scriptwsgihandler/script /app /uwsgi /etc/pam.d/uwsgi: @include common-auth @include common-account On Fri, Mar 29, 2013 at 11:45 AM, Matt Broadstone mbroa...@gmail.com wrote: Hi, We're trying to migrate our web2py deployment to nginx and running into a problem using pam_auth as a login method. Before I go further I should clarify that PAM authentication works just fine with apache2 and a simple debug run with rocket. Also, we are trying to do this on Ubuntu 12.04, and the nginx setup is basically verbatim from the script provided by web2py (scripts/setup-web2py-nginx-uwsgi-ubuntu.sh). I am unable to log into web2py with local users, and the only relevant log message I can find is in my /var/log/auth.log: Mar 29 11:38:17 mbroadst-build unix_chkpwd[7073]: check pass; user unknown Mar 29 11:38:17 mbroadst-build unix_chkpwd[7073]: password check failed for user (mbroadst) Mar 29 11:38:17 mbroadst-build uwsgi: pam_unix(login:auth): authentication failure; logname= uid=33 euid=33 tty= ruser= rhost= user=mbroadst There is surprisingly little information on the internet related to these messages, but it seems (from a post on Cherokees forums) that this indicates that the user is unable to access the /etc/shadow file. I can verify that the nginx and uwsgi configurations are correct, and working. Both are running as the www-data user, and the www-data user has been added to the shadow group. Does anyone have a clue what's going on here? I'm getting to the point that maybe web2py's pam auth module is the culprit, but I am very inexperienced with the technologies involved here. Matt -- --- 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/groups/opt_out.
[web2py] nginx + uwsgi + web2py + PAM
Hi, We're trying to migrate our web2py deployment to nginx and running into a problem using pam_auth as a login method. Before I go further I should clarify that PAM authentication works just fine with apache2 and a simple debug run with rocket. Also, we are trying to do this on Ubuntu 12.04, and the nginx setup is basically verbatim from the script provided by web2py (scripts/setup-web2py-nginx-uwsgi-ubuntu.sh). I am unable to log into web2py with local users, and the only relevant log message I can find is in my /var/log/auth.log: Mar 29 11:38:17 mbroadst-build unix_chkpwd[7073]: check pass; user unknown Mar 29 11:38:17 mbroadst-build unix_chkpwd[7073]: password check failed for user (mbroadst) Mar 29 11:38:17 mbroadst-build uwsgi: pam_unix(login:auth): authentication failure; logname= uid=33 euid=33 tty= ruser= rhost= user=mbroadst There is surprisingly little information on the internet related to these messages, but it seems (from a post on Cherokees forums) that this indicates that the user is unable to access the /etc/shadow file. I can verify that the nginx and uwsgi configurations are correct, and working. Both are running as the www-data user, and the www-data user has been added to the shadow group. Does anyone have a clue what's going on here? I'm getting to the point that maybe web2py's pam auth module is the culprit, but I am very inexperienced with the technologies involved here. Matt -- --- 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/groups/opt_out.
Re: [web2py] Re: nginx + uwsgi + web2py + PAM
On Fri, Mar 29, 2013 at 12:05 PM, Niphlod niph...@gmail.com wrote: uhm. Before smashing heads against the wall, there are 3 different available methods here. 1) rely on nginx to authenticate users through pam (kinda of a basic auth, but checked against PAM) 2) rely on uwsgi to authenticate users through pam (kinda of a basic auth, but checked against PAM) 3) rely on web2py module to authenticate users through pam Yes, this is my understanding as well. You want the users to reach web2py no matter what, and let the authentication happen using web2py's logic assuming that the only thing you want is not having the username/password combos checked against a table in web2py's database but against PAM's database. Yes, this is what we are trying to do. To reiterate: we always want to provide access to web2py, and through web2py's auth (using a username and password form) we want to authenticate using PAM in the backend. Unless I understood it wrong, apache and rocket work. This means (if you didn't mess with apache configs) that 3) works out of the box What it seems by your config is that you're trying to do 2), i.e. stopping users one step before, letting uwsgi interact deal pam authentication..that is a different thing. Do you want 1), 2) or 3) ? My config is not doing 1 or 2, you may be confused by the fact that I provided an /etc/pam.d/uwsgi configuration, and specified pam in the uwsgi configuration. Here's what I _think_ is going on (though my understanding is spotty at best). * nginx is serving a python application using uwsgi * nginx is properly configured, I can access the site and the web2py app shows up * web2py is running in the context of uwsgi (and thus inherits its permissions) * web2py has a pam auth module that loads a pam library, attempts to connect to pam and authenticate with the credentials provided after all of those steps, I get the messages in my auth.log that I posted above, indicating to me that whatever user is trying to authenticate with pam doesn't actually have the rights to authenticate against the /etc/shadow file. That was my intention with playing around with /etc/pam.d/uwsgi config file, etc. Matt -- --- 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/groups/opt_out. -- --- 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/groups/opt_out.
Re: [web2py] Re: Can't import external modules
On Wed, Aug 15, 2012 at 10:03 PM, Anthony abasta...@gmail.com wrote: Is there any way around this? This seems to have broken only with the upgrade to Mountain Lion. We develop this app primarily on (and for) linux, however I do most of my development on my laptop, so it's quite inconvenient to have to use a separate install just on this computer. Do you have any idea where to look in order to solve this problem? I am very willing (and motivated!) to help fix this problem. What are you trying to work around? If you want to use the Python installed on your system along with any modules you may have installed with it, then just run the source version of web2py -- it works fine on OS X and is just as easy to install (just download and unzip). What do you mean by a separate install just on this computer -- you'll need web2py installed on any computer on which you want to use it? I might be experiencing a different problem here. I'm currently having a problem where I can no longer import modules from the modules directory in my application on osx. I've updated to the latest 1.99.7 to no avail, and am currently trying to work through why it's no longer loading properly (this worked just fine in 1.99.4, but as I said I also upgraded to Mountain Lion this past weekend). Anthony -- --
Re: [web2py] use PAM groups for group membership decorators
On Wed, Apr 25, 2012 at 11:39 AM, Matt mbroa...@gmail.com wrote: It seems that web2py group membership is restricted to groups created by web2py. We have a situation where we are bypassing web2py's user management and using PAM directly. This works great for just logging in, but we have no access to group information because web2py is looking to its own database of user groups, rather than those of the system user. Is there an easy way to fix this? Could someone possibly give me direction on where the work needs to be done to implement this so I can get started? It seems to me that the only thing blocking me from returning the PAM groups for the auth module groups method (and related membership functionality), is the ability to determine if a user has indeed logged in through PAM or through web2py's user system. Is there a way to do this? Does it make sense to update the web2py user tables to include a login-type column? Matt
Re: [web2py] Re: basic authentication using pam
Not sure if you will get updates on that ticket (because its been closed as fixed), but I added an extra missing piece of code for that patch. The url again is: http://code.google.com/p/web2py/issues/detail?id=532. Matt On Mon, Nov 21, 2011 at 6:34 PM, Massimo Di Pierro massimo.dipie...@gmail.com wrote: Your patch is good (for pam and other methods that allow the app to handle the password) and it is in trunk On Nov 21, 3:35 pm, Matt Broadstone mbroa...@gmail.com wrote: On Mon, Nov 21, 2011 at 3:25 PM, Massimo Di Pierromassimo.dipie...@gmail.com wrote: Good point. Basic auth may not work with PAM. Please open a ticket. OK, issue created:http://code.google.com/p/web2py/issues/detail?id=532 Also, in the comments section I've included a patch to allow PAM authentication. As I note in the comment I don't have time to check that this works for all auth cases, but we only allow PAM and form based logins so this solution suffices for our needs. Matt On Nov 21, 1:26 pm, Matt Broadstone mbroa...@gmail.com wrote: Is it possible to use PAM for basic auth? I have basic auth working (thanks to Hong-Khoan Quach's patch), however I can't seem to link it to PAM. We are using PAM successfully for web based user authentication, but basic auth seems to be ignoring this. Thanks, Matt
[web2py] PAM users added to auth_user
Hopefully this is the last in my thread of auth related emails ;) I was wondering if there is an easy way to stop web2py adding users to its own auth_user database when the users are PAM users. I imagine this is probably an issue for all alternative login methods, not just PAM, but that's the only one we're using right now. Mat
Re: [web2py] Re: PAM users added to auth_user
On Nov 23, 2011, at 12:33 PM, Massimo Di Pierro massimo.dipie...@gmail.com wrote: Please open a ticket and we can get this done Done, it's located here: http://code.google.com/p/web2py/issues/detail?id=535thanks=535ts=1322086748 I've been perusing the code for this and it seems to be this way by design though I'm not sure why. The offending code seems to be tools.py:1685. Obviously this PAM solution is not complete because if system credentials change for that user, web2py will still use the old stored info (I believe). I'll work on a patch Matt On Nov 23, 8:50 am, Matt Broadstone mbroa...@gmail.com wrote: Hopefully this is the last in my thread of auth related emails ;) I was wondering if there is an easy way to stop web2py adding users to its own auth_user database when the users are PAM users. I imagine this is probably an issue for all alternative login methods, not just PAM, but that's the only one we're using right now. Mat
[web2py] basic auth with custom get_or_create_user call
Hello, In our project we need to create a temporary user for the web2py app so that a remote system can send back a singe status update. In order to do this, when the command is sent out we create a temporary user like this: settings[serverUser] = str(uuid.uuid4()) settings[serverPassword] = str(uuid.uuid4()) user = auth.get_or_create_user(dict(username=settings[serverUser], password=settings[serverPassword])) This adds the user/password to the database just fine, however, login fails because of this line in login_bare: password = table_user[passfield].validate(password)[0] if I remove this line, the password is as expected, which leads me to think that we are not adding the password in the first case properly. Does it need to be hashed some way? Matt
Re: [web2py] Re: basic auth with custom get_or_create_user call
On Tue, Nov 22, 2011 at 9:21 AM, Massimo Di Pierro massimo.dipie...@gmail.com wrote: must be hashed Hmm I can't seem to get this working. I should probably have mentioned that we are using basic auth to use this user on the client side. When I hash the password and insert it into the database it is not hashing the password passed in from basic login. Does this mean that we should be changing the basic method to hash the password that it finds there also? like this: (username, password) = base64.b64decode(basic[6:]).split(':') password = db.auth_user.password.validate(str(uuid.uuid4()))[0] return self.login_bare(username, password) Just to be clear, I'll reiterate what we're trying to do here. A temporary user is created in the system with a uuid username and uuid password like this: settings[serverUser] = str(uuid.uuid4()) settings[serverPassword] = db.auth_user.password.validate(str(uuid.uuid4()))[0] user = auth.get_or_create_user(dict(username=settings[serverUser], password=settings[serverPassword])) then, on the client side, we are using curl to call a restful action on the server using this login info, like this: curl https://localhost:2345/some/rest/verb -u serverUser from above:serverPassword from above and its still redirecting. I can confirm that the passwords passed in to login_bare are the same until this is called: password = table_user[passfield].validate(password)[0] settings[serverPassword] = db.auth_user.password.validate(str(uuid.uuid4()))[0] On Nov 22, 8:19 am, Matt Broadstone mbroa...@gmail.com wrote: Hello, In our project we need to create a temporary user for the web2py app so that a remote system can send back a singe status update. In order to do this, when the command is sent out we create a temporary user like this: settings[serverUser] = str(uuid.uuid4()) settings[serverPassword] = str(uuid.uuid4()) user = auth.get_or_create_user(dict(username=settings[serverUser], password=settings[serverPassword])) This adds the user/password to the database just fine, however, login fails because of this line in login_bare: password = table_user[passfield].validate(password)[0] if I remove this line, the password is as expected, which leads me to think that we are not adding the password in the first case properly. Does it need to be hashed some way? Matt
Re: [web2py] Re: basic auth with custom get_or_create_user call
On Tue, Nov 22, 2011 at 1:32 PM, Massimo Di Pierro massimo.dipie...@gmail.com wrote: If the password is a UUID how are the users supposed to know what it and use it to login. I am missing something here. its a temporary password, for a one time callback. On Nov 22, 12:08 pm, Matt Broadstone mbroa...@gmail.com wrote: On Tue, Nov 22, 2011 at 9:21 AM, Massimo Di Pierromassimo.dipie...@gmail.com wrote: must be hashed Hmm I can't seem to get this working. I should probably have mentioned that we are using basic auth to use this user on the client side. When I hash the password and insert it into the database it is not hashing the password passed in from basic login. Does this mean that we should be changing the basic method to hash the password that it finds there also? like this: (username, password) = base64.b64decode(basic[6:]).split(':') password = db.auth_user.password.validate(str(uuid.uuid4()))[0] return self.login_bare(username, password) Just to be clear, I'll reiterate what we're trying to do here. A temporary user is created in the system with a uuid username and uuid password like this: settings[serverUser] = str(uuid.uuid4()) settings[serverPassword] = db.auth_user.password.validate(str(uuid.uuid4()))[0] user = auth.get_or_create_user(dict(username=settings[serverUser], password=settings[serverPassword])) then, on the client side, we are using curl to call a restful action on the server using this login info, like this: curlhttps://localhost:2345/some/rest/verb-u serverUser from above:serverPassword from above and its still redirecting. I can confirm that the passwords passed in to login_bare are the same until this is called: password = table_user[passfield].validate(password)[0] settings[serverPassword] = db.auth_user.password.validate(str(uuid.uuid4()))[0] On Nov 22, 8:19 am, Matt Broadstone mbroa...@gmail.com wrote: Hello, In our project we need to create a temporary user for the web2py app so that a remote system can send back a singe status update. In order to do this, when the command is sent out we create a temporary user like this: settings[serverUser] = str(uuid.uuid4()) settings[serverPassword] = str(uuid.uuid4()) user = auth.get_or_create_user(dict(username=settings[serverUser], password=settings[serverPassword])) This adds the user/password to the database just fine, however, login fails because of this line in login_bare: password = table_user[passfield].validate(password)[0] if I remove this line, the password is as expected, which leads me to think that we are not adding the password in the first case properly. Does it need to be hashed some way? Matt
Re: [web2py] Re: basic auth with custom get_or_create_user call
On Tue, Nov 22, 2011 at 2:31 PM, Matt Broadstone mbroa...@gmail.com wrote: On Tue, Nov 22, 2011 at 1:32 PM, Massimo Di Pierro massimo.dipie...@gmail.com wrote: If the password is a UUID how are the users supposed to know what it and use it to login. I am missing something here. its a temporary password, for a one time callback. Aren't passwords always hashed when entered in the database? If so, why aren't they hashed in the basic method before they are sent to login_bare? Matt On Nov 22, 12:08 pm, Matt Broadstone mbroa...@gmail.com wrote: On Tue, Nov 22, 2011 at 9:21 AM, Massimo Di Pierromassimo.dipie...@gmail.com wrote: must be hashed Hmm I can't seem to get this working. I should probably have mentioned that we are using basic auth to use this user on the client side. When I hash the password and insert it into the database it is not hashing the password passed in from basic login. Does this mean that we should be changing the basic method to hash the password that it finds there also? like this: (username, password) = base64.b64decode(basic[6:]).split(':') password = db.auth_user.password.validate(str(uuid.uuid4()))[0] return self.login_bare(username, password) Just to be clear, I'll reiterate what we're trying to do here. A temporary user is created in the system with a uuid username and uuid password like this: settings[serverUser] = str(uuid.uuid4()) settings[serverPassword] = db.auth_user.password.validate(str(uuid.uuid4()))[0] user = auth.get_or_create_user(dict(username=settings[serverUser], password=settings[serverPassword])) then, on the client side, we are using curl to call a restful action on the server using this login info, like this: curlhttps://localhost:2345/some/rest/verb-u serverUser from above:serverPassword from above and its still redirecting. I can confirm that the passwords passed in to login_bare are the same until this is called: password = table_user[passfield].validate(password)[0] settings[serverPassword] = db.auth_user.password.validate(str(uuid.uuid4()))[0] On Nov 22, 8:19 am, Matt Broadstone mbroa...@gmail.com wrote: Hello, In our project we need to create a temporary user for the web2py app so that a remote system can send back a singe status update. In order to do this, when the command is sent out we create a temporary user like this: settings[serverUser] = str(uuid.uuid4()) settings[serverPassword] = str(uuid.uuid4()) user = auth.get_or_create_user(dict(username=settings[serverUser], password=settings[serverPassword])) This adds the user/password to the database just fine, however, login fails because of this line in login_bare: password = table_user[passfield].validate(password)[0] if I remove this line, the password is as expected, which leads me to think that we are not adding the password in the first case properly. Does it need to be hashed some way? Matt
Re: [web2py] Re: basic auth with custom get_or_create_user call
On Tue, Nov 22, 2011 at 3:50 PM, Anthony abasta...@gmail.com wrote: On Tuesday, November 22, 2011 3:00:46 PM UTC-5, Matt wrote: Aren't passwords always hashed when entered in the database? Not necessarily. You have to have the CRYPT() validator on the password field for hashing. It is there by default, but is not required and could be removed. Anthony Well, temporarily I have removed the password validation line: password = table_user[passfield].validate(password)[0] and everything works, but this is not ideal, as I would prefer to not have project-specific changes to gluon. Is there another solution for this? Matt
Re: [web2py] Re: basic auth with custom get_or_create_user call
On Tue, Nov 22, 2011 at 4:11 PM, Anthony abasta...@gmail.com wrote: I haven't been following the discussion. Do you want to remove the CRYPT validator? If so, I think something like: db.auth_user.password.requires = None This seems to have fixed the issue, thank you both Matt Anthony On Tuesday, November 22, 2011 3:57:18 PM UTC-5, Matt wrote: On Tue, Nov 22, 2011 at 3:50 PM, Anthony abas...@gmail.com wrote: On Tuesday, November 22, 2011 3:00:46 PM UTC-5, Matt wrote: Aren't passwords always hashed when entered in the database? Not necessarily. You have to have the CRYPT() validator on the password field for hashing. It is there by default, but is not required and could be removed. Anthony Well, temporarily I have removed the password validation line: password = table_user[passfield].validate(password)[0] and everything works, but this is not ideal, as I would prefer to not have project-specific changes to gluon. Is there another solution for this? Matt
[web2py] basic authentication using pam
Is it possible to use PAM for basic auth? I have basic auth working (thanks to Hong-Khoan Quach's patch), however I can't seem to link it to PAM. We are using PAM successfully for web based user authentication, but basic auth seems to be ignoring this. Thanks, Matt
Re: [web2py] Re: basic authentication using pam
On Mon, Nov 21, 2011 at 3:25 PM, Massimo Di Pierro massimo.dipie...@gmail.com wrote: Good point. Basic auth may not work with PAM. Please open a ticket. OK, issue created: http://code.google.com/p/web2py/issues/detail?id=532 Also, in the comments section I've included a patch to allow PAM authentication. As I note in the comment I don't have time to check that this works for all auth cases, but we only allow PAM and form based logins so this solution suffices for our needs. Matt On Nov 21, 1:26 pm, Matt Broadstone mbroa...@gmail.com wrote: Is it possible to use PAM for basic auth? I have basic auth working (thanks to Hong-Khoan Quach's patch), however I can't seem to link it to PAM. We are using PAM successfully for web based user authentication, but basic auth seems to be ignoring this. Thanks, Matt
Re: [web2py] Re: login form errors
When I looked at how the generated sample app handled showing that there was an error with logging in, it showed the message in a flash area in the view. To be clear here: the controller is a two-liner: def user(): return dict(form=auth()) so there is no setup in the controller, as it relates to flash at least. This lead me to believe that whatever is going on in the creation of the auth form, it places errors into the session.flash variable, and I figured I could just add that to my view and the error would show up. This was not the case. What I'm really asking here is how to access that error information. It doesn't appear in session.flash, it doesn't appear in form.errors. Matt On Tue, Nov 8, 2011 at 5:08 PM, Cliff cjk...@gmail.com wrote: Is there a div with the id of 'flash' in your view? On Nov 8, 11:14 am, Matt mbroa...@gmail.com wrote: Greetings, We are currently experiencing an issue with invalid logins not showing errors. For auth we are using a combination of basic auth and PAM, and the actual controller/view combo for the login form is basically the same as the generated scaffolding. When an invalid username/password is entered the page simply reloads without any indication of what the error was. I tried to display the flash (we are not currently using the session flash, so this had to be added to this page) and that has no info in it, I have also tried to display auth.login_form()'s errors, which do not exist either. Is there some way to get this information? Thank you, Matt
Re: [web2py] Re: serving a zip file
On Fri, Oct 14, 2011 at 9:35 AM, peter peterchutchin...@gmail.com wrote: If I now do exactly what I did one month ago, there is now no error with zip streaming. So maybe you have changed things in response.stream since then. Peter On Oct 14, 1:24 pm, peter peterchutchin...@gmail.com wrote: I sent from my wifes emailhttp://groups.google.com/group/web2py/browse_thread/thread/fe85dca9e4... However with hindsight I think I did not give sufficient information in my forum entry. I guess I was seeing if other people had had problems with downloading zip files. Today, I just tried the following def downloady(): import os import contenttype as c path=somepath/album.zip response.headers['Content-Type'] = c.contenttype(path) response.headers['Content-Disposition'] = 'attachment; filename=album.zip'# to force download as attachment return response.stream(open(path,'rb'),chunk_size=4096) Does this actually work for you? When I use this code, I get a download, but it saves out a zero byte file with the proper name. and this did work correctly. So I do not know why I was having problems last month, when I repeatedly had problems with downloaded zip files not unzipping. So I aplogise for suggesting there was a bug here. I will see if I can recreate the problems I was having and get to the root cause. Peter On Oct 14, 12:22 am, Massimo Di Pierro massimo.dipie...@gmail.com wrote: On Oct 13, 12:46 pm, peter peterchutchin...@gmail.com wrote: As I have reported previously in this forum, I think that response.stream does not quite stream zip files correctly. I have no bug report about this. Can you tell us more so we can fix it?- Hide quoted text - - Show quoted text -
Re: [web2py] Re: serving a zip file
On Fri, Oct 14, 2011 at 12:48 PM, Massimo Di Pierro massimo.dipie...@gmail.com wrote: What browser? That was chrome. The previously fix suggested by Brian works for me (thanks!). Matt On Oct 14, 10:30 am, Matt Broadstone mbroa...@gmail.com wrote: On Fri, Oct 14, 2011 at 9:35 AM, peter peterchutchin...@gmail.com wrote: If I now do exactly what I did one month ago, there is now no error with zip streaming. So maybe you have changed things in response.stream since then. Peter On Oct 14, 1:24 pm, peter peterchutchin...@gmail.com wrote: I sent from my wifes emailhttp://groups.google.com/group/web2py/browse_thread/thread/fe85dca9e4... However with hindsight I think I did not give sufficient information in my forum entry. I guess I was seeing if other people had had problems with downloading zip files. Today, I just tried the following def downloady(): import os import contenttype as c path=somepath/album.zip response.headers['Content-Type'] = c.contenttype(path) response.headers['Content-Disposition'] = 'attachment; filename=album.zip'# to force download as attachment return response.stream(open(path,'rb'),chunk_size=4096) Does this actually work for you? When I use this code, I get a download, but it saves out a zero byte file with the proper name. and this did work correctly. So I do not know why I was having problems last month, when I repeatedly had problems with downloaded zip files not unzipping. So I aplogise for suggesting there was a bug here. I will see if I can recreate the problems I was having and get to the root cause. Peter On Oct 14, 12:22 am, Massimo Di Pierro massimo.dipie...@gmail.com wrote: On Oct 13, 12:46 pm, peter peterchutchin...@gmail.com wrote: As I have reported previously in this forum, I think that response.stream does not quite stream zip files correctly. I have no bug report about this. Can you tell us more so we can fix it?- Hide quoted text - - Show quoted text -
[web2py] access to extra template files
Hello, I am trying to dynamically load templates that I have stored in a subdirectory of one of my views. The structure looks like this: app/ views/ test/ index.html list.html edit.html add.html templates/ first.html second.html (I hope that formatting is preserved..) I have this set up because I want to show different profiles for each test item - this is a composition. For edit, this works just fine, in the template I use include to import the proper template based on the type of the member variable. The problem I face now, is that in add I want to have a select box that loads the proper template, but have no idea how to actually load this file from the browser-side (this seems the only solution, without having to reload the whole page with the proper template). Is there a way to reference these html files from the browser side? http://site/app/test/templates/first.html does not work, for instance. Matt
[web2py] serving a zip file
Hi, In our project, we are trying to provide the ability to download a dataset in a zipped format. We've been transitioning old code to use web2py, and while I've been able to serve files using web2py elsewhere (images, for instance), I can't quite figure out how to serve this particular file. Below is the code I've come up with. When I take out the code to zip the file, it serves perfectly. Does anyone have experience with this? filename = %s-backup % (time.strftime(%Y%m%d-%H%M)) raw_data = a bunch of data stream = cStringIO.StringIO() zip_file = zipfile.ZipFile(stream, w, zipfile.ZIP_DEFLATED, False) zip_file.writestr(filename, raw_data) response.headers['Content-Type'] = application/octet-stream response.headers['Content-Disposition'] = attachment; filename=%s%s.bin % (time.strftime(%Y%m%d-%H%M), filename) return response.stream(stream, request=request) Thanks, Matt
Re: [web2py] Re: serving a zip file
On Thu, Oct 13, 2011 at 11:34 AM, pbreit pbreitenb...@gmail.com wrote: My first suggestion would be to save the files to disk and serve statically if possible. I would prefer not to touch the disk if possible, these are not huge files just logs. I think I'm very close, when I serve this without the zipfile code (just wrapping raw_data in a StringIO), a dialog pops up asking me to save the file. However, with the zipfile code, the request seems to take much longer (as if its downloading something) and then an error is displayed in the dev console: Failed to load resource Unsafe JavaScript attempt to access frame with URL chrome://chromewebdata/ from frame with URL http://10.0.15.97:2345/. Domains, protocols and ports must match. Perhaps the headers need to be modified to serve the zip file? Any suggestions are welcome here! Matt
[web2py] serving binary data
Greetings, I am trying to serve binary image data from one of my controllers. The data comes in via xmlrpc, and as such I have access to an xmlrpc Binary object of the image data. I've written a controller that tries to emulate what response.download does, but it doesn't seem to work. Can anyone point me in the right direction here: def view(): icon_name = request.vars.name if request.vars else None icon_name = urllib.unquote(icon_name) if icon_name: icon_object = bw.objectQuery(icon, icon_name) response.headers['Content-Type'] = 'image/png' icon_stream = cStringIO.StringIO(icon_object['icon']) return response.stream(icon_stream, request=request); Matt
[web2py] Re: serving binary data
Whoops, I just needed to refer to the direct binary data, it was passing an object in. On Tue, Oct 11, 2011 at 12:11 PM, Matt Broadstone mbroa...@gmail.com wrote: Greetings, I am trying to serve binary image data from one of my controllers. The data comes in via xmlrpc, and as such I have access to an xmlrpc Binary object of the image data. I've written a controller that tries to emulate what response.download does, but it doesn't seem to work. Can anyone point me in the right direction here: def view(): icon_name = request.vars.name if request.vars else None icon_name = urllib.unquote(icon_name) if icon_name: icon_object = bw.objectQuery(icon, icon_name) response.headers['Content-Type'] = 'image/png' icon_stream = cStringIO.StringIO(icon_object['icon']) return response.stream(icon_stream, request=request); Matt
Re: [web2py] Re: checkbox input default value
I'm using the Field in a rather unconventional way - I just have a number of Field objects in a class that I refer to as my model (its not actually connected to any database), and I use the SQLFORM.factory to generate the form. The actual Field entry in the form looks like this: AutoStart = Field('AutoStart', 'boolean', label=T(info)) in the view I use it inside a custom form like so: dd{{=form.custom.widget.AutoStart}}{{=form.custom.label.AutoStart}}/dd the resulting HTML is: ddinput class=boolean id=no_table_AutoStart name=AutoStart type=checkbox value=oninfo/dd pretty straight forward, but you can see that the value is somehow there. Matt On Mon, Oct 10, 2011 at 4:05 PM, Wikus van de Merwe dupakrop...@googlemail.com wrote: Are you using list:string? Can you post the relevant parts of your model and controller?
[web2py] More robust SELECT helper
Is it possible to pass in a dictionary to the SELECT helper, so that I can maintain a difference between representation and value of entries in a select element? I've tried to invoke this a few ways, but it seems its not built-in. Unfortunately, I'm not familiar enough with gluon to supply a patch for this (yet!), can someone point me towards how to go about implementing this? Thanks, Matt
[web2py] composite views
Good morning, I have a situation where I want to display composite views (a view for an object inside a view for its parent object). I have a class Connection that has a Profile associated with it. Profile can be one of a number of different subclasses (AProfile, BProfile, CProfile). I also have views associated for each of the profiles, within a template directory under the views/connection directory. The way I've tried to go about solving this is to make a view.html (associated with the view() method in the controller) as a base template with a block for profile_section inside of it. Then, in each of the profile templates, I extend view.html and then fill out the block for the profile. The problem I am now facing is how to properly route to the right template file from within the controller's view method. I know I could just create a new method in the controller for each profile type, but I'd rather not do that if possible. I also think that a simple redirect is not the right solution here. Can anyone advise as to the best way to do this? Or am I just on the wrong track with the whole extend idea? Thank you, Matt
Re: [web2py] composite views
On Mon, Oct 3, 2011 at 10:11 AM, Bruno Rocha rochacbr...@gmail.com wrote: You can always set if x: response.view = 'folder/file.html' elif y: response.view = '' Also, you can use: def action: return response.render(file.html, dict(context=context)) I tried this with the following code in my controller: if (isinstance(p, TestProtocol)): response.view = connection/templates/test.html and I get this error: Traceback (most recent call last): File /home/mbroadstone/app/src/web2py/gluon/template.py, line 437, in _get_file_text fileobj = open(filepath, 'rb') IOError: [Errno 2] No such file or directory: '/home/mbroadstone/app/src/web2py/applications/app/views/../edit.html' I then tried to print out what response.view should have been prior, and it contained connection/edit.html as expected. What am I doing wrong here? Matt On Mon, Oct 3, 2011 at 10:16 AM, Matt Broadstone mbroa...@gmail.com wrote: Good morning, I have a situation where I want to display composite views (a view for an object inside a view for its parent object). I have a class Connection that has a Profile associated with it. Profile can be one of a number of different subclasses (AProfile, BProfile, CProfile). I also have views associated for each of the profiles, within a template directory under the views/connection directory. The way I've tried to go about solving this is to make a view.html (associated with the view() method in the controller) as a base template with a block for profile_section inside of it. Then, in each of the profile templates, I extend view.html and then fill out the block for the profile. The problem I am now facing is how to properly route to the right template file from within the controller's view method. I know I could just create a new method in the controller for each profile type, but I'd rather not do that if possible. I also think that a simple redirect is not the right solution here. Can anyone advise as to the best way to do this? Or am I just on the wrong track with the whole extend idea? Thank you, Matt -- -- Bruno Rocha [ About me: http://zerp.ly/rochacbruno ] [ Aprenda a programar: http://CursoDePython.com.br ] [ O seu aliado nos cuidados com os animais: http://AnimalSystem.com.br ] [ Consultoria em desenvolvimento web: http://www.blouweb.com ]
Re: [web2py] composite views
On Mon, Oct 3, 2011 at 10:49 AM, Matt Broadstone mbroa...@gmail.com wrote: On Mon, Oct 3, 2011 at 10:11 AM, Bruno Rocha rochacbr...@gmail.com wrote: You can always set if x: response.view = 'folder/file.html' elif y: response.view = '' Also, you can use: def action: return response.render(file.html, dict(context=context)) I tried this with the following code in my controller: if (isinstance(p, TestProtocol)): response.view = connection/templates/test.html and I get this error: Traceback (most recent call last): File /home/mbroadstone/app/src/web2py/gluon/template.py, line 437, in _get_file_text fileobj = open(filepath, 'rb') IOError: [Errno 2] No such file or directory: '/home/mbroadstone/app/src/web2py/applications/app/views/../edit.html' I then tried to print out what response.view should have been prior, and it contained connection/edit.html as expected. What am I doing wrong here? Apologies, this has to do with the extend being used in the sub-template. Thank you very much for your help Matt On Mon, Oct 3, 2011 at 10:16 AM, Matt Broadstone mbroa...@gmail.com wrote: Good morning, I have a situation where I want to display composite views (a view for an object inside a view for its parent object). I have a class Connection that has a Profile associated with it. Profile can be one of a number of different subclasses (AProfile, BProfile, CProfile). I also have views associated for each of the profiles, within a template directory under the views/connection directory. The way I've tried to go about solving this is to make a view.html (associated with the view() method in the controller) as a base template with a block for profile_section inside of it. Then, in each of the profile templates, I extend view.html and then fill out the block for the profile. The problem I am now facing is how to properly route to the right template file from within the controller's view method. I know I could just create a new method in the controller for each profile type, but I'd rather not do that if possible. I also think that a simple redirect is not the right solution here. Can anyone advise as to the best way to do this? Or am I just on the wrong track with the whole extend idea? Thank you, Matt -- -- Bruno Rocha [ About me: http://zerp.ly/rochacbruno ] [ Aprenda a programar: http://CursoDePython.com.br ] [ O seu aliado nos cuidados com os animais: http://AnimalSystem.com.br ] [ Consultoria em desenvolvimento web: http://www.blouweb.com ]
[web2py] field.represent value
Hello, Is there a way to specify a value for the representation of a Field object? I have a class (lets call it A) with a Field object member variable (lets call it B), in my view I call {{=A.B.represent}} in order to display the default widget for this field. I would like to fill that widget with a value as well, is that possible? Matt
Re: [web2py] Re: field.represent value
On Tue, Sep 27, 2011 at 11:41 AM, Anthony abasta...@gmail.com wrote: Do you need the field's widget or it's represent (they're two different things)? Note, the represent attribute is a function/callable (usually a lambda) that takes a value (and optionally a record), so if you want to use it directly, you have to call it and pass a value to it. {{=A.B.represent(your_value, optional_record)}} Would be similar for the widget. Anthony From what I read in the source, I determined that was how to do it. However, when I try to call represent that way I'm getting an error that the 'NoneType' object is not callable. This is what I've got: model: class Test: name = Field('name', 'string') view: {{=terminal.name.represent(test)}} Matt On Tuesday, September 27, 2011 11:19:08 AM UTC-4, Matt wrote: Hello, Is there a way to specify a value for the representation of a Field object? I have a class (lets call it A) with a Field object member variable (lets call it B), in my view I call {{=A.B.represent}} in order to display the default widget for this field. I would like to fill that widget with a value as well, is that possible? Matt
Re: [web2py] Re: field.represent value
On Tue, Sep 27, 2011 at 11:49 AM, Anthony abasta...@gmail.com wrote: In Field(), represent defaults to None -- you have to specify a represent function of your own. Anthony Ah, I see. Is there a way to leverage the representations defined in SQLFORM.factory for this? SQLFORM.factory worked to a certain degree for my needs, but it also did not give me much freedom to design the view the way I wanted. Instead, I've ended up creating this model with the fields that I want, and I'm placing them one by one in the view. The actual widgets that were rendered by SQLFORM.factory were just fine - so can I use those somehow? Matt On Tuesday, September 27, 2011 11:46:58 AM UTC-4, Matt wrote: On Tue, Sep 27, 2011 at 11:41 AM, Anthony abas...@gmail.com wrote: Do you need the field's widget or it's represent (they're two different things)? Note, the represent attribute is a function/callable (usually a lambda) that takes a value (and optionally a record), so if you want to use it directly, you have to call it and pass a value to it. {{=A.B.represent(your_value, optional_record)}} Would be similar for the widget. Anthony From what I read in the source, I determined that was how to do it. However, when I try to call represent that way I'm getting an error that the 'NoneType' object is not callable. This is what I've got: model: class Test: name = Field('name', 'string') view: {{=terminal.name.represent(test)}} Matt On Tuesday, September 27, 2011 11:19:08 AM UTC-4, Matt wrote: Hello, Is there a way to specify a value for the representation of a Field object? I have a class (lets call it A) with a Field object member variable (lets call it B), in my view I call {{=A.B.represent}} in order to display the default widget for this field. I would like to fill that widget with a value as well, is that possible? Matt
Re: [web2py] Re: field.represent value
On Tue, Sep 27, 2011 at 12:32 PM, Anthony abasta...@gmail.com wrote: You can use SQLFORM.factory and still have complete control over the form layout/appearance -- see http://web2py.com/book/default/chapter/07#Custom-forms. But if you want to access any of the SQLFORM widgets independently, they are of the form SQLFORM.widgets.[field type].widget -- see http://web2py.com/book/default/chapter/07#Widgets. Anthony Somehow I completely missed this! Many apologies. Still, using this approach I am still unclear as to how I might fill those widgets when I'm using the SQLFORM custom form method. Ideally, I would fill the form from the controller before display. I've tried: - form.vars.var = value - form.custom.var.widget.value = value Neither of which work. Is this possible? Matt On Tuesday, September 27, 2011 11:52:43 AM UTC-4, Matt wrote: On Tue, Sep 27, 2011 at 11:49 AM, Anthony abas...@gmail.com wrote: In Field(), represent defaults to None -- you have to specify a represent function of your own. Anthony Ah, I see. Is there a way to leverage the representations defined in SQLFORM.factory for this? SQLFORM.factory worked to a certain degree for my needs, but it also did not give me much freedom to design the view the way I wanted. Instead, I've ended up creating this model with the fields that I want, and I'm placing them one by one in the view. The actual widgets that were rendered by SQLFORM.factory were just fine - so can I use those somehow? Matt On Tuesday, September 27, 2011 11:46:58 AM UTC-4, Matt wrote: On Tue, Sep 27, 2011 at 11:41 AM, Anthony aba...@gmail.com wrote: Do you need the field's widget or it's represent (they're two different things)? Note, the represent attribute is a function/callable (usually a lambda) that takes a value (and optionally a record), so if you want to use it directly, you have to call it and pass a value to it. {{=A.B.represent(your_value, optional_record)}} Would be similar for the widget. Anthony From what I read in the source, I determined that was how to do it. However, when I try to call represent that way I'm getting an error that the 'NoneType' object is not callable. This is what I've got: model: class Test: name = Field('name', 'string') view: {{=terminal.name.represent(test)}} Matt On Tuesday, September 27, 2011 11:19:08 AM UTC-4, Matt wrote: Hello, Is there a way to specify a value for the representation of a Field object? I have a class (lets call it A) with a Field object member variable (lets call it B), in my view I call {{=A.B.represent}} in order to display the default widget for this field. I would like to fill that widget with a value as well, is that possible? Matt
Re: [web2py] Re: xmlrpc backend
I think I will end up just writing my own model for this (a la Anthony's suggestion), but the problem remains that model as it relates to web2py presumes SQL, and that fact limits design. While it would be possible to write an XMLRPC adapter to the DAL, that is sort of like jamming a square piece into a triangle hole - more than not you'll probably end up wishing you just used the direct database connection! I think the long term solution to this problem is to decouple the data models from database access. Cheers, Matt On Mon, Sep 26, 2011 at 2:05 PM, Ross Peoples ross.peop...@gmail.com wrote: Please forgive me if this post shows up a bunch of different times, but I'm having trouble with Google Groups not posting my replies, even though it says it did. So for the fourth time: We could add an XMLRPC adapter to the DAL that instead of making SQL calls, could build an XML version of the query that could be passed on to another web2py app via xmlrpc. That app could then return the results as XML, which is then converted back to Row objects and returned to the application, making XMLRPC remote database access completely transparent and make things like SQLFORM.grid work. The only problem I see (aside from there being a lot of work to do) would be security. We would have to make web2py apps acts as a db service, like it does with CAS, and restrict who can access the XMLRPC-DB service. But this would be VERY cool and extremely helpful in building scalable (multi-tier) apps. I would be interested in helping to write code to make this happen.