[web2py] Re: SQLite query with random not working anymore
Hi Anthony, Thanks a lot for your help. Le vendredi 21 novembre 2014 17:15:44 UTC+1, Anthony a écrit : > > > Can you show more of your code? In particular, how are you displaying the > results to determine the order? Are you sure there is not some subsequent > step that is re-ordering the records? > > My code is exactly like this one: db.define_table('person', Field('name')) db.define_table('thing', Field('name')) db.define_table('ownership', Field('person', 'reference person'), Field('thing', 'reference thing')) def populate_db(): db.person.insert(name='alex') db.person.insert(name='bob') db.person.insert(name='curt') db.thing.insert(name='boat') db.thing.insert(name='chair') db.thing.insert(name='shoes') db.ownership.insert(person=1, thing=1) # Alex owns Boat db.ownership.insert(person=1, thing=2) # Alex owns Chair db.ownership.insert(person=2, thing=3) # Bob owns Shoes db.ownership.insert(person=3, thing=1) # Curt owns Boat too db.ownership.insert(person=2, thing=1) # Bob owns Boat too return def m2m_query(): persons_and_things = db((db.person.id==db.ownership.person)& (db.thing.id==db.ownership.thing)) all_rows = persons_and_things.select(db.person.name, db.thing.name, orderby='') alex_rows = persons_and_things(db.person.name=='alex').select(db.person.name, db.thing.name) boat_rows = persons_and_things(db.thing.name=='boat').select(db.person.name, db.thing.name, orderby='') return dict(all_rows = all_rows, alex_rows=alex_rows, boat_rows=boat_rows, lastSQL=db._lastsql) I am sure that the display of the results is ok and that there is no re-ordering of the records. The db._lastsql provides me with the correct SQL query and the rows shown are those resulting from the query. SELECT person.name, thing.name FROM person, ownership, thing WHERE (((person.id = ownership.person) AND (thing.id = ownership.thing)) AND (thing.name = 'boat')) ORDER BY Random(); Are you absolutely sure that: > > rows=db(...).select().sort(lambda row: random.random()) > > > produces the same Rows object as: > > rows=db(...).select() > > > That would imply that either the .sort method or the built-in > random.random method are not working. > No, they're different. The problem lies in somewhere else. The problem only exist on the website at PythonAnywhere. On my local machine, everything is fine. Since I don't want to lose your time and mine, I'm going to "clean up" my code (I am not a professional developer !!), the database and install the application again. I'll come back later if the problem remains. Thanks a lot for your help and your time. I really appreciate. Dominique -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: SQLite query with random not working anymore
Hi Anthony, Thanks for replying. I already withdrew all references to cache to make sure it is not the cause of the problem. But... it's the same. Dominique Le vendredi 21 novembre 2014 16:50:04 UTC+1, Anthony a écrit : > > The .sort() method is done in Python and has nothing to do with SQLite. > That makes me think something else is going on, such as something being > cached and therefore not updating with your code changes. > > Anthony > > On Friday, November 21, 2014 9:32:00 AM UTC-5, Dominique wrote: >> >> Hello, >> >> I have a small personal website published on PythonAnywhere. >> PythonAnywhere upgraded SQLITE some time ago. >> Since then, one query doesn't work anymore. >> >> It is a query with a many to many relationship and the select should give >> results at random. >> rows = db(...).select(..., orderby='') >> It doesn't return me a random set of rows but rather always the same >> rows, starting from the beginning of the possible matching rows. >> >> I tried to address the problem without success. >> >> I also tried not using the web2py dialect and replacing it with >> >> import random >> rows=db(...).select().sort(lambda row: random.random()) >> >> >> as explained in the web2py doc. No success either. >> >> I also replaced the query with explicit SQL statement using >> db.executesql( SELECT.ORDER BY RANDOM() ) >> >> No success ! >> >> I downloaded the database onto my home pc and tested with the same >> website in local. >> It works perfectly at home. >> >> I tested on PythonAnywhere another model (based on the docs >> http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Many-to-many >> ). >> It works fine returning results randomly. So it seems the upgrade of >> SQLite done by PythonAnywhere is not responsible for the problem. >> >> Does anybody have an idea what's going on, why the query doesn't work on >> PythonAnywhere and works locally ? >> >> Thanks for any hint >> Dominique >> >> -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] SQLite query with random not working anymore
Hello, I have a small personal website published on PythonAnywhere. PythonAnywhere upgraded SQLITE some time ago. Since then, one query doesn't work anymore. It is a query with a many to many relationship and the select should give results at random. rows = db(...).select(..., orderby='') It doesn't return me a random set of rows but rather always the same rows, starting from the beginning of the possible matching rows. I tried to address the problem without success. I also tried not using the web2py dialect and replacing it with import random rows=db(...).select().sort(lambda row: random.random()) as explained in the web2py doc. No success either. I also replaced the query with explicit SQL statement using db.executesql( SELECT.ORDER BY RANDOM() ) No success ! I downloaded the database onto my home pc and tested with the same website in local. It works perfectly at home. I tested on PythonAnywhere another model (based on the docs http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Many-to-many ). It works fine returning results randomly. So it seems the upgrade of SQLite done by PythonAnywhere is not responsible for the problem. Does anybody have an idea what's going on, why the query doesn't work on PythonAnywhere and works locally ? Thanks for any hint Dominique -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] x-webkit-speech
Hello, A simple and non essential question: is there a way to have x-webkit-speech work with web2py ? Thank you Dominique -- 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: CSS table width not limited as wished
Thank you very much Paolo for your time spent for my small problem. I would never have found this alone, stick behind my screen... I applied your advices that I appreciate Thanks again Dominique Le mercredi 26 février 2014 21:49:45 UTC+1, Paolo Caruccio a écrit : > > I'm glad to hear this but please keep in mind that the modify you made > will change the width of all elements with "text" and "password" type > attribute as well as select elements. > Therefore if you will be able to target only the interested elements it > will be better. For example: > > table#t1 [type="text"], table#t1 [type="password"], table#t1 select { > width: auto !important; > } > > should also work but only for the elements children of the table with > id="t1". > > Moreover, I suggest you to don't modify web2py files. In the specific case > you should create your css file and reference it in the layout.html as last > css file. > > Il giorno mercoledì 26 febbraio 2014 20:39:08 UTC+1, Dominique ha scritto: >> >> Fantastic ! >> Now that works fine ! >> I changed the line 33 of web2py.css as you advised. >> >> Thank you very much Paolo ! >> Dominique >> >> Le mercredi 26 février 2014 20:09:36 UTC+1, Paolo Caruccio a écrit : >>> >>> Generally speaking the issue is due to a rule in web2py.css ( >>> https://github.com/web2py/web2py/blob/master/applications/welcome/static/css/web2py.css#L33 >>> ): >>> >>> [type="text"], [type="password"], select { >>> margin-right: 5px; width: 300px; >>> } >>> >>> You should override this rule in your css (increasing the specificity). >>> There are several ways to accomplish this goal. One is that in my >>> previous post. >>> Another, more general and therefore less controllable, is: >>> >>> [type="text"], [type="password"], select { >>> width: auto !important; >>> } >>> >>> >>> Il giorno mercoledì 26 febbraio 2014 18:04:08 UTC+1, Dominique ha >>> scritto: >>>> >>>> Thank you Paolo. >>>> It works perfectly on the test model. >>>> >>>> But not on my app, for whatever reason... >>>> I'll investigate that later... >>>> >>>> Anyway thank you very much >>>> Dominique >>>> >>>> Le mardi 25 février 2014 20:01:56 UTC+1, Paolo Caruccio a écrit : >>>>> >>>>> Please try with: >>>>> >>>>> table#t1 input{width:auto;} >>>>> >>>>> >>>>> Il giorno martedì 25 febbraio 2014 18:45:31 UTC+1, Dominique ha >>>>> scritto: >>>>>> >>>>>> Unfortunately, no ... >>>>>> >>>>>> Le mardi 25 février 2014 18:29:38 UTC+1, Massimo Di Pierro a écrit : >>>>>>> >>>>>>> I think the problem may be the size of the INPUT. Try add this in >>>>>>> style >>>>>>> >>>>>>> input { width: 50px; } >>>>>>> >>>>>>> >>>>>>> >>>>>>> On Tuesday, 25 February 2014 10:49:07 UTC-6, Dominique wrote: >>>>>>>> >>>>>>>> Hello Massino, >>>>>>>> >>>>>>>> Thank you so much for spending some of your time for me. I >>>>>>>> appreciate. >>>>>>>> >>>>>>>> The following codes will show you my problem: >>>>>>>> In the controller: >>>>>>>> >>>>>>>>> def form_test(): >>>>>>>>> form = FORM(TABLE(TR(FIELDSET('This is a test for Field 1: ', >>>>>>>>> INPUT(_name='f1', id='f1')), >>>>>>>>> FIELDSET('This is a test for Field 2: ', >>>>>>>>> INPUT(_name='f2', id='f2')), >>>>>>>>> FIELDSET('This is a test for Field 3: ', >>>>>>>>> INPUT(_name='f3', id='f3')), >>>>>>>>> FIELDSET('This is a test for Field 4: ', >>>>>>>>> INPUT(_name='f4', id='f4')), >>>>>>>>>
[web2py] Re: CSS table width not limited as wished
Fantastic ! Now that works fine ! I changed the line 33 of web2py.css as you advised. Thank you very much Paolo ! Dominique Le mercredi 26 février 2014 20:09:36 UTC+1, Paolo Caruccio a écrit : > > Generally speaking the issue is due to a rule in web2py.css ( > https://github.com/web2py/web2py/blob/master/applications/welcome/static/css/web2py.css#L33 > ): > > [type="text"], [type="password"], select { > margin-right: 5px; width: 300px; > } > > You should override this rule in your css (increasing the specificity). > There are several ways to accomplish this goal. One is that in my previous > post. > Another, more general and therefore less controllable, is: > > [type="text"], [type="password"], select { > width: auto !important; > } > > > Il giorno mercoledì 26 febbraio 2014 18:04:08 UTC+1, Dominique ha scritto: >> >> Thank you Paolo. >> It works perfectly on the test model. >> >> But not on my app, for whatever reason... >> I'll investigate that later... >> >> Anyway thank you very much >> Dominique >> >> Le mardi 25 février 2014 20:01:56 UTC+1, Paolo Caruccio a écrit : >>> >>> Please try with: >>> >>> table#t1 input{width:auto;} >>> >>> >>> Il giorno martedì 25 febbraio 2014 18:45:31 UTC+1, Dominique ha scritto: >>>> >>>> Unfortunately, no ... >>>> >>>> Le mardi 25 février 2014 18:29:38 UTC+1, Massimo Di Pierro a écrit : >>>>> >>>>> I think the problem may be the size of the INPUT. Try add this in style >>>>> >>>>> input { width: 50px; } >>>>> >>>>> >>>>> >>>>> On Tuesday, 25 February 2014 10:49:07 UTC-6, Dominique wrote: >>>>>> >>>>>> Hello Massino, >>>>>> >>>>>> Thank you so much for spending some of your time for me. I appreciate. >>>>>> >>>>>> The following codes will show you my problem: >>>>>> In the controller: >>>>>> >>>>>>> def form_test(): >>>>>>> form = FORM(TABLE(TR(FIELDSET('This is a test for Field 1: ', >>>>>>> INPUT(_name='f1', id='f1')), >>>>>>> FIELDSET('This is a test for Field 2: ', >>>>>>> INPUT(_name='f2', id='f2')), >>>>>>> FIELDSET('This is a test for Field 3: ', >>>>>>> INPUT(_name='f3', id='f3')), >>>>>>> FIELDSET('This is a test for Field 4: ', >>>>>>> INPUT(_name='f4', id='f4')), >>>>>>> FIELDSET('This is a test for Field 3: ', >>>>>>> INPUT(_name='f5', id='f5')) >>>>>>> ), _id='t1')) >>>>>>> return dict(form=form) >>>>>>> >>>>>> >>>>>> In the view: >>>>>> >>>>>>> {{extend 'layout.html'}} >>>>>>> >>>>>>> table { font-size: 12px; max-width:80%} >>>>>>> td{font-weight:bold;vertical-align:top;} >>>>>>> fieldset {width:25%; border: groove} >>>>>>> >>>>>>> {{=form}} >>>>>>> >>>>>>> What I get and what I want are shown in the attached images: I want >>>>>> all the fields to appear on screen without scrollbars. >>>>>> Note that the image "what I want" is just the code (form + css >>>>>> script) copied in notepad and opened in firefox. >>>>>> >>>>>> The table css properties I add in my script seem not to be taken into >>>>>> account in web2py. >>>>>> The point is that I don't know which web2py file I need to modify >>>>>> (and where). >>>>>> >>>>>> I hope it's clearer ;) >>>>>> >>>>>> Thank you for your help >>>>>> Dominique >>>>>> >>>>> -- 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: CSS table width not limited as wished
Thank you Paolo. It works perfectly on the test model. But not on my app, for whatever reason... I'll investigate that later... Anyway thank you very much Dominique Le mardi 25 février 2014 20:01:56 UTC+1, Paolo Caruccio a écrit : > > Please try with: > > table#t1 input{width:auto;} > > > Il giorno martedì 25 febbraio 2014 18:45:31 UTC+1, Dominique ha scritto: >> >> Unfortunately, no ... >> >> Le mardi 25 février 2014 18:29:38 UTC+1, Massimo Di Pierro a écrit : >>> >>> I think the problem may be the size of the INPUT. Try add this in style >>> >>> input { width: 50px; } >>> >>> >>> >>> On Tuesday, 25 February 2014 10:49:07 UTC-6, Dominique wrote: >>>> >>>> Hello Massino, >>>> >>>> Thank you so much for spending some of your time for me. I appreciate. >>>> >>>> The following codes will show you my problem: >>>> In the controller: >>>> >>>>> def form_test(): >>>>> form = FORM(TABLE(TR(FIELDSET('This is a test for Field 1: ', >>>>> INPUT(_name='f1', id='f1')), >>>>> FIELDSET('This is a test for Field 2: ', >>>>> INPUT(_name='f2', id='f2')), >>>>> FIELDSET('This is a test for Field 3: ', >>>>> INPUT(_name='f3', id='f3')), >>>>> FIELDSET('This is a test for Field 4: ', >>>>> INPUT(_name='f4', id='f4')), >>>>> FIELDSET('This is a test for Field 3: ', >>>>> INPUT(_name='f5', id='f5')) >>>>> ), _id='t1')) >>>>> return dict(form=form) >>>>> >>>> >>>> In the view: >>>> >>>>> {{extend 'layout.html'}} >>>>> >>>>> table { font-size: 12px; max-width:80%} >>>>> td{font-weight:bold;vertical-align:top;} >>>>> fieldset {width:25%; border: groove} >>>>> >>>>> {{=form}} >>>>> >>>>> What I get and what I want are shown in the attached images: I want >>>> all the fields to appear on screen without scrollbars. >>>> Note that the image "what I want" is just the code (form + css script) >>>> copied in notepad and opened in firefox. >>>> >>>> The table css properties I add in my script seem not to be taken into >>>> account in web2py. >>>> The point is that I don't know which web2py file I need to modify (and >>>> where). >>>> >>>> I hope it's clearer ;) >>>> >>>> Thank you for your help >>>> Dominique >>>> >>> -- 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: CSS table width not limited as wished
Unfortunately, no ... Le mardi 25 février 2014 18:29:38 UTC+1, Massimo Di Pierro a écrit : > > I think the problem may be the size of the INPUT. Try add this in style > > input { width: 50px; } > > > > On Tuesday, 25 February 2014 10:49:07 UTC-6, Dominique wrote: >> >> Hello Massino, >> >> Thank you so much for spending some of your time for me. I appreciate. >> >> The following codes will show you my problem: >> In the controller: >> >>> def form_test(): >>> form = FORM(TABLE(TR(FIELDSET('This is a test for Field 1: ', >>> INPUT(_name='f1', id='f1')), >>> FIELDSET('This is a test for Field 2: ', >>> INPUT(_name='f2', id='f2')), >>> FIELDSET('This is a test for Field 3: ', >>> INPUT(_name='f3', id='f3')), >>> FIELDSET('This is a test for Field 4: ', >>> INPUT(_name='f4', id='f4')), >>> FIELDSET('This is a test for Field 3: ', >>> INPUT(_name='f5', id='f5')) >>> ), _id='t1')) >>> return dict(form=form) >>> >> >> In the view: >> >>> {{extend 'layout.html'}} >>> >>> table { font-size: 12px; max-width:80%} >>> td{font-weight:bold;vertical-align:top;} >>> fieldset {width:25%; border: groove} >>> >>> {{=form}} >>> >>> What I get and what I want are shown in the attached images: I want all >> the fields to appear on screen without scrollbars. >> Note that the image "what I want" is just the code (form + css script) >> copied in notepad and opened in firefox. >> >> The table css properties I add in my script seem not to be taken into >> account in web2py. >> The point is that I don't know which web2py file I need to modify (and >> where). >> >> I hope it's clearer ;) >> >> Thank you for your help >> Dominique >> > -- 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: CSS table width not limited as wished
Hello, Any idea to help me. I am not a professional, did you notice ? ;) Thank you in advance Dom -- 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] CSS table width not limited as wished
Hello, The form I designed is not shown as I'd like it to be. I am using the web2py design (web2py.css, web2py_bootstrap.css, bootstrap_min.css,...). I'd like the elements of a row to be entirely seen on screen, without adding scrollbars which are automatically added by the web2py css design. The following code, once copied in a file, shows what I want. > > > table { font-size: 12px; max-width:80%} > > td {font-weight:bold;vertical-align:top;} > > fieldset {width:25%; border: groove} > > > > >> > > > > > > This is a test for Field 1: > /> > > This is a test for Field 2: > /> > > This is a test for Field 3: > /> > > This is a test for Field 4: > /> > > This is a test for Field 3: > /> > > > > Other rows withdrawn for simplicity > > > > > Using this style (added in my view which extends layout.html) gives no results. So I tried to modify layout.html by adding the style (line 60). This results in fonts and borders being correctly taken into account but not the width parameter which is precisely what I'd like to change (I don't want any scrollbars). Can anybody explain to me which line of which web2py css file I need to modify and how ? Additionally, why changing the css directly in the view is not taken into account ? Thanks you so much in advance for your help Dom -- 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] jQuery Noob question: usage of this
Answer: I should have put: onclick="jQuery(this).dosomething()"/> In the input. Dom -- 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] jQuery Noob question: usage of this
Hello, That's a noob question... Thanks for helping Inside a function in a script, I'm trying to get the value of a button when clicked. I just can't figure out the usage of "this" in that case. There are a certain number of buttons in the page and several functions attached to them so I don't want to do jQuery('.A1').val() in the fuction each time a button is clicked. I want the function to detect which button is clicked and its value jQuery(document).ready(function(){ $.fn.dosomething = function(){ var currentval = $(this).val(); console.log(currentval); }; }); Thanks a lot for any help Dominique -- 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: Happy new year
Bonne et heureuse année à tous ! Dominique On Jan 1, 6:20 pm, Manuele Pesenti wrote: > Un felice anno a tutti! :) > > Manuele > > Il 01/01/2012 08:26, Massimo Di Pierro ha scritto: > > > > > > > > > Happy new year everybody!
[web2py] Re: Special select widget returning form errors when submitted ("no data")
Anthony gave me the answer: I had to change the name of the widget to _name='r_name', which is the field name in the db... I hope it will help some others ... Now the widget works great ;) Dominique
[web2py] Special select widget returning form errors when submitted ("no data")
Hello All, I need some help to have a widget work correctly. BTW, once corrected, I think it could be useful to other users... I built a widget to expose in a SELECT regions and their sub-regions ('departement') to choose. For instance: a region A is divided into departement 11 and departement 12 and so on. The user can choose either a region or a specific departement (sub-region). The widget works except that when submitted, the form returns errors: "r_name: no data". Below is a working example to show the problem. Could anybody help me having this widget work correctly without returning errors, please. I would greatly appreciate your kind help. Thanks a lot in advance. Dominique in the model: db.define_table('region', Field('r_name', 'string', length=250, required=True) ) db.define_table('departement', Field('d_name', 'string', length=250, required=True), Field('d_code', 'string', length=3, required=True), Field('d_region', db.region) ) def region_widget(f,v,_class= "options"): """ Widget that shows regions and departements in a SELECT. Can be used with SQLFORM and SQLFORM.factory Usage: db.region.r_name.widget = region_dptt_select_widget """ region_dptt = db(db.region.id==db.departement.d_region)\ .select(db.region.r_name, db.region.id, db.departement.d_name, db.departement.d_code, db.departement.id, \ orderby=db.region.r_name, cache=(cache.ram,6)) def prepare_select(rows): """ Creates a list of tuples to be used in the SELECT helper: ['Region A', OPTGROUP('SubRegion 1','SubRegion 2', 'SubRegion 3'), 'Region B', OPTGROUP('SubRegion 4','SubRegion 5', 'SubRegion 6')] """ l_r=[] for row in rows: r = row.region.r_name if row.region.r_name not in l_r: l_r.append(row.region.r_name) interm_list=[] for reg in l_r: l_sr=[] for row in rows: if reg == row.region.r_name: reg_id = row.region.id dep = row.departement.d_code + ' ' + row.departement.d_name dep_id = row.departement.id l_sr.append(OPTION(dep,_value=row.departement.d_code)) option_reg = OPTION(reg, _value= 'R'+str(reg_id)) interm_list.append((option_reg,l_sr)) res=[] for reg, l_sr in interm_list: res.append(reg) res.append(OPTGROUP(*l_sr)) return res return SELECT(*prepare_select(region_dptt), **dict(_name='region_to_search', _value=v, _id='region_to_search', _type = 'string', _class="options")) in the controller: def test(): db.region.r_name.widget = region_widget fields=['r_name'] labels = {'r_name':T('')} form= SQLFORM(db.region, fields = fields, labels = labels) a=None if form.accepts(request.vars, session, formname='test_form', dbio=False): a = form.vars elif form.errors: a = form.errors return dict(form=form, a = a) def insertions():# TO RUN one time db.region.insert(r_name="Region A") db.region.insert(r_name="Region B") db.departement.insert(d_name="SubRegion 1", d_code="11", d_region=1) db.departement.insert(d_name="SubRegion 2", d_code="12", d_region=1) db.departement.insert(d_name="SubRegion 3", d_code="21", d_region=2) db.departement.insert(d_name="SubRegion 4", d_code="22", d_region=2) db.departement.insert(d_name="SubRegion 5", d_code="25", d_region=2) db.departement.insert(d_name="SubRegion 6", d_code="26", d_region=2)
[web2py] Re: Manual upload for a specific row
Yep Too simple !! Thanks a lot Anthony. I appreciate. Dominique On Nov 17, 5:13 pm, Anthony wrote: > On Thursday, November 17, 2011 11:01:34 AM UTC-5, Dominique wrote: > > > Hello, > > > Chapter 6 explains manual upoloads. > > > >>> db.define_table('myfile',Field('image','upload')) > > >>> stream = open(filename,'rb') > > >>> db.myfile.insert(image=db.myfile.image.store(stream,filename)) > > That works fine when the table is empty. > > > But how to upload an image file in order to update a specific row (ie. > > when the other fields of the row are already filled in the db) ? > > Did the usual update method(s) not work? > > db(db.myfile.id == id).update(image=db.myfile.image.store(stream,filename)) > > or > > db.myfile[id] = dict(image=db.myfile.image.store(stream,filename)) > > Anthony
[web2py] Manual upload for a specific row
Hello, Chapter 6 explains manual upoloads. >>> db.define_table('myfile',Field('image','upload')) >>> stream = open(filename,'rb') >>> db.myfile.insert(image=db.myfile.image.store(stream,filename)) That works fine when the table is empty. But how to upload an image file in order to update a specific row (ie. when the other fields of the row are already filled in the db) ? Any help greatly appreciated Thanks in advance Dominique
[web2py] Re: How to change the position of submit button in a SQLFORM
Hi, Thanks DenesL, Anthony and Massimo for your help. I appreciate. That works fine ! Thanks a lot Dominique
[web2py] How to change the position of submit button in a SQLFORM
Hello All, I have a form built with SQLFORM.factory. I would like to change the position of the submit button. I know how to insert an element somewhere with for instance form[0][3][1].insert(-1, my_element) but not how to move the submit button from its pre-defined place (last row) to another place. I'd prefer not to define its place in the view but rather in the controller. For info, the hierarchy of the form is: form input1 select1 div1 div2 div class="w2p_fl" div class="w2p_fw" select id='bla1" select id="bla2" div class="w2p_fc" div3 id="submit_record_row" iv class="w2p_fl" div class="w2p_fw" input type="submit" div class="w2p_fc" I'd like to move the submit button (which is in the div3) to the div2, just after the select id="bla2" Thanks in advance for any help Dominique
[web2py] How to use this specific widget with a simple FORM ?
Hello, I 'd like to use this great widget (slice 85 http://www.web2pyslices.com/slices/take_slice/85) with a simple form FORM helper. It works great with a SQLFORM but I need to use it (slightly modified) in a FORM. I saw that for this slice (http://www.web2pyslices.com/main/slices/ take_slice/22) , it was necessary to add _class="date" to the input field definition (see http://groups.google.com/group/web2py/browse_thread/thread/6bc48492ecde4ee2/842449026c28b152?lnk=gst&q=Adding+a+Widget+to+a+simple+FORM%28%29+input%28%29+#842449026c28b152). I just don't know what to do. Can anyone give me a hint ? Thanks in advance for your help Dominique
[web2py] Re: SELECT / OPTGROUP
Hello, I answer to myself, since it was not so complex ;) ... Oops! Hum hum ... Dominique In Controller: def search_form(): q = db(db.region.id==db.subregion.region).select(orderby=db.region.name | db.subregion.name) def prepare_select(rows): """ Creates a list to be used in the SELECT helper: ['Region A', OPTGROUP('SubRegion 1','SubRegion 2', 'SubRegion 3'), 'Region B', OPTGROUP('SubRegion 4','SubRegion 5', 'SubRegion 6')] """ l_r=[] for row in rows: r = row.region.name if row.region.name not in l_r: l_r.append(row.region.name) interm_list=[] for reg in l_r: l_sr=[] for row in rows: if reg == row.region.name: l_sr.append(row.subregion.name) interm_list.append((reg,l_sr)) res=[] for reg, l_sr in interm_list: res.append(reg) res.append(OPTGROUP(*l_sr)) return res form=FORM(TR("",SELECT(*prepare_select(q), **dict(_name='region_to_search', value=request.vars.requested_categ_name))), TR("",INPUT(_type="submit",_value="Search"))) if form.accepts(request.vars, session, keepvalues=True): request.vars.requested_categ_name = form.vars.region_to_search response.flash="%s"%form.vars.region_to_search return dict(form=form,)
[web2py] Re: SELECT / OPTGROUP
Thanks for replying. value=""bla bla bla SubRegion 3" already tried without success ... Any other idea ? On Oct 6, 7:27 pm, puercoespin wrote: > For selected, try > > (_name="region_to_search", > value="bla bla bla SubRegion 3") > > instead of > > (_name="region_to_search", > selected="bla bla bla SubRegion 3") > > On 6 oct, 18:27, Dominique wrote: > > > > > > > > > Hello All, > > > First things first: congratulations to Massimo and all those who > > help. > > Web2py is really a great framework. > > Even for non-professional developers like me, it is both easy and > > powerful. > > A big big thank for providing such a nice framework. > > I am trying to learn web2py (with an average Python level), so forgive > > me for my silly questions (there will be others ;)) > > > Could anybody help me with this SELECT / OPTGROUP problem ? > > The following SELECT with OPTGROUP example illustrates my problems > > (see below). > > May be it is more a python difficulty than a web2py problem... (I am > > not a professional). > > > 1) How to make an item of the list "selected", for instance 'SubRegion > > 3' ? I tried with value= 'SubRegion 3' or selected='SubRegion 3' but > > in this case, it doesn't work. > > Idea: the visitor gives his region, then his region is automatically > > pre-selected when he's in the search area. > > He can change it too. > > 2) keepvalues=True does not work in my example (although it usually > > works fine with INPUTs, SELECTs,...) > > 3) If someone has a more elegant way to program the building of the > > select, I would appreciate ;) > > 4) Something else: I also made another form to generate a query (and > > its result) with a sort order. > > Is there a way to programmatically trigger the submit button when the > > sort order is changed ? > > (ie: I want the user to avoid having to click on submit after he > > changed the sort order) > > > Thanks in advance for any help > > Dominique > > > In models: > > db.define_table('region', > > Field('name', 'string', length=250)) > > db.define_table('subregion', > > Field('name', 'string', length=250), > > Field('region', db.region)) > > db.region.insert(name="Region A") > > db.region.insert(name="Region B") > > db.subregion.insert(name="SubRegion 1", region=1) > > db.subregion.insert(name="SubRegion 2", region=1) > > db.subregion.insert(name="SubRegion 3", region=2) > > db.subregion.insert(name="SubRegion 4", region=2) > > db.subregion.insert(name="SubRegion 5", region=2) > > db.subregion.insert(name="SubRegion 6", region=2) > > > In Controller: > > def search_form(): > > q = db(db.region.id==db.subregion.region)\ > > .select(orderby=db.region.name | db.subregion.name) > > > def get_it(rows): > > """ > > Creates a list of tuples to be used in the SELECT helper: > > [('Region A',['bla bla bla SubRegion 1','bla bla bla > > SubRegion 2', 'bla bla bla SubRegion 3']), > > ('Region A',['bla bla bla SubRegion 4','bla bla bla > > SubRegion 5', 'bla bla bla SubRegion 6'])] > > """ > > alist=[] > > for row in rows: > > nr = row.region.name > > if nr not in alist: > > alist.append(nr) > > the_list=[] > > for elem in alist: > > newlist=[] > > for row in rows: > > if row.region.name == elem: > > newlist.append('bla bla bla '+row.subregion.name) > > the_list.append([elem,OPTGROUP(*newlist)]) > > return the_list > > > t=None > > form=FORM( > > TR("",SELECT(*get_it(q), **dict(_name="region_to_search", > > selected="bla bla bla SubRegion 3"))), > > TR("",INPUT(_type="submit",_value="Search")) > > ) > > > if form.accepts(request.vars, session, keepvalues=True): > > t=form.vars.region_to_search > > response.flash="%s"%t > > > return dict(q=q, form=form) > > > All this returns something like (there are gluon objects inside...): > > > > Region A > > > > bla bla bla SubRegion 1 > option> > > bla bla bla SubRegion 2 > option> > > > > > > Region B > > bla bla bla SubRegion 3 > option> > > bla bla bla SubRegion 4 > option> > > bla bla bla SubRegion 5 > option> > > bla bla bla SubRegion 6 > option> > > > > > >
[web2py] SELECT / OPTGROUP
Hello All, First things first: congratulations to Massimo and all those who help. Web2py is really a great framework. Even for non-professional developers like me, it is both easy and powerful. A big big thank for providing such a nice framework. I am trying to learn web2py (with an average Python level), so forgive me for my silly questions (there will be others ;)) Could anybody help me with this SELECT / OPTGROUP problem ? The following SELECT with OPTGROUP example illustrates my problems (see below). May be it is more a python difficulty than a web2py problem... (I am not a professional). 1) How to make an item of the list "selected", for instance 'SubRegion 3' ? I tried with value= 'SubRegion 3' or selected='SubRegion 3' but in this case, it doesn't work. Idea: the visitor gives his region, then his region is automatically pre-selected when he's in the search area. He can change it too. 2) keepvalues=True does not work in my example (although it usually works fine with INPUTs, SELECTs,...) 3) If someone has a more elegant way to program the building of the select, I would appreciate ;) 4) Something else: I also made another form to generate a query (and its result) with a sort order. Is there a way to programmatically trigger the submit button when the sort order is changed ? (ie: I want the user to avoid having to click on submit after he changed the sort order) Thanks in advance for any help Dominique In models: db.define_table('region', Field('name', 'string', length=250)) db.define_table('subregion', Field('name', 'string', length=250), Field('region', db.region)) db.region.insert(name="Region A") db.region.insert(name="Region B") db.subregion.insert(name="SubRegion 1", region=1) db.subregion.insert(name="SubRegion 2", region=1) db.subregion.insert(name="SubRegion 3", region=2) db.subregion.insert(name="SubRegion 4", region=2) db.subregion.insert(name="SubRegion 5", region=2) db.subregion.insert(name="SubRegion 6", region=2) In Controller: def search_form(): q = db(db.region.id==db.subregion.region)\ .select(orderby=db.region.name | db.subregion.name) def get_it(rows): """ Creates a list of tuples to be used in the SELECT helper: [('Region A',['bla bla bla SubRegion 1','bla bla bla SubRegion 2', 'bla bla bla SubRegion 3']), ('Region A',['bla bla bla SubRegion 4','bla bla bla SubRegion 5', 'bla bla bla SubRegion 6'])] """ alist=[] for row in rows: nr = row.region.name if nr not in alist: alist.append(nr) the_list=[] for elem in alist: newlist=[] for row in rows: if row.region.name == elem: newlist.append('bla bla bla '+row.subregion.name) the_list.append([elem,OPTGROUP(*newlist)]) return the_list t=None form=FORM( TR("",SELECT(*get_it(q), **dict(_name="region_to_search", selected="bla bla bla SubRegion 3"))), TR("",INPUT(_type="submit",_value="Search")) ) if form.accepts(request.vars, session, keepvalues=True): t=form.vars.region_to_search response.flash="%s"%t return dict(q=q, form=form) All this returns something like (there are gluon objects inside...): Region A bla bla bla SubRegion 1 bla bla bla SubRegion 2 Region B bla bla bla SubRegion 3 bla bla bla SubRegion 4 bla bla bla SubRegion 5 bla bla bla SubRegion 6