Re: [web2py] Internal ip to external access
On 23 August 2012 16:50, Gerald Klein j...@zognet.com wrote: Hi all, I was wondering if anyone could direct me to a resource that will outline the techniques used to grant external access to an internal ip, along the lines of NetMeeting. I have tried to google and not getting a lot of traction on the subject, if someone knows a resource that would be great. The app is not a meeting app but to programmatically allow external access to internal ip cameras on a users internal network. Did you consider using ssh tunneling? A Google search for 'ssh tunnel' will take you to lots of howto's. Regards Johann -- Because experiencing your loyal love is better than life itself, my lips will praise you. (Psalm 63:3) --
Re: [web2py] Re: How to ask how many active sessions?
The ones I want to measure are anonymous. On Thursday, August 23, 2012 5:06:16 PM UTC+8, Khalil KHAMLICHI wrote: are your users logged-in or anonymous ? On Thu, Aug 23, 2012 at 5:48 AM, weheh richard...@verizon.netjavascript: wrote: Let me add a little more to this. Clearly, one could keep track in a db a list of all the sessions spawned by the system. However, (and I apologize for not having looked deeply into the code for this) it seems like web2py would already know this info. So wondering if there's a way to get at it without having to do a lot of work. -- --
[web2py] Re: web2py login user problem
I am using version Version 1.99.4 (2011-12-14 14:46:14) stable The whole traceback msg is Traceback (most recent call last): File C:\workspaces\Python\portal_iUrnik_web2py\gluon\restricted.py, line 204, in restricted exec ccode in environment File C:/workspaces/Python/portal_iUrnik_web2py/applications/portalov_iurnik/controllers/default.py http://192.168.100.101/admin/default/edit/portalov_iurnik/controllers/default.py, line 35, in module File C:\workspaces\Python\portal_iUrnik_web2py\gluon\globals.py, line 172, in lambda self._caller = lambda f: f() File C:/workspaces/Python/portal_iUrnik_web2py/applications/portalov_iurnik/controllers/default.py http://192.168.100.101/admin/default/edit/portalov_iurnik/controllers/default.py, line 33, in user form = auth() NameError: global name 'auth' is not defined On Friday, August 24, 2012 1:08:43 PM UTC+2, Anthony wrote: Also, what version of web2py are you using? On Friday, August 24, 2012 7:07:49 AM UTC-4, Anthony wrote: Can you show the traceback(). Also, maybe pack and attach a minimal app that reproduces the problem. On Friday, August 24, 2012 5:14:20 AM UTC-4, Yebach wrote: Hello So I am really struggling with web2py user registration I have a database that contains come required tables for webapp to work. Now I want to create a user register form etc. In db.py I added a create table #This is used to connect also to all other tables, SHOULD I CREATE A NEW CONNECTION FOR USER TABLES? db = DAL('postgres://postgres:postgres@localhost/'+request.vars['school'], migrate=False) from gluon.tools import Auth auth = Auth(db, hmac_key=Auth.get_or_create_key()) auth.define_tables() ## configure auth policy auth.settings.registration_requires_verification = False auth.settings.registration_requires_approval = False auth.settings.reset_password_requires_verification = True And In my controler I have the following code in default.py def user(): return dict(form=auth()) In view I have the following script {{='auth' in globals() and auth.navbar(separators=(' ',' | ',''))}} I copied all this from web2py welcome app. I get an error NameError: global name 'auth' is not defined Any suggestions? The tables for user are not created yet. Is a user function in a wrong controler, should I created a new one? Because If I do, then the wrong funciton is called and again I get an error. --
Re: [web2py] Re: Referencing other tables, two ways of doing it
On 26 August 2012 20:33, Anthony abasta...@gmail.com wrote: the second method is the only way to keep the referenced table lazy (the first method will trigger the table to be defined). Does that mean that the lazy table option will not work for a system using a uuid-based reference in stead if id-based? Regards Johann -- Because experiencing your loyal love is better than life itself, my lips will praise you. (Psalm 63:3) --
Re: [web2py] Re: Nginx-uwsgi problem.
On 26 August 2012 23:05, apps in tables ad...@aqar-riyadh.com wrote: Hi, where can i find tree example(file system) built by web2py ? In the Web2py directory tree? Regards Johann -- Because experiencing your loyal love is better than life itself, my lips will praise you. (Psalm 63:3) --
Re: [web2py] Re: Defining stored procedures
+1 -- Because experiencing your loyal love is better than life itself, my lips will praise you. (Psalm 63:3) --
Re: [web2py] Re: Defining stored procedures
We just added it a couple days ago. If you get a chance to try it, let us know if there are any problems. Anthony On Sunday, August 26, 2012 8:55:52 PM UTC-4, Andrew wrote: Thanks Anthony, Wasn't aware of that one, and it looks quite useful. On Monday, August 27, 2012 6:29:55 AM UTC+12, Anthony wrote: Often wondered about this too. You would also have to call them with executesql. So should the dal API support stored procedure , database macro definitions and execution? Would require work in each database adapter, but could we come up with a single interface ? Do you mean for creating stored procedures, or calling them? To call them, you can use db.executesql(). If you want the returned data to be parsed into a DAL Rows object like a regular select() would be, you can now specify a fields argument to executesql(). Here's the docstring explaining its usage: Added 2012-08-24 fields optional argument. If not None, the results cursor returned by the DB driver will be converted to a DAL Rows object using the db._adapter.parse() method. This requires specifying the fields argument as a list of DAL Field objects that match the fields returned from the DB. The Field objects should be part of one or more Table objects defined on the DAL object. The fields list can include one or more DAL Table objects in addition to or instead of including Field objects, or it can be just a single table (not in a list). In that case, the Field objects will be extracted from the table(s). The field names will be extracted from the Field objects, or optionally, a list of field names can be provided (in tablename.fieldname format) via the colnames argument. Note, the fields and colnames must be in the same order as the fields in the results cursor returned from the DB. Anthony --
[web2py] Re: Tree view, Rendering
Hi Simon I found that the best way of getting the data out of the table was to use a WITH RECURSIVE query. Hope that is of interest. Regards, D On Tuesday, April 3, 2012 1:21:12 AM UTC+1, Simon Ashley wrote: Pretty new to this and stumbling a little. We need to generate a Treeview structure with the bottom node ending with some links to other pages (graphs etc) Have a 7 level deep structure (each level in a different table) with each level have a table format simple to the following: db.define_table('node', Field('parent',db.parent), Field('node_name')) Tables will be maintained using smartgrid The intention is to use jsTree or similiar loaded/ rendered from a JSON response. (structure could get big so may need to look at some dynamic loading) Was wondering if there is some sample code/ app that some one is will to share to shed some light on which way to go? (have looked at sqlabs but that's not giving us the fuller picture) TIA --
Re: [web2py] Re: Referencing other tables, two ways of doing it
Not sure what you mean. Can you show your code? On Monday, August 27, 2012 4:22:18 AM UTC-4, Johann Spies wrote: On 26 August 2012 20:33, Anthony abas...@gmail.com javascript: wrote: the second method is the only way to keep the referenced table lazy (the first method will trigger the table to be defined). Does that mean that the lazy table option will not work for a system using a uuid-based reference in stead if id-based? Regards Johann -- Because experiencing your loyal love is better than life itself, my lips will praise you. (Psalm 63:3) --
[web2py] Re: IMPORTANT - NEED HELP: more speed improvements to be tested
OK, I have downloaded the latest trunk from Git and have imported a simple application: A copy of my site at http://www.ec2scripts.com, which is based on Plugin_Wiki and seems to (mostly) work. On the page which is the equivalent of http://www.ec2scripts.com/welcome/plugin_wiki/page/submit-your-recipe instead of Sorry, you need to be registeredhttp://www.ec2scripts.com/welcome/default/user/register and logged in http://www.ec2scripts.com/welcome/default/user/login to submit I just get: system error But there are no errors in the admin app, and the console running web2py.py does not spit out any system.out type stuff. Sorry I cannot be more specific. I can provide the wiki template that generates that page, if required. Not sure of the exact version I just pulled. The download is labelled web2py-web2py-6d78589, and the top of my CHANGELOG file says: ## 2.00.1 ### DAL Improvements - Support for DAL(lazy_tables=True) and db.define_table(on_define=lambda table:), thanks Jonathan - MongoDB support in DAL (experimental), thanks Mark Breedveld - geodal and spatialite, thanks Denes and Fran (experimental) etc Is this the kind of testing you were after, or were you wanting people to change over to lazy tables to see if that works, the way Ron did? --
[web2py] Pass arg or var to Active directory related SQLFORM
Hello, we have a small issue with trying to pass an argument/variable to one of our function. It seems the solution should be simple, but we just can't figure it out! The idea is simple: we have an input field for a userID and when you submit is would pull data with the users other attributes (job title, team name, etc). We would like the SQLFORM to appear below the submit section when a valid username is entered. We tried all sorts of methods with LOAD, the built-in ajax function and the component 'part' of the A helper... so our view looks like this: {{extend 'layout.html'}} script jQuery(document).ready(function(){ jQuery('#button').click(function(){ ajax({{=URL(c='ajax',f='ldap_fill.load')}},['name'],'placeholder'); return False; }); }); /script forminput name=name id='name'/form {{=A('CLICK HERE', _id=button, component=URL('ajax', 'ldap_fill.load', args=['name']), target='placeholder')}} div id='placeholder'/div There are two attempted solutions, but they don't work out: 1. With the jQuery on the top the SQLFORM that is returned by our ldap_fill function simply does not appear in the placeholder. 2. If we use the component of the A helper we can't figure out how to pass the contents of the input field as an argument. If I hardcode my username there then it brings up the SQLFORM filled with my details and when I submit it adds the entry to our app's database. So we just need a solution on how to have an input field and only show the SQLFORM below when a username is submitted. Thanks for anyone's time in advance!! --
[web2py] Re: need a simple wiki...
Works well! Just wondering are we keeping the ability to embed template code with the new auth.wiki? It would be handy to be able to {{=include.things}} using nothing more than the wiki form (for advanced users). Or do we always need to use LOAD now or something? The menu makes sense to me. Glad we kept the plugin_wiki style of having it in one place. --
[web2py] Re: need a simple wiki...
I'be been testing the wiki for a while and have some random comments. -I created .wiki() in the model and used it in a given function, but it doesn't add by default the menu entries -Doing auth.wiki() in any function is not apt for lazyness. i'd add the option to decorate them: @auth.wikify() def afunction(): ... return dict() -And also a app-wide command to make any action a wiki would be cool -I think that the scaffolding layout should have a wiki block or similar to automagically put the wiki contents -There's need for sort of a request arguments handling, to support using the wiki with other objects in the view. For instance: If you create the wiki in the model to allow crud with appadmin, insert/select/... commands fail for wiki rewrites the request I managed to filter the appadmin controller in the wiki code so it prevents it, but it will fail with other features like custom .grid objects arguments exposed in the same view Current auth.wiki rocks, but with those enhancements, I think it would be even better. --
[web2py] Re: need a simple wiki...
El lunes, 27 de agosto de 2012 08:06:00 UTC-3, Alan Etkin escribió:I'be been testing the wiki for a while and have some random comments. Wouldn't be better to separate the Wiki class setup and plugging phases? For example, set welcome by default with something like: # model wiki = Wiki(opt=val) # controller @auth.wiki() # optional def index(): return dict() # layout.html {{block wiki}} {{if _wiki in locals():}} {{=_wiki.content}} {{pass}} {{end}} --
[web2py] Re: IMPORTANT - NEED HELP: more speed improvements to be tested
Not sure whether this would help... I've had something similar before. I found that if I was logged in and re-visited the url it would then give more complete info. Rgds, D On Monday, August 27, 2012 11:54:02 AM UTC+1, duncan macneil wrote: OK, I have downloaded the latest trunk from Git and have imported a simple application: A copy of my site at http://www.ec2scripts.com, which is based on Plugin_Wiki and seems to (mostly) work. On the page which is the equivalent of http://www.ec2scripts.com/welcome/plugin_wiki/page/submit-your-recipe instead of Sorry, you need to be registeredhttp://www.ec2scripts.com/welcome/default/user/register and logged in http://www.ec2scripts.com/welcome/default/user/login to submit I just get: system error But there are no errors in the admin app, and the console running web2py.py does not spit out any system.out type stuff. Sorry I cannot be more specific. I can provide the wiki template that generates that page, if required. Not sure of the exact version I just pulled. The download is labelled web2py-web2py-6d78589, and the top of my CHANGELOG file says: ## 2.00.1 ### DAL Improvements - Support for DAL(lazy_tables=True) and db.define_table(on_define=lambda table:), thanks Jonathan - MongoDB support in DAL (experimental), thanks Mark Breedveld - geodal and spatialite, thanks Denes and Fran (experimental) etc Is this the kind of testing you were after, or were you wanting people to change over to lazy tables to see if that works, the way Ron did? --
[web2py] How to call controller function upon onClick from html?
Hi, I have created one html file with list of records, each records are there in a row of table in html and there is one corresponding button (type as button) for each record so when user clicks on it , it should take the id of that record from the html call controller function which will further use id to fetch the complete records from the database and rendered the data onto the new html page. below is the button creation code in html: td style=text-align: center; vertical-align: middle; Button type=button name =seeting_button onClick = record_config(); IMG src={{=URL('static','images/Settings.png')}} ALIGN=absmiddle /td here record_config() function defined in controller (default.py) which will fetch data from db and display to another html page named record_config.html. Problem: record_config() function is not getting called upon clicking on the button, can anyone please suggest me the possible way to achieve the same? --
Re: [web2py] Re: Referencing other tables, two ways of doing it
On 27 August 2012 12:55, Anthony abasta...@gmail.com wrote: Not sure what you mean. Can you show your code? On Monday, August 27, 2012 4:22:18 AM UTC-4, Johann Spies wrote: On 26 August 2012 20:33, Anthony abas...@gmail.com wrote: the second method is the only way to keep the referenced table lazy (the first method will trigger the table to be defined). Does that mean that the lazy table option will not work for a system using a uuid-based reference in stead if id-based? I am referring to this type of code (from the book): db.define_table('person', Field('uuid', length=64, default=lambda:str(uuid.uuid4())), Field('modified_on', 'datetime', default=now), Field('name'), format='%(name)s') db.define_table('dog', Field('uuid', length=64, default=lambda:str(uuid.uuid4())), Field('modified_on', 'datetime', default=now), Field('owner', length=64), Field('name'), format='%(name)s') db.dog.owner.requires = IS_IN_DB(db,'person.uuid','%(name)s') if not db(db.person.id).count(): id = uuid.uuid4() db.person.insert(name=Massimo, uuid=id) db.dog.insert(owner=id, name=Snoopy) Regards Johann -- Because experiencing your loyal love is better than life itself, my lips will praise you. (Psalm 63:3) --
[web2py] Re: Book - Overview Typo
Another mistake is here: http://web2py.com/books/default/chapter/29/6#Copy-data-from-one-db-into-another hocalhost - localhost (multiple times) And I also thing that this is wrong: postgresql:// - postgres:// (multiple times) -rif miercuri, 15 august 2012, 16:33:18 UTC+3, Anthony a scris: Thanks for pointing this out. Note, the ) should actually go after (keyword): db(db.page.title.contains(keyword)).select().as_list() Anthony On Wednesday, August 15, 2012 5:52:53 AM UTC-4, Frank Cheong wrote: Just spotted one typo in the middle of the Overview Chapter inside the xmlrpc section, ) is missing at the end of code. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. service = Service() @service.xmlrpc def find_by(keyword): finds pages that contain keyword for XML-RPC return db(db.page.title.contains(keyword).select().as_list() def call(): exposes all registered services, including XML-RPC return service() whereas the final statement of the function find_by:- return db(db.page.title.contains(keyword).select().as_list() should be replaced by:- return db(db.page.title.contains(keyword).select().as_list()) --
Re: [web2py] Re: Referencing other tables, two ways of doing it
I am referring to this type of code (from the book): db.define_table('person', Field('uuid', length=64, default=lambda:str(uuid.uuid4())), Field('modified_on', 'datetime', default=now), Field('name'), format='%(name)s') db.define_table('dog', Field('uuid', length=64, default=lambda:str(uuid.uuid4())), Field('modified_on', 'datetime', default=now), Field('owner', length=64), Field('name'), format='%(name)s') db.dog.owner.requires = IS_IN_DB(db,'person.uuid','%(name)s') Doing db.dog triggers the table to be defined, so to avoid that, just move the requires into the Field definition: Field('owner', length=64, requires=IS_IN_DB(db,'person.uuid','%(name)s')) if not db(db.person.id).count(): id = uuid.uuid4() db.person.insert(name=Massimo, uuid=id) db.dog.insert(owner=id, name=Snoopy) Of course, the above code would trigger the table definition as well. Anthony --
[web2py] Re: How to call controller function upon onClick from html?
The onclick property of an HTML element must be Javascript. You cannot call a server-side Python function directly from the browser. If you want the button to work like a regular link and simply load a new page in place of the current page, you can do: Button type=button name =seeting_button onclick = 'window.location={{=URL('default', 'record_config', args=[record_id])}};' In that case, you would need Python code in the view to get the record_id for each link (presumably the buttons would be generated in a for loop that cycles through the record id's). Anthony On Monday, August 27, 2012 7:27:20 AM UTC-4, Amit wrote: Hi, I have created one html file with list of records, each records are there in a row of table in html and there is one corresponding button (type as button) for each record so when user clicks on it , it should take the id of that record from the html call controller function which will further use id to fetch the complete records from the database and rendered the data onto the new html page. below is the button creation code in html: td style=text-align: center; vertical-align: middle; Button type=button name =seeting_button onClick = record_config(); IMG src={{=URL('static','images/Settings.png')}} ALIGN=absmiddle /td here record_config() function defined in controller (default.py) which will fetch data from db and display to another html page named record_config.html. Problem: record_config() function is not getting called upon clicking on the button, can anyone please suggest me the possible way to achieve the same? --
[web2py] Re: DAL not returning results on temp table query
Massimo- Just tried testing with latest trunk DAL- it still fails silently and returns None results when trying to execute multiple statements with a single call On Saturday, August 25, 2012 4:39:23 PM UTC-4, Massimo Di Pierro wrote: Exately. On top of this until yesterday executesql had a try fetchall() except return None. which is now gone. If you get the latest web2py from trunk it should give you an error. On Saturday, 25 August 2012 13:52:42 UTC-5, Niphlod wrote: I think the DBAPI doesn't support several results set in a single statement. If you cared to do those one line at a time you'd noticed that: create temporary table tmp like people does not return results. insert into tmp select * from people returns the just inserted values select * from tmp returns your lines. I think that as long as you have only one statement (and it's the last ) in your executesql() wrapped string you'll be fine. If some of your lines returns results, then the driver doesn't know what set to actually return. Anyway splitting those lines in multiple db.executesql()s is working great. On Saturday, August 25, 2012 5:58:40 PM UTC+2, Yarin wrote: I'm trying to execute some SQL from the DAL that relies on a temp table: CREATE TEMPORARY TABLE tmp LIKE people; INSERT INTO tmp SELECT * FROM people; INSERT INTO tmp SELECT * FROM people; SELECT * FROM tmp; This code works fine in a SQL panel, but fails when used in the DAL: def test(): db_test = DAL('mysql://root:root@localhost/test') sql = CREATE TEMPORARY TABLE tmp LIKE people; INSERT INTO tmp SELECT * FROM people; INSERT INTO tmp SELECT * FROM people; SELECT * FROM tmp; results = db_test.executesql(sql) Results always returns None. No idea why or how to proceed. --
[web2py] short url's and 404
Hello I want to shorten url's and use hyphens in my paths. I also want to get a 404 if the user tries an invalid url. I have played with routes.py but the effect I get is shorter url's (good), hyphens in url's translated to underscores in function and view (good) , but all invalid url's route to the default a/c/f (bad). So the user doesn't see they have used an invalid url, they just get the home page. With this as my routes.py routers = dict( BASE = dict( default_application = 'app', map_hyphen = 'True', ), app = dict( default_controller = 'cc', default_function = 'f1', functions = ['f1', 'f2', ...], ), ) then http://domain/ -- home page http://domain/app -- home page http://domain/app/cc -- home page etc. http://domain/f2 -- f2 correctly But http://domain/bad-app-name -- home page too, which I don't want. Is this correct behaviour? How can I achieve my goal? Thanks very much. --
[web2py] DAL calls fail after first stored procedure call
Once I call a stored procedure through the DAL, any subsequent calls are returning None results. *Basic stored procedure:* BEGIN SELECT * FROM people; END *Works:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) return str(sproc_results) *Works:* def test(): sql = SELECT * FROM people; reg_results = db_test.executesql(sql) return str(reg_results) *Returns None:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) sql = SELECT * FROM people; reg_results = db_test.executesql(sql) return str(reg_results) *Returns None:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) return str(sproc_results) --
[web2py] Re: IMPORTANT - NEED HELP: more speed improvements to be tested
The following code is broken in trunk: db = DAL('sqlite://test.sqlite') db.define_table('t',Field('x')) db.t.insert(x=1) db(db.t).select(db.t.id,db.t.x+1).first()(db.t.id) Throws AttributeError: 'Row' object has no attribute 'id' The point seems to be the _extra entry created in the row object if we have a computed value in the select. Am Sonntag, 26. August 2012 14:47:35 UTC schrieb Massimo Di Pierro: Michele, Jonathan, Bruno, Anthony and I have continued test possible ways to improve web2py code. We have lazy tables in trunk and they can increase the speed of your code a lot but require minor rewrites of models. We are also looking at ways to improve the speed of your code without any rewrite and we have some important changes in trunk. They really need to be tested to make sure they do not break backward compatibility. accessing: request.anything response.anything session.anything as you can imagine this is everywhere. this is a major bottleneck. We made it 2-3x faster accessing: db.tablename we made this 2x faster accessing: db.tablename.fieldname we made this 20x faster (not a typo, 20x) Given row = db(db.table).select()[0] accessing: row.fieldname This is also a major bottleneck. We make this 10x faster. WE NEED TESTERS. Does the latest trunk/nightly built break your app? WE NEED INDEPENDENT BENCHMARKS AGAINST 1.99.7. Here is the code to benchmark: - import time db=DAL() db.define_table('person',Field('name')) db.test.insert(name='one') n = 10 t0 = time.time() for k in range(n): y = db.person.name print (time.time()-t0)/n row = db(db.person).select().first() t0 = time.time() for k in range(n): y = row.name print (time.time()-t0)/n -- Massimo --
Re: [web2py] Query by latitude and longitude
if you are doing GEO stuff i would highly recommend postrgres with postgis! then you can just ask for a point, point in polygon, polygon contains point etc. On Sunday, August 26, 2012 8:54:40 PM UTC-7, Andrew Evans wrote: nvm just found acos cos and such are not available in Dal or sqlite and I will need to use mysql *cheers ty :D On Sun, Aug 26, 2012 at 8:43 PM, Andrew Evans dj.set...@gmail.comjavascript: wrote: I was able to figure out the jquery side of things and found a query that suggests a way to do this. How can I do this below query in DAL using SQLite ;-) *cheers SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance 25 ORDER BY distance LIMIT 0 , 20; --
[web2py] Re: Facebook login only works when hosts is set to localhost?
you need to have a different FB app for test and for production. on facebook you set the valid domain for an app, and that is the only domain that it will accept redirect_uri to. (unless FB has improved and you can set multiple domains per appbut in either case you have to login to FB and update the app settings). cfh On Sunday, August 26, 2012 6:24:36 AM UTC-7, user1438003 wrote: Unfortunately I keep getting this error: { error: { message: Invalid redirect_uri: Given URL is not allowed by the Application configuration., type: OAuthException, code: 191 } } Login works however when my /etc/hosts file is set to: 127.0.0.1 [mysite]. rhcloud.com, it only fails when I view the actual [mysite].rhcloud.com. I am running the exact same application (on a different server) locally as the one I'm running on rhcloud. Specifically the local-remote web-application directories are synced. URL information When attempting login remotely the URL looks like this; and fails with aforementioned error: https://graph.facebook.com/oauth/authorize?scope=user_photos%2Cfriends_photosredirect_uri=http%3A%2F%2F[mypublicipaddress]%2Fuser%2Floginresponse_type=codeclient_id=[hidden] Whereas attempting to login locally the URL looks like this; and works: https://www.facebook.com/dialog/permissions.request?app_id=[hidden]display=pagenext=http%3A%2F%2F[hidden].rhcloud.com%2Fuser%2Floginresponse_type=codeperms=user_photos%2Cfriends_photosfbconnect=1 Note that I followed your guide for setting up Facebook with OAuth2: http://web2py.com/books/default/chapter/29/9 FYI: I also posted on StackOverflow http://stackoverflow.com/q/12078246 --
Re: [web2py] short url's and 404
On 27 Aug 2012, at 7:30 AM, jc j-cl...@lineone.net wrote: I want to shorten url's and use hyphens in my paths. I also want to get a 404 if the user tries an invalid url. I have played with routes.py but the effect I get is shorter url's (good), hyphens in url's translated to underscores in function and view (good) , but all invalid url's route to the default a/c/f (bad). So the user doesn't see they have used an invalid url, they just get the home page. With this as my routes.py routers = dict( BASE = dict( default_application = 'app', map_hyphen = 'True', ), app = dict( default_controller = 'cc', default_function = 'f1', functions = ['f1', 'f2', ...], ), ) then http://domain/ -- home page http://domain/app -- home page http://domain/app/cc -- home page etc. http://domain/f2 -- f2 correctly But http://domain/bad-app-name -- home page too, which I don't want. Is this correct behaviour? How can I achieve my goal? It's correct behavior. In your example, the router interprets your example as http://domain/app/cc/f1/bad-app-name because it figures that 'bad-app-name' must be an arg (request.args[0]). You can avoid that by leaving out the functions= line. The downside of *that* will be that 'f1' will not be omitted if there really is an arg. --
[web2py] Re: IMPORTANT - NEED HELP: more speed improvements to be tested
WE NEED INDEPENDENT BENCHMARKS AGAINST 1.99.7. Here is the code to benchmark: - import time db=DAL() db.define_table('person',Field('name')) db.test.insert(name='one') db.person.insert(name='one') n = 10 t0 = time.time() for k in range(n): y = db.person.name print (time.time()-t0)/n row = db(db.person).select().first() t0 = time.time() for k in range(n): y = row.name print (time.time()-t0)/n -- gcc version 4.5.3 (Gentoo 4.5.3-r2 p1.1, pie-0.4.7) Python 2.7.3 Version 1.99.7 (2012-03-04 22:12:08) stable: 7.47010946274e-06 5.64429044724e-06 Version 2.00.0 (2012-08-27 07:41:29) dev: 4.28411960602e-07 2.50899791718e-07 Daniel --
Re: [web2py] short url's and 404
That is very helpful, thank you. --
[web2py] user login tables
Hello My problem is that my app has to go to specific database on postgres to check for users. you can visit my app on http://portal.iurnik.si/ You can see that the user select a value from popup and then the app goes to a specific database to read data. After that I want to create a login form. I created it but,. I created a separate model users.py with this code database = now it is hardcoded so it works all the time baza = DAL('postgres://postgres:postgres@localhost/'+ database, migrate=True) auth = Auth(baza, hmac_key=Auth.get_or_create_key()) auth.settings.controller=user auth.define_tables() But what I would like to do is read the database name from url and the right url comes only after user selects the right value from popup. And that is why the app chashes if I don't hard code the db name. Logically. What do you suggest? also after logout user would stay on the second page not to go to default page (where do I set that parameter) Thank you --
[web2py] TypeError: can't pickle file objects
After placing gLib.py module into directory models web2py (versions 2.0 and 1.99.7 on Windows and Ubuntu) fails: Traceback (most recent call last): File /home/aabelyakov/MyPython/web2py/gluon/main.py, line 528, in wsgibase session._try_store_on_disk(request, response) File /home/aabelyakov/MyPython/web2py/gluon/globals.py, line 594, in _try_store_on_disk cPickle.dump(dict(self), response.session_file) File /usr/lib/python2.7/copy_reg.py, line 70, in _reduce_ex raise TypeError, can't pickle %s objects % base.__name__ TypeError: can't pickle file objects In what could be the reason? --
[web2py] Re: Pass arg or var to Active directory related SQLFORM
Maybe try something simple and build on that. For example, you could make simple form to submit the ref with a get variable... form = SQLFORM.factory(Field('ref',length=10,label='Test Ref'), _method = 'GET', _action=URL()) Then you can test to see whether the variable has been received: if request.get_vars.ref If so, find the record and make a normal SQLFORM to display it. Hope it gives you an idea. Regards, David On Monday, August 27, 2012 11:16:11 AM UTC+1, Fred Kornyev wrote: Hello, we have a small issue with trying to pass an argument/variable to one of our function. It seems the solution should be simple, but we just can't figure it out! The idea is simple: we have an input field for a userID and when you submit is would pull data with the users other attributes (job title, team name, etc). We would like the SQLFORM to appear below the submit section when a valid username is entered. We tried all sorts of methods with LOAD, the built-in ajax function and the component 'part' of the A helper... so our view looks like this: {{extend 'layout.html'}} script jQuery(document).ready(function(){ jQuery('#button').click(function(){ ajax({{=URL(c='ajax',f='ldap_fill.load')}},['name'],'placeholder'); return False; }); }); /script forminput name=name id='name'/form {{=A('CLICK HERE', _id=button, component=URL('ajax', 'ldap_fill.load', args=['name']), target='placeholder')}} div id='placeholder'/div There are two attempted solutions, but they don't work out: 1. With the jQuery on the top the SQLFORM that is returned by our ldap_fill function simply does not appear in the placeholder. 2. If we use the component of the A helper we can't figure out how to pass the contents of the input field as an argument. If I hardcode my username there then it brings up the SQLFORM filled with my details and when I submit it adds the entry to our app's database. So we just need a solution on how to have an input field and only show the SQLFORM below when a username is submitted. Thanks for anyone's time in advance!! --
[web2py] Use drop down in sql grid type 'exceptions.ValueError' too many values to unpack
Tryin to use the example shown in Validators between classical and professional usage http://web2py.wordpress.com/category/web2py-validators/to change the values and widget for an SQLFORM.grid. I need to display an Assign Trainers page with an SQLFORM.grid (or something similar) of new dogs that have not been assigned to a trainer but can only be assigned to new trainers that have not been given dogs. So I thought simple query the is_active property on both cases, append the validator make ( process) my form. db.define_table('trainer', Field('name'), Field('specialty'), auth.signature, format='%(name)s') db.trainer.is_active.default=False db.define_table('dogs', Field('name'), Field('bites', 'boolean'), Field('trainer', 'reference trainer', default=1, widget=SQLFORM.widgets.options.widget, requires=[IS_IN_DB('db.trainer', IS_UPPER())]), auth.signature, migrate=True) db.dogs.is_active.default=False Controller: def assign_trainers(): trainers=db(db.trianer._is_active==False) new_dogs=db(db.dogs._is_active==False) new_dogs.trainer.requires.append(IS_IN_SET(trainers)) grid = SQLFORM.grid(new_dogs) return locals() Been working on this solution for two days now. Read all the books, bought the Cookbookhttps://play.google.com/books/reader?id=cwjpG47z_7ICprintsec=frontcoveroutput=readerauthuser=0hl=enpg=GBS.PA1read the blogs and now I'm out of time with my prototype presentation due Thursday. ANY help is very much needed at this point. Thank you, Bill --
[web2py] Re: DAL calls fail after first stored procedure call
Pretty desperate on this one- brought everything to a screeching halt. We need to be able to call more than one stored procedure per request. Anybody got any ideas? On Monday, August 27, 2012 10:37:45 AM UTC-4, Yarin wrote: Once I call a stored procedure through the DAL, any subsequent calls are returning None results. *Basic stored procedure:* BEGIN SELECT * FROM people; END *Works:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) return str(sproc_results) *Works:* def test(): sql = SELECT * FROM people; reg_results = db_test.executesql(sql) return str(reg_results) *Returns None:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) sql = SELECT * FROM people; reg_results = db_test.executesql(sql) return str(reg_results) *Returns None:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) return str(sproc_results) --
[web2py] Re: DAL calls fail after first stored procedure call
Just a thought - does db.commit() help? Rgds, D On Monday, August 27, 2012 3:37:45 PM UTC+1, Yarin wrote: Once we call a stored procedure through the DAL, any subsequent DAL calls are returning None results. *Basic stored procedure:* BEGIN SELECT * FROM people; END *Works:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) return str(sproc_results) *Works:* def test(): sql = SELECT * FROM people; reg_results = db_test.executesql(sql) return str(reg_results) *Returns None:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) sql = SELECT * FROM people; reg_results = db_test.executesql(sql) return str(reg_results) *Returns None:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) return str(sproc_results) --
[web2py] Re: DAL calls fail after first stored procedure call
Villas- Thanks but no it doesn't- tried that.. On Monday, August 27, 2012 1:53:32 PM UTC-4, villas wrote: Just a thought - does db.commit() help? Rgds, D On Monday, August 27, 2012 3:37:45 PM UTC+1, Yarin wrote: Once we call a stored procedure through the DAL, any subsequent DAL calls are returning None results. *Basic stored procedure:* BEGIN SELECT * FROM people; END *Works:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) return str(sproc_results) *Works:* def test(): sql = SELECT * FROM people; reg_results = db_test.executesql(sql) return str(reg_results) *Returns None:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) sql = SELECT * FROM people; reg_results = db_test.executesql(sql) return str(reg_results) *Returns None:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) return str(sproc_results) --
[web2py] Re: Pass arg or var to Active directory related SQLFORM
Hey David, thanks for taking the time! Actually we have solved it by embedding our form in the form.accept part, so if the user types in a valid username into the first form (just an input field and a submit button) then the second form is called. On Monday, 27 August 2012 19:03:49 UTC+2, villas wrote: Maybe try something simple and build on that. For example, you could make simple form to submit the ref with a get variable... form = SQLFORM.factory(Field('ref',length=10,label='Test Ref'), _method = 'GET', _action=URL()) Then you can test to see whether the variable has been received: if request.get_vars.ref If so, find the record and make a normal SQLFORM to display it. Hope it gives you an idea. Regards, David On Monday, August 27, 2012 11:16:11 AM UTC+1, Fred Kornyev wrote: Hello, we have a small issue with trying to pass an argument/variable to one of our function. It seems the solution should be simple, but we just can't figure it out! The idea is simple: we have an input field for a userID and when you submit is would pull data with the users other attributes (job title, team name, etc). We would like the SQLFORM to appear below the submit section when a valid username is entered. We tried all sorts of methods with LOAD, the built-in ajax function and the component 'part' of the A helper... so our view looks like this: {{extend 'layout.html'}} script jQuery(document).ready(function(){ jQuery('#button').click(function(){ ajax({{=URL(c='ajax',f='ldap_fill.load')}},['name'],'placeholder'); return False; }); }); /script forminput name=name id='name'/form {{=A('CLICK HERE', _id=button, component=URL('ajax', 'ldap_fill.load', args=['name']), target='placeholder')}} div id='placeholder'/div There are two attempted solutions, but they don't work out: 1. With the jQuery on the top the SQLFORM that is returned by our ldap_fill function simply does not appear in the placeholder. 2. If we use the component of the A helper we can't figure out how to pass the contents of the input field as an argument. If I hardcode my username there then it brings up the SQLFORM filled with my details and when I submit it adds the entry to our app's database. So we just need a solution on how to have an input field and only show the SQLFORM below when a username is submitted. Thanks for anyone's time in advance!! --
Re: [web2py] Use drop down in sql grid type 'exceptions.ValueError' too many values to unpack
Hello, If I resume correctly you want to assign a trainer to a dog only if the trainer haven't been assign to any dogs yet? So, what you have to do it to build a set instead of only define an simple IS_IN_DB()... I would do something like this (not tested) : not_assign_yet_trainer_set = db(~db.trainers.id.belongs(db(db.dogs.id0).select(db.dogs.trainer, distinct=True))) Than you only have to use your set instead of db.trainers in the IS_IN_DB() where you normally define the db table to use. Does it help? Richard On Mon, Aug 27, 2012 at 1:12 PM, Bill Thayer bill.tha...@live.com wrote: Tryin to use the example shown in Validators between classical and professional usagehttp://web2py.wordpress.com/category/web2py-validators/to change the values and widget for an SQLFORM.grid. I need to display an Assign Trainers page with an SQLFORM.grid (or something similar) of new dogs that have not been assigned to a trainer but can only be assigned to new trainers that have not been given dogs. So I thought simple query the is_active property on both cases, append the validator make ( process) my form. db.define_table('trainer', Field('name'), Field('specialty'), auth.signature, format='%(name)s') db.trainer.is_active.default=False db.define_table('dogs', Field('name'), Field('bites', 'boolean'), Field('trainer', 'reference trainer', default=1, widget=SQLFORM.widgets.options.widget, requires=[IS_IN_DB('db.trainer', IS_UPPER())]), auth.signature, migrate=True) db.dogs.is_active.default=False Controller: def assign_trainers(): trainers=db(db.trianer._is_active==False) new_dogs=db(db.dogs._is_active==False) new_dogs.trainer.requires.append(IS_IN_SET(trainers)) grid = SQLFORM.grid(new_dogs) return locals() Been working on this solution for two days now. Read all the books, bought the Cookbookhttps://play.google.com/books/reader?id=cwjpG47z_7ICprintsec=frontcoveroutput=readerauthuser=0hl=enpg=GBS.PA1read the blogs and now I'm out of time with my prototype presentation due Thursday. ANY help is very much needed at this point. Thank you, Bill -- --
[web2py] Re: DAL not returning results on temp table query
Please check agin. there is no more try-except in there. On Monday, 27 August 2012 09:01:26 UTC-5, Yarin wrote: Massimo- Just tried testing with latest trunk DAL- it still fails silently and returns None results when trying to execute multiple statements with a single call On Saturday, August 25, 2012 4:39:23 PM UTC-4, Massimo Di Pierro wrote: Exately. On top of this until yesterday executesql had a try fetchall() except return None. which is now gone. If you get the latest web2py from trunk it should give you an error. On Saturday, 25 August 2012 13:52:42 UTC-5, Niphlod wrote: I think the DBAPI doesn't support several results set in a single statement. If you cared to do those one line at a time you'd noticed that: create temporary table tmp like people does not return results. insert into tmp select * from people returns the just inserted values select * from tmp returns your lines. I think that as long as you have only one statement (and it's the last ) in your executesql() wrapped string you'll be fine. If some of your lines returns results, then the driver doesn't know what set to actually return. Anyway splitting those lines in multiple db.executesql()s is working great. On Saturday, August 25, 2012 5:58:40 PM UTC+2, Yarin wrote: I'm trying to execute some SQL from the DAL that relies on a temp table: CREATE TEMPORARY TABLE tmp LIKE people; INSERT INTO tmp SELECT * FROM people; INSERT INTO tmp SELECT * FROM people; SELECT * FROM tmp; This code works fine in a SQL panel, but fails when used in the DAL: def test(): db_test = DAL('mysql://root:root@localhost/test') sql = CREATE TEMPORARY TABLE tmp LIKE people; INSERT INTO tmp SELECT * FROM people; INSERT INTO tmp SELECT * FROM people; SELECT * FROM tmp; results = db_test.executesql(sql) Results always returns None. No idea why or how to proceed. --
[web2py] Re: IMPORTANT - NEED HELP: more speed improvements to be tested
Thanks. This confirms my results. There is also a better db(...).select(cache=(cache.rame,3600)) It should be much faster than before. On Monday, 27 August 2012 09:55:49 UTC-5, Daniel Haag wrote: WE NEED INDEPENDENT BENCHMARKS AGAINST 1.99.7. Here is the code to benchmark: - import time db=DAL() db.define_table('person',Field('name')) db.test.insert(name='one') db.person.insert(name='one') n = 10 t0 = time.time() for k in range(n): y = db.person.name print (time.time()-t0)/n row = db(db.person).select().first() t0 = time.time() for k in range(n): y = row.name print (time.time()-t0)/n -- gcc version 4.5.3 (Gentoo 4.5.3-r2 p1.1, pie-0.4.7) Python 2.7.3 Version 1.99.7 (2012-03-04 22:12:08) stable: 7.47010946274e-06 5.64429044724e-06 Version 2.00.0 (2012-08-27 07:41:29) dev: 4.28411960602e-07 2.50899791718e-07 Daniel --
[web2py] Re: user login tables
If this is a new app you may want to replace auth = Auth(baza, hmac_key=Auth.get_or_create_key()) with auth = Auth(baza) as it will be faster and same security because latest Auth has built-in salting. About your problem. You cannot complete let the user specify it. You must have a default and a set of default values: database = session.get('database','default_database') The you can have a form that stores the one they want into session.database On Monday, 27 August 2012 10:09:34 UTC-5, Yebach wrote: Hello My problem is that my app has to go to specific database on postgres to check for users. you can visit my app on http://portal.iurnik.si/ You can see that the user select a value from popup and then the app goes to a specific database to read data. After that I want to create a login form. I created it but,. I created a separate model users.py with this code database = now it is hardcoded so it works all the time baza = DAL('postgres://postgres:postgres@localhost/'+ database, migrate=True) auth = Auth(baza, hmac_key=Auth.get_or_create_key()) auth.settings.controller=user auth.define_tables() But what I would like to do is read the database name from url and the right url comes only after user selects the right value from popup. And that is why the app chashes if I don't hard code the db name. Logically. What do you suggest? also after logout user would stay on the second page not to go to default page (where do I set that parameter) Thank you --
[web2py] Re: TypeError: can't pickle file objects
gLib.py is probably a module, not a model. I would put it there. Why it fails I cannot say, I do not know what it does. On Monday, 27 August 2012 11:22:31 UTC-5, aabelyakov wrote: After placing gLib.py module into directory models web2py (versions 2.0 and 1.99.7 on Windows and Ubuntu) fails: Traceback (most recent call last): File /home/aabelyakov/MyPython/web2py/gluon/main.py, line 528, in wsgibase session._try_store_on_disk(request, response) File /home/aabelyakov/MyPython/web2py/gluon/globals.py, line 594, in _try_store_on_disk cPickle.dump(dict(self), response.session_file) File /usr/lib/python2.7/copy_reg.py, line 70, in _reduce_ex raise TypeError, can't pickle %s objects % base.__name__ TypeError: can't pickle file objects In what could be the reason? --
[web2py] Re: DAL calls fail after first stored procedure call
I do not think this is a DAL issue. This looks database issue or a driver issue. Web2py does not do another else but pass your SQL to the driver and fetch responses. Is this SQLITE? In any case, I suggest you try the native driver APIs. On Monday, 27 August 2012 09:37:45 UTC-5, Yarin wrote: Once we call a stored procedure through the DAL, any subsequent DAL calls are returning None results. *Basic stored procedure:* BEGIN SELECT * FROM people; END *Works:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) return str(sproc_results) *Works:* def test(): sql = SELECT * FROM people; reg_results = db_test.executesql(sql) return str(reg_results) *Returns None:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) sql = SELECT * FROM people; reg_results = db_test.executesql(sql) return str(reg_results) *Returns None:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) return str(sproc_results) --
[web2py] Re: Use drop down in sql grid type 'exceptions.ValueError' too many values to unpack
Try this... Model db.define_table('trainer', Field('name'), Field('specialty'), auth.signature, format='%(name)s', migrate=True, ) db.define_table('dogs', Field('name'), Field('bites', 'boolean'), Field('trainer', 'reference trainer'), auth.signature, format='%(name)s', migrate=True, ) unassignedtrainers = (~db.trainer.id.belongs(db()._select(db.dogs.trainer))) db.dogs.trainer.requires = IS_IN_DB(db(unassignedtrainers), 'trainer.id', '%(name)s',zero=T('choose one')) if not db(db.trainer.id0).count(): db.trainer.insert( name=Alan, specialty=alsatians ) db.trainer.insert( name=Ben, specialty=blind dogs ) db.trainer.insert( name=Carl, specialty=corgis ) if not db(db.dogs.id0).count(): db.dogs.insert( name=Fido, bites=False, trainer=None ) db.dogs.insert( name=Rover, bites=True, trainer=None ) Controller: def assign_trainers(): grid = SQLFORM.grid((db.dogs.trainer==None),user_signature=False) return locals() I think it works, but I didn't test it very much. Rgds, David --
[web2py] Re: DAL calls fail after first stored procedure call
This is MySQL using the default driver, whatever that is. I'm going to test on other drivers/dbs and will report back.. On Monday, August 27, 2012 3:03:15 PM UTC-4, Massimo Di Pierro wrote: I do not think this is a DAL issue. This looks database issue or a driver issue. Web2py does not do another else but pass your SQL to the driver and fetch responses. Is this SQLITE? In any case, I suggest you try the native driver APIs. On Monday, 27 August 2012 09:37:45 UTC-5, Yarin wrote: Once we call a stored procedure through the DAL, any subsequent DAL calls are returning None results. *Basic stored procedure:* BEGIN SELECT * FROM people; END *Works:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) return str(sproc_results) *Works:* def test(): sql = SELECT * FROM people; reg_results = db_test.executesql(sql) return str(reg_results) *Returns None:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) sql = SELECT * FROM people; reg_results = db_test.executesql(sql) return str(reg_results) *Returns None:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) return str(sproc_results) --
[web2py] Re: Use drop down in sql grid type 'exceptions.ValueError' too many values to unpack
Thank you David, I'll try it as soon as I finish my current round of debugging. -Bill On Monday, August 27, 2012 2:05:24 PM UTC-5, villas wrote: Try this... Model db.define_table('trainer', Field('name'), Field('specialty'), auth.signature, format='%(name)s', migrate=True, ) db.define_table('dogs', Field('name'), Field('bites', 'boolean'), Field('trainer', 'reference trainer'), auth.signature, format='%(name)s', migrate=True, ) unassignedtrainers = (~db.trainer.id.belongs(db()._select(db.dogs.trainer ))) db.dogs.trainer.requires = IS_IN_DB(db(unassignedtrainers), 'trainer.id', '%(name)s',zero=T('choose one')) if not db(db.trainer.id0).count(): db.trainer.insert( name=Alan, specialty=alsatians ) db.trainer.insert( name=Ben, specialty=blind dogs ) db.trainer.insert( name=Carl, specialty=corgis ) if not db(db.dogs.id0).count(): db.dogs.insert( name=Fido, bites=False, trainer=None ) db.dogs.insert( name=Rover, bites=True, trainer=None ) Controller: def assign_trainers(): grid = SQLFORM.grid((db.dogs.trainer==None),user_signature=False) return locals() I think it works, but I didn't test it very much. Rgds, David --
Re: [web2py] Use drop down in sql grid type 'exceptions.ValueError' too many values to unpack
Thank you Richard, I'll try it as soon as I finish my current round of debugging. -Bill On Monday, August 27, 2012 1:20:49 PM UTC-5, Richard wrote: Hello, If I resume correctly you want to assign a trainer to a dog only if the trainer haven't been assign to any dogs yet? So, what you have to do it to build a set instead of only define an simple IS_IN_DB()... I would do something like this (not tested) : not_assign_yet_trainer_set = db(~db.trainers.id.belongs(db(db.dogs.id0).select(db.dogs.trainer, distinct=True))) Than you only have to use your set instead of db.trainers in the IS_IN_DB() where you normally define the db table to use. Does it help? Richard On Mon, Aug 27, 2012 at 1:12 PM, Bill Thayer bill@live.comjavascript: wrote: Tryin to use the example shown in Validators between classical and professional usagehttp://web2py.wordpress.com/category/web2py-validators/to change the values and widget for an SQLFORM.grid. I need to display an Assign Trainers page with an SQLFORM.grid (or something similar) of new dogs that have not been assigned to a trainer but can only be assigned to new trainers that have not been given dogs. So I thought simple query the is_active property on both cases, append the validator make ( process) my form. db.define_table('trainer', Field('name'), Field('specialty'), auth.signature, format='%(name)s') db.trainer.is_active.default=False db.define_table('dogs', Field('name'), Field('bites', 'boolean'), Field('trainer', 'reference trainer', default=1, widget=SQLFORM.widgets.options.widget, requires=[IS_IN_DB('db.trainer', IS_UPPER())]), auth.signature, migrate=True) db.dogs.is_active.default=False Controller: def assign_trainers(): trainers=db(db.trianer._is_active==False) new_dogs=db(db.dogs._is_active==False) new_dogs.trainer.requires.append(IS_IN_SET(trainers)) grid = SQLFORM.grid(new_dogs) return locals() Been working on this solution for two days now. Read all the books, bought the Cookbookhttps://play.google.com/books/reader?id=cwjpG47z_7ICprintsec=frontcoveroutput=readerauthuser=0hl=enpg=GBS.PA1read the blogs and now I'm out of time with my prototype presentation due Thursday. ANY help is very much needed at this point. Thank you, Bill -- --
[web2py] Re: DAL calls fail after first stored procedure call
Try use mysqldb too. The default pymysql has some problems. We even have to monkeypatch it for security. Massimo On Monday, 27 August 2012 14:20:00 UTC-5, Yarin wrote: This is MySQL using the default driver, whatever that is. I'm going to test on other drivers/dbs and will report back.. On Monday, August 27, 2012 3:03:15 PM UTC-4, Massimo Di Pierro wrote: I do not think this is a DAL issue. This looks database issue or a driver issue. Web2py does not do another else but pass your SQL to the driver and fetch responses. Is this SQLITE? In any case, I suggest you try the native driver APIs. On Monday, 27 August 2012 09:37:45 UTC-5, Yarin wrote: Once we call a stored procedure through the DAL, any subsequent DAL calls are returning None results. *Basic stored procedure:* BEGIN SELECT * FROM people; END *Works:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) return str(sproc_results) *Works:* def test(): sql = SELECT * FROM people; reg_results = db_test.executesql(sql) return str(reg_results) *Returns None:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) sql = SELECT * FROM people; reg_results = db_test.executesql(sql) return str(reg_results) *Returns None:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) return str(sproc_results) --
[web2py] Re: IMPORTANT - NEED HELP: more speed improvements to be tested
FYI, in trunk, response.toolbar() now includes a new db tables button, which shows the tables that were fully defined (i.e., those that did not remain lazy) during the request. You can use this to verify which tables are getting defined and which are remaining lazy depending on the URL being called. Anthony On Sunday, August 26, 2012 10:47:35 AM UTC-4, Massimo Di Pierro wrote: Michele, Jonathan, Bruno, Anthony and I have continued test possible ways to improve web2py code. We have lazy tables in trunk and they can increase the speed of your code a lot but require minor rewrites of models. We are also looking at ways to improve the speed of your code without any rewrite and we have some important changes in trunk. They really need to be tested to make sure they do not break backward compatibility. accessing: request.anything response.anything session.anything as you can imagine this is everywhere. this is a major bottleneck. We made it 2-3x faster accessing: db.tablename we made this 2x faster accessing: db.tablename.fieldname we made this 20x faster (not a typo, 20x) Given row = db(db.table).select()[0] accessing: row.fieldname This is also a major bottleneck. We make this 10x faster. WE NEED TESTERS. Does the latest trunk/nightly built break your app? WE NEED INDEPENDENT BENCHMARKS AGAINST 1.99.7. Here is the code to benchmark: - import time db=DAL() db.define_table('person',Field('name')) db.test.insert(name='one') n = 10 t0 = time.time() for k in range(n): y = db.person.name print (time.time()-t0)/n row = db(db.person).select().first() t0 = time.time() for k in range(n): y = row.name print (time.time()-t0)/n -- Massimo --
[web2py] Re: DAL calls fail after first stored procedure call
This is an issue with pymsql: http://code.google.com/p/pymysql/issues/detail?id=72, https://github.com/petehunt/PyMySQL/blob/master/pymysql/cursors.py Running against pymysql's api directly, I can execute sproc calls on on two different connections, but not on the same connection. So... - What's the best way to emulate closing/opening a connection through the DAL- does it mean instantiating a new DAL object? Is working with multiple DAL objects a bad idea, or is that a good workaround? - If I switch to mysqldb, does that mean i've got to write my own adapter? If there's already adapters/recipes ready for using mysqldb I'll try it, otherwise I can't spare the time right now.. On Monday, August 27, 2012 3:52:06 PM UTC-4, Massimo Di Pierro wrote: Try use mysqldb too. The default pymysql has some problems. We even have to monkeypatch it for security. Massimo On Monday, 27 August 2012 14:20:00 UTC-5, Yarin wrote: This is MySQL using the default driver, whatever that is. I'm going to test on other drivers/dbs and will report back.. On Monday, August 27, 2012 3:03:15 PM UTC-4, Massimo Di Pierro wrote: I do not think this is a DAL issue. This looks database issue or a driver issue. Web2py does not do another else but pass your SQL to the driver and fetch responses. Is this SQLITE? In any case, I suggest you try the native driver APIs. On Monday, 27 August 2012 09:37:45 UTC-5, Yarin wrote: Once we call a stored procedure through the DAL, any subsequent DAL calls are returning None results. *Basic stored procedure:* BEGIN SELECT * FROM people; END *Works:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) return str(sproc_results) *Works:* def test(): sql = SELECT * FROM people; reg_results = db_test.executesql(sql) return str(reg_results) *Returns None:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) sql = SELECT * FROM people; reg_results = db_test.executesql(sql) return str(reg_results) *Returns None:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) return str(sproc_results) --
[web2py] New Feature: DIV.elements(..., replace=...)
Previously, you could use the .elements() method to find matching elements nested within an HTML helper object (such as a form), and you could mutuate the matched elements (e.g., add attributes and insert components), but you could not completely replace or remove the matched elements. The only way to replace or remove elements was to use list indexing (e.g., form[0][0][1], etc.), but that requires you to know the exact index values ahead of time. Now (in trunk) you can use the .elements() method to replace or remove nested elements or text using the new replace and find_text arguments. Below is the updated docstring, including some examples (will be added to the book as well). Please test and report any problems (particularly if any of the old .elements() functionality has broken). Anthony Docstring: Elements that are matched can also be replaced or removed by specifying a replace argument (note, a list of the original matching elements is still returned as usual). a = DIV(DIV(SPAN('x', _class='abc'), DIV(SPAN('y', _class='abc'), SPAN('z', _class='abc' b = a.elements('span.abc', replace=P('x', _class='xyz')) print a divdivp class=xyzx/pdivp class=xyzx/pp class=xyzx/p/div/div/div replace can be a callable, which will be passed the original element and should return a new element to replace it. a = DIV(DIV(SPAN('x', _class='abc'), DIV(SPAN('y', _class='abc'), SPAN('z', _class='abc' b = a.elements('span.abc', replace=lambda el: P(el[0], _class='xyz')) print a divdivp class=xyzx/pdivp class=xyzy/pp class=xyzz/p/div/div/div If replace=None, matching elements will be removed completely. a = DIV(DIV(SPAN('x', _class='abc'), DIV(SPAN('y', _class='abc'), SPAN('z', _class='abc' b = a.elements('span', find='y', replace=None) print a divdivspan class=abcx/spandivspan class=abcz/span/div/div/div If a find_text argument is specified, elements will be searched for text components that match find_text, and any matching text components will be replaced (find_text is ignored if replace is not also specified). Like the find argument, find_text can be a string or a compiled regex. a = DIV(DIV(SPAN('x', _class='abc'), DIV(SPAN('y', _class='abc'), SPAN('z', _class='abc' b = a.elements(find_text=re.compile('x|y|z'), replace='hello') print a divdivspan class=abchello/spandivspan class=abchello/spanspan class=abchello/span/div/div/div If other attributes are specified along with find_text, then only components that match the specified attributes will be searched for find_text. a = DIV(DIV(SPAN('x', _class='abc'), DIV(SPAN('y', _class='efg'), SPAN('z', _class='abc' b = a.elements('span.efg', find_text=re.compile('x|y|z'), replace='hello') print a divdivspan class=abcx/spandivspan class=efghello/spanspan class=abcz/span/div/div/div --
[web2py] Re: DAL calls fail after first stored procedure call
The existing adapter should work with mysqldb. Try: import mysqldb from gluon.dal import MySQLAdapter MySQLAdapter.driver = mysqldb db=DAL('mysql://') Anthony On Monday, August 27, 2012 4:37:42 PM UTC-4, Yarin wrote: This is an issue with pymsql: http://code.google.com/p/pymysql/issues/detail?id=72, https://github.com/petehunt/PyMySQL/blob/master/pymysql/cursors.py Running against pymysql's api directly, I can execute sproc calls on on two different connections, but not on the same connection. So... - What's the best way to emulate closing/opening a connection through the DAL- does it mean instantiating a new DAL object? Is working with multiple DAL objects a bad idea, or is that a good workaround? - If I switch to mysqldb, does that mean i've got to write my own adapter? If there's already adapters/recipes ready for using mysqldb I'll try it, otherwise I can't spare the time right now.. On Monday, August 27, 2012 3:52:06 PM UTC-4, Massimo Di Pierro wrote: Try use mysqldb too. The default pymysql has some problems. We even have to monkeypatch it for security. Massimo On Monday, 27 August 2012 14:20:00 UTC-5, Yarin wrote: This is MySQL using the default driver, whatever that is. I'm going to test on other drivers/dbs and will report back.. On Monday, August 27, 2012 3:03:15 PM UTC-4, Massimo Di Pierro wrote: I do not think this is a DAL issue. This looks database issue or a driver issue. Web2py does not do another else but pass your SQL to the driver and fetch responses. Is this SQLITE? In any case, I suggest you try the native driver APIs. On Monday, 27 August 2012 09:37:45 UTC-5, Yarin wrote: Once we call a stored procedure through the DAL, any subsequent DAL calls are returning None results. *Basic stored procedure:* BEGIN SELECT * FROM people; END *Works:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) return str(sproc_results) *Works:* def test(): sql = SELECT * FROM people; reg_results = db_test.executesql(sql) return str(reg_results) *Returns None:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) sql = SELECT * FROM people; reg_results = db_test.executesql(sql) return str(reg_results) *Returns None:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) return str(sproc_results) --
[web2py] how can i allow both web2py and shellinabox to share an https port?
i am running both web2py and shellinabox ( http://code.google.com/p/shellinabox/ ) on my vps. i am running shellinabox so that i uses the https port to keep it secure. currently web2py is running on its own built-in web server and i just navigate to the ip address of my vps @ port 80. i'd like to be able to login and use the admin interface but the https port is taken up. is there a way to make these two programs share a port? or perhaps embed shellinabox within web2py somehow? --
[web2py] how to escape data from request.post_vars to prevent SQLi
How can I escape the data submitted by my form to prevent SQL Injection. I read using request.post_vars does not escape the data, I am using a form built in HTML and submitting the data passing request.post_vars as variables to my SQL Query. Any ideas *cheers --
[web2py] Executesql Not returning results
I am trying to figure out why executesql is not returning any results in this query. I am using mysql, any suggestions would be greatly appreciated. There are no errors just an empty view *cheers Code Below *Controller* def location(): current_lat = request.post_vars[lat] current_lon = request.post_vars[lon] val = request.post_vars[search-distance] distance = db.executesql(SELECT *, (3959 * acos(cos(radians(%f)) * cos(radians(latitude)) * cos(radians(longitude) - radians(%f)) + sin(radians(%f)) * sin(radians(latitude AS distance FROM listing HAVING distance %d ORDER BY distance LIMIT 0, 20; % (float(current_lat), float(current_lon), float(current_lat), int(val))) return dict(distance=distance) *Example View* {{for query in distance:}} div class=listingItem h2{{=query[2]}}/h2 p {{=query[3]}} --
[web2py] Re: Executesql Not returning results
Nvm I got it to work my latitude and longitude were in the wrong entries :D On Mon, Aug 27, 2012 at 7:12 AM, Andrew Evans dj.setili...@gmail.comwrote: I am trying to figure out why executesql is not returning any results in this query. I am using mysql, any suggestions would be greatly appreciated. There are no errors just an empty view *cheers Code Below *Controller* def location(): current_lat = request.post_vars[lat] current_lon = request.post_vars[lon] val = request.post_vars[search-distance] distance = db.executesql(SELECT *, (3959 * acos(cos(radians(%f)) * cos(radians(latitude)) * cos(radians(longitude) - radians(%f)) + sin(radians(%f)) * sin(radians(latitude AS distance FROM listing HAVING distance %d ORDER BY distance LIMIT 0, 20; % (float(current_lat), float(current_lon), float(current_lat), int(val))) return dict(distance=distance) *Example View* {{for query in distance:}} div class=listingItem h2{{=query[2]}}/h2 p {{=query[3]}} --
Re: [web2py] Query by latitude and longitude
hey thanks I was able to get it to working using that MySQL query and Web2py's executesql method *cheers On Mon, Aug 27, 2012 at 7:46 AM, howesc how...@umich.edu wrote: if you are doing GEO stuff i would highly recommend postrgres with postgis! then you can just ask for a point, point in polygon, polygon contains point etc. On Sunday, August 26, 2012 8:54:40 PM UTC-7, Andrew Evans wrote: nvm just found acos cos and such are not available in Dal or sqlite and I will need to use mysql *cheers ty :D On Sun, Aug 26, 2012 at 8:43 PM, Andrew Evans dj.set...@gmail.comwrote: I was able to figure out the jquery side of things and found a query that suggests a way to do this. How can I do this below query in DAL using SQLite ;-) *cheers SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance 25 ORDER BY distance LIMIT 0 , 20; -- --
[web2py] Re: how to escape data from request.post_vars to prevent SQLi
Is there a reason you can't use the DAL to do the insert? On Monday, August 27, 2012 4:32:09 PM UTC-4, Andrew Evans wrote: How can I escape the data submitted by my form to prevent SQL Injection. I read using request.post_vars does not escape the data, I am using a form built in HTML and submitting the data passing request.post_vars as variables to my SQL Query. Any ideas *cheers --
Re: [web2py] Re: how to escape data from request.post_vars to prevent SQLi
yes I have a peculiar SQL query that is using ACOS(), COS() etc for geolocation. I would love to use DAL but it is for a mobile device :D *cheers On Mon, Aug 27, 2012 at 2:11 PM, Anthony abasta...@gmail.com wrote: Is there a reason you can't use the DAL to do the insert? On Monday, August 27, 2012 4:32:09 PM UTC-4, Andrew Evans wrote: How can I escape the data submitted by my form to prevent SQL Injection. I read using request.post_vars does not escape the data, I am using a form built in HTML and submitting the data passing request.post_vars as variables to my SQL Query. Any ideas *cheers -- --
[web2py] Re: need a simple wiki...
I am not sure I fully understand the reason for these suggestions. You seem to need access to the Wiki object in more then one controller. Why? I can see why one may want to define the wiki outside of an action to benefit from the menu (if you delete models/menu.py) all actions will have the wiki menu but only one action should actually expose the menu. Perhaps I misunderstood. massimo On Monday, 27 August 2012 06:06:00 UTC-5, Alan Etkin wrote: I'be been testing the wiki for a while and have some random comments. -I created .wiki() in the model and used it in a given function, but it doesn't add by default the menu entries -Doing auth.wiki() in any function is not apt for lazyness. i'd add the option to decorate them: @auth.wikify() def afunction(): ... return dict() -And also a app-wide command to make any action a wiki would be cool -I think that the scaffolding layout should have a wiki block or similar to automagically put the wiki contents -There's need for sort of a request arguments handling, to support using the wiki with other objects in the view. For instance: If you create the wiki in the model to allow crud with appadmin, insert/select/... commands fail for wiki rewrites the request I managed to filter the appadmin controller in the wiki code so it prevents it, but it will fail with other features like custom .grid objects arguments exposed in the same view Current auth.wiki rocks, but with those enhancements, I think it would be even better. --
Re: [web2py] Re: SEO Friendly URLs and Page Titles
Okay, but do I leave everything else alone? All I want to do is make it www.mysite.com/equipment/id/title currently, title is set up as slug in the DB. What am I doing wrong. In my view: equipment_id = request.args(0) equipment_slug = request.args(1) query = (db.equipment.id == item_id) (db.equipment.slug == item_slug) item = db(query).select().first() try: equipment = db.equipment[int(request.args(0))] except: equipment = db.equipment(request.args(0)) or db(db.equipment.slug == request.args(0)).select().first() and then my link in sqlform: links = [lambda row: A('Details',_href=URL('default','equipment', args=[row.slug]))] On Sunday, August 26, 2012 5:52:52 PM UTC-6, rochacbruno wrote: def show(): item_id = request.args(0) item_slug = request.args(1) query = (db.items.id == item_id) (db.items.slug == item_slug) item = db(query).select().first() return dict(item=item) http://myapp/items/show/1/awesome-product http://myapp/items/show/2/awesome-product On Sun, Aug 26, 2012 at 4:01 AM, SeamusSeamus morrisjam...@gmail.comjavascript: wrote: I would like to make it part of the URLbut am unsure how to do it...any tutorials or a quick way? On Saturday, August 25, 2012 6:59:29 PM UTC-6, Anthony wrote: Oh, yeah, I guess you probably can't use the id in a compute because there is no id until the record has been inserted. You could instead make the id part of the URL (like Stack Overflow), or maybe make it a virtual field, or generate your own unique id (separate from the record id). Anthony On Saturday, August 25, 2012 8:34:22 PM UTC-4, SeamusSeamus wrote: Thanks for the info Anthony... When I do this: Field('slug', compute=lambda row: IS_SLUG()(row.title + - + str( row.id))[0]) I get none as a slug... On Saturday, August 25, 2012 5:53:49 PM UTC-6, Anthony wrote: Sure, something like that seems fine. Look at what SO does -- for example: http://stackoverflow.**com/questions/12050934/web2py-** build-forms-in-controller-or-**viewhttp://stackoverflow.com/questions/12050934/web2py-build-forms-in-controller-or-view. I think they use the number as the unique record identifier, but also include a slug (which doesn't necessarily have to be unique). Anthony On Saturday, August 25, 2012 7:16:50 PM UTC-4, SeamusSeamus wrote: This runs into a problem where if I have two items of the same 'title', the user will only be linked to the first one that was created. Can I make it so the slug is a field that I designate? Or make it so the slug adds a incrementing number such as: Field('slug', compute=lambda row: IS_SLUG()(row.title *+ row.id* )[0]) I know thats not how you do it, but do you get what I mean? Is there a better way? On Thursday, August 23, 2012 1:18:16 AM UTC-6, Anthony wrote: links = [lambda ro w: A('Details',_href=URL('**default','show', args=[row.slug]))] fields = [db.equipment.category, db.equipment.title, db.equipment.price] You have not included slug in your list of fields, so I believe it will not be included in the data query. Instead of specifying the list of fields, you can set the readable attribute to False for fields you don't want displayed (including slug). In that case, all fields will be included in the query (including slug), but only the fields you want to show will be visible in the grid. Anthony -- --
Re: [web2py] Re: SEO Friendly URLs and Page Titles
I don't know if you picked this up, but you don't seem to have row.id as part of the sqlfrom url. Perhaps try: links = [lambda row: A('Details',_href=URL('default','equipment', args=[row.id, row.slug]))] On Tuesday, August 28, 2012 10:28:39 AM UTC+12, SeamusSeamus wrote: Okay, but do I leave everything else alone? All I want to do is make it www.mysite.com/equipment/id/title currently, title is set up as slug in the DB. What am I doing wrong. In my view: equipment_id = request.args(0) equipment_slug = request.args(1) query = (db.equipment.id == item_id) (db.equipment.slug == item_slug) item = db(query).select().first() try: equipment = db.equipment[int(request.args(0))] except: equipment = db.equipment(request.args(0)) or db(db.equipment.slug == request.args(0)).select().first() and then my link in sqlform: links = [lambda row: A('Details',_href=URL('default','equipment', args=[row.slug]))] --
Re: [web2py] Re: SEO Friendly URLs and Page Titles
ah, yes, all is well now...however, this is strange. Now, when I click the link on the table to take me to the 'equipment.html' page (I renamed it from details.html), it shows the controller in the URL: www.mysite.com/default/equipment/id/title how do I make it so the 'default' does not show up? It didnt show up before it looked like this: links = [lambda row: A('Details',_href=URL('default', 'details', args=[row.id, row.slug]))] I changed to links = [lambda row: A('Details',_href=URL('default', 'equipment', args=[row.id, row.slug]))] I also changed the controller from def default to def equipment, and also changed default.html to equipment.html in views... now it shows the controller in the URL... my routes looks like this routers = dict( BASE = dict(default_application='equipment', default_controller = 'default',), ) On Monday, August 27, 2012 4:38:41 PM UTC-6, Limedrop wrote: I don't know if you picked this up, but you don't seem to have row.id as part of the sqlfrom url. Perhaps try: links = [lambda row: A('Details',_href=URL('default','equipment', args=[row.id, row.slug]))] On Tuesday, August 28, 2012 10:28:39 AM UTC+12, SeamusSeamus wrote: Okay, but do I leave everything else alone? All I want to do is make it www.mysite.com/equipment/id/title currently, title is set up as slug in the DB. What am I doing wrong. In my view: equipment_id = request.args(0) equipment_slug = request.args(1) query = (db.equipment.id == item_id) (db.equipment.slug == item_slug) item = db(query).select().first() try: equipment = db.equipment[int(request.args(0))] except: equipment = db.equipment(request.args(0)) or db(db.equipment.slug == request.args(0)).select().first() and then my link in sqlform: links = [lambda row: A('Details',_href=URL('default','equipment', args=[row.slug]))] --
Re: [web2py] Re: SEO Friendly URLs and Page Titles
nevermind I fixed it. Not sure why, but if it was named 'equipment' the controller showed up...any other name it doesnt. I just renamed On Monday, August 27, 2012 5:05:44 PM UTC-6, SeamusSeamus wrote: ah, yes, all is well now...however, this is strange. Now, when I click the link on the table to take me to the 'equipment.html' page (I renamed it from details.html), it shows the controller in the URL: www.mysite.com/default/equipment/id/title how do I make it so the 'default' does not show up? It didnt show up before it looked like this: links = [lambda row: A('Details',_href=URL('default', 'details', args=[ row.id, row.slug]))] I changed to links = [lambda row: A('Details',_href=URL('default', 'equipment', args=[row.id, row.slug]))] I also changed the controller from def default to def equipment, and also changed default.html to equipment.html in views... now it shows the controller in the URL... my routes looks like this routers = dict( BASE = dict(default_application='equipment', default_controller = 'default',), ) On Monday, August 27, 2012 4:38:41 PM UTC-6, Limedrop wrote: I don't know if you picked this up, but you don't seem to have row.id as part of the sqlfrom url. Perhaps try: links = [lambda row: A('Details',_href=URL('default','equipment', args=[row.id, row.slug]))] On Tuesday, August 28, 2012 10:28:39 AM UTC+12, SeamusSeamus wrote: Okay, but do I leave everything else alone? All I want to do is make it www.mysite.com/equipment/id/title currently, title is set up as slug in the DB. What am I doing wrong. In my view: equipment_id = request.args(0) equipment_slug = request.args(1) query = (db.equipment.id == item_id) (db.equipment.slug == item_slug) item = db(query).select().first() try: equipment = db.equipment[int(request.args(0))] except: equipment = db.equipment(request.args(0)) or db(db.equipment.slug == request.args(0)).select().first() and then my link in sqlform: links = [lambda row: A('Details',_href=URL('default','equipment', args=[row.slug]))] --
Re: [web2py] Re: SEO Friendly URLs and Page Titles
On 27 Aug 2012, at 4:56 PM, SeamusSeamus morrisjamespatr...@gmail.com wrote: nevermind I fixed it. Not sure why, but if it was named 'equipment' the controller showed up...any other name it doesnt. I just renamed Because you also have an application named 'equipment', so some URLs are ambiguous. On Monday, August 27, 2012 5:05:44 PM UTC-6, SeamusSeamus wrote: ah, yes, all is well now...however, this is strange. Now, when I click the link on the table to take me to the 'equipment.html' page (I renamed it from details.html), it shows the controller in the URL: www.mysite.com/default/equipment/id/title how do I make it so the 'default' does not show up? It didnt show up before it looked like this: links = [lambda row: A('Details',_href=URL('default', 'details', args=[row.id, row.slug]))] I changed to links = [lambda row: A('Details',_href=URL('default', 'equipment', args=[row.id, row.slug]))] I also changed the controller from def default to def equipment, and also changed default.html to equipment.html in views... now it shows the controller in the URL... my routes looks like this routers = dict( BASE = dict(default_application='equipment', default_controller = 'default',), ) --
[web2py] Re: IMPORTANT - NEED HELP: more speed improvements to be tested
Thanks Anthony, this really helped confirm the lazy_tables=True is working as expected. On average I am using 8 to 10 tables out of 30 total per request depending on the URL visited. Here is the relevant output from httpserver.log when I ran the application through a sequence of operations. The applications are running on latest trunk as of Monday afternoon Aug 27. Results for application before lazy_tables conversion 127.0.0.1, 2012-08-27 17:13:14, GET, /ccimsb/default/user/login, HTTP/1.1, 200, 0.040427 127.0.0.1, 2012-08-27 17:13:18, POST, /ccimsb/default/user/login, HTTP/1.1, 303, 0.046311 127.0.0.1, 2012-08-27 17:13:19, GET, /ccimsb/default/index, HTTP/1.1, 200, 0.085805 127.0.0.1, 2012-08-27 17:13:23, GET, /ccimsb/map/index, HTTP/1.1, 303, 0.040259 127.0.0.1, 2012-08-27 17:13:23, GET, /ccimsb/map/display/region/AK, HTTP/1.1, 200, 0.060424 127.0.0.1, 2012-08-27 17:13:25, GET, /ccimsb/map/display/site/VDZ, HTTP/1.1, 200, 0.064545 127.0.0.1, 2012-08-27 17:13:28, GET, /ccimsb/live/display/camera/VDZ/vdz-ca06, HTTP/1.1, 200, 0.249349 127.0.0.1, 2012-08-27 17:13:31, GET, /ccimsb/live/display/camera/VDZ/vdz-ca07, HTTP/1.1, 200, 0.433233 127.0.0.1, 2012-08-27 17:13:35, GET, /ccimsb/archive/site/VDZ, HTTP/1.1, 303, 0.118293 127.0.0.1, 2012-08-27 17:13:35, GET, /ccimsb/archive/display/menu/VDZ, HTTP/1.1, 200, 0.066299 127.0.0.1, 2012-08-27 17:13:36, POST, /ccimsb/archive/control/VDZ, HTTP/1.1, 200, 0.041629 127.0.0.1, 2012-08-27 17:13:37, POST, /ccimsb/archive/control/VDZ, HTTP/1.1, 200, 0.045691 127.0.0.1, 2012-08-27 17:13:40, GET, /ccimsb/default/user/logout, HTTP/1.1, 303, 0.047035 127.0.0.1, 2012-08-27 17:13:40, GET, /ccimsb/default/index, HTTP/1.1, 200, 0.042211 The applcation model converted to use lazy_tables 127.0.0.1, 2012-08-27 17:11:21, GET, /ccims/default/user/login, HTTP/1.1, 200, 0.075939 127.0.0.1, 2012-08-27 17:11:27, POST, /ccims/default/user/login, HTTP/1.1, 303, 0.060465 127.0.0.1, 2012-08-27 17:11:27, GET, /ccims/default/index, HTTP/1.1, 200, 0.089743 127.0.0.1, 2012-08-27 17:11:31, GET, /ccims/map/index, HTTP/1.1, 303, 0.029557 127.0.0.1, 2012-08-27 17:11:31, GET, /ccims/map/display/region/AK, HTTP/1.1, 200, 0.058424 127.0.0.1, 2012-08-27 17:11:36, GET, /ccims/map/display/site/VDZ, HTTP/1.1, 200, 0.057399 127.0.0.1, 2012-08-27 17:11:39, GET, /ccims/live/display/camera/VDZ/vdz-ca06, HTTP/1.1, 200, 0.220563 127.0.0.1, 2012-08-27 17:11:41, GET, /ccims/live/display/camera/VDZ/vdz-ca07, HTTP/1.1, 200, 0.450254 127.0.0.1, 2012-08-27 17:11:43, GET, /ccims/archive/site/VDZ, HTTP/1.1, 303, 0.030611 127.0.0.1, 2012-08-27 17:11:44, GET, /ccims/archive/display/menu/VDZ, HTTP/1.1, 200, 0.062489 127.0.0.1, 2012-08-27 17:11:44, POST, /ccims/archive/control/VDZ, HTTP/1.1, 200, 0.029913 127.0.0.1, 2012-08-27 17:11:49, POST, /ccims/archive/control/VDZ, HTTP/1.1, 200, 0.032068 127.0.0.1, 2012-08-27 17:11:54, GET, /ccims/default/user/logout, HTTP/1.1, 303, 0.064506 127.0.0.1, 2012-08-27 17:11:54, GET, /ccims/default/index, HTTP/1.1, 200, 0.030596 This is an improvement in performance for the new lazy_tables. The login and logout numbers are a bit longer for the new version but it doesn't matter for that. Thanks for the many improvements, Ron --
[web2py] Neither suggestion worked...
...no trainers are being returned. I even tried moving unassignedtrainers = (~db.trainer.id.belongs(db()._select(db.dogs.trainer))) db.dogs.trainer.requires = IS_IN_DB(db(unassignedtrainers), 'trainer.id', '%(name)s',zero=T('choose one')) to the controller. No luck. The drop down boxes do not appear, If I click the edit link there are no trainers to select. Tried Richards line to get the trainers without dogs as well. Am I making this harder than it has to be? On Monday, August 27, 2012 2:49:22 PM UTC-5, Bill Thayer wrote: Thank you Richard, I'll try it as soon as I finish my current round of debugging. -Bill On Monday, August 27, 2012 1:20:49 PM UTC-5, Richard wrote: Hello, If I resume correctly you want to assign a trainer to a dog only if the trainer haven't been assign to any dogs yet? So, what you have to do it to build a set instead of only define an simple IS_IN_DB()... I would do something like this (not tested) : not_assign_yet_trainer_set = db(~db.trainers.id.belongs(db(db.dogs.id0).select(db.dogs.trainer, distinct=True))) Than you only have to use your set instead of db.trainers in the IS_IN_DB() where you normally define the db table to use. Does it help? Richard On Mon, Aug 27, 2012 at 1:12 PM, Bill Thayer bill@live.com wrote: Tryin to use the example shown in Validators between classical and professional usagehttp://web2py.wordpress.com/category/web2py-validators/to change the values and widget for an SQLFORM.grid. I need to display an Assign Trainers page with an SQLFORM.grid (or something similar) of new dogs that have not been assigned to a trainer but can only be assigned to new trainers that have not been given dogs. So I thought simple query the is_active property on both cases, append the validator make ( process) my form. db.define_table('trainer', Field('name'), Field('specialty'), auth.signature, format='%(name)s') db.trainer.is_active.default=False db.define_table('dogs', Field('name'), Field('bites', 'boolean'), Field('trainer', 'reference trainer', default=1, widget=SQLFORM.widgets.options.widget, requires=[IS_IN_DB('db.trainer', IS_UPPER())]), auth.signature, migrate=True) db.dogs.is_active.default=False Controller: def assign_trainers(): trainers=db(db.trianer._is_active==False) new_dogs=db(db.dogs._is_active==False) new_dogs.trainer.requires.append(IS_IN_SET(trainers)) grid = SQLFORM.grid(new_dogs) return locals() Been working on this solution for two days now. Read all the books, bought the Cookbookhttps://play.google.com/books/reader?id=cwjpG47z_7ICprintsec=frontcoveroutput=readerauthuser=0hl=enpg=GBS.PA1read the blogs and now I'm out of time with my prototype presentation due Thursday. ANY help is very much needed at this point. Thank you, Bill -- --
[web2py] Drop-down with Other (fill in text) option?
Given a simple table like: db.define_table( 'foo', Field('bar', requires=IS_IN_SET([1,2,3,4,'fzr',6,7,8,9, 'Other']) # If other is picked, display text-box with IS_ALPHANUMERIC validator) How do I add this option? - I'm guessing it would be solved best using SQLFORM.factory. Thanks for all suggestions, Alec Taylor --
[web2py] Re: DAL calls fail after first stored procedure call
Thanks Anthony- ill give it a try On Monday, August 27, 2012 4:58:01 PM UTC-4, Anthony wrote: The existing adapter should work with mysqldb. Try: import mysqldb from gluon.dal import MySQLAdapter MySQLAdapter.driver = mysqldb db=DAL('mysql://') Anthony On Monday, August 27, 2012 4:37:42 PM UTC-4, Yarin wrote: This is an issue with pymsql: http://code.google.com/p/pymysql/issues/detail?id=72, https://github.com/petehunt/PyMySQL/blob/master/pymysql/cursors.py Running against pymysql's api directly, I can execute sproc calls on on two different connections, but not on the same connection. So... - What's the best way to emulate closing/opening a connection through the DAL- does it mean instantiating a new DAL object? Is working with multiple DAL objects a bad idea, or is that a good workaround? - If I switch to mysqldb, does that mean i've got to write my own adapter? If there's already adapters/recipes ready for using mysqldb I'll try it, otherwise I can't spare the time right now.. On Monday, August 27, 2012 3:52:06 PM UTC-4, Massimo Di Pierro wrote: Try use mysqldb too. The default pymysql has some problems. We even have to monkeypatch it for security. Massimo On Monday, 27 August 2012 14:20:00 UTC-5, Yarin wrote: This is MySQL using the default driver, whatever that is. I'm going to test on other drivers/dbs and will report back.. On Monday, August 27, 2012 3:03:15 PM UTC-4, Massimo Di Pierro wrote: I do not think this is a DAL issue. This looks database issue or a driver issue. Web2py does not do another else but pass your SQL to the driver and fetch responses. Is this SQLITE? In any case, I suggest you try the native driver APIs. On Monday, 27 August 2012 09:37:45 UTC-5, Yarin wrote: Once we call a stored procedure through the DAL, any subsequent DAL calls are returning None results. *Basic stored procedure:* BEGIN SELECT * FROM people; END *Works:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) return str(sproc_results) *Works:* def test(): sql = SELECT * FROM people; reg_results = db_test.executesql(sql) return str(reg_results) *Returns None:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) sql = SELECT * FROM people; reg_results = db_test.executesql(sql) return str(reg_results) *Returns None:* def test(): sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) sql = CALL GetPeople(); sproc_results = db_test.executesql(sql) return str(sproc_results) --
Re: [web2py] Major speed improvement need testers
Possible Issue, this might be due to the dal changes (or it could be me?): I'm running a variation of Bruno's Modelless App (and I tried his out of the box) https://github.com/rochacbruno/web2py_model_less_app , and I get: AttributeError: 'DataBase' object has no attribute '_LAZY_TABLES' On Sunday, August 26, 2012 8:37:16 AM UTC+12, Massimo Di Pierro wrote: Exactly. mytable.myfield.set_attributes(readable=True,writable=True) is just a shortcut for mytable.myfield.readable=True mytable.myfield.writable=True without it the lambda notation would not be very usable. On Saturday, 25 August 2012 11:50:10 UTC-5, Jonathan Lundell wrote: On 23 Aug 2012, at 7:25 AM, Massimo Di Pierro massimo@gmail.com wrote: So now in trunk you can do: db = DAL(lazy_tables=True) db.define_table('person',Field('name'),Field('age','integer'), on_define=lambda table: [ table.name.set_attributes(requires=IS_NOT_EMPTY(),default=''), table.age.set_attributes(requires=IS_INT_IN_RANGE(0,120),default=30), ]) and the attributes will be set lazily. This is a good idea! Thanks Jonathan. Clear something up for me, please. I was a little confused before about how this was implemented, but I've read the code and it looks like what I proposed. What I'm not following is the role of set_attributes. Is it simply to facilitate the lambda? Is this equivalent? def on_define(table): table.name.requires = IS_NOT_EMPTY() table.name.default = '' table.age.requires = IS_INT_IN_RANGE(0,120) table.age.default = 30 db = DAL(lazy_tables=True) db.define_table('person', Field('name'), Field('age','integer'), on_define=on_define) --
[web2py] Re: Screenplay formatting with web2py - markdown2.py
*Thanks* Massimo... I didn't know you could do it without modifying the .py file, I'll try some things out. Rob --
Re: [web2py] Major speed improvement need testers
To solve this issue include in the line 88 of myapp.py https://github.com/rochacbruno/web2py_model_less_app/blob/master/modules/myapp.py#L88 self._LAZY_TABLES = [] On Mon, Aug 27, 2012 at 11:33 PM, Andrew awillima...@gmail.com wrote: Possible Issue, this might be due to the dal changes (or it could be me?): I'm running a variation of Bruno's Modelless App (and I tried his out of the box) https://github.com/rochacbruno/web2py_model_less_app , and I get: AttributeError: 'DataBase' object has no attribute '_LAZY_TABLES' On Sunday, August 26, 2012 8:37:16 AM UTC+12, Massimo Di Pierro wrote: Exactly. mytable.myfield.set_**attributes(readable=True,**writable=True) is just a shortcut for mytable.myfield.readable=True mytable.myfield.writable=True without it the lambda notation would not be very usable. On Saturday, 25 August 2012 11:50:10 UTC-5, Jonathan Lundell wrote: On 23 Aug 2012, at 7:25 AM, Massimo Di Pierro massimo@gmail.com wrote: So now in trunk you can do: db = DAL(lazy_tables=True) db.define_table('person',**Field('name'),Field('age','**integer'), on_define=lambda table: [ table.name.set_attributes(**requires=IS_NOT_EMPTY(),**default=''), table.age.set_attributes(**requires=IS_INT_IN_RANGE(0,**120),default=30), ]) and the attributes will be set lazily. This is a good idea! Thanks Jonathan. Clear something up for me, please. I was a little confused before about how this was implemented, but I've read the code and it looks like what I proposed. What I'm not following is the role of set_attributes. Is it simply to facilitate the lambda? Is this equivalent? def on_define(table): table.name.requires = IS_NOT_EMPTY() table.name.default = '' table.age.requires = IS_INT_IN_RANGE(0,120) table.age.default = 30 db = DAL(lazy_tables=True) db.define_table('person', Field('name'), Field('age','integer'), on_define=on_define) -- --
Re: [web2py] Major speed improvement need testers
Thanks very much for a quick response, and add the next line too : self._LAZY_TABLES = [] self._tables = [] On Tuesday, August 28, 2012 2:53:01 PM UTC+12, rochacbruno wrote: To solve this issue include in the line 88 of myapp.py https://github.com/rochacbruno/web2py_model_less_app/blob/master/modules/myapp.py#L88 self._LAZY_TABLES = [] On Mon, Aug 27, 2012 at 11:33 PM, Andrew awill...@gmail.com javascript: wrote: Possible Issue, this might be due to the dal changes (or it could be me?): I'm running a variation of Bruno's Modelless App (and I tried his out of the box) https://github.com/rochacbruno/web2py_model_less_app , and I get: AttributeError: 'DataBase' object has no attribute '_LAZY_TABLES' On Sunday, August 26, 2012 8:37:16 AM UTC+12, Massimo Di Pierro wrote: Exactly. mytable.myfield.set_**attributes(readable=True,**writable=True) is just a shortcut for mytable.myfield.readable=True mytable.myfield.writable=True without it the lambda notation would not be very usable. On Saturday, 25 August 2012 11:50:10 UTC-5, Jonathan Lundell wrote: On 23 Aug 2012, at 7:25 AM, Massimo Di Pierro massimo@gmail.com wrote: So now in trunk you can do: db = DAL(lazy_tables=True) db.define_table('person',**Field('name'),Field('age','**integer'), on_define=lambda table: [ table.name.set_attributes(**requires=IS_NOT_EMPTY(),**default=''), table.age.set_attributes(**requires=IS_INT_IN_RANGE(0,**120),default=30), ]) and the attributes will be set lazily. This is a good idea! Thanks Jonathan. Clear something up for me, please. I was a little confused before about how this was implemented, but I've read the code and it looks like what I proposed. What I'm not following is the role of set_attributes. Is it simply to facilitate the lambda? Is this equivalent? def on_define(table): table.name.requires = IS_NOT_EMPTY() table.name.default = '' table.age.requires = IS_INT_IN_RANGE(0,120) table.age.default = 30 db = DAL(lazy_tables=True) db.define_table('person', Field('name'), Field('age','integer'), on_define=on_define) -- --
[web2py] Update...dumb people like me should use smart_query... making progress but still need help.
model db.define_table('trainer', Field('name'), Field('specialty'), auth.signature, format='%(name)s', migrate=True, ) db.trainer.is_active.default=False db.define_table('dogs', Field('name'), Field('bites', 'boolean'), Field('trainer', 'reference trainer', default=1), auth.signature, format='%(name)s', migrate=True, ) controller def assign_trainers(): db.dogs.trainer.requires = IS_IN_DB(db(db.trainer.is_active==False), 'trainer.id', '%(name)s',zero=T('choose one')) search='trainer equal 1 or trainer equal 0' #1 is the default value of a trainer named Unassigned rows = db.smart_query([db.dogs], search).select() grid = SQLFORM.smartgrid(db.dogs) return locals() view {{extend 'layout.html'}} h2Assign Trainers/h2 ppage used as an example posted to user group for help {{=grid}} {{=rows}} The rows are what I want from the dogs thanks to smart_query() but they are not in the smartgrid. The smartgrid shows all the dogs but will not take rows as a paramter. Click on the edit button and the edit page drop downs now only shows trainers who's in_active field == False. So I'm getting closer to my goal of making one grid with drop downs to assign new trainers to new unassigned dogs. my_need_for_help.is_active=True #still -Bill --
[web2py] Re: TypeError: can't pickle file objects
gLib.py - this is a common library of functions and procedures. It uses global variables attached to the session. понедельник, 27 августа 2012 г., 23:00:37 UTC+4 пользователь Massimo Di Pierro написал: gLib.py is probably a module, not a model. I would put it there. Why it fails I cannot say, I do not know what it does. --
[web2py] Doing larger translations...
I am wanting to create large amounts of content that needs to be translated. Is the Lazy T() way the best for this? Whole pages of text will need to be translated. BR, Jason Brower --
[web2py] how to send function arguments value from redirect()?
hi, I have to send the arguments value from redirect to the target function, for e.g: redirect(URL(r=request,f='record_config')) def record_config(record_id): I have to send the value of record_id from the redirect() to the record_config() function OR is it some other way to send value of record_id and access it inside record_config() function So i can avoid defining argument in the function? --