[web2py] db and variables
Hi, I'm trying to write loops in db.py: letters = ['a', 'b', 'c', 'd'] for i in range(len(letters)): for j in range(len(letters)): db.define_table('connection'+letters[i]+letters[j], SQLField('smthng', db.???letters[i])) What should I use instead of ??? to make the computer understand that as db.a when i=0 and j=0? Thanks in advance for help!
[web2py] generating a table
Hi, I want to generate a table like this: db.define_table(objects[i], SQLField(locus), SQLField(before) SQLField(after) SQLField(name) SQLField(main_name) ...with a code similar to this : objects = ['substance', 'process', 'condition'] linksubobjects = ['locus', 'before', 'after'] unlinksubobjects = ['name', 'main_name'] for i in range(len(objects)): db.define_table(objects[i], for k in range(len(linksubobjects[k])): SQLField([linksubobjects[k]]), for l in range(len(unlinksubobjects)): SQLField([unlinksubobjects[l]]), ) ...but I get errors on the "k" and "l" loops. Does anyone have an idea how to make these loops work? Thanks in advance for help!
[web2py] Initiating table
Hi, I would like to link a table to its own model like this: db.define_table('person', Field('name'), Field('child', db.person)) I understand that I should first initiate the table and then link it to itself. But how to do that? Thanks in advance for help!
[web2py] submit many forms
Hi, Let's say that there are a number of forms on the same page. There would be no problem to put a submit button after each of them, but how to submit all forms at the same time with one single submit button? Thanks in advance for help!
[web2py] variable into db.table.field
Hi, Let's say that in a controller file there are three variables (a, b and c) each of them contains a string. In a model file there is a table called 'Table' that has three fields (a_id, b_id and c_id). My question is how to: 1. Check in the database if there already is a 'Table'-object with an a_id that is equal to the a-string. 2. If statement 1 is false, then create a new 'Table'-object and put the a-string into a_id, the b-string into b_id and the c-string into c_id. I guess I should do something like this in the controller file: db = DAL(something) #is it necessary to define the db in the controller file as well? a="stringA" b="stringB" c="stringC" db.Table[0]=dict(name=a) db.Table[1]=dict(name=b) db.Table[2]=dict(name=c) This is perhaps a basic-level question, but I'm just a n00b. Thanks in advance for help!
[web2py] loop generated forms
Hi, How to generate multiple forms with a loop? In my controller file there are forms generated with this loop: thing=[one, two, three] def theFunction(): for thing1 in varibale1: form=FORM(':', INPUT(_name='name') ) return dict(form=form) ...but this code doesn't work. I just get the message "invalid view". I suppose the reason that I get this message is that all the forms have the same name in the view file. Therefor I also tried with: return dict(form=[thing]) ...but got: SyntaxError: keyword can't be an expression I've tried with this code in the view file: {{extend 'layout.html'}} {{=form}} ...and also with this: {{extend 'layout.html'}} {{thing=[one, two, three]}} {{for thing1 in varibale1:}} {{=form}} ...but none of them worked. Thanks in advance for help
[web2py] Re: loop generated forms
Thanks for your inspiring answer, After I found this page: http://code.activestate.com/recipes/440502-a-dictionary-with-multiple-values-for-each-key/ ...I tried with: return dict['form'].append([x]) ...but my new code doesn't work neither. I just get "TypeError: 'type' object is unsubscriptable". Though I think this code is nearer the solution. On Jul 12, 10:44 pm, JmiXIII wrote: > Hello , > > I've used something like this : > def listform(): > listf=[] > thing = [one two three] > for x in thing: > form=FORM(':', INPUT(_name="name")) > listf.append(form) > return dict(listf=listf) > > Yet I usually use SQLFORM and add a submit button > > As this is my firts answer to a coding question, do not hesitate to > tell if I'm wrong > > On 12 juil, 22:26, Rick wrote: > > > > > Hi, > > > How to generate multiple forms with a loop? > > > In my controller file there are forms generated with this loop: > > > thing=[one, two, three] > > def theFunction(): > > for thing1 in varibale1: > > form=FORM(':', > > INPUT(_name='name') > > ) > > return dict(form=form) > > > ...but this code doesn't work. I just get the message "invalid view". > > I suppose the reason that I get this message is that all the forms > > have the same name in the view file. Therefor I also tried with: > > return dict(form=[thing]) > > ...but got: > > SyntaxError: keyword can't be an expression > > > I've tried with this code in the view file: > > > {{extend 'layout.html'}} > > {{=form}} > > > ...and also with this: > > > {{extend 'layout.html'}} > > > > {{thing=[one, two, three]}} > > {{for thing1 in varibale1:}} > > {{=form}} > > > > > ...but none of them worked. > > > Thanks in advance for help
[web2py] Re: loop generated forms
This gives no error: dict()[x] = [x] ..but my web page is still not shown in the browser, it's just printed "None". Maybe the controller-file-code is correct but something should be added to the view file? On Jul 13, 12:19 am, Jonathan Lundell wrote: > On Jul 12, 2010, at 3:04 PM, Rick wrote: > > > Thanks for your inspiring answer, > > > After I found this page: > >http://code.activestate.com/recipes/440502-a-dictionary-with-multiple... > > ...I tried with: > > return dict['form'].append([x]) > > ...but my new code doesn't work neither. I just get "TypeError: 'type' > > object is unsubscriptable". > > Don't use the word 'dict'. > > > > > Though I think this code is nearer the > > solution. > > > On Jul 12, 10:44 pm, JmiXIII wrote: > >> Hello , > > >> I've used something like this : > >> def listform(): > >> listf=[] > >> thing = [one two three] > >> for x in thing: > >> form=FORM(':', INPUT(_name="name")) > >> listf.append(form) > >> return dict(listf=listf) > > >> Yet I usually use SQLFORM and add a submit button > > >> As this is my firts answer to a coding question, do not hesitate to > >> tell if I'm wrong > > >> On 12 juil, 22:26, Rick wrote: > > >>> Hi, > > >>> How to generate multiple forms with a loop? > > >>> In my controller file there are forms generated with this loop: > > >>> thing=[one, two, three] > >>> def theFunction(): > >>> for thing1 in varibale1: > >>> form=FORM(':', > >>> INPUT(_name='name') > >>> ) > >>> return dict(form=form) > > >>> ...but this code doesn't work. I just get the message "invalid view". > >>> I suppose the reason that I get this message is that all the forms > >>> have the same name in the view file. Therefor I also tried with: > >>> return dict(form=[thing]) > >>> ...but got: > >>> SyntaxError: keyword can't be an expression > > >>> I've tried with this code in the view file: > > >>> {{extend 'layout.html'}} > >>> {{=form}} > > >>> ...and also with this: > > >>> {{extend 'layout.html'}} > >>> > >>> {{thing=[one, two, three]}} > >>> {{for thing1 in varibale1:}} > >>> {{=form}} > >>> > > >>> ...but none of them worked. > > >>> Thanks in advance for help
[web2py] Re: loop generated forms
Thanks a lot JmiXIII and Jonathan! The solution you suggested works! Since I'm just a n00b it took a while to get everything right. Here is the view file code: {{for i in range(0, 2):}} {{=listf[i]}} {{pass}} On Jul 13, 11:13 pm, Jonathan Lundell wrote: > On Jul 13, 2010, at 1:56 PM, Rick wrote: > > > This gives no error: > > dict()[x] = [x] > > ..but my web page is still not shown in the browser, it's just printed > > "None". Maybe the controller-file-code is correct but something should > > be added to the view file? > > It's not at all clear what you're trying to do. The line above creates a dict > with a single entry whose key is x, and whose value is a list with x as a > member. That doesn't seem very useful. > > If you want a variable number of forms to be displayed, try creating a list > of forms, and passing the list to your view in a dict as usual. The code that > JmiXIII gave is a good example: > > def listform(): > listf=[] > thing = [one two three] > for x in thing: > form=FORM(':', INPUT(_name="name")) > listf.append(form) > return dict(listf=listf) > > In your view, you'll have to loop through the list and output each form. > > One problem with the code above is that you'll need to give each form a > unique name. See "Multiple forms per page" in the manual, Chapter 7. > > > > > > > On Jul 13, 12:19 am, Jonathan Lundell wrote: > >> On Jul 12, 2010, at 3:04 PM, Rick wrote: > > >>> Thanks for your inspiring answer, > > >>> After I found this page: > >>>http://code.activestate.com/recipes/440502-a-dictionary-with-multiple... > >>> ...I tried with: > >>> return dict['form'].append([x]) > >>> ...but my new code doesn't work neither. I just get "TypeError: 'type' > >>> object is unsubscriptable". > > >> Don't use the word 'dict'. > > >>> Though I think this code is nearer the > >>> solution. > > >>> On Jul 12, 10:44 pm, JmiXIII wrote: > >>>> Hello , > > >>>> I've used something like this : > >>>> def listform(): > >>>> listf=[] > >>>> thing = [one two three] > >>>> for x in thing: > >>>> form=FORM(':', INPUT(_name="name")) > >>>> listf.append(form) > >>>> return dict(listf=listf) > > >>>> Yet I usually use SQLFORM and add a submit button > > >>>> As this is my firts answer to a coding question, do not hesitate to > >>>> tell if I'm wrong > > >>>> On 12 juil, 22:26, Rick wrote: > > >>>>> Hi, > > >>>>> How to generate multiple forms with a loop? > > >>>>> In my controller file there are forms generated with this loop: > > >>>>> thing=[one, two, three] > >>>>> def theFunction(): > >>>>> for thing1 in varibale1: > >>>>> form=FORM(':', > >>>>> INPUT(_name='name') > >>>>> ) > >>>>> return dict(form=form) > > >>>>> ...but this code doesn't work. I just get the message "invalid view". > >>>>> I suppose the reason that I get this message is that all the forms > >>>>> have the same name in the view file. Therefor I also tried with: > >>>>> return dict(form=[thing]) > >>>>> ...but got: > >>>>> SyntaxError: keyword can't be an expression > > >>>>> I've tried with this code in the view file: > > >>>>> {{extend 'layout.html'}} > >>>>> {{=form}} > > >>>>> ...and also with this: > > >>>>> {{extend 'layout.html'}} > >>>>> > >>>>> {{thing=[one, two, three]}} > >>>>> {{for thing1 in varibale1:}} > >>>>> {{=form}} > >>>>> > > >>>>> ...but none of them worked. > > >>>>> Thanks in advance for help
[web2py] web2py install on nginx?
Can anyone share his experience installing and working with web2py on nginx? Which if the best install approach? fastcgi? Any hints will be appreciated, Brgds -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] Re: NGINX + FCGI + web2py = routes.py not working correctly
Hi Ahmed, Can you share with us how you got web2py running on nginx with fastcgi? brgds On Feb 23, 2:12 pm, Ahmed Sameh wrote: > Hi All, > > I have configured web2py to work with NGINX through FCGI, and > everything works fine except for routes.py. > > I am using routes.py to redirect various sub domains to their > applications. > > I have compared between the output of the request object in the case > of using CherryPy and in the case of using FCGI. > I found that the difference is in the HTTP_REFERER field, so I tried > to solve this with NGINX, but It hasn't been solved. > > So, I tried another solution which is setting the HTTP_HOST variable > to HTTP_REFERER from NGINX using server_name_in_redirect off , So the > next step is forcing web2py rewrite module to use HTTP_HOST instead of > HTTP_REFERER, which I couldn't DO. > > So, Is there anyone can help me to force web2py rewrite module to use > HTTP_HOST instead of HTTP_REFERER > or has another solution to the problem without using NGINX rewrite > rules, as I prefer to do it from routes.py. -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] Re: web2py install on nginx?
Thanks ;) On Feb 23, 11:43 pm, Ahmed Sameh wrote: > Hi rick, > > I have installed it but there is a problem using routes.py with NGINX > +FCGI , I have posted about that earlier. > But using NGINX + CherrPy + web2py works fine and you can find many > other posts discussing that. > > I think that NGINX + FCGI is so much faster than NGINX + CherryPy, I > will benchmark the performance soon. > > Here is my notes about installing NGINX + FCGI + web2py : > > NGINX --> Socket file <--- web2py > > 1- Have the latest release of NGINX. > > 2- Edit the configuration file of your site so that it can use FCGI as > follows: > > fastcgi_pass unix:/tmp/web2py.sock; > include fastcgi_params; > > 3- Edit fcgihandler.py which is located in the root directory of > web2py, change the socket file to web2py.sock > > 4- Run fcgihandler.py --> python fcgihandler.py > > 5- Change the permissions of /tmp/web2py.sock to something that is > accessible by NGINX and web2py, > for testing use chmod 777 /tmp/web2py.sock > > On Feb 23, 5:39 pm, rick wrote: > > > Can anyone share his experience installing and working with web2py on > > nginx? > > Which if the best install approach? fastcgi? > > > Any hints will be appreciated, > > Brgds -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] database question
Hi, I'm having trouble figuring out the syntax for this type of database inquiry. I have three tables: 1) stores, which has a name 2) regions, which has a 2-letter abbreviation 3) store-region, which puts stores in certain regions. I want to pass in a 2-letter region abbreviation, and receive back the names of the stores in that region. So I need to use the results of one query (regions with the abbreviation "NY", say), to get another set of results (store ids with that region id), to get the third set of results (stores names that matched the store ids) Thanks for reading..
[web2py] JQuery plugin
Hi, I'd like to make a button that generates a sound when clicking on it. This JQuery plugin was the best way I could found: http://plugins.jquery.com/project/sound and I wrote this code: views/default/index.html: {{extend 'layout.html'}} onClick="jQuery(this).sound.play(/static/success.wav)" views/layout.html: {{response.files.append(URL(r=request,c='static',f='jquery.sound.js'))}} Since I'm totally new to JQuery I understand that this is completely wrong. Could anyone tell me how it should look like, please?
[web2py] Re: JQuery plugin
Thanks! I think there are better plugins for this purpose than this sound- plugin. But now I know how to install it into my application. On Sep 24, 8:26 pm, Bruno Rocha wrote: > You should append JS files before the {{include 'web2py_ajax.html'}} > > views/layout.html: > > > {{response.files.append(URL(r=request,c='static',f='jquery.sound.js'))}} > > {{include 'web2py_ajax.html'}} > > > and in your div the OnClick event is used in the wrong way, it is not > recommended to use onclick event in a div, you should use , or > another element, and the file URL should be build with URL helper: > > views/default/index.html: > {{extend 'layout.html'}} > > > onclick="jQuery(this).sound.play({{=URL('static',args='success.wav')}})"> > Click here to listen the sound > > > > 2010/9/24 Rick > > > > > > > Hi, > > > I'd like to make a button that generates a sound when clicking on it. > > This JQuery plugin was the best way I could found: > >http://plugins.jquery.com/project/sound > > and I wrote this code: > > > views/default/index.html: > > {{extend 'layout.html'}} > > > > onClick="jQuery(this).sound.play(/static/success.wav)" > > > > > views/layout.html: > > > > > {{response.files.append(URL(r=request,c='static',f='jquery.sound.js'))}} > > > > > Since I'm totally new to JQuery I understand that this is completely > > wrong. Could anyone tell me how it should look like, please? > > -- > > http://rochacbruno.com.br
[web2py] Re: JQuery plugin
Thanks for the suggestions. Now I consider this plugin: http://www.happyworm.com/jquery/jplayer/ On Sep 25, 3:33 am, Magnitus wrote: > Assuming that you know how to create sound effects in regular > Javascript, making your own pluggin for it doesn't seem that > difficult. > > Lets assume that you want a pluggin that affect only div elements in a > wrapped set and you want to be able to specify the sound... > > It'd look something like this (note that this is a quick-and-dirty > piece of code... totally untested): > > {function($){ > $.fn.AddSoundOnClick = function(SoundEffect) { > return this.filter('div').bind('click',function(event){ > //Stick the logic to emit the sound effect here > }).end(); > }; > > })(jQuery); > > Afterwards, lets say that you have a sound effect stored in the > variable CowSound and a div with class "SoundDiv", you could add the > cow sound like this: > > jQuery('div.SoundDiv').AddSoundOnClick(CowSound); > > Here's terrific book for jQuery: > > http://www.amazon.ca/jQuery-Action-Second-Bear-Bibeault/dp/1935182323... > > If you're serious about using jQuery properly, it'll be the best 30$ > you ever spent. Sure learned a lot from it. > > On Sep 24, 4:13 pm, Rick wrote: > > > > > Hi, > > > I'd like to make a button that generates a sound when clicking on it. > > This JQuery plugin was the best way I could > > found:http://plugins.jquery.com/project/sound > > and I wrote this code: > > > views/default/index.html: > > {{extend 'layout.html'}} > > > > onClick="jQuery(this).sound.play(/static/success.wav)" > > > > > views/layout.html: > > > > > {{response.files.append(URL(r=request,c='static',f='jquery.sound.js'))}} > > > > > Since I'm totally new to JQuery I understand that this is completely > > wrong. Could anyone tell me how it should look like, please?
[web2py] GAE address
Hi, When I upload my app with GAE the address will be myapp.appspot.com/ myapp . On the site myapp.appspot.com there is the administrative interface that doesn't work with GAE. My question is: how to put my app on myapp.appspot.com ? Thanks in advance for help!
[web2py] superfish
Hi, I've put this into a viewer file named layout.html but it doesn't work: {{response.files.append(URL(request.application,'static','superfish.js'))}} {{include 'web2py_ajax.html'}} ...some code {{ response.menu=[ ('Home',request.function=='home',URL(r=request,f='home'),[]), ('Store Information',request.function=='info',URL(r=request,f=info'), []),] }} Thanks in advance for help! {{## superfish menu }} {{=MENU(response.menu,_class='sf-menu')}} jQuery(document).ready(function(){ jQuery('ul.sf-menu').superfish({delay:400});});
[web2py] Re: superfish
Thanks for taking the time for my problem. I couldn't find any good example that shows how to make a nice menu. While trying different solutions I made a mess of the code. But at the end I made this solution: {{ submenu1=[ ['item1',False,URL(r=request,f='item1')], ['item2',False,URL(r=request,f='item2')], ] submenu2=[ ['item3',False,URL(r=request,f='item3')], ['item4',False,URL(r=request,f='item4')], ] response.menu=[ ['header1',False,'#',submenu1], ['header2',False,'#',submenu2], ]}} {{## superfish menu }} {{=MENU(response.menu,_class='sf-menu')}} jQuery(document).ready(function(){ jQuery('ul.sf-menu').superfish({delay:400});}); On Sep 29, 1:23 pm, mdipierro wrote: > everything I see here appears correct. Can we see the generated html? > Can you try load the page with firebug and see if you get any error? > > On Sep 28, 11:50 pm, Rick wrote: > > > > > Hi, > > > I've put this into a viewer file named layout.html but it doesn't > > work: > > > > > {{response.files.append(URL(request.application,'static','superfish.js'))}} > > {{include 'web2py_ajax.html'}} > > > > > ...some code > > > {{ > > response.menu=[ > > > > ('Home',request.function=='home',URL(r=request,f='home'),[]), > > ('Store > > Information',request.function=='info',URL(r=request,f=info'), > > []),] > > }} > > > Thanks in advance for help! > > > {{## superfish menu }} > > {{=MENU(response.menu,_class='sf-menu')}} > > > > jQuery(document).ready(function(){ > > jQuery('ul.sf-menu').superfish({delay:400});}); > >
[web2py] Re: GAE address
But how to upload it in my local copy? I understand that I'd somehow get the app on the address http://127.0.0.1:8000 but I don't understand how to get it there. It has still the address: http://127.0.0.1:8000/myapp I'm running linux. Perhaps that has an impact on the procedure? On Sep 28, 5:46 pm, mdipierro wrote: > You have to upload it in your local copy and then doply it again. > > On Sep 28, 11:20 am, Rick wrote: > > > > > Hi, > > > When I upload my app with GAE the address will be myapp.appspot.com/ > > myapp . On the site myapp.appspot.com there is the administrative > > interface that doesn't work with GAE. My question is: how to put my > > app on myapp.appspot.com ? > > > Thanks in advance for help!
[web2py] Re: GAE address
Thanks for the link and the answer. Now I've figured out what I exactly try to ask: How to make the "root site" 127.0.0.1:8080 redirect to 127.0.0.1:8080/myapp/views/default/index instead of 127.0.0.1:8080/myapp/welcome/default/index ? On Sep 30, 8:20 pm, mdipierro wrote: > This is what I do: > > - I run web2py.py using 127.0.0.1:8000 > - I test in dev_appserver on 127.0.0.1:8080 > > On port 8000 admin works and I can deploy apps locally. They will then > be visible on port 8080 too. > After I test that everything works I deply using the AppEngineLauncher > or appcfg.py > > This may also help: > > http://gluonframework.wordpress.com/2010/03/02/shell-only-web2py/ > > Massimo > > On Sep 30, 12:06 pm, Rick wrote: > > > But how to upload it in my local copy? I understand that I'd somehow > > get the app on the address http://127.0.0.1:8000butI don't > > understand how to get it there. It has still the > > address:http://127.0.0.1:8000/myapp > > I'm running linux. Perhaps that has an impact on the procedure? > > > On Sep 28, 5:46 pm, mdipierro wrote: > > > > You have to upload it in your local copy and then doply it again. > > > > On Sep 28, 11:20 am, Rick wrote: > > > > > Hi, > > > > > When I upload my app with GAE the address will be myapp.appspot.com/ > > > > myapp . On the site myapp.appspot.com there is the administrative > > > > interface that doesn't work with GAE. My question is: how to put my > > > > app on myapp.appspot.com ? > > > > > Thanks in advance for help! > >
[web2py] list:string thoughts
I'm getting frustrated with the list:string field type. I store products, each product has "keywords" that describe the product. db.define_table('products', Field('keywords', 'list:string')) I don't know what the keywords will be, so I can't use IS_IN_SET() It seems to stores the keywords fine, as long as (I'm using Crud) I separate the keywords like this: green|blue|red But when I make this call rows = db(db.products.keywords.contains(keyword)).select() I don't get all the products back that I should! In fact, it seems that I need to do an update on the product (again using Crud, and any sort of update) before the product's keywords will be picked up. Is this a problem with using Crud? In all honesty, I'd be more comfortable not using list:string, and having a separate table "keywords" that linked (many-to-one) to the products table, but I really don't know how I would even begin to do that in web2py.. Thanks for reading! - rick
[web2py:32796] Re: Error with Database (MySQL) when using latest release....
I have also come across this with web2py 1.67.2, using stock MySQL on Ubuntu 8.10, when I add unique=True to a string column in a table definition. On Sep 22, 11:13 am, Yannick wrote: > Hello mate, > Below you can find the error message that I received from Database > (MySQL) when using the latest Web2py version: 1.67.1 BUT when I use an > old version Web2py: 1.66.2, I have NO problem NO error using the same > environment... > I wonder why this new release complaint ? > > Please let me if you have any hint ??? > > Traceback (most recent call last): > File "/home/fedora/src/web2py/gluon/restricted.py", line 178, in > restricted > exec ccode in environment > File "/home/fedora/src/web2py/applications/AppName/models/db.py", > line 104, in > buDefineTable.define_tables() > File "/home/fedora/src/web2py/applications/AppName/modules/ > dbDefinition.py", line 126, in define_tables > migrate = True) > File "/home/fedora/src/web2py/gluon/sql.py", line 1033, in > define_table > query = t._create(migrate=migrate) > File "/home/fedora/src/web2py/gluon/sql.py", line 1368, in _create > self._db._execute(query) > File "/home/fedora/src/web2py/gluon/sql.py", line 739, in > self._execute = lambda *a, **b: self._cursor.execute(*a, **b) > File "/usr/lib/python2.6/site-packages/MySQLdb/cursors.py", line > 173, in execute > self.errorhandler(self, exc, value) > File "/usr/lib/python2.6/site-packages/MySQLdb/connections.py", line > 36, in defaulterrorhandler > raise errorclass, errorvalue > OperationalError: (1071, 'Specifiedkeywastoolong; maxkeylength > is 767 bytes') --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~--~~~~--~~--~--~---
[web2py] simple db app
Hi, I'm trying to make a data base for storing names and addresses, but since I'm a n00b then I can't get it working. I've no idea what's wrong. The problem is that the input function doesn't redirect to the show function and that the show function doesn't show any data. Here's the code: the controller file: def show(): id=request.vars.id record=db(db.measure.id==id).select() return dict(record=record) def input(): form = SQLFORM(db.addresses) if form.accepts(request.vars, session): redirect(URL(r=request, f='show')) return dict(form=form) ** and the model file table: db.define_table('addresses', Field('person'), Field('adress')) ** input.html {{extend 'layout.html'}} {{=form}} ** show.html: {{extend 'layout.html'}} Addresses {{for record in record:}} {{=record.name}} : {{=record.address}} {{pass}} ** Thanks in advance for help!
[web2py] Re: simple db app
Thanks for the reply. Unfortunately this code idea gives the same result as mine. On Dec 14, 2:51 am, pbreit wrote: > I would envision something more like this (not tested): > > == db.py == > db.define_table('address', > Field('person'), > Field('address')) > > == default.py == > def index(): > records = db().select(db.address.ALL, orderby=db.address.name) > return dict(records=records) > > def create(): > form = SQLFORM(table) > if form.accepts(request.post_vars, session): > session.flash = 'Address saved.' > redirect(URL('index')) > > == default/index.html == > {{extend 'layout.html'}} > Addresses > {{for record in records:}} > {{=record.name}} : {{=record.address}} > {{pass}} > [ {{=A('Add Address', _href=URL('create'))}} ] > > == default/create.html == > {{extend 'layout.html'}} > {{=form}}
[web2py] Re: simple db app
Thanks for the help! I got it working with this code: == controller file == def index(): records = db().select(db.addresses.ALL, orderby=db.addresses.person) return dict(records=records) def create(): form = SQLFORM(db.addresses) if form.accepts(request.post_vars, session): session.flash = 'Address saved.' redirect(URL('index')) return dict(form=form) == db.py == db.define_table('addresses', Field('person'), Field('address')) == index.html == {{extend 'layout.html'}} Addresses {{for record in records:}} {{=record.person}} : {{=record.address}} {{pass}} [ {{=A('Add Address', _href=URL('create'))}} ] == create.html == {{extend 'layout.html'}} {{=form}} On Dec 14, 5:16 pm, DenesL wrote: > Correction, you should not set vars using field names already in the > form, otherwise they will be duplicated. > > def show(): > rid=request.vars.rid > record=db(db.addresses.id==rid).select() > > def input(): > form = SQLFORM(db.addresses) > if form.accepts(request.vars, session): > redirect(URL(r=request, > f='show',vars={'rid':form.vars.id})) > return dict(form=form) > > On Dec 13, 10:48 pm, DenesL wrote: > > > > > > > > > Hi Rick, > > > On Dec 13, 6:55 pm, Rick wrote: > > > > Hi, > > > > I'm trying to make a data base for storing names and addresses, but > > > since I'm a n00b then I can't get it working. I've no idea what's > > > wrong. The problem is that the input function doesn't redirect to the > > > show function and that the show function doesn't show any data. Here's > > > the code: > > > > the controller file: > > > def show(): > > > id=request.vars.id > > > record=db(db.measure.id==id).select() > > > record=db(db.addresses.id==id).select() > > > > return dict(record=record) > > > > def input(): > > > form = SQLFORM(db.addresses) > > > if form.accepts(request.vars, session): > > > redirect(URL(r=request, f='show')) > > > redirect(URL(r=request, f='show',vars={'id':form.vars.id})) > > > > return dict(form=form) > > > > ** > > > > and the model file table: > > > > db.define_table('addresses', > > > Field('person'), > > > Field('adress')) > > > Field('address')) > > > > ** > > > > input.html > > > {{extend 'layout.html'}} > > > {{=form}} > > > > ** > > > > show.html: > > > {{extend 'layout.html'}} > > > Addresses > > > {{for record in record:}} > > > {{=record.name}} : {{=record.address}} > > > {{=record.person}} : {{=record.address}} > > > > {{pass}} > > > > ** > > > > Thanks in advance for help!
[web2py] auth model
Hi, I'm trying to make a very simple todo application for many users. The passwords and usernames would be given from a administrator, so hence there wouldn't be any registration through e-mail. My problem is that I don't know how to properly write the model/db.py file. I tried with this, where there is one table for auth and one for the todo post, I I just get error messages: from gluon.settings import settings from gluon.tools import * # if running on Google App Engine if settings.web2py_runtime_gae: from gluon.contrib.gql import * # connect to Google BigTable db = DAL('gae') # and store sessions there session.connect(request, response, db=db) else: # if not, use SQLite or other DB db = DAL("sqlite://db.db") auth = Auth(globals(), db) auth.define_tables() db.define_table('todo', Field('time'), tha Field('thing')) db.define_table( auth.settings.table_user_name, Field('password', 'password', length=512, readable=False, label='Password'), Field('registration_id', length=512, writable=False, readable=False, default='')) Thanks for help in advance
[web2py] Re: auth model
Thanks for the advice. This code seems to work: ** from gluon.settings import settings from gluon.tools import * # if running on Google App Engine if settings.web2py_runtime_gae: from gluon.contrib.gql import * # connect to Google BigTable db = DAL('gae') # and store sessions there session.connect(request, response, db=db) else: # if not, use SQLite or other DB db = DAL("sqlite://db.db") db.define_table('todo', Field('time'), Field('thing')) auth = Auth(globals(), db) db.define_table( auth.settings.table_user_name, Field('name'), Field('password')) auth.define_tables() custom_auth_table = db[auth.settings.table_user_name] # get the custom_auth_table ** ...but now I try to write a kind of log in/out interface in views/ layout.html. I don't know how it should look like in the case of custom auth. I tried with this that that gave an error mesage: {{if not auth.user and not request.function=='user':}} {{=atuh.login(next=URL(r=request,args=args))}} {{pass}} Any ideas? On Dec 15, 2:37 am, pbreit wrote: > To customize auth, have a look > at:http://web2py.com/book/default/chapter/08#Customizing-Auth > > For one thing, the table definitely needs to be placed between auth = > Auth(globals(), db) and auth.define_tables()
[web2py] Re: auth model
Now I've changed a little, but it still doesn't work: from db.py auth = Auth(globals(), db) db.define_table( auth.settings.table_user_name, Field('username'), Field('password')) auth.define_tables() custom_auth_table = db[auth.settings.table_user_name] # get the custom_auth_table custom_auth_table.requires = IS_NOT_IN_DB(db, custom_auth_table.username) from layout.html {{if not custom_auth_table.username and not request.function=='username':}} {{=custom_auth_table.login (next=URL(r=request,args=args))}} {{pass}} {{include}} **** On Dec 15, 9:55 pm, Rick wrote: > Thanks for the advice. This code seems to work: > > ** > from gluon.settings import settings > from gluon.tools import * > > # if running on Google App Engine > if settings.web2py_runtime_gae: > from gluon.contrib.gql import * > # connect to Google BigTable > db = DAL('gae') > # and store sessions there > session.connect(request, response, db=db) > else: > # if not, use SQLite or other DB > db = DAL("sqlite://db.db") > > db.define_table('todo', > Field('time'), > Field('thing')) > > auth = Auth(globals(), db) > > db.define_table( > auth.settings.table_user_name, > Field('name'), > Field('password')) > > auth.define_tables() > > custom_auth_table = db[auth.settings.table_user_name] # get the > custom_auth_table > ** > > ...but now I try to write a kind of log in/out interface in views/ > layout.html. I don't know how it should look like in the case of > custom auth. I tried with this that that gave an error mesage: > > {{if not auth.user and not request.function=='user':}} > {{=atuh.login(next=URL(r=request,args=args))}} > {{pass}} > > Any ideas? > > On Dec 15, 2:37 am, pbreit wrote: > > > > > > > > > To customize auth, have a look > > at:http://web2py.com/book/default/chapter/08#Customizing-Auth > > > For one thing, the table definitely needs to be placed between auth = > > Auth(globals(), db) and auth.define_tables()
[web2py] interval in a list
Hi, In the database there are value records for 31 days. Now I'm trying to make a html file where a value is presented for each day of a week. The code below presents all the recorded values, and I don't know how to make it printing the 7 first records only, or the last 3 records. Thanks in advance for help. Day| Value| {{for record in records:}} {{=record.day}} {{=record.value}} {{pass}}
[web2py] Re: interval in a list
Thanks a lot! The final code looks like this: {{for record in db().select(db.table.ALL, orderby=db.table.day, limitby=(0, 7)):}} On Dec 18, 12:59 am, Luther Goh Lu Feng wrote: > Fromhttp://web2py.com/book/default/chapter/06#orderby,-groupby,-limitby,-... > > I think the following may work: > > for row in db().select(db.table.ALL, limitby=(0, 7)): > print row.record > > for row in db().select(db.table.ALL, limitby=(0, 3). > orderby=~db.table.id): > print row.record > > On Dec 18, 7:30 am, Rick wrote: > > > > > > > > > Hi, > > > In the database there are value records for 31 days. Now I'm trying to > > make a html file where a value is presented for each day of a week. > > The code below presents all the recorded values, and I don't know how > > to make it printing the 7 first records only, or the last 3 records. > > > Thanks in advance for help. > > > > > > > Day| Value| > > {{for record in records:}} > > {{=record.day}} {{=record.value}} > > {{pass}} > > > >
[web2py] Re: interval in a list
Sorry for spamming, but I want to be exact. Here is the final code, where n is the week number: {{for record in db().select(db.table.ALL, orderby=db.table.day, limitby=(n*0, n*7)):}} On Dec 18, 1:24 am, Rick wrote: > Thanks a lot! The final code looks like this: > {{for record in db().select(db.table.ALL, orderby=db.table.day, > limitby=(0, 7)):}} > > On Dec 18, 12:59 am, Luther Goh Lu Feng wrote: > > > > > > > > > Fromhttp://web2py.com/book/default/chapter/06#orderby,-groupby,-limitby,-... > > > I think the following may work: > > > for row in db().select(db.table.ALL, limitby=(0, 7)): > > print row.record > > > for row in db().select(db.table.ALL, limitby=(0, 3). > > orderby=~db.table.id): > > print row.record > > > On Dec 18, 7:30 am, Rick wrote: > > > > Hi, > > > > In the database there are value records for 31 days. Now I'm trying to > > > make a html file where a value is presented for each day of a week. > > > The code below presents all the recorded values, and I don't know how > > > to make it printing the 7 first records only, or the last 3 records. > > > > Thanks in advance for help. > > > > > > > > > > Day| Value| > > > {{for record in records:}} > > > {{=record.day}} {{=record.value}} > > > {{pass}} > > > > > >
[web2py] Re: interval in a list
Oh no, the code above failed. Here is the final code where n is the week number: {{for record in db().select(db.table.ALL, orderby=db.table.day, limitby=((n-1)*7, n*7)):}} On Dec 18, 1:30 am, Rick wrote: > Sorry for spamming, but I want to be exact. Here is the final code, > where n is the week number: > {{for record in db().select(db.table.ALL, orderby=db.table.day, > limitby=(n*0, n*7)):}} > > On Dec 18, 1:24 am, Rick wrote: > > > > > > > > > Thanks a lot! The final code looks like this: > > {{for record in db().select(db.table.ALL, orderby=db.table.day, > > limitby=(0, 7)):}} > > > On Dec 18, 12:59 am, Luther Goh Lu Feng wrote: > > > > Fromhttp://web2py.com/book/default/chapter/06#orderby,-groupby,-limitby,-... > > > > I think the following may work: > > > > for row in db().select(db.table.ALL, limitby=(0, 7)): > > > print row.record > > > > for row in db().select(db.table.ALL, limitby=(0, 3). > > > orderby=~db.table.id): > > > print row.record > > > > On Dec 18, 7:30 am, Rick wrote: > > > > > Hi, > > > > > In the database there are value records for 31 days. Now I'm trying to > > > > make a html file where a value is presented for each day of a week. > > > > The code below presents all the recorded values, and I don't know how > > > > to make it printing the 7 first records only, or the last 3 records. > > > > > Thanks in advance for help. > > > > > > > > > > > > > Day| Value| > > > > {{for record in records:}} > > > > {{=record.day}} {{=record.value}} > > > > {{pass}} > > > > > > > >
[web2py] variables
Hi, I want to change the value of a variable by clicking on an tag, but can't find any information about the topic. I suppose the code would look something like this: {{=A('<', request n=n-1) }} Thanks in advance for help
[web2py] variables
Hi, I want to change the value of a variable by clicking on an tag, but can't find any information about the topic. I suppose the code would look something like this: {{=A('<', request n=n-1) }} Thanks in advance for help
[web2py] Re: variables
Thanks for the replies! The variable that I'm operating with is python type, not javascript. Mdipierro, your solution looks nice, but i can't get it working. The value of the variable doesn't seem to change. Here is my code: from views/default/index.html: {{n=1}} plus {{=n}} controller.py def plus_n(): # check this was called by the ajax post if request.env.request_method=='POST': # do anything you need to do session.n=session.n+1 # optional return instructions in JS return "$('.flash').html('n was incremented').slideDown();" On Dec 18, 2:26 am, pbreit wrote: > I don't really understand the question. Do you want to change a JavaScript > variable? Or a variable in your web2py code? I don't think you would be able > to modify a web2py variable as the result of a click. By the time the suer > views your page, all the web2py code has been rendered into HTML. You'll > either need to code some JavaScript or perform some sort of Ajax call back > to your server. > > What exactly are you trying to do?
[web2py] Re: variables
Perhaps there is a way to get different variable values depending on what address you load??? For example: http:...default/index.html...something...n=1,m=0 On Dec 18, 4:07 am, Luther Goh Lu Feng wrote: > You can use javascript or jquery(since web2py includes jquery) to do > this: > > ==javascript== > $('#some_id).click(function() > { > $('#target").val( ($('#target").val()+1) ); > } > ) > > ==html== > Click me > > 2 > > This should more or less work. > > On Dec 18, 10:02 am, Rick wrote: > > > > > > > > > Thanks for the replies! The variable that I'm operating with is python > > type, not javascript. Mdipierro, your solution looks nice, but i can't > > get it working. The value of the variable doesn't seem to change. Here > > is my code: > > > from views/default/index.html: > > {{n=1}} > > plus > > {{=n}} > > > controller.py > > def plus_n(): > > # check this was called by the ajax post > > if request.env.request_method=='POST': > > # do anything you need to do > > session.n=session.n+1 > > # optional return instructions in JS > > return "$('.flash').html('n was incremented').slideDown();" > > > On Dec 18, 2:26 am, pbreit wrote: > > > > I don't really understand the question. Do you want to change a JavaScript > > > variable? Or a variable in your web2py code? I don't think you would be > > > able > > > to modify a web2py variable as the result of a click. By the time the suer > > > views your page, all the web2py code has been rendered into HTML. You'll > > > either need to code some JavaScript or perform some sort of Ajax call back > > > to your server. > > > > What exactly are you trying to do?
[web2py] Re: variables
If "n" would be a global variable in a controller file, can I use something like this then? {{=n}} plus On Dec 18, 4:23 pm, Rick wrote: > Perhaps there is a way to get different variable values depending on > what address you load??? For example: > http:...default/index.html...something...n=1,m=0 > > On Dec 18, 4:07 am, Luther Goh Lu Feng wrote: > > > > > > > > > You can use javascript or jquery(since web2py includes jquery) to do > > this: > > > ==javascript== > > $('#some_id).click(function() > > { > > $('#target").val( ($('#target").val()+1) ); > > } > > ) > > > ==html== > > Click me > > > 2 > > > This should more or less work. > > > On Dec 18, 10:02 am, Rick wrote: > > > > Thanks for the replies! The variable that I'm operating with is python > > > type, not javascript. Mdipierro, your solution looks nice, but i can't > > > get it working. The value of the variable doesn't seem to change. Here > > > is my code: > > > > from views/default/index.html: > > > {{n=1}} > > > plus > > > {{=n}} > > > > controller.py > > > def plus_n(): > > > # check this was called by the ajax post > > > if request.env.request_method=='POST': > > > # do anything you need to do > > > session.n=session.n+1 > > > # optional return instructions in JS > > > return "$('.flash').html('n was incremented').slideDown();" > > > > On Dec 18, 2:26 am, pbreit wrote: > > > > > I don't really understand the question. Do you want to change a > > > > JavaScript > > > > variable? Or a variable in your web2py code? I don't think you would be > > > > able > > > > to modify a web2py variable as the result of a click. By the time the > > > > suer > > > > views your page, all the web2py code has been rendered into HTML. You'll > > > > either need to code some JavaScript or perform some sort of Ajax call > > > > back > > > > to your server. > > > > > What exactly are you trying to do?
[web2py] reload a div
Hi, How to reload/update a div tag as that below with AJAX? {{=variable}} update the div Thanks in advance for replies.
[web2py] How to delete a user?
Hi, I don't know if the way I add users is proper, but it works. Now I try to write a tag for deleting users, and it doesn't work. Here is the code: ==in a controller file== def admin(): records = db().select(custom_auth_table.ALL, orderby=custom_auth_table.username) #records = SQLFORM(custom_auth_table, user, deletable=True) form = SQLFORM(db[auth.settings.table_user_name]) if form.accepts(request.post_vars, session): session.flash = 'Address saved.' redirect(URL('admin')) return dict(form=form, records=records) ==admin.html== {{extend 'layout.html'}} Add a user: {{=form}} Users: {{for record in records:}} {{=record.username}} : {{=record.password}} [ Delete this user ] {{pass}} Thanks in advance for help
[web2py] Re: How to delete a user?
I changed the code but it still doesn't work: ==admin.html== {{extend 'layout.html'}} Add a user: {{=form}} Users: {{for record in records:}} {{=record.username}} : {{=record.password}} [ Delete this user ] {{pass}} ==Here is some code from models/db.py== auth = Auth(globals(), db) db.define_table( auth.settings.table_user_name, Field('username'), Field('password'), Field('registration_key', default='')) auth.define_tables() custom_auth_table = db[auth.settings.table_user_name] # get the custom_auth_table == On Dec 30 2010, 6:21 pm, Rick wrote: > Hi, > > I don't know if the way I add users is proper, but it works. Now I try > to write a tag for deleting users, and it doesn't work. Here is > the code: > > ==in a controller file== > def admin(): > records = db().select(custom_auth_table.ALL, > orderby=custom_auth_table.username) > #records = SQLFORM(custom_auth_table, user, deletable=True) > form = SQLFORM(db[auth.settings.table_user_name]) > if form.accepts(request.post_vars, session): > session.flash = 'Address saved.' > redirect(URL('admin')) > return dict(form=form, records=records) > > > ==admin.html== > {{extend 'layout.html'}} > Add a user: > {{=form}} > > Users: > > {{for record in records:}} > {{=record.username}} : {{=record.password}} > [ > onclick="ajax('{{=URL('db[auth.remove.record.username]')}}', > [],'')">Delete this user > ] > > {{pass}} > > > Thanks in advance for help
[web2py] Re: How to delete a user?
Thanks, I changed the code to this: Users: ==in admin.html== {{for record in records:}} {{=record.username}} : {{=record.password}} [ {{session.username=record.username}} Delete this user ] {{pass}} ==in a controller file== def deleteusr(): db(custom_auth_table.username==session.username).delete() return 'the record has been deleted' ...but I don't know how to reload the page automatically after deleting a user. Any ideas? On Jan 2, 5:13 pm, Jonathan Lundell wrote: > On Jan 2, 2011, at 7:01 AM, Rick wrote: > > > > > I changed the code but it still doesn't work: > > Here's a fragment of my code that I use to delete a user. It's not ajax, but > you'll get the idea: > > ut = auth.settings.table_user > uu = urow.auth_user > ... > if not db(ut.username == username).count(): > ...complain and redirect... > auth.del_group(auth.user_group(uu.id)) # uu.id is the user id > I'm deleting > db(ut.username == username).delete() > > If you look at auth.del_group, you'll see that it does quite a bit of work to > clean a user out of the group tables. I think I picked up this logic from the > admin app, but I don't quite remember. > > I think it'd be nice if auth had a comprehensive delete-user function. > > > > > > > > > > > ==admin.html== > > {{extend 'layout.html'}} > > Add a user: > > {{=form}} > > > > Users: > > > > {{for record in records:}} > > {{=record.username}} : {{=record.password}} > > [ > > > onclick="ajax('{{=URL('db(auth.settings.table_user_name==record.username).d > > elete()')}}', > > [],'')">Delete this user > > ] > > {{pass}} > > > > > ==Here is some code from models/db.py== > > auth = Auth(globals(), db) > > > db.define_table( > > auth.settings.table_user_name, > > Field('username'), > > Field('password'), > > Field('registration_key', default='')) > > > auth.define_tables() > > > custom_auth_table = db[auth.settings.table_user_name] # get the > > custom_auth_table > > == > > > On Dec 30 2010, 6:21 pm, Rick wrote: > >> Hi, > > >> I don't know if the way I add users is proper, but it works. Now I try > >> to write a tag for deleting users, and it doesn't work. Here is > >> the code: > > >> ==in a controller file== > >> def admin(): > >> records = db().select(custom_auth_table.ALL, > >> orderby=custom_auth_table.username) > >> #records = SQLFORM(custom_auth_table, user, deletable=True) > >> form = SQLFORM(db[auth.settings.table_user_name]) > >> if form.accepts(request.post_vars, session): > >> session.flash = 'Address saved.' > >> redirect(URL('admin')) > >> return dict(form=form, records=records) > >> > > >> ==admin.html== > >> {{extend 'layout.html'}} > >> Add a user: > >> {{=form}} > >> > >> Users: > >> > >> {{for record in records:}} > >> {{=record.username}} : {{=record.password}} > >> [ > >> >> onclick="ajax('{{=URL('db[auth.remove.record.username]')}}', > >> [],'')">Delete this user > >> ] > >> > >> {{pass}} > >> > > >> Thanks in advance for help
[web2py] Re: How to delete a user?
Thanks a lot! I find this being a good solution: ==in admin.html== {{=A(("Delete this user"), _href=URL('deleteusr'))}} ==in the controller file== def deleteusr(): db(custom_auth_table.username==session.username).delete() redirect(URL('admin')) On Jan 2, 8:19 pm, Jonathan Lundell wrote: > On Jan 2, 2011, at 11:10 AM, Arun K.Rajeevan wrote: > > > Try this, > > Delete this > > user > > > I haven't tested, but must work. > > If I were coding this for myself, I think I'd self-submit and conditionally > do the user-delete and redirect in the original controller.
[web2py] Number of records
Hi, In addition to the records that are submitted with a SQLFORM, I want to give each record a specific "identification" number, so that the first record has number=1 and so on: ==from model/db.py== db.define_table('input', Field('number', 'integer'), Field('value', 'integer')) ...My problem is that I don't know how to automatically add the number to this form: form = SQLFORM(db.input, fields=['value']) Thanks in advance for help.
[web2py] Re: Number of records
Thanks for the advice. I changed my code, but I don't know if I'm on the right track. Anyhow it doesn't work. ==in a model file== db.define_table('input', Field('value', 'integer')) class MyVirtualFields(object): def input_number(self): return self.input.value ==in a controller file== def create(): records = db().select(db.day.ALL, orderby=db.day.thedate) form = SQLFORM(db.input, fields=['value']) db.day.virtualfields.append(MyVirtualFields()) return dict(form = form) def deleterec(): session.virtualfields.remove(MyVirtualFields()) db.input.input_number.remove(MyVirtualFields()) redirect(URL('create')) ==in create.html== {{for record in records:}} {{session.virtualfields=record.virtualfields}} {{=record.value}} : [ {{=A(("Delete this record"), _href=URL('deleterec'))}} >On Jan 2, 10:36 pm, Kenneth Lundström wrote: > If you only want to display a number I guess virtual fields is what you > need. Look at > > http://www.web2py.com/book/default/chapter/06?search=virtual#Virtual-... > > Kenneth > > > > > > > > > Hi, > > In addition to the records that are submitted with a SQLFORM, I want > > to give each record a specific "identification" number, so that the > > first record has number=1 and so on: > > > ==from model/db.py== > > db.define_table('input', > > Field('number', 'integer'), > > Field('value', 'integer')) > > > ...My problem is that I don't know how to automatically add the number > > to this form: > > form = SQLFORM(db.input, fields=['value']) > > > Thanks in advance for help.
[web2py] Re: Number of records
Thanks for the replies. Now I try to add the ability to delete records, but it doesn't seem to work: db(db.input.virtualfields==session.virtualfields).delete() >On Jan 3, 1:52 pm, Bruno Rocha wrote: > [ Copy Paste Mystake ] > > Correct is: > > you have two options: > > 1. define the virtual fields in model > > =in a model file== > db.define_table('input', > Field('value', 'integer')) > class MyVirtualFields(object): > def input_number(self): > return self.input.value > > db.input.virtualfields.append(MyVirtualFields()) > > 2. In controller use the setvirtualfields method of Rows > > ==in a controller file== > records = db(db.input.id>0).select() # or any other query > records.setvirtualfields(virtual=MyVirtualFields()) > > > > > > > > > > > > > 2011/1/3 Rick > > > Thanks for the advice. I changed my code, but I don't know if I'm on > >> the right track. Anyhow it doesn't work. > > >> ==in a model file== > >> db.define_table('input', > >> Field('value', 'integer')) > >> class MyVirtualFields(object): > >> def input_number(self): > >> return self.input.value > > >> ==in a controller file== > >> def create(): > >> records = db().select(db.day.ALL, orderby=db.day.thedate) > >> form = SQLFORM(db.input, fields=['value']) > >> db.day.virtualfields.append(MyVirtualFields()) > >> return dict(form = form) > >> def deleterec(): > >> session.virtualfields.remove(MyVirtualFields()) > >> db.input.input_number.remove(MyVirtualFields()) > >> redirect(URL('create')) > > >> ==in create.html== > >> {{for record in records:}} > >> {{session.virtualfields=record.virtualfields}} > >> {{=record.value}} : [ {{=A(("Delete this record"), > >> _href=URL('deleterec'))}} > > >> >On Jan 2, 10:36 pm, Kenneth Lundström > >> wrote: > >> > If you only want to display a number I guess virtual fields is what you > >> > need. Look at > > >> >http://www.web2py.com/book/default/chapter/06?search=virtual#Virtual-. > >> .. > > >> > Kenneth > > >> > > Hi, > >> > > In addition to the records that are submitted with a SQLFORM, I want > >> > > to give each record a specific "identification" number, so that the > >> > > first record has number=1 and so on: > > >> > > ==from model/db.py== > >> > > db.define_table('input', > >> > > Field('number', 'integer'), > >> > > Field('value', 'integer')) > > >> > > ...My problem is that I don't know how to automatically add the number > >> > > to this form: > >> > > form = SQLFORM(db.input, fields=['value']) > > >> > > Thanks in advance for help. > > > -- > > > Bruno Rocha > >http://about.me/rochacbruno/bio > > -- > > Bruno Rochahttp://about.me/rochacbruno/bio
[web2py] Re: Number of records
Perhaps this would be a good idea to keep track of the records: ==in a model file== n = 0 class MyVirtualFields(): def day_number(self): n=n+1 return n but I'm not sure about how to write this idea properly in python. Perhaps there should be some kind of loop in the controller file? On Jan 3, 7:39 pm, Rick wrote: > Thanks for the replies. Now I try to add the ability to delete > records, but it doesn't seem to work: > db(db.input.virtualfields==session.virtualfields).delete() > > > > > > > > >On Jan 3, 1:52 pm, Bruno Rocha wrote: > > [ Copy Paste Mystake ] > > > Correct is: > > > you have two options: > > > 1. define the virtual fields in model > > > =in a model file== > > db.define_table('input', > > Field('value', 'integer')) > > class MyVirtualFields(object): > > def input_number(self): > > return self.input.value > > > db.input.virtualfields.append(MyVirtualFields()) > > > 2. In controller use the setvirtualfields method of Rows > > > ==in a controller file== > > records = db(db.input.id>0).select() # or any other query > > records.setvirtualfields(virtual=MyVirtualFields()) > > > > 2011/1/3 Rick > > > > Thanks for the advice. I changed my code, but I don't know if I'm on > > >> the right track. Anyhow it doesn't work. > > > >> ==in a model file== > > >> db.define_table('input', > > >> Field('value', 'integer')) > > >> class MyVirtualFields(object): > > >> def input_number(self): > > >> return self.input.value > > > >> ==in a controller file== > > >> def create(): > > >> records = db().select(db.day.ALL, orderby=db.day.thedate) > > >> form = SQLFORM(db.input, fields=['value']) > > >> db.day.virtualfields.append(MyVirtualFields()) > > >> return dict(form = form) > > >> def deleterec(): > > >> session.virtualfields.remove(MyVirtualFields()) > > >> db.input.input_number.remove(MyVirtualFields()) > > >> redirect(URL('create')) > > > >> ==in create.html== > > >> {{for record in records:}} > > >> {{session.virtualfields=record.virtualfields}} > > >> {{=record.value}} : [ {{=A(("Delete this record"), > > >> _href=URL('deleterec'))}} > > > >> >On Jan 2, 10:36 pm, Kenneth Lundström > > >> wrote: > > >> > If you only want to display a number I guess virtual fields is what you > > >> > need. Look at > > > >> >http://www.web2py.com/book/default/chapter/06?search=virtual#Virtual-. > > >> .. > > > >> > Kenneth > > > >> > > Hi, > > >> > > In addition to the records that are submitted with a SQLFORM, I want > > >> > > to give each record a specific "identification" number, so that the > > >> > > first record has number=1 and so on: > > > >> > > ==from model/db.py== > > >> > > db.define_table('input', > > >> > > Field('number', 'integer'), > > >> > > Field('value', 'integer')) > > > >> > > ...My problem is that I don't know how to automatically add the > > >> > > number > > >> > > to this form: > > >> > > form = SQLFORM(db.input, fields=['value']) > > > >> > > Thanks in advance for help. > > > > -- > > > > Bruno Rocha > > >http://about.me/rochacbruno/bio > > > -- > > > Bruno Rochahttp://about.me/rochacbruno/bio
[web2py] Re: Number of records
Unfortunately the code bellow seems to be errors-prone: ==in a model file== class MyVirtualFields(object): def input_number(self): return some_variable db.input.virtualfields.append(MyVirtualFields()) >On Jan 3, 8:03 pm, Rick wrote: > Perhaps this would be a good idea to keep track of the records: > > ==in a model file== > n = 0 > class MyVirtualFields(): > def day_number(self): > n=n+1 > return n > > but I'm not sure about how to write this idea properly in python. > Perhaps there should be some kind of loop in the controller file? > > On Jan 3, 7:39 pm, Rick wrote: > > > > > > > > > Thanks for the replies. Now I try to add the ability to delete > > records, but it doesn't seem to work: > > db(db.input.virtualfields==session.virtualfields).delete() > > > >On Jan 3, 1:52 pm, Bruno Rocha wrote: > > > [ Copy Paste Mystake ] > > > > Correct is: > > > > you have two options: > > > > 1. define the virtual fields in model > > > > =in a model file== > > > db.define_table('input', > > > Field('value', 'integer')) > > > class MyVirtualFields(object): > > > def input_number(self): > > > return self.input.value > > > > db.input.virtualfields.append(MyVirtualFields()) > > > > 2. In controller use the setvirtualfields method of Rows > > > > ==in a controller file== > > > records = db(db.input.id>0).select() # or any other query > > > records.setvirtualfields(virtual=MyVirtualFields()) > > > > > 2011/1/3 Rick > > > > > Thanks for the advice. I changed my code, but I don't know if I'm on > > > >> the right track. Anyhow it doesn't work. > > > > >> ==in a model file== > > > >> db.define_table('input', > > > >> Field('value', 'integer')) > > > >> class MyVirtualFields(object): > > > >> def input_number(self): > > > >> return self.input.value > > > > >> ==in a controller file== > > > >> def create(): > > > >> records = db().select(db.day.ALL, orderby=db.day.thedate) > > > >> form = SQLFORM(db.input, fields=['value']) > > > >> db.day.virtualfields.append(MyVirtualFields()) > > > >> return dict(form = form) > > > >> def deleterec(): > > > >> session.virtualfields.remove(MyVirtualFields()) > > > >> db.input.input_number.remove(MyVirtualFields()) > > > >> redirect(URL('create')) > > > > >> ==in create.html== > > > >> {{for record in records:}} > > > >> {{session.virtualfields=record.virtualfields}} > > > >> {{=record.value}} : [ {{=A(("Delete this record"), > > > >> _href=URL('deleterec'))}} > > > > >> >On Jan 2, 10:36 pm, Kenneth Lundström > > > >> wrote: > > > >> > If you only want to display a number I guess virtual fields is what > > > >> > you > > > >> > need. Look at > > > > >> >http://www.web2py.com/book/default/chapter/06?search=virtual#Virtual-. > > > >> .. > > > > >> > Kenneth > > > > >> > > Hi, > > > >> > > In addition to the records that are submitted with a SQLFORM, I > > > >> > > want > > > >> > > to give each record a specific "identification" number, so that the > > > >> > > first record has number=1 and so on: > > > > >> > > ==from model/db.py== > > > >> > > db.define_table('input', > > > >> > > Field('number', 'integer'), > > > >> > > Field('value', 'integer')) > > > > >> > > ...My problem is that I don't know how to automatically add the > > > >> > > number > > > >> > > to this form: > > > >> > > form = SQLFORM(db.input, fields=['value']) > > > > >> > > Thanks in advance for help. > > > > > -- > > > > > Bruno Rocha > > > >http://about.me/rochacbruno/bio > > > > -- > > > > Bruno Rochahttp://about.me/rochacbruno/bio
[web2py] account for each user
Hi, I suppose that this is a very elementary question, but I can't find the solution. My question is -- how to make a account for each user? I've tried with this code, but it gives just one account for all user: ==on the model file== db.define_table( auth.settings.table_user_name, Field('username'), Field('password'), Field('registration_key', default='')) auth.define_tables() custom_auth_table = db[auth.settings.table_user_name] # get the custom_auth_table db.define_table('day', Field('person', db[auth.settings.table_user_name]), Field('thedate','date'), Field('value', 'integer')) ==in a controller file== @auth.requires_login() def create(): some code def user(): return dict(form=auth())
[web2py] Re: Number of records
Thanks for the suggestion! The 'id' field looks like a smart solution. But there seem to be a problem -- This line creates an error when I add the 'id' field and 'migrate=False' to the day table: records = db().select(db.day.ALL, orderby=db.day.thedate) Any ideas? On Jan 4, 4:03 am, Fabiano wrote: > What stops you from using 'id' field?
[web2py] Re: Number of records
So the problem was that the controller file line creates an error when I add the 'id' field and 'migrate=False' to the day table. Here is some more code: ===in the model file=== import datetime now = datetime.date.today() db.define_table('day', Field('the_id', 'id'), Field('thedate','date', default=request.now), Field('value', 'integer'), migrate=False) ===in the controller file=== records = db().select(db.day.ALL, orderby=db.day.thedate) On Jan 15, 8:16 am, Kenneth Lundström wrote: > Could you shows us the relevant part of your models file, where the > table is defined and then also the error ticket. > > Kenneth > > > > > > > > > Thanks for the suggestion! The 'id' field looks like a smart solution. > > But there seem to be a problem -- This line creates an error when I > > add the 'id' field and 'migrate=False' to the day table: > > records = db().select(db.day.ALL, orderby=db.day.thedate) > > Any ideas? > > > On Jan 4, 4:03 am, Fabiano wrote: > >> What stops you from using 'id' field?
[web2py] Re: account for each user
Thanks for the replies. My problem is that with the code I can create one account for all users, but I want to create one account for each user. >On Jan 4, 1:14 am, Martín Mulone wrote: > Commonly in internet, the users create their accounts, via > (/myapp/default/user/register/) > > But if you want to create some accounts take a look to this: > > def new_user(first_name, last_name, email, passw): > > users = db(db.auth_user.email==email).select() > if users: > return users[0].id > else: > my_crypt = CRYPT(key=auth.settings.hmac_key) > crypt_pass = my_crypt(passw)[0] > id_user= db.auth_user.insert( > first_name=first_name, > last_name=last_name, > email = email, > password = crypt_pass > > ) > return id_user > > iduser = new_user('Chris','Mills','ch...@nobody.com','somepasswordhere') > > 2011/1/3 mdipierro : > > > > > > > > > > > I do not understand the question.sorry. > > > On Jan 3, 3:46 pm, Rick wrote: > >> Hi, > > >> I suppose that this is a very elementary question, but I can't find > >> the solution. My question is -- how to make a account for each user? > > >> I've tried with this code, but it gives just one account for all user: > > >> ==on the model file== > >> db.define_table( > >> auth.settings.table_user_name, > >> Field('username'), > >> Field('password'), > >> Field('registration_key', default='')) > >> auth.define_tables() > >> custom_auth_table = db[auth.settings.table_user_name] # get the > >> custom_auth_table > >> db.define_table('day', > >> Field('person', db[auth.settings.table_user_name]), > >> Field('thedate','date'), > >> Field('value', 'integer')) > > >> ==in a controller file== > >> @auth.requires_login() > >> def create(): > >> some code > > >> def user(): > >> return dict(form=auth()) > > -- > My blog:http://martin.tecnodoc.com.ar > My portfolio *spanish*:http://www.tecnodoc.com.ar > Checkout my last proyect instant-press:http://www.instant2press.com > Expert4Solution Profile:http://www.experts4solutions.com/e4s/default/expert/6
[web2py] Re: account for each user
Perhaps I should reformulate the problem -- I want to make one table for each auth-user, so that an auth-user can't see the records of ohters auth-users. On Jan 15, 11:52 pm, pbreit wrote: > I may not understand either. The user authentication functionality is > automatically provided by web2py scaffolding. I would suggest using it > without modifications until you run into limitations.
[web2py] Re: account for each user
...or maybe the problem lies int this function in the controller file: def admin(): records = db().select(custom_auth_table.ALL, orderby=custom_auth_table.username) form = SQLFORM(db[auth.settings.table_user_name]) if form.accepts(request.post_vars, session): session.flash = 'saved.' redirect(URL('admin')) return dict(form=form, records=records) On Jan 16, 1:08 am, Rick wrote: > Perhaps I should reformulate the problem -- I want to make one table > for each auth-user, so that an auth-user can't see the records of > ohters auth-users. > > On Jan 15, 11:52 pm, pbreit wrote: > > > > > > > > > I may not understand either. The user authentication functionality is > > automatically provided by web2py scaffolding. I would suggest using it > > without modifications until you run into limitations.
[web2py] Re: account for each user
Hurray, I'm getting somewhere now! Thanks pbreit, now I try to do what I want to do without modifying the authentication functionality and it works better. But I get the message "invalid function" when I try to login. Here is the code: ===in the model file=== auth = Auth(globals(), db) auth.define_tables(username=True) ===in the controller file=== def users(): return users[0].id def admin(): records = db().select(auth.settings.table_user.ALL, orderby=auth.settings.table_user.username) form = SQLFORM(auth.settings.table_user, fields=['username','password'],) if form.accepts(request.post_vars, session): session.flash = 'Address saved.' redirect(URL('admin')) return dict(form=form, records=records) ===in user.html=== {{extend 'layout.html'}} {{=request.args(0).replace('_',' ').capitalize()}} {{=form}} {{if request.args(0)=='login':}} {{pass}} >On Jan 16, 3:24 am, Rick wrote: > ...or maybe the problem lies int this function in the controller file: > def admin(): > records = db().select(custom_auth_table.ALL, > orderby=custom_auth_table.username) > form = SQLFORM(db[auth.settings.table_user_name]) > if form.accepts(request.post_vars, session): > session.flash = 'saved.' > redirect(URL('admin')) > return dict(form=form, records=records) > > On Jan 16, 1:08 am, Rick wrote: > > > > > > > > > Perhaps I should reformulate the problem -- I want to make one table > > for each auth-user, so that an auth-user can't see the records of > > ohters auth-users. > > > On Jan 15, 11:52 pm, pbreit wrote: > > > > I may not understand either. The user authentication functionality is > > > automatically provided by web2py scaffolding. I would suggest using it > > > without modifications until you run into limitations.
[web2py] Re: account for each user
I changed the code and I suppose I'm on the right track but I get an error message when I try to run the app: ./create.html", line 91 response.write(form) ^ SyntaxError: invalid syntax Here is the code: ===in a controller file=== @auth.requires_login() def create(): records = db(auth.settings.table_user==auth.user).select(db.day.theauth, distinct=True, orderby=db.day.thedate) form = SQLFORM(db.day, fields=['thedate','value']) if form.accepts(request.post_vars, session): session.flash = 'Saved.' redirect(URL('create')) return dict(records=records, form=form) ===in create.html=== {{for record in records:}} {{#if recording!=record.thedate:}} {{#=record.thedate}} {{pass}} {{#session.uuid=record.uuid}} {{=record.value}} {{pass}} {{=form}} ===in the model file=== auth = Auth(globals(), db) auth.define_tables(username=True) import uuid import datetime now = datetime.date.today() db.define_table('day', Field('uuid', length=64, default=uuid.uuid4()), Field('thedate','date', default=request.now), Field('value', 'integer'), Field('theauth', auth.settings.table_user)) On Jan 16, 4:58 am, Rick wrote: > Hurray, I'm getting somewhere now! Thanks pbreit, now I try to do what > I want to do without modifying the authentication functionality and it > works better. But I get the message "invalid function" when I try to > login. Here is the code: > > ===in the model file=== > auth = Auth(globals(), db) > auth.define_tables(username=True) > > ===in the controller file=== > def users(): > return users[0].id > > def admin(): > records = db().select(auth.settings.table_user.ALL, > orderby=auth.settings.table_user.username) > form = SQLFORM(auth.settings.table_user, > fields=['username','password'],) > if form.accepts(request.post_vars, session): > session.flash = 'Address saved.' > redirect(URL('admin')) > return dict(form=form, records=records) > > ===in user.html=== > {{extend 'layout.html'}} > {{=request.args(0).replace('_',' ').capitalize()}} > {{=form}} > {{if request.args(0)=='login':}} > {{pass}} > > > > > > > > >On Jan 16, 3:24 am, Rick wrote: > > ...or maybe the problem lies int this function in the controller file: > > def admin(): > > records = db().select(custom_auth_table.ALL, > > orderby=custom_auth_table.username) > > form = SQLFORM(db[auth.settings.table_user_name]) > > if form.accepts(request.post_vars, session): > > session.flash = 'saved.' > > redirect(URL('admin')) > > return dict(form=form, records=records) > > > On Jan 16, 1:08 am, Rick wrote: > > > > Perhaps I should reformulate the problem -- I want to make one table > > > for each auth-user, so that an auth-user can't see the records of > > > ohters auth-users. > > > > On Jan 15, 11:52 pm, pbreit wrote: > > > > > I may not understand either. The user authentication functionality is > > > > automatically provided by web2py scaffolding. I would suggest using it > > > > without modifications until you run into limitations.
[web2py] request.vars and lists question
I have a simple function: def simpletest(animals): theAnimals = request.vars["animals"] leng = len(theAnimals) return dict(leng = leng) When I call it with two animals: http://mySite.com/myApp/default/call/run/simpletest?animals=cat&animals=dog .. I get the answer 2, as I would expect When I call it with only one animal: http://mySite.com/myApp/default/call/run/simpletest?animals=cat .. I get the answer 3, the length of the string "cat" I would prefer to get a list with only a single value, like ["cat"], of length 1. What could I do differently to make that happen? Thank you, rick
[web2py] Re: request.vars and lists question
Ah! Thank you, that works great. - rick On Jan 16, 3:10 pm, Jonathan Lundell wrote: > Try: theAnimals = request.vars.getlist("animals")
[web2py] Re: request.vars and lists question
Ah! Thank you, that works great. - rick On Jan 16, 3:10 pm, Jonathan Lundell wrote: > Try: theAnimals = request.vars.getlist("animals")
[web2py] Re: request.vars and lists question
Ah! Thank you, that works great. - rick On Jan 16, 3:10 pm, Jonathan Lundell wrote: > Try: theAnimals = request.vars.getlist("animals")
[web2py] Re: account for each user
thanks for the comments. I deleted the #. At the beginning of create.html there is this code: {{import datetime}} {{import uuid}} {{recording=datetime.date(2000,01,01)}} ...but the error remains :( On Jan 16, 2:13 pm, "Martin.Mulone" wrote: > in create.html > > #if recording!=record.thedate:} > > you commented this line but you hasn't commented the pass, the same to > {{#session.uuid=record.uuid}} > and what is recording??.
[web2py] Re: account for each user
Yes, {{=form}} works without the other code. On Jan 16, 6:35 pm, Martín Mulone wrote: > to test, put only {{=form}} in create.html remove all the other. Now the > error continue? > > 2011/1/16 Rick > > > > > > > > > > > thanks for the comments. I deleted the #. At the beginning of > > create.html there is this code: > > {{import datetime}} > > {{import uuid}} > > {{recording=datetime.date(2000,01,01)}} > > ...but the error remains :( > > > On Jan 16, 2:13 pm, "Martin.Mulone" wrote: > > > in create.html > > > > #if recording!=record.thedate:} > > > > you commented this line but you hasn't commented the pass, the same to > > > {{#session.uuid=record.uuid}} > > > and what is recording??. > > -- > Pablo Martín Mulone (mar...@tecnodoc.com.ar)http://www.tecnodoc.com.ar/ > Paraná, Entre Ríos, Argentina (CP 3100). > > My blog:http://martin.tecnodoc.com.ar > Expert4Solution Profile:http://www.experts4solutions.com/e4s/default/expert/6
[web2py] Re: account for each user
Perhaps the previous post was a bit vague. I meant that create.html works when it only contains {{=form}}. On Jan 16, 8:35 pm, Rick wrote: > Yes, {{=form}} works without the other code. > > On Jan 16, 6:35 pm, Martín Mulone wrote: > > > > > > > > > to test, put only {{=form}} in create.html remove all the other. Now the > > error continue? > > > 2011/1/16 Rick > > > > thanks for the comments. I deleted the #. At the beginning of > > > create.html there is this code: > > > {{import datetime}} > > > {{import uuid}} > > > {{recording=datetime.date(2000,01,01)}} > > > ...but the error remains :( > > > > On Jan 16, 2:13 pm, "Martin.Mulone" wrote: > > > > in create.html > > > > > #if recording!=record.thedate:} > > > > > you commented this line but you hasn't commented the pass, the same to > > > > {{#session.uuid=record.uuid}} > > > > and what is recording??. > > > -- > > Pablo Martín Mulone (mar...@tecnodoc.com.ar)http://www.tecnodoc.com.ar/ > > Paraná, Entre Ríos, Argentina (CP 3100). > > > My blog:http://martin.tecnodoc.com.ar > > Expert4Solution > > Profile:http://www.experts4solutions.com/e4s/default/expert/6
[web2py] Re: account for each user
Hmmm... strange... the error disappeared, but it was replaced by another one: KeyError: 'thedate' ...and this error arises from the html-table in the create.html -- the code works when i delete the table. On Jan 16, 8:40 pm, Rick wrote: > Perhaps the previous post was a bit vague. I meant that create.html > works when it only contains {{=form}}. > > On Jan 16, 8:35 pm, Rick wrote: > > > > > > > > > Yes, {{=form}} works without the other code. > > > On Jan 16, 6:35 pm, Martín Mulone wrote: > > > > to test, put only {{=form}} in create.html remove all the other. Now the > > > error continue? > > > > 2011/1/16 Rick > > > > > thanks for the comments. I deleted the #. At the beginning of > > > > create.html there is this code: > > > > {{import datetime}} > > > > {{import uuid}} > > > > {{recording=datetime.date(2000,01,01)}} > > > > ...but the error remains :( > > > > > On Jan 16, 2:13 pm, "Martin.Mulone" wrote: > > > > > in create.html > > > > > > #if recording!=record.thedate:} > > > > > > you commented this line but you hasn't commented the pass, the same to > > > > > {{#session.uuid=record.uuid}} > > > > > and what is recording??. > > > > -- > > > Pablo Martín Mulone (mar...@tecnodoc.com.ar)http://www.tecnodoc.com.ar/ > > > Paraná, Entre Ríos, Argentina (CP 3100). > > > > My blog:http://martin.tecnodoc.com.ar > > > Expert4Solution > > > Profile:http://www.experts4solutions.com/e4s/default/expert/6
[web2py] Re: account for each user
I suppose that the problem is that the "records" list isn't completely returned from the controller file to create.html and that the "thedate" field is lost in that process. On Jan 16, 9:32 pm, Rick wrote: > Hmmm... strange... the error disappeared, but it was replaced by > another one: > KeyError: 'thedate' > ...and this error arises from the html-table in the create.html -- the > code works when i delete the table. > > On Jan 16, 8:40 pm, Rick wrote: > > > > > > > > > Perhaps the previous post was a bit vague. I meant that create.html > > works when it only contains {{=form}}. > > > On Jan 16, 8:35 pm, Rick wrote: > > > > Yes, {{=form}} works without the other code. > > > > On Jan 16, 6:35 pm, Martín Mulone wrote: > > > > > to test, put only {{=form}} in create.html remove all the other. Now > > > > the > > > > error continue? > > > > > 2011/1/16 Rick > > > > > > thanks for the comments. I deleted the #. At the beginning of > > > > > create.html there is this code: > > > > > {{import datetime}} > > > > > {{import uuid}} > > > > > {{recording=datetime.date(2000,01,01)}} > > > > > ...but the error remains :( > > > > > > On Jan 16, 2:13 pm, "Martin.Mulone" wrote: > > > > > > in create.html > > > > > > > #if recording!=record.thedate:} > > > > > > > you commented this line but you hasn't commented the pass, the same > > > > > > to > > > > > > {{#session.uuid=record.uuid}} > > > > > > and what is recording??. > > > > > -- > > > > Pablo Martín Mulone (mar...@tecnodoc.com.ar)http://www.tecnodoc.com.ar/ > > > > Paraná, Entre Ríos, Argentina (CP 3100). > > > > > My blog:http://martin.tecnodoc.com.ar > > > > Expert4Solution > > > > Profile:http://www.experts4solutions.com/e4s/default/expert/6
[web2py] Re: account for each user
I found that this line is the error-prone one: records = db(auth.settings.table_user==auth.user).select(db.day.theauth, distinct=True, orderby=db.day.thedate) ...I tested the next version too, but it also gave an error: records = db(db.day.theauth==auth.user).select(db.day.ALL, orderby=db.day.thedate) ...The last version worked, but it doesn't fulfill the function I want it to have, namely to select records that are associated with the user that is logged in: records = db().select(db.day.ALL, orderby=db.day.thedate) Any ideas? >On Jan 16, 9:54 pm, Rick wrote: > I suppose that the problem is that the "records" list isn't completely > returned from the controller file to create.html and that the > "thedate" field is lost in that process. > > On Jan 16, 9:32 pm, Rick wrote: > > > > > > > > > Hmmm... strange... the error disappeared, but it was replaced by > > another one: > > KeyError: 'thedate' > > ...and this error arises from the html-table in the create.html -- the > > code works when i delete the table. > > > On Jan 16, 8:40 pm, Rick wrote: > > > > Perhaps the previous post was a bit vague. I meant that create.html > > > works when it only contains {{=form}}. > > > > On Jan 16, 8:35 pm, Rick wrote: > > > > > Yes, {{=form}} works without the other code. > > > > > On Jan 16, 6:35 pm, Martín Mulone wrote: > > > > > > to test, put only {{=form}} in create.html remove all the other. Now > > > > > the > > > > > error continue? > > > > > > 2011/1/16 Rick > > > > > > > thanks for the comments. I deleted the #. At the beginning of > > > > > > create.html there is this code: > > > > > > {{import datetime}} > > > > > > {{import uuid}} > > > > > > {{recording=datetime.date(2000,01,01)}} > > > > > > ...but the error remains :( > > > > > > > On Jan 16, 2:13 pm, "Martin.Mulone" wrote: > > > > > > > in create.html > > > > > > > > #if recording!=record.thedate:} > > > > > > > > you commented this line but you hasn't commented the pass, the > > > > > > > same to > > > > > > > {{#session.uuid=record.uuid}} > > > > > > > and what is recording??. > > > > > > -- > > > > > Pablo Martín Mulone > > > > > (mar...@tecnodoc.com.ar)http://www.tecnodoc.com.ar/ > > > > > Paraná, Entre Ríos, Argentina (CP 3100). > > > > > > My blog:http://martin.tecnodoc.com.ar > > > > > Expert4Solution > > > > > Profile:http://www.experts4solutions.com/e4s/default/expert/6
[web2py] passing varibales
Hi, My problem is that I want to make a {{=A...}} tag that also changes the value of the variable session.variable, and I don't know how to do this. I tried with: {{=A(("[ < ]"), session.variable=-1, _href=URL('function'))}} ...but it didn't work.
[web2py] Re: passing varibales
Thanks for the replies. I wrote a special def for the operation: def minorvar(): variable-=1 redirect(URL('index')) ...but I get an error that says that: local variable 'variable' referenced before assignment ...even though I've defined the variable as global at the beginning of the controller file. On Jan 22, 9:19 pm, Jason Brower wrote: > Yup... I think you should do that in the controller before you pass it. > It's a two second job so not hard to do. > That and session.variable=-1 is well... -1 it should be variable-=1. > On the other had, you may be going for -1 :P and you may be using a > special loop or something that needs to change as the page is formated. > Always exceptions when you have to print from the top down and build the > page before sending it to the client. :D > BR, > Jason > > On 01/22/2011 02:53 PM, b0j3 wrote: > > > > > > > > > On 22 jan., 11:47, Rick wrote: > >> Hi, > >> My problem is that I want to make a {{=A...}} tag that also changes > >> the value of the variable session.variable, and I don't know how to do > >> this. I tried with: > >> {{=A(("[< ]"), session.variable=-1, _href=URL('function'))}} > >> ...but it didn't work. > > Hi. > > > I'm not sure if that is a good way to program. Some would say, that > > you shouldn't change variable in the view so I don't think (I might be > > wrong, though), that it could work like that. > > > What would you like to achieve? > > > B.
[web2py] Re: passing varibales
Here is some code from the controller file: variable = 0 def index() some operations with the variable... def minorvar(): variable-=1 redirect(URL('index')) I also tried with this code, but the variable isn't changed after redirecting it to the index-function: variable = 0 session. variable = variable def index() variable=session. variable some operations with the variable... def minorvar(): session.variable-=1 redirect(URL('index')) On Jan 23, 3:13 am, Jason Brower wrote: > I would recommend that you use session.variable if that's what you want > to do. > Could we see the controller for the page before? I wonder if there is a > way we could put the action in there to make your code a bit cleaner. > BR, > JB > > On 01/23/2011 01:04 AM, Rick wrote: > > > > > > > > > Thanks for the replies. I wrote a special def for the operation: > > def minorvar(): > > variable-=1 > > redirect(URL('index')) > > ...but I get an error that says that: > > local variable 'variable' referenced before assignment > > ...even though I've defined the variable as global at the beginning of > > the controller file. > > > On Jan 22, 9:19 pm, Jason Brower wrote: > >> Yup... I think you should do that in the controller before you pass it. > >> It's a two second job so not hard to do. > >> That and session.variable=-1 is well... -1 it should be variable-=1. > >> On the other had, you may be going for -1 :P and you may be using a > >> special loop or something that needs to change as the page is formated. > >> Always exceptions when you have to print from the top down and build the > >> page before sending it to the client. :D > >> BR, > >> Jason > > >> On 01/22/2011 02:53 PM, b0j3 wrote: > > >>> On 22 jan., 11:47, Rick wrote: > >>>> Hi, > >>>> My problem is that I want to make a {{=A...}} tag that also changes > >>>> the value of the variable session.variable, and I don't know how to do > >>>> this. I tried with: > >>>> {{=A(("[< ]"), session.variable=-1, _href=URL('function'))}} > >>>> ...but it didn't work. > >>> Hi. > >>> I'm not sure if that is a good way to program. Some would say, that > >>> you shouldn't change variable in the view so I don't think (I might be > >>> wrong, though), that it could work like that. > >>> What would you like to achieve? > >>> B.
[web2py] Re: passing varibales
Thanks a lot! It works now. On Jan 23, 4:37 am, Jason Brower wrote: > Ok here is what I see as the problem. > What you are doing is setting variable as 0 every time you start a webpage. > Every time you start a webpage this entire file is look over as if it > was never seen before. Doing so is a great thing but you have to take > the approch differently knowing this. > For example here... > variable = 0 > session.variable = variable > this resets it to 0 at every load. > What you should do is something like this because you have data that > needs to be checked first... > if not session.variable: > session.variable = 0 > > This then checks if you have any data there (if it doesn't it returns None) > Place that at the beginning of your file where you have variable = 0 and > see if that is more of what you expected. > --- > Best Regards, > Jason Brower > > On 01/23/2011 05:15 AM, Rick wrote: > > > > > > > > > Here is some code from the controller file: > > > > variable = 0 > > > def index() > > some operations with the variable... > > > def minorvar(): > > variable-=1 > > redirect(URL('index')) > > > > I also tried with this code, but the variable isn't changed after > > redirecting it to the index-function: > > > > variable = 0 > > session. variable = variable > > > def index() > > variable=session. variable > > some operations with the variable... > > > def minorvar(): > > session.variable-=1 > > redirect(URL('index')) > > > > > On Jan 23, 3:13 am, Jason Brower wrote: > >> I would recommend that you use session.variable if that's what you want > >> to do. > >> Could we see the controller for the page before? I wonder if there is a > >> way we could put the action in there to make your code a bit cleaner. > >> BR, > >> JB > > >> On 01/23/2011 01:04 AM, Rick wrote: > > >>> Thanks for the replies. I wrote a special def for the operation: > >>> def minorvar(): > >>> variable-=1 > >>> redirect(URL('index')) > >>> ...but I get an error that says that: > >>> local variable 'variable' referenced before assignment > >>> ...even though I've defined the variable as global at the beginning of > >>> the controller file. > >>> On Jan 22, 9:19 pm, Jason Brower wrote: > >>>> Yup... I think you should do that in the controller before you pass it. > >>>> It's a two second job so not hard to do. > >>>> That and session.variable=-1 is well... -1 it should be variable-=1. > >>>> On the other had, you may be going for -1 :P and you may be using a > >>>> special loop or something that needs to change as the page is formated. > >>>> Always exceptions when you have to print from the top down and build the > >>>> page before sending it to the client. :D > >>>> BR, > >>>> Jason > >>>> On 01/22/2011 02:53 PM, b0j3 wrote: > >>>>> On 22 jan., 11:47, Rick wrote: > >>>>>> Hi, > >>>>>> My problem is that I want to make a {{=A...}} tag that also changes > >>>>>> the value of the variable session.variable, and I don't know how to do > >>>>>> this. I tried with: > >>>>>> {{=A(("[< ]"), session.variable=-1, _href=URL('function'))}} > >>>>>> ...but it didn't work. > >>>>> Hi. > >>>>> I'm not sure if that is a good way to program. Some would say, that > >>>>> you shouldn't change variable in the view so I don't think (I might be > >>>>> wrong, though), that it could work like that. > >>>>> What would you like to achieve? > >>>>> B.
[web2py] Overlapping periods
Hi, I try to make a function that puts periods of time into a database. The function should only add periods that doesn't overlap any of the already registered ones. But the function does not work, and I can't see what's wrong. Any idea? Thanks in advance for help! code from the controller file: def addingperiod(): if request.args and request.args[0]: item_id=request.args[0] prerecords = db().select(db.period.ALL, orderby=db.period.begindate) if not session.timedelta2==timedelta(days=0): for prerecord in prerecords: if prerecord.theauth==auth.user_id: accepted1="true" accepted2="true" if previous.enddate: if item_id.vars.begindate < previousenddate: accepted1="false" if item_id.vars.enddate < prerecord.begindate: accepted2="false" if item_id.vars.enddate < prerecord.enddate: accepted2="false" previousenddate = prerecord.enddate if accepted1=="true": if accepted2=="true": period.append(item_id) redirect(URL(c=request.controller,f='goal'))
Re: [web2py] Overlapping periods
Thanks for the replies. Pbreit, you pointed the real issue -- what should I call the arguments (addperiodform.vars.id), that are passed from the goal function to the addingperiod function? from the controller file: def goal(): ...some code... addperiodform = SQLFORM(db.period, fields=['begindate','enddate', 'planned'], labels={'begindate':'First day','enddate':'Last day','planned':'Goal'},submit_button='Submit',formstyle='table2cols') if addperiodform.accepts(request.post_vars, session): redirect(URL('default', 'addingperiod', args=addperiodform.vars.id)) ...some code... def addingperiod(): if request.args and request.args[0]: item_id=request.args[0] prerecords = db().select(db.period.ALL, orderby=db.period.begindate) for prerecord in prerecords: if prerecord.theauth==auth.user_id: accepted1="true" accepted2="true" ...some if-statements... if accepted1=="true": if accepted2=="true": db.period.insert(item_id) #this line creates an error redirect(URL(f='goal')) On Saturday, April 14, 2012 10:44:28 AM UTC+2, backseat wrote: > > On Fri, 13 Apr 2012 11:38:25 -0700 (PDT), sababa.sab...@gmail.com said: > > > The > > function should only add periods that doesn't overlap any of the > > already registered ones. > > Let me try to help (I owe this group a lot of help). I've ignored your > code, and I don't know what schema you're using, but here's the pseudo > and untested code: > > def should_this_period_be_inserted(start,end): > # Check that all periods that started before this one > # also finished before this one started > q = ((db.period.begindatestart)) > if db(query).count(): > return False > # Check that no periods started while this one was in progress > q = ((db.period.begindate>=start)&(db.period.begindate<=end)) > if db(query).count(): > return False > # If we got this far, the period didn't overlap > return True > > Have I understood what you're trying to do? > -- > "You can have everything in life you want if you help enough other people > get what they want" - Zig Ziglar. > > Who did you help today? > >
[web2py] date variables, json and jqplot
Hi, I want to draw a graph with jqplot, where the x-axis is a date- timeline, but I get this message: TypeError: datetime.date(2011, 10, 2) is not JSON serializable Does anyone know an easy way to pass date variable to json? Thanks in advance for help. Here is some code from the files: >From the controller file: points=[[point.thedate, point.value] for point in pointlist] return dict(points=points) from the view file:
[web2py] Re: date variables, json and jqplot
Thanks, your answer inspired me. The solution that works is this: >From the controller file: points=[[point.thedate.strftime('%Y-%m-%d'), point.value] for point in pointlist] >From the view file: <!-- jQuery(document).ready(function() { var p = {{=XML(response.json(points))}} $.jqplot('chart1', [p], { title:'Default Date Axis', axes:{xaxis:{renderer:$.jqplot.DateAxisRenderer}}, series:[{lineWidth:4, markerOptions:{style:'square'}}] }); }); --> On Oct 8, 7:09 pm, DenesL wrote: > try > > points=[[point.thedate.strftime('%Y%m%d'), point.value] for point in > pointlist] > > or some other format that suits your needs. > > On Oct 8, 10:29 am, Rick wrote: > > > > > > > > > Hi, > > I want to draw a graph with jqplot, where the x-axis is a date- > > timeline, but I get this message: > > TypeError: datetime.date(2011, 10, 2) is not JSON serializable > > Does anyone know an easy way to pass date variable to json? > > > Thanks in advance for help. Here is some code from the files: > > > > > > From the controller file: > > points=[[point.thedate, point.value] for point in pointlist] > > return dict(points=points) > > > > > > from the view file: > > > > <!-- > > jQuery(document).ready(function() { > > $.jqplot('chart1', [{{=simplejson.dumps(points)}}], { > > title:'Default Date Axis', > > axes:{xaxis:{renderer:$.jqplot.DateAxisRenderer}}, > > series:[{lineWidth:4, markerOptions:{style:'square'}}] > > });}); > > > --> > > > > > >
[web2py] Submit gutton in fields
Hi, How to change the text on the submit button in fields? Here'sthe code: Field('thedate', 'date', label=T(''), widget=SQLFORM.widgets.date.widget)) I tried with this, but i didn't work: Field('thedate', 'date', label=T(''), submit=INPUT(_type='submit'('Some text')), widget=SQLFORM.widgets.date.widget)) Thanks in advance for help!
[web2py] Re: Submit gutton in fields
Thanks! This is the final code: dayform = SQLFORM.factory( Field('thedate', 'date', label=T(''), widget=SQLFORM.widgets.date.widget), submit_button='Some text') On Dec 1, 10:12 pm, Anthony wrote: > Submit buttons are not in fields, they are added as an input element to an > entire form. Where is that Field definition -- in a table definition or > SQLFORM.factory? Anyway, SQLFORM takes a 'submit_button' argument, which is > the text for the submit button. > > Anthony > > > > > > > > On Thursday, December 1, 2011 3:57:30 PM UTC-5, Rick wrote: > > > Hi, > > How to change the text on the submit button in fields? Here'sthe code: > > > Field('thedate', 'date', label=T(''), > > widget=SQLFORM.widgets.date.widget)) > > > I tried with this, but i didn't work: > > Field('thedate', 'date', label=T(''), > > submit=INPUT(_type='submit'('Some text')), > > widget=SQLFORM.widgets.date.widget)) > > > Thanks in advance for help!
[web2py] Re: Submit gutton in fields
Now I've a similar problem. How to make a button that shows a calendar when you click on it? The reason why I want to do that kind of button is that each time I try to write a date in the field the calendar pops up, even though I don't need it. Here is my code again: dayform = SQLFORM.factory( Field('thedate', 'date', label=T(''), widget=SQLFORM.widgets.date.widget), submit_button='Some text') Thanks in advance for help On Dec 1, 10:37 pm, Rick wrote: > Thanks! This is the final code: > dayform = SQLFORM.factory( > Field('thedate', 'date', label=T(''), > widget=SQLFORM.widgets.date.widget), > submit_button='Some text') > > On Dec 1, 10:12 pm, Anthony wrote: > > > > > > > > > Submit buttons are not in fields, they are added as an input element to an > > entire form. Where is that Field definition -- in a table definition or > > SQLFORM.factory? Anyway, SQLFORM takes a 'submit_button' argument, which is > > the text for the submit button. > > > Anthony > > > On Thursday, December 1, 2011 3:57:30 PM UTC-5, Rick wrote: > > > > Hi, > > > How to change the text on the submit button in fields? Here'sthe code: > > > > Field('thedate', 'date', label=T(''), > > > widget=SQLFORM.widgets.date.widget)) > > > > I tried with this, but i didn't work: > > > Field('thedate', 'date', label=T(''), > > > submit=INPUT(_type='submit'('Some text')), > > > widget=SQLFORM.widgets.date.widget)) > > > > Thanks in advance for help!
[web2py] ttf and fonts
Hi, How to use a local font? I put a library with ttf-files inte the static/css directory and write this code in the css file: @font-face { font-style: normal; font-weight: normal font-family: "myfont"; src: url(ttf/DejaVuSans.ttf); } html, body { font:myfont} But it doesn't work. What is the corrcet way of doing this in web2py? Thanks in advance
[web2py] date and sum
Hi, I've a stack of records where records with the same date has different values, eg: record.date[0] = 2011-12-01 record.value[0] = 10 record.date[1] = 2011-12-01 record.value[1] = 20 record.date[3] = 2011-12-02 record.value[3] = 10 And now I want to summarize the values that are recorded for respective date: sumlist.date[0] = 2011-12-01 sumlist.value[0] = 30 sumlist.date[1] = 2011-12-02 sumlist.value[1] = 10 I suppose I should use "filter" and "sum", but I don't know how. Any ideas? Thanks in advance for help!
[web2py] Re: date and sum
I tried to apply the solution to my code, but it still doesn't work. Here is the code: prerecords = db().select(db.day.ALL, orderby=db.day.thedate)for prerecord in prerecords:if prerecord.theauth==auth.user_id: if session.adate==prerecord.thedate: records.append(prerecord) rows = select(records.thedate,records.value.sum(),orderby=records.thedate) for row in rows:print row.records.thedate, row(records.value.sum()) On Dec 5, 3:04 am, Massimo Di Pierro wrote: > rows = > db(...).select(db.table.date,db.table.value.sum(),groupby=db.table.date) > for row in rows: print row.table.date, row(db.table.value.sum()) > > mind that 'date' and 'value' are not good field names. Will work with > sqlite but will break with other engines. > > On Dec 4, 8:00 pm, Rick wrote: > > > > > > > > > Hi, > > I've a stack of records where records with the same date has different > > values, eg: > > record.date[0] = 2011-12-01 > > record.value[0] = 10 > > record.date[1] = 2011-12-01 > > record.value[1] = 20 > > record.date[3] = 2011-12-02 > > record.value[3] = 10 > > And now I want to summarize the values that are recorded for > > respective date: > > sumlist.date[0] = 2011-12-01 > > sumlist.value[0] = 30 > > sumlist.date[1] = 2011-12-02 > > sumlist.value[1] = 10 > > > I suppose I should use "filter" and "sum", but I don't know how. Any > > ideas? > > > Thanks in advance for help!
[web2py] Re: date and sum
Perhaps I should explain my problem once again. I'd like to summarize the values for each day in the record list. With other words, so that this: record.thedate[0] = 2011-12-01 record.value[0] = 10 record.thedate[1] = 2011-12-01 record.value[1] = 20 record.thedate[3] = 2011-12-02 record.value[3] = 10 ...becomes this: sumlist.thedate[0] = 2011-12-01 sumlist.value[0] = 30 sumlist.thedate[1] = 2011-12-02 sumlist.value[1] = 10 Here is the code: from the model file: db.define_table('day', Field('thedate','date', default=request.now), Field('value', 'integer'), Field('theauth', db.auth_user, default=auth.user_id), Field('uuid', length=64, default=uuid.uuid4())) from the controller file: prerecords = db().select(db.day.ALL, orderby=db.day.thedate) for prerecord in prerecords: if prerecord.theauth==auth.user_id: if session.adate==prerecord.thedate: records.append(prerecord) On Dec 5, 3:49 pm, Anthony wrote: > It doesn't look like you applied Massimo's solution. You're calling > select() all by itself (not as a method of a Set object) -- doesn't that > raise an error (there's no function called 'select' in web2py)? The sum > should be applied in the initial query, not on the returned rows after the > query. > > Anthony > > > > > > > > On Sunday, December 4, 2011 9:33:42 PM UTC-5, Rick wrote: > > > I tried to apply the solution to my code, but it still doesn't work. > > Here is the code: > > > prerecords = db().select(db.day.ALL, orderby=db.day.thedate) for > > prerecord in prerecords: if prerecord.theauth==auth.user_id: if > > session.adate==prerecord.thedate: records.append(prerecord) rows = > > select(records.thedate,records.value.sum(),orderby=records.thedate) > > for row in rows: print row.records.thedate, row(records.value.sum()) > > On Dec 5, 3:04 am, Massimo Di Pierro > > wrote: > > > rows = > > > db(...).select(db.table.date,db.table.value.sum(),groupby=db.table.date) > > > for row in rows: print row.table.date, row(db.table.value.sum()) > > > > mind that 'date' and 'value' are not good field names. Will work with > > > sqlite but will break with other engines. > > > > On Dec 4, 8:00 pm, Rick wrote: > > > > > Hi, > > > > I've a stack of records where records with the same date has different > > > > values, eg: > > > > record.date[0] = 2011-12-01 > > > > record.value[0] = 10 > > > > record.date[1] = 2011-12-01 > > > > record.value[1] = 20 > > > > record.date[3] = 2011-12-02 > > > > record.value[3] = 10 > > > > And now I want to summarize the values that are recorded for > > > > respective date: > > > > sumlist.date[0] = 2011-12-01 > > > > sumlist.value[0] = 30 > > > > sumlist.date[1] = 2011-12-02 > > > > sumlist.value[1] = 10 > > > > > I suppose I should use "filter" and "sum", but I don't know how. Any > > > > ideas? > > > > > Thanks in advance for help!
[web2py] avoid logging-in-site
Hi, >From my controller file: @auth.requires_login() def create(): ... def somethingelse(): ... When the user isn't logged in but tries to open the site "create.html", then he's redirected to the logging-in-site. My problem is that I'd like the user to be redirected to "somethingelse.html" instead of the logging-in-site. How to code that? Thanks in advance for help
[web2py] possibly difficult database form
I'd like to do something quite challenging (in my view) with web2py. I have a table (products), where each product has one or more codes. The list of possible codes are stored in a separate table (codes), and a third table (product_codes) stores the relationship(s) between the product and the code(s). I'd like a form that allows the user, on creating a new product, to choose one or more codes for the product. I assume this would be using checkboxes, pre-populated from the codes table. Upon submission, two tables are affected: the new product goes into the product table, and one or more records into the product_codes table. Is this possible? Is it possible using CRUD or SQLFORM? I'm at a loss as to how to start this. Thank you for your help, in advance.
[web2py] list and loop problem
Hi, I want to print a linked list and add a "delete this item" button next to each item: [item 1][delete this item] [item 2][delete this item] [item 3][delete this item] ...but I've no clue how to write the code. The problem is to direct the second delete button to the second item. Thanks in advance for help!
[web2py] Re: list and loop problem
I'd like to print the list in a html file. On Mar 10, 6:16 pm, Bruno Rocha wrote: > where do you want to output this? > > in to pure HTML or in a SQLTABLE? > > 2011/3/10 Rick > > > > > > > > > Hi, > > > I want to print a linked list and add a "delete this item" button next > > to each item: > > > > [item 1][delete this item] > > [item 2][delete this item] > > [item 3][delete this item] > > > > ...but I've no clue how to write the code. The problem is to direct > > the second delete button to the second item. > > > Thanks in advance for help!
[web2py] Re: list and loop problem
I meant that I'd like to print on a html _page_. On Mar 10, 6:34 pm, Rick wrote: > I'd like to print the list in a html file. > > On Mar 10, 6:16 pm, Bruno Rocha wrote: > > > > > > > > > where do you want to output this? > > > in to pure HTML or in a SQLTABLE? > > > 2011/3/10 Rick > > > > Hi, > > > > I want to print a linked list and add a "delete this item" button next > > > to each item: > > > > > > [item 1][delete this item] > > > [item 2][delete this item] > > > [item 3][delete this item] > > > > > > ...but I've no clue how to write the code. The problem is to direct > > > the second delete button to the second item. > > > > Thanks in advance for help!
[web2py] "settings site" membership_panel and AJAX
Hi, I'm trying to make a setting-site for the logged in user, but it doesn't work. I try to use the membership_panel, but desipte of searching, I haven't found any tutorial or similar about the panel. Thanks in advance for help! Here is the code: @auth.requires_login() def user_settings(): membership_panel = LOAD(request.controller, 'manage_membership.html', #current user id: args=auth.user.id, ajax=True) return dict(membership_panel=membership_panel) -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: "settings site" membership_panel and AJAX
Sorry for the thread. I read this link and thought that *membership_panel*was a part of web2py: http://www.web2pyslices.com/slice/show/1542/manage-users-and-memebership-in-the-same-form but now I've fixed the problem by studying *virtual fields*. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: "settings site" membership_panel and AJAX
Thanks a lot! -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] How to insert rows in a database from a html page in web2py?
How to insert rows from a view-file? The site doesn't produce any error, but an empty row is added to the database.: >From the model file db.define_table('next_list', Field('node'), Field('next_node')) >From the view file: {{nextrows = db(db.next_list)}} {{db.next_list.insert(**db.next_list._filter_fields({ "db.next_list.node" : "test1" , "db.next_list.next_node":"test2" }))}} What's wrong? Thanks in advance for help and ideas! -- -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/ac174d5a-8245-44e5-b708-08258a60f70fn%40googlegroups.com.
Re: [web2py] How to insert rows in a database from a html page in web2py?
That unfortunately gives a ticket with this information: sqlite3.IntegrityError: FOREIGN KEY constraint failed On Thursday, 6 July 2023 at 15:02:05 UTC+2 Massimiliano wrote: > try this: > > {{db.next_list.insert(**db.next_list._filter_fields({ "node" : "test1" , > "next_node":"test2" }))}} > > Il giorno gio 6 lug 2023 alle ore 13:47 Rick ha > scritto: > >> How to insert rows from a view-file? The site doesn't produce any error, >> but an empty row is added to the database.: >> >> From the model file >> db.define_table('next_list', Field('node'), Field('next_node')) >> >> >> From the view file: >> {{nextrows = db(db.next_list)}} >> {{db.next_list.insert(**db.next_list._filter_fields({ "db.next_list.node" >> : "test1" , "db.next_list.next_node":"test2" }))}} >> >> >> >> What's wrong? Thanks in advance for help and ideas! >> -- >> >> >> -- >> Resources: >> - http://web2py.com >> - http://web2py.com/book (Documentation) >> - http://github.com/web2py/web2py (Source code) >> - https://code.google.com/p/web2py/issues/list (Report Issues) >> --- >> You received this message because you are subscribed to the Google Groups >> "web2py-users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to web2py+un...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/web2py/ac174d5a-8245-44e5-b708-08258a60f70fn%40googlegroups.com >> >> <https://groups.google.com/d/msgid/web2py/ac174d5a-8245-44e5-b708-08258a60f70fn%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > > > -- > Massimiliano > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/4e07ad77-4727-44a8-8710-bda5909cb287n%40googlegroups.com.
Re: [web2py] How to insert rows in a database from a html page in web2py?
Thanks Massimiliano for the answering quickly. The suggested code produces this error: IntegrityError(FOREIGN KEY constraint failed) If I change the model file lines to db.define_table('next_list', Field('node'), Field('next_node', text)) then the error changes to: NameError(name 'text' is not defined) On Thursday, 6 July 2023 at 16:12:59 UTC+2 Massimiliano wrote: > Maybe on your model there is more than you showed : > > db.define_table('next_list', Field('node'), Field('next_node')) > > db.next_list.insert(**db.next_list._filter_fields({ "node" : "test1" , > "next_node":"test2" })) > > print(db(db.next_list).select()) > > next_list.id,next_list.node,next_list.next_node > > 1,test1,test2 > > > db.next_list.insert(**db.next_list._filter_fields({ "node" : "test1" , > "next_node":"test2" })) > > print(db(db.next_list).select()) > > next_list.id,next_list.node,next_list.next_node > > 1,test1,test2 > > 2,test1,test2 > > > > Il giorno gio 6 lug 2023 alle ore 16:07 Rick ha > scritto: > >> That unfortunately gives a ticket with this information: >> sqlite3.IntegrityError: FOREIGN KEY constraint failed >> On Thursday, 6 July 2023 at 15:02:05 UTC+2 Massimiliano wrote: >> >>> try this: >>> >>> {{db.next_list.insert(**db.next_list._filter_fields({ "node" : "test1" >>> , "next_node":"test2" }))}} >>> >>> Il giorno gio 6 lug 2023 alle ore 13:47 Rick ha >>> scritto: >>> >>>> How to insert rows from a view-file? The site doesn't produce any >>>> error, but an empty row is added to the database.: >>>> >>>> From the model file >>>> db.define_table('next_list', Field('node'), Field('next_node')) >>>> >>>> >>>> From the view file: >>>> {{nextrows = db(db.next_list)}} >>>> {{db.next_list.insert(**db.next_list._filter_fields({ >>>> "db.next_list.node" : "test1" , "db.next_list.next_node":"test2" }))}} >>>> >>>> >>>> >>>> What's wrong? Thanks in advance for help and ideas! >>>> -- >>>> >>>> >>>> -- >>>> Resources: >>>> - http://web2py.com >>>> - http://web2py.com/book (Documentation) >>>> - http://github.com/web2py/web2py (Source code) >>>> - https://code.google.com/p/web2py/issues/list (Report Issues) >>>> --- >>>> You received this message because you are subscribed to the Google >>>> Groups "web2py-users" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to web2py+un...@googlegroups.com. >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/web2py/ac174d5a-8245-44e5-b708-08258a60f70fn%40googlegroups.com >>>> >>>> <https://groups.google.com/d/msgid/web2py/ac174d5a-8245-44e5-b708-08258a60f70fn%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> >>> >>> >>> -- >>> Massimiliano >>> >> -- >> Resources: >> - http://web2py.com >> - http://web2py.com/book (Documentation) >> - http://github.com/web2py/web2py (Source code) >> - https://code.google.com/p/web2py/issues/list (Report Issues) >> --- >> You received this message because you are subscribed to the Google Groups >> "web2py-users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to web2py+un...@googlegroups.com. >> > To view this discussion on the web visit >> https://groups.google.com/d/msgid/web2py/4e07ad77-4727-44a8-8710-bda5909cb287n%40googlegroups.com >> >> <https://groups.google.com/d/msgid/web2py/4e07ad77-4727-44a8-8710-bda5909cb287n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > > > -- > Massimiliano > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/b59e89fc-3492-41cc-ae15-8c8d7cfae4ccn%40googlegroups.com.
Re: [web2py] How to insert rows in a database from a html page in web2py?
Thank you for pointing out that there was an issue with the database. After deleting the content of the database folder everything works. Tanks for the help! On Friday, 7 July 2023 at 16:16:06 UTC+2 Rick wrote: > Thanks Massimiliano for the answering quickly. The suggested code produces > this error: > IntegrityError(FOREIGN KEY constraint failed) > > If I change the model file lines to > db.define_table('next_list', Field('node'), Field('next_node', text)) > then the error changes to: > NameError(name 'text' is not defined) > > > On Thursday, 6 July 2023 at 16:12:59 UTC+2 Massimiliano wrote: > >> Maybe on your model there is more than you showed : >> >> db.define_table('next_list', Field('node'), Field('next_node')) >> >> db.next_list.insert(**db.next_list._filter_fields({ "node" : "test1" , >> "next_node":"test2" })) >> >> print(db(db.next_list).select()) >> >> next_list.id,next_list.node,next_list.next_node >> >> 1,test1,test2 >> >> >> db.next_list.insert(**db.next_list._filter_fields({ "node" : "test1" , >> "next_node":"test2" })) >> >> print(db(db.next_list).select()) >> >> next_list.id,next_list.node,next_list.next_node >> >> 1,test1,test2 >> >> 2,test1,test2 >> >> >> >> Il giorno gio 6 lug 2023 alle ore 16:07 Rick ha >> scritto: >> >>> That unfortunately gives a ticket with this information: >>> sqlite3.IntegrityError: FOREIGN KEY constraint failed >>> On Thursday, 6 July 2023 at 15:02:05 UTC+2 Massimiliano wrote: >>> >>>> try this: >>>> >>>> {{db.next_list.insert(**db.next_list._filter_fields({ "node" : "test1" >>>> , "next_node":"test2" }))}} >>>> >>>> Il giorno gio 6 lug 2023 alle ore 13:47 Rick ha >>>> scritto: >>>> >>>>> How to insert rows from a view-file? The site doesn't produce any >>>>> error, but an empty row is added to the database.: >>>>> >>>>> From the model file >>>>> db.define_table('next_list', Field('node'), Field('next_node')) >>>>> >>>>> >>>>> From the view file: >>>>> {{nextrows = db(db.next_list)}} >>>>> {{db.next_list.insert(**db.next_list._filter_fields({ >>>>> "db.next_list.node" : "test1" , "db.next_list.next_node":"test2" }))}} >>>>> >>>>> >>>>> >>>>> What's wrong? Thanks in advance for help and ideas! >>>>> -- >>>>> >>>>> >>>>> -- >>>>> Resources: >>>>> - http://web2py.com >>>>> - http://web2py.com/book (Documentation) >>>>> - http://github.com/web2py/web2py (Source code) >>>>> - https://code.google.com/p/web2py/issues/list (Report Issues) >>>>> --- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "web2py-users" group. >>>>> To unsubscribe from this group and stop receiving emails from it, send >>>>> an email to web2py+un...@googlegroups.com. >>>>> To view this discussion on the web visit >>>>> https://groups.google.com/d/msgid/web2py/ac174d5a-8245-44e5-b708-08258a60f70fn%40googlegroups.com >>>>> >>>>> <https://groups.google.com/d/msgid/web2py/ac174d5a-8245-44e5-b708-08258a60f70fn%40googlegroups.com?utm_medium=email&utm_source=footer> >>>>> . >>>>> >>>> >>>> >>>> -- >>>> Massimiliano >>>> >>> -- >>> Resources: >>> - http://web2py.com >>> - http://web2py.com/book (Documentation) >>> - http://github.com/web2py/web2py (Source code) >>> - https://code.google.com/p/web2py/issues/list (Report Issues) >>> --- >>> You received this message because you are subscribed to the Google >>> Groups "web2py-users" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to web2py+un...@googlegroups.com. >>> >> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/web2py/4e07ad77-4727-44a8-8710-bda5909cb287n%40googlegroups.com >>> >>> <https://groups.google.com/d/msgid/web2py/4e07ad77-4727-44a8-8710-bda5909cb287n%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> >> >> -- >> Massimiliano >> > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/3b7dcd0f-275f-415e-bd2c-2d7d40e2f3e8n%40googlegroups.com.
[web2py] Call def with arguments from html view
How to call a def with request.vars arguments from an onclick-event in a view file? What is wrong with the code? Thanks in advance for help! Controller: def insnext(): nodename=request.vars['nodename'] nrowid=request.vars['nrowid'] db.next_list.update_or_insert(**db.next_list._filter_fields({ "node" : nodename , "next_node":nrowid })) def delnext(): nextrowid=request.vars['value'] db(db.next_list.id==nextrowid).delete() View: delete insert {{=nrow['name']}} {{=nrowid}} -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/aaed257d-7d4b-45b7-bcc7-7a21628a0a70n%40googlegroups.com.
Re: [web2py] Re: Initiating table
Thanks for the link. My actual problem is more complicated than the example I gave. I realize that I need to link a field to a table that isn't initiated yet (item2): objects = ['substance', 'process', 'condition', 'locus'] linksubobjects = ['locus', 'before', 'after'] unlinksubobjects = ['name', 'main_name'] for object in objects: for item1 in linksubobjects+unlinksubobjects: for item2 in objects: fields=[Field(item1, 'reference item2')] db.define_table(object,*fields) I suppose the solution would be to initiate the table names and then add the fields either in db.py, or in the controller file. But I have no idea how to do this. On 7/3/10, Yarko Tymciurak wrote: > The online book has a fairly useful search; > > For your question, see: > http://web2py.com/book/default/section/6/13 > > Regards, > - Yarko > > On Jul 3, 8:45 am, Rick wrote: >> Hi, >> >> I would like to link a table to its own model like this: >> >> db.define_table('person', >> Field('name'), >> Field('child', db.person)) >> >> I understand that I should first initiate the table and then link it >> to itself. But how to do that? >> >> Thanks in advance for help!
Re: [web2py] Re: Initiating table
Thanks for the answers. I'm trying to create these tables: db.define_table( 'substance', Field( 'substance', db.substance), Field( 'process', db.process), Field( 'condition', db.condition), Field( 'locus', db.locus), Field( 'name'), Field( 'main_name')) db.define_table( 'process', Field( 'substance', db.substance), Field( 'process', db.process), Field( 'condition', db.condition), Field( 'locus', db.locus), Field( 'name'), Field( 'main_name')) db.define_table( 'condition', Field( 'substance', db.substance), Field( 'process', db.process), Field( 'condition', db.condition), Field( 'locus', db.locus), Field( 'name'), Field( 'main_name')) db.define_table( 'locus', Field( 'substance', db.substance), Field( 'process', db.process), Field( 'condition', db.condition), Field( 'locus', db.locus), Field( 'name'), Field( 'main_name')) On 7/4/10, mdipierro wrote: > Could you explain to us in English what you are trying to model? I am > sure there is a simpler solution using link tables. > > On 3 Lug, 12:14, Rick Hultgren wrote: >> Thanks for the link. My actual problem is more complicated than the >> example I gave. I realize that I need to link a field to a table that >> isn't initiated yet (item2): >> >> objects = ['substance', 'process', 'condition', 'locus'] >> linksubobjects = ['locus', 'before', 'after'] >> unlinksubobjects = ['name', 'main_name'] >> for object in objects: >> for item1 in linksubobjects+unlinksubobjects: >> for item2 in objects: >> fields=[Field(item1, 'reference item2')] >> db.define_table(object,*fields) >> >> I suppose the solution would be to initiate the table names and then >> add the fields either in db.py, or in the controller file. But I have >> no idea how to do this. >> >> On 7/3/10, Yarko Tymciurak wrote: >> >> > The online book has a fairly useful search; >> >> > For your question, see: >> >http://web2py.com/book/default/section/6/13 >> >> > Regards, >> > - Yarko >> >> > On Jul 3, 8:45 am, Rick wrote: >> >> Hi, >> >> >> I would like to link a table to its own model like this: >> >> >> db.define_table('person', >> >> Field('name'), >> >> Field('child', db.person)) >> >> >> I understand that I should first initiate the table and then link it >> >> to itself. But how to do that? >> >> >> Thanks in advance for help!
Re: [web2py] Re: Initiating table
perhaps the table names will be changed, so please don't bother about "before" and "after"...the point is -- how to refer/link to the table name "locus", when that table is not yet created/declared/made? On 7/4/10, Rick Hultgren wrote: > Thanks for the answers. I'm trying to create these tables: > > db.define_table( 'substance', > Field( 'substance', db.substance), > Field( 'process', db.process), > Field( 'condition', db.condition), > Field( 'locus', db.locus), > Field( 'name'), > Field( 'main_name')) > > db.define_table( 'process', > Field( 'substance', db.substance), > Field( 'process', db.process), > Field( 'condition', db.condition), > Field( 'locus', db.locus), > Field( 'name'), > Field( 'main_name')) > > db.define_table( 'condition', > Field( 'substance', db.substance), > Field( 'process', db.process), > Field( 'condition', db.condition), > Field( 'locus', db.locus), > Field( 'name'), > Field( 'main_name')) > > db.define_table( 'locus', > Field( 'substance', db.substance), > Field( 'process', db.process), > Field( 'condition', db.condition), > Field( 'locus', db.locus), > Field( 'name'), > Field( 'main_name')) > > > On 7/4/10, mdipierro wrote: >> Could you explain to us in English what you are trying to model? I am >> sure there is a simpler solution using link tables. >> >> On 3 Lug, 12:14, Rick Hultgren wrote: >>> Thanks for the link. My actual problem is more complicated than the >>> example I gave. I realize that I need to link a field to a table that >>> isn't initiated yet (item2): >>> >>> objects = ['substance', 'process', 'condition', 'locus'] >>> linksubobjects = ['locus', 'before', 'after'] >>> unlinksubobjects = ['name', 'main_name'] >>> for object in objects: >>> for item1 in linksubobjects+unlinksubobjects: >>> for item2 in objects: >>> fields=[Field(item1, 'reference item2')] >>> db.define_table(object,*fields) >>> >>> I suppose the solution would be to initiate the table names and then >>> add the fields either in db.py, or in the controller file. But I have >>> no idea how to do this. >>> >>> On 7/3/10, Yarko Tymciurak wrote: >>> >>> > The online book has a fairly useful search; >>> >>> > For your question, see: >>> >http://web2py.com/book/default/section/6/13 >>> >>> > Regards, >>> > - Yarko >>> >>> > On Jul 3, 8:45 am, Rick wrote: >>> >> Hi, >>> >>> >> I would like to link a table to its own model like this: >>> >>> >> db.define_table('person', >>> >> Field('name'), >>> >> Field('child', db.person)) >>> >>> >> I understand that I should first initiate the table and then link it >>> >> to itself. But how to do that? >>> >>> >> Thanks in advance for help! >
Re: [web2py] Re: Initiating table
...with other words -- how to add fields to a table that is already declared? Is it possible? On 7/4/10, Rick Hultgren wrote: > perhaps the table names will be changed, so please don't bother about > "before" and "after"...the point is -- how to refer/link to the table > name "locus", when that table is not yet created/declared/made? > > On 7/4/10, Rick Hultgren wrote: >> Thanks for the answers. I'm trying to create these tables: >> >> db.define_table( 'substance', >> Field( 'substance', db.substance), >> Field( 'process', db.process), >> Field( 'condition', db.condition), >> Field( 'locus', db.locus), >> Field( 'name'), >> Field( 'main_name')) >> >> db.define_table( 'process', >> Field( 'substance', db.substance), >> Field( 'process', db.process), >> Field( 'condition', db.condition), >> Field( 'locus', db.locus), >> Field( 'name'), >> Field( 'main_name')) >> >> db.define_table( 'condition', >> Field( 'substance', db.substance), >> Field( 'process', db.process), >> Field( 'condition', db.condition), >> Field( 'locus', db.locus), >> Field( 'name'), >> Field( 'main_name')) >> >> db.define_table( 'locus', >> Field( 'substance', db.substance), >> Field( 'process', db.process), >> Field( 'condition', db.condition), >> Field( 'locus', db.locus), >> Field( 'name'), >> Field( 'main_name')) >> >> >> On 7/4/10, mdipierro wrote: >>> Could you explain to us in English what you are trying to model? I am >>> sure there is a simpler solution using link tables. >>> >>> On 3 Lug, 12:14, Rick Hultgren wrote: >>>> Thanks for the link. My actual problem is more complicated than the >>>> example I gave. I realize that I need to link a field to a table that >>>> isn't initiated yet (item2): >>>> >>>> objects = ['substance', 'process', 'condition', 'locus'] >>>> linksubobjects = ['locus', 'before', 'after'] >>>> unlinksubobjects = ['name', 'main_name'] >>>> for object in objects: >>>> for item1 in linksubobjects+unlinksubobjects: >>>> for item2 in objects: >>>> fields=[Field(item1, 'reference >>>> item2')] >>>> db.define_table(object,*fields) >>>> >>>> I suppose the solution would be to initiate the table names and then >>>> add the fields either in db.py, or in the controller file. But I have >>>> no idea how to do this. >>>> >>>> On 7/3/10, Yarko Tymciurak wrote: >>>> >>>> > The online book has a fairly useful search; >>>> >>>> > For your question, see: >>>> >http://web2py.com/book/default/section/6/13 >>>> >>>> > Regards, >>>> > - Yarko >>>> >>>> > On Jul 3, 8:45 am, Rick wrote: >>>> >> Hi, >>>> >>>> >> I would like to link a table to its own model like this: >>>> >>>> >> db.define_table('person', >>>> >> Field('name'), >>>> >> Field('child', db.person)) >>>> >>>> >> I understand that I should first initiate the table and then link it >>>> >> to itself. But how to do that? >>>> >>>> >> Thanks in advance for help! >> >
Re: [web2py] Re: Initiating table
...so these tables: db.define_table( 'A', Field( 'A_id', db.A), Field( 'B_id', db.B), Field( 'C_id', db.C)) db.define_table( 'B', Field( 'A_id', db.A), Field( 'B_id', db.B), Field( 'C_id', db.C)) db.define_table( 'C', Field( 'A_id', db.A), Field( 'B_id', db.B), Field( 'C_id', db.C)) ...can be generated with this code: letters=['A', 'B', 'C'] fields=[] for letter in letters: db.define_table(letter, *fields) fields=[Field(item) for item in letters] Thanks a lot for the help! On 7/4/10, mdipierro wrote: > No. > > Given db.define_table('sometable',*fields), you cannot add fields > outside this statement but you can call the statement in a separate > http request and add fields to the *fields list. > > On 4 Lug, 13:45, Rick Hultgren wrote: >> ...with other words -- how to add fields to a table that is already >> declared? Is it possible? >> >> On 7/4/10, Rick Hultgren wrote: >> >> > perhaps the table names will be changed, so please don't bother about >> > "before" and "after"...the point is -- how to refer/link to the table >> > name "locus", when that table is not yet created/declared/made? >> >> > On 7/4/10, Rick Hultgren wrote: >> >> Thanks for the answers. I'm trying to create these tables: >> >> >> db.define_table( 'substance', >> >> Field( 'substance', db.substance), >> >> Field( 'process', db.process), >> >> Field( 'condition', db.condition), >> >> Field( 'locus', db.locus), >> >> Field( 'name'), >> >> Field( 'main_name')) >> >> >> db.define_table( 'process', >> >> Field( 'substance', db.substance), >> >> Field( 'process', db.process), >> >> Field( 'condition', db.condition), >> >> Field( 'locus', db.locus), >> >> Field( 'name'), >> >> Field( 'main_name')) >> >> >> db.define_table( 'condition', >> >> Field( 'substance', db.substance), >> >> Field( 'process', db.process), >> >> Field( 'condition', db.condition), >> >> Field( 'locus', db.locus), >> >> Field( 'name'), >> >> Field( 'main_name')) >> >> >> db.define_table( 'locus', >> >> Field( 'substance', db.substance), >> >> Field( 'process', db.process), >> >> Field( 'condition', db.condition), >> >> Field( 'locus', db.locus), >> >> Field( 'name'), >> >> Field( 'main_name')) >> >> >> On 7/4/10, mdipierro wrote: >> >>> Could you explain to us in English what you are trying to model? I am >> >>> sure there is a simpler solution using link tables. >> >> >>> On 3 Lug, 12:14, Rick Hultgren wrote: >> >>>> Thanks for the link. My actual problem is more complicated than the >> >>>> example I gave. I realize that I need to link a field to a table that >> >>>> isn't initiated yet (item2): >> >> >>>> objects = ['substance', 'process', 'condition', 'locus'] >> >>>> linksubobjects = ['locus', 'before', 'after'] >> >>>> unlinksubobjects = ['name', 'main_name'] >> >>>> for object in objects: >> >>>> for item1 in linksubobjects+unlinksubobjects: >> >>>> for item2 in objects: >> >>>> fields=[Field(item1, 'reference >> >>>> item2')] >> >>>> db.define_table(object,*fields) >> >> >>>> I suppose the solution would be to initiate the table names and then >> >>>> add the fields either in db.py, or in the controller file. But I have >> >>>> no idea how to do this. >> >> >>>> On 7/3/10, Yarko Tymciurak wrote: >> >> >>>> > The online book has a fairly useful search; >> >> >>>> > For your question, see: >> >>>> >http://web2py.com/book/default/section/6/13 >> >> >>>> > Regards, >> >>>> > - Yarko >> >> >>>> > On Jul 3, 8:45 am, Rick wrote: >> >>>> >> Hi, >> >> >>>> >> I would like to link a table to its own model like this: >> >> >>>> >> db.define_table('person', >> >>>> >> Field('name'), >> >>>> >> Field('child', db.person)) >> >> >>>> >> I understand that I should first initiate the table and then link >> >>>> >> it >> >>>> >> to itself. But how to do that? >> >> >>>> >> Thanks in advance for help!
Re: [web2py] Re: Initiating table
ooops... this should be the correct code: letters=['A', 'B', 'C'] fields=[] for letter in letters: db.define_table(letter, *fields) fields=[Field(item+'_id', db[item]) for item in letters] ...sorry for the bad code int the previous message. On 7/6/10, Rick Hultgren wrote: > ...so these tables: > > db.define_table( 'A', > Field( 'A_id', db.A), > Field( 'B_id', db.B), > Field( 'C_id', db.C)) > > db.define_table( 'B', > Field( 'A_id', db.A), > Field( 'B_id', db.B), > Field( 'C_id', db.C)) > > db.define_table( 'C', > Field( 'A_id', db.A), > Field( 'B_id', db.B), > Field( 'C_id', db.C)) > > ...can be generated with this code: > > letters=['A', 'B', 'C'] > fields=[] > for letter in letters: > db.define_table(letter, *fields) > fields=[Field(item) for item in letters] > > Thanks a lot for the help! > > On 7/4/10, mdipierro wrote: >> No. >> >> Given db.define_table('sometable',*fields), you cannot add fields >> outside this statement but you can call the statement in a separate >> http request and add fields to the *fields list. >> >> On 4 Lug, 13:45, Rick Hultgren wrote: >>> ...with other words -- how to add fields to a table that is already >>> declared? Is it possible? >>> >>> On 7/4/10, Rick Hultgren wrote: >>> >>> > perhaps the table names will be changed, so please don't bother about >>> > "before" and "after"...the point is -- how to refer/link to the table >>> > name "locus", when that table is not yet created/declared/made? >>> >>> > On 7/4/10, Rick Hultgren wrote: >>> >> Thanks for the answers. I'm trying to create these tables: >>> >>> >> db.define_table( 'substance', >>> >> Field( 'substance', db.substance), >>> >> Field( 'process', db.process), >>> >> Field( 'condition', db.condition), >>> >> Field( 'locus', db.locus), >>> >> Field( 'name'), >>> >> Field( 'main_name')) >>> >>> >> db.define_table( 'process', >>> >> Field( 'substance', db.substance), >>> >> Field( 'process', db.process), >>> >> Field( 'condition', db.condition), >>> >> Field( 'locus', db.locus), >>> >> Field( 'name'), >>> >> Field( 'main_name')) >>> >>> >> db.define_table( 'condition', >>> >> Field( 'substance', db.substance), >>> >> Field( 'process', db.process), >>> >> Field( 'condition', db.condition), >>> >> Field( 'locus', db.locus), >>> >> Field( 'name'), >>> >> Field( 'main_name')) >>> >>> >> db.define_table( 'locus', >>> >> Field( 'substance', db.substance), >>> >> Field( 'process', db.process), >>> >> Field( 'condition', db.condition), >>> >> Field( 'locus', db.locus), >>> >> Field( 'name'), >>> >> Field( 'main_name')) >>> >>> >> On 7/4/10, mdipierro wrote: >>> >>> Could you explain to us in English what you are trying to model? I >>> >>> am >>> >>> sure there is a simpler solution using link tables. >>> >>> >>> On 3 Lug, 12:14, Rick Hultgren wrote: >>> >>>> Thanks for the link. My actual problem is more complicated than the >>> >>>> example I gave. I realize that I need to link a field to a table >>> >>>> that >>> >>>> isn't initiated yet (item2): >>> >>> >>>> objects = ['substance', 'process', 'condition', 'locus'] >>> >>>> linksubobjects = ['locus', 'before', 'after'] >>> >>>> unlinksubobjects = ['name', 'main_name'] >>> >>>> for object in objects: >>> >>>> for item1 in linksubobjects+unlinksubobjects: >>> >>>> for item2 in objects: >>> >>>> fields=[Field(item1, 'reference >>> >>>> item2')] >>> >>>> db.define_table(object,*fields) >>> >>> >>>> I suppose the solution would be to initiate the table names and >>> >>>> then >>> >>>> add the fields either in db.py, or in the controller file. But I >>> >>>> have >>> >>>> no idea how to do this. >>> >>> >>>> On 7/3/10, Yarko Tymciurak wrote: >>> >>> >>>> > The online book has a fairly useful search; >>> >>> >>>> > For your question, see: >>> >>>> >http://web2py.com/book/default/section/6/13 >>> >>> >>>> > Regards, >>> >>>> > - Yarko >>> >>> >>>> > On Jul 3, 8:45 am, Rick wrote: >>> >>>> >> Hi, >>> >>> >>>> >> I would like to link a table to its own model like this: >>> >>> >>>> >> db.define_table('person', >>> >>>> >> Field('name'), >>> >>>> >> Field('child', db.person)) >>> >>> >>>> >> I understand that I should first initiate the table and then >>> >>>> >> link >>> >>>> >> it >>> >>>> >> to itself. But how to do that? >>> >>> >>>> >> Thanks in advance for help! >