Re: [web2py] Re: Autocomplete Widget changed after upgrade
Hi Massimo, Solved the issue. The new widget / ajax is looking for a ID in the table. I just added the id to the view, and it works fine! regards Martin On Thu, Nov 17, 2011 at 2:45 PM, Massimo Di Pierro massimo.dipie...@gmail.com wrote: Can you helps us debug? Use chrome, check out the callback url, call it directly, does it return a ticket? On Nov 17, 1:53 am, Ole Martin Maeland olemael...@gmail.com wrote: Hi Massimo, upgrade from version 1.89.5 (2010-11-21), so old version. I have tried to substitute the built in autocomplete with s-cubism suggest_widget. It works the same way - no function when I try to read from db view, but works fine when directly from db. regards Martin On Thu, Nov 17, 2011 at 7:47 AM, Massimo Di Pierro massimo.dipie...@gmail.com wrote: what did you upgrade from? On Nov 16, 3:07 pm, Ole Martin Maeland olemael...@gmail.com wrote: Hi, I upgraded web2py to latest version. everything works fine exept the autocomplete widget I use MySQL as my database. The autocomplete is reading from a db VIEW. The reason for this is that I have 2 columns in a db: short_name and ISIN that is the name, and ISIN that is the ID. By doing union select it worked fine until I upgraded. after the upgrade to the latest version it is not recognising the VIEW as a DB. in my db setup I have set it to be a DB with migrate=False. I have tried to use the widget directly with a DB, and then it works fine. Initially I thought the problem were due to new adapter: pymysql, but I have changed it using: import MySQLdb from gluon.dal import MySQLAdapter MySQLAdapter.driver = MySQLdb but that is not the problem. It does not read the VIEW as a DB anymore.. I have several VIEW's in my DB and it works fine for all other queries.. any idea how to fix it ? regards martin -- Hilsen Ole Martin Mob: 95227471 -- Hilsen Ole Martin Mob: 95227471
[web2py] Autocomplete Widget changed after upgrade
Hi, I upgraded web2py to latest version. everything works fine exept the autocomplete widget I use MySQL as my database. The autocomplete is reading from a db VIEW. The reason for this is that I have 2 columns in a db: short_name and ISIN that is the name, and ISIN that is the ID. By doing union select it worked fine until I upgraded. after the upgrade to the latest version it is not recognising the VIEW as a DB. in my db setup I have set it to be a DB with migrate=False. I have tried to use the widget directly with a DB, and then it works fine. Initially I thought the problem were due to new adapter: pymysql, but I have changed it using: import MySQLdb from gluon.dal import MySQLAdapter MySQLAdapter.driver = MySQLdb but that is not the problem. It does not read the VIEW as a DB anymore.. I have several VIEW's in my DB and it works fine for all other queries.. any idea how to fix it ? regards martin
Re: [web2py] Re: Autocomplete Widget changed after upgrade
Hi Massimo, upgrade from version 1.89.5 (2010-11-21), so old version. I have tried to substitute the built in autocomplete with s-cubism suggest_widget. It works the same way - no function when I try to read from db view, but works fine when directly from db. regards Martin On Thu, Nov 17, 2011 at 7:47 AM, Massimo Di Pierro massimo.dipie...@gmail.com wrote: what did you upgrade from? On Nov 16, 3:07 pm, Ole Martin Maeland olemael...@gmail.com wrote: Hi, I upgraded web2py to latest version. everything works fine exept the autocomplete widget I use MySQL as my database. The autocomplete is reading from a db VIEW. The reason for this is that I have 2 columns in a db: short_name and ISIN that is the name, and ISIN that is the ID. By doing union select it worked fine until I upgraded. after the upgrade to the latest version it is not recognising the VIEW as a DB. in my db setup I have set it to be a DB with migrate=False. I have tried to use the widget directly with a DB, and then it works fine. Initially I thought the problem were due to new adapter: pymysql, but I have changed it using: import MySQLdb from gluon.dal import MySQLAdapter MySQLAdapter.driver = MySQLdb but that is not the problem. It does not read the VIEW as a DB anymore.. I have several VIEW's in my DB and it works fine for all other queries.. any idea how to fix it ? regards martin -- Hilsen Ole Martin Mob: 95227471
Re: [web2py] Callable as Field.default
instead of default=now use default = request.now also change default = now in modified_on to update=request.now regards Martin On Wed, Jan 26, 2011 at 1:36 AM, Bernd Rothert roth...@googlemail.comwrote: A table definition from the DAL chapter of the Web2py book: db.define_table('person', Field('uuid', length=64, default=uuid.uuid4()), Field('modified_on', 'datetime', default=now), Field('name'), format='%(name)s') now usually contains the current datetime from request.now and that's fine but the default for uuid would be identical for all inserts. Although the example doesn't use the default so it is not a problem there. If you omit the parenthesis behind default=uuid.uuid4() and simple pass the uuid4 function as the default it works as expected - the default is evaluated at insert time and yields a fresh uuid for each new record. I assume this is the intended behaviour although I couldn't find it documented(!?). Strangely replacing default=now in the same way with e.g. default=datetime.datetime.now does not work: now=datetime.datetime.now db.define_table('person', Field('uuid', length=64, default=uuid.uuid4), Field('modified_on', 'datetime', default=now), Field('name'), format='%(name)s') db.person.insert(name='Ernie') db.person.insert(name='Bert') db(db.person).select() ValueError: invalid literal for int() with base 10: 'built' Umm,... db.executesql(db(db.person)._select()) [(1, u'b35cc052-3800-42a9-b7eb-bb9bc8ada271', u'built-in method now of type object at 0x37c520', u'Ernie'), (2, u'003ab438-f3aa-4474-8c24-b07d85406930', u'built-in method now of type object at 0x37c520', u'Bert')] (only works with Sqlite - MySQL would throw an error earlier) I think this check in BaseAdapter.represent (dal.py) is the culprit: def represent(self, obj, fieldtype): if type(obj) in (types.LambdaType, types.FunctionType): obj = obj() print type(datetime.datetime.now) in (types.LambdaType, types.FunctionType) False This version lets you use any callable for generating dynamic default values (plus it's 3-4 times faster): def represent(self, obj, fieldtype): if callable(obj): obj = obj() I hope this doesn't cause any side effects - at least I could not find any (at this late/early hour)... Thanks -- Hilsen Ole Martin Mob: 95227471
[web2py] autocomplete - style: widht hard coded ??
Hi, I have a autocomplete field in a form, and I would like it to be wider. Looking at the code it looks like it is hard coded - width: 200px, how do I overriede that in CSS ?? jQuery('#_autocomplete_paper_div').fadeOut('slow'); type=textinput id=_autocomplete_paper_auto name=paper value= type=hiddendiv id=_autocomplete_paper_div style=position: absolute; display: none;select style=width: 200px; class=autocomplete Regards, Martin
Re: [web2py] autocomplete - style: widht hard coded ??
the code is a autogenerated form using SQLFORM - from the construction of the db, where I defined the autocomplete widget. would not like to hardcode it in the view template - so are there any other way to change the widht ?? regards Ole Martin 2010/12/27 Branko Vukelić stu...@brankovukelic.com Better modify the code. On Mon, Dec 27, 2010 at 11:28 AM, Ole Martin Maeland olemael...@gmail.com wrote: Hi, I have a autocomplete field in a form, and I would like it to be wider. Looking at the code it looks like it is hard coded - width: 200px, how do I overriede that in CSS ?? jQuery('#_autocomplete_paper_div').fadeOut('slow'); type=textinput id=_autocomplete_paper_auto name=paper value= type=hiddendiv id=_autocomplete_paper_div style=position: absolute; display: none;select style=width: 200px; class=autocomplete Regards, Martin -- Branko Vukelic stu...@brankovukelic.com http://www.brankovukelic.com/ -- Hilsen Ole Martin Mob: 95227471
Re: [web2py] How to do this in web2py..?
http://www.web2pyslices.com/main/slices/take_slice/85 On Mon, Dec 20, 2010 at 10:13 AM, Fabiano fabianoeng...@gmail.com wrote: Hi, I am new to web2py and sure not if I am doing things the best way. I am designing an app and would like your opinion on my choices and also how could I implement some stuff in web2py. My problem: I have classes of stuff that I want to store on the database. Stuff here is very generic and could be anything. (Not related to OO, it is part of the problem I am modeling). The final end users of my app will be able to select a class to create an instance, by giving a name to it and selecting options for it. For each class I insert on my database I may have different options available with different values. For example, I may have a class person with option sex with values male, female. A user may select this class person to create a person, giving a name to it and selecting one value for its sex option. I may have a class Pie One on my database, with an option flavor with values flavor 1, flavor 2, flavor 3 and another option Fruit with values apple, banana. I may have another class Pie Two also with an option flavor but now with different available values for it: flavor 2, flavor 4 an no option Fruit now. When user chooses that it wants a Pie One, he must also choose a value for its flavor, but only from available flavor for Pie One, and also must choose a value for its fruit option. If user wants a Pie Two, the only option is flavor, there is no fruit nor sex option for this class. So far, we could have tables like this: Stuff id: name: 1 'person' 2 'pie one' 3 'pie two' Option id: name: 1 'sex' 2 'flavor' 3 'fruit' OptionValue id: option_id: name: 1 1'male' 2 1'female' 3 2'flavor 1' 4 2'flavor 2' 5 2'flavor 3' 6 2'flavor 4' 7 3'apple' 8 3'banana' StuffOption stuff_id: option_value: 1 1 1 2 2 3 2 4 2 5 2 7 2 8 3 4 3 6 From this, I can derive the option names available for each class by its option values (values grouped by option names actually). When user will instantiate a class of pie one, I want to show him a field flavor with a dropdown box with available flavors for this class, and another field fruit with fruits available for this class in a dropdown box. I may have many options for each class (or none) and the values available for the same option may be different in different classes, so this has to be generic. How could I show these dropdowns in web2py? There is more. Each of theses classes will be classified in categories, but each one may be in none or more than one category. Also, when I display all classes of a category I must be able to customize the order where the classes appear, and the order will be independent for each category. I thought in implement this with something like: Category id: name: 1'people' 2'pies' StuffCategory category_id: stuff_id: position: 2 2 2 2 3 1 I would them retrieve items inverse ordered by position column, and also set this column as autoincrement. This way, when I insert a new class it will always show first on the list by default. If, lets say, I want to insert an item on position 7, before insert it I would do: UPDATE StuffCategory SET position = position + 1 WHERE position = 7 and then insert it with its position = 7. It would be similar to move an class to a specific position, update all position values between it and the desired position, before setting the desired position. Would you guys say is this a good way to achieve this functionality or is there a better way? Also, I don't want to write SQL directly, how could I do this nicely in web2py? An additional interface I'd like to provide to admin to change the order would be to list all classes in the right order, and in from of each class, there would be two buttons: up and down arrows. clicking on them would swap its position with the next record. I think this would be great in an ajax interface, but I don't have a clue how to do it in web2py yet. And now, my last problem. Each of these classes will have a number of images associated with them. One of the images of each class will be its main image. Each value may have one of its image associate with it also. For this, I may have an Image table: Image id: stuff_id: image: And add a main_image_id column to stuff table. I thought of main_image column be a reference to image table so it would be easy to change the main image between the images available for that class. For the option values, I could add a column image_id also, where
Re: [web2py] Create table without id field
Create a table in web2py, migrate=False create table in db, no autincrement.. thats it. regards Martin On Mon, Dec 13, 2010 at 11:11 AM, demetrio dgzabal...@gmail.com wrote: Hi everyone, i've searched if there is any way to create a table without an id field. I've tryed with: param primarykey = None but this doesn't works. There is any way to do it? Thanks
[web2py] Re: ajax search select field using crud or sqlform
I have found a solution on it. steps: 1. create a view in the db - usin union selects 2. create a fake db - migrate = False 3. use the SQLFORM autocomplete as normal, ref the fake db. the fake db have to be set up before the db were the autocomplete widget is used. that's it. I have found a workaround to the problem by using sqlform.widget.autocomplete. that is working for 1 column. problem is that i would like to search in 3 columns. I can work around that by creating a view in the databasee (also belive it will be more efficient) by using union selects on the tre columns. that is working fine, but I cant get access to the view from web2py. I tried to make a fake table with to fields and Migrate=False, but it looks in the db.table On Tue, Dec 7, 2010 at 6:00 PM, Ole Martin Maeland olemael...@gmail.comwrote: Hi, I would like to create a form were I get a dropdown list that search 3 rows in one table. it should then pick the .id field for the record. It would be similar to the ajax search with autocomplete: http://web2pyslices.com/main/slices/take_slice/51 I could use that, but how do I embed it in a SQLFORM ?? Any Idea ?? regards Martin
[web2py] ajax search select field using crud or sqlform
Hi, I would like to create a form were I get a dropdown list that search 3 rows in one table. it should then pick the .id field for the record. It would be similar to the ajax search with autocomplete: http://web2pyslices.com/main/slices/take_slice/51 I could use that, but how do I embed it in a SQLFORM ?? Any Idea ?? regards Martin
Re: [web2py] Name error, but only if I run it in view..
Hi, That will not work. I just read the output from dict - companies - that is a query on db.newcomp. So only keys in dict will be the database names - id, uuid, address. It works for id and uuid, but not for name and address. state that it is not defined, but it's in the db, it's in the db model. so it's something else... but I have no idea.. regards Ole Martin def list_companies(): form=crud.create(db.newcomp) companies=db(db.newcomp.id0).select(orderby=db.newcomp.id) return dict(companies=companies,form=form) 2010/11/19 Kenneth Lundström kenneth.t.lundst...@gmail.com {{for company in companies:}} tr td{{=uuid}}/td td{{=address}}/td /tr {{pass}} Shouldn´t this be like td{{=company.uuid}}/td td{{=company.address}}/td or maybe td{{=companies[company].uuid}}/td td{{=campanies[company].address}}/td Kenneth -- Hilsen Ole Martin Mob: 95227471
Re: [web2py] Re: Standalone DAL - connection to sqlite db - running web2py
thanks ! On Thu, Nov 18, 2010 at 5:24 PM, mart msenecal...@gmail.com wrote: Hey, It took me a few tries before getting this to work. So, I see 2 things that you may want to try to look at: 1) I don't really use windows, but I think the first line is problematic. (unless more recent windows versions have gotten smarter about slashes?). dbfolder='C:\web2py\web2py\applications\teqb\databases' db = dal.DAL('sqlite://storage', folder=dbfolder) should be: dbfolder='C:/web2py/web2py/applications/teqb/databases' (or you can escape the back slash (C:\\web2py\\web2py\\...)) 2) I remember importing DAL was a little finicky (sometimes). SO, you may want to try drilling down one more level in you import: instead of db = dal.DAL('sqlite://storage', folder=dbfolder) you may want to try: from yourPath.gluon.dal import DAL db = DAL('sqlite://storage', folder=dbfolder) I do the following without any problems on Mac, linux and windows: I have 2 instances of web2py, some both running on the same machine, so stand alone is renamed with blue prefixes (blueDAL, bluedb, blueTHIS, blueTHAT, etc. and gluon is renamed to blueSQL in case they run 2 different versions of web2py, I want to quickly and visually set them apart when reading script. tail,head = os.path.split(sys.argv[0]) dataFiles = [storage.sqlite, sql.log] dbFolder = {0}/blueLite/db_storage.format(tail) try: for f in os.listdir(dbFolder): if .table in f: fTable = {0}/{1}.format(dbFolder,f) os.remove(fTable) print(removed {0}.format(fTable)) for dFile in dataFiles: os.remove({0}/blueLite/db_storage/{1}.format(tail,dFile)) print(removed {0}/blueLite/db_storage/ {1}.format(tail,dFile)) except Exception as errObj: print(str(errObj)) from blueLite.pyUtils.sql.blueSQL.dal import DAL as blueDal from blueLite.pyUtils.sql.blueSQL.dal import SQLField bluedb = blueDal(sqlite://storage.sqlite, folder={0}/blueLite/ db_storage.format(tail)) bluedb.define_table('cmdObjects', SQLField('name'), SQLField('pyModule'), SQLField('pyPath'), SQLField('cmdProperties','blob'), SQLField('dict_objCmd','blob'), SQLField('dfo_objCmd', 'blob'), SQLField('etree_objCmd','blob')) bluedb.commit() Then I pass bluedb to all other classes which is why I use the full path when pointing to the DB folder (NEVER relative). hope it helps. Mart :) On Nov 18, 9:56 am, Ole Martin Maeland olemael...@gmail.com wrote: Hi Massimo, I have administrator access on the folder. The database is running a small web2py application that is crypted. Do I have to pass the crypt string to the db, or do I have to use administrator password in order to access it. I reach it by using SQLite Manager.. regards Martin On Thu, Nov 18, 2010 at 3:06 PM, mdipierro mdipie...@cs.depaul.edu wrote: I think you do not have write access on this file/folder On Nov 18, 7:36 am, Ole Martin Maeland olemael...@gmail.com wrote: Hi, I am trying to connect to sqlite db that works fine with a small web2py applicaiton. connection parameters: dbfolder='C:\web2py\web2py\applications\teqb\databases' db = dal.DAL('sqlite://storage', folder=dbfolder) error message: Traceback (most recent call last): File interactive input, line 1, in module File C:\Python27\lib\site-packages\gluon\dal.py, line 2031, in __init__ self._logger = Logger(folder) File C:\Python27\lib\site-packages\gluon\dal.py, line 140, in __init__ self.file = open(os.path.join(folder,name),'a') IOError: [Errno 22] invalid mode ('a') or filename: 'C:\\web2py\\web2py\x07pplications\teqb\\databases\\sql.log' any ide how I could get this to work? regards Martin -- Hilsen Ole Martin Mob: 95227471 -- Hilsen Ole Martin Mob: 95227471
[web2py] Name error, but only if I run it in view..
Hi, If anyone have a answer - pls. reply: *My model:* db.define_table('newcomp', Field('uuid', length=64, default=uuid.uuid1()), Field('name'), Field('address')) db.newcomp.uuid.writable=False when I run this directly from the controller, or in db admin tool is works fine. When I run it from view I get a name error. *Here is the view model:* {{response.files.append(URL(r=request,c='static',f='jquery.dataTables.min.js'))}} {{response.files.append(URL(r=request,c='static',f='demo_table.css'))}} {{extend 'layout.html'}} script $(document).ready(function() { jQuery('.smarttable').dataTable(); }); /script h1List Companies/h1 [a href=#nil onclick=jQuery('.form').slideToggle();new company/a] div class=form hidden br / {{=form}} /div br /br / table class=smarttable thead tr thName/ththcompany/th /tr /thead tbody {{for company in companies:}} tr td{{=uuid}}/td td{{=address}}/td /tr {{pass}} /tbody /table ___ this works fine if I use {{=uuid}} and / or {{=id}}. If I add the address or name field I get this: Traceback (most recent call last): File C:\web2py\web2py\gluon\restricted.py, line 188, in restricted exec ccode in environment File C:\web2py\web2py\applications\tq/views\default/list_newcomp.html, line 77, in module NameError: name 'address' is not defined -- Hilsen Ole Martin Mob: 95227471
[web2py] Standalone DAL - connection to sqlite db - running web2py
Hi, I am trying to connect to sqlite db that works fine with a small web2py applicaiton. connection parameters: dbfolder='C:\web2py\web2py\applications\teqb\databases' db = dal.DAL('sqlite://storage', folder=dbfolder) error message: Traceback (most recent call last): File interactive input, line 1, in module File C:\Python27\lib\site-packages\gluon\dal.py, line 2031, in __init__ self._logger = Logger(folder) File C:\Python27\lib\site-packages\gluon\dal.py, line 140, in __init__ self.file = open(os.path.join(folder,name),'a') IOError: [Errno 22] invalid mode ('a') or filename: 'C:\\web2py\\web2py\x07pplications\teqb\\databases\\sql.log' any ide how I could get this to work? regards Martin
Re: [web2py] Re: Standalone DAL - connection to sqlite db - running web2py
Hi Massimo, I have administrator access on the folder. The database is running a small web2py application that is crypted. Do I have to pass the crypt string to the db, or do I have to use administrator password in order to access it. I reach it by using SQLite Manager.. regards Martin On Thu, Nov 18, 2010 at 3:06 PM, mdipierro mdipie...@cs.depaul.edu wrote: I think you do not have write access on this file/folder On Nov 18, 7:36 am, Ole Martin Maeland olemael...@gmail.com wrote: Hi, I am trying to connect to sqlite db that works fine with a small web2py applicaiton. connection parameters: dbfolder='C:\web2py\web2py\applications\teqb\databases' db = dal.DAL('sqlite://storage', folder=dbfolder) error message: Traceback (most recent call last): File interactive input, line 1, in module File C:\Python27\lib\site-packages\gluon\dal.py, line 2031, in __init__ self._logger = Logger(folder) File C:\Python27\lib\site-packages\gluon\dal.py, line 140, in __init__ self.file = open(os.path.join(folder,name),'a') IOError: [Errno 22] invalid mode ('a') or filename: 'C:\\web2py\\web2py\x07pplications\teqb\\databases\\sql.log' any ide how I could get this to work? regards Martin -- Hilsen Ole Martin Mob: 95227471