[web2py] Re: Is there a way to use an Alias for a COUNT() field
If I use what you recommend then what would be the best way to generate the JSON output Thanks Massimo On Saturday, May 12, 2012 12:29:09 AM UTC-4:30, Massimo Di Pierro wrote: > > No, but you can do > > for row in rows: row['count'] = row[count] > > > > On Friday, 11 May 2012 23:44:57 UTC-5, Franklin Freitas wrote: >> >> Having the following >> >> def by_country(): >> count = db.procesados.idpublicacion.count() >> rows = db().select(db.procesados.pais, count, >> groupby=db.procesados.pais) >> return rows.json() >> >> It generates the JSON: >> >> [{"pais": "", "COUNT(procesados.idpublicacion)": 236}, {"pais": "AE", >> "COUNT(procesados.idpublicacion)": 3}] >> >> >> Is there a way to assign an Alias to the COUNT field so I won't have that >> long name "COUNT(procesados.idpublicacion)" in the JSON output >> >> >> >> Thanks >> >>
[web2py] Is there a way to use an Alias for a COUNT() field
Having the following def by_country(): count = db.procesados.idpublicacion.count() rows = db().select(db.procesados.pais, count, groupby=db.procesados.pais) return rows.json() It generates the JSON: [{"pais": "", "COUNT(procesados.idpublicacion)": 236}, {"pais": "AE", "COUNT(procesados.idpublicacion)": 3}] Is there a way to assign an Alias to the COUNT field so I won't have that long name "COUNT(procesados.idpublicacion)" in the JSON output Thanks
[web2py] Re: Numbers Format
Thanks a lot I live in Venezuela and that's the format I need Thanks for your help On Nov 8, 10:12 am, Vinicius Assef wrote: > No. I said probably you're using format() in a version it is not > supported yet. But I'm not sure about it. > > I never lay on server locale dependancy. > > I live in Brazil, and here we have numbers formatted this way: > "1.000,00". (dot separates thousands. Comma separates decimal). > So, I did this simple funcion: > def g_brazilian_decimal(s): > return s.replace('.', '*').replace(',', '.').replace('*', ',') > > And when I need to show some decimal data, I call: > {{=g_brazilian_decimal('%.2f' % row.my_decimal_field)}} > > I don't know if your need is alike mine, but this is how I manage it. > > -- > Vinicius Assef. > > On Tue, Nov 8, 2011 at 11:10 AM,FranklinFreitas > > > > > > > > wrote: > > Hi Vinicius, > > > You mean I can use str.format() to format numbers with thousand > > separators instead of my function ?, that would be great Could you > > give me an example ?? > > > Thanks > > > On Nov 7, 6:42 pm, Vinicius Assef wrote: > >> Possibly the python version in your production server. > > >> str.format() is available since python 2.6. > > >> -- > >> Vinicius Assef. > > >> On Mon, Nov 7, 2011 at 7:41 PM,FranklinFreitas > > >> wrote: > >> > In order to format numbers with thousands separator and custom number > >> > of decimals, I created the following function and included it in my > >> > "db.py" model so it could be accessed through the entire application. > > >> > def number_format(num, places=0): > >> > return locale.format("%.*f", (places, num), True) > > >> > I use it my views like: > > >> > {{=number_format(x.vebamt,2)}} > > >> > It works great in my development environment, but after migrating it > >> > to production (I am using a linode vps) the function doesn't work, I > >> > doesn't give me an error, it just doesn't format the numbers. > > >> > Any ideas what could be wrong ? I searched the group for a solution > >> > for formatting numbers and didn't find a previous post on this matter > > >> > Thanks for your help > > >> >Franklin
[web2py] Re: Numbers Format
Hi Vinicius, You mean I can use str.format() to format numbers with thousand separators instead of my function ?, that would be great Could you give me an example ?? Thanks On Nov 7, 6:42 pm, Vinicius Assef wrote: > Possibly the python version in your production server. > > str.format() is available since python 2.6. > > -- > Vinicius Assef. > > On Mon, Nov 7, 2011 at 7:41 PM,FranklinFreitas > > > > > > > > wrote: > > In order to format numbers with thousands separator and custom number > > of decimals, I created the following function and included it in my > > "db.py" model so it could be accessed through the entire application. > > > def number_format(num, places=0): > > return locale.format("%.*f", (places, num), True) > > > I use it my views like: > > > {{=number_format(x.vebamt,2)}} > > > It works great in my development environment, but after migrating it > > to production (I am using a linode vps) the function doesn't work, I > > doesn't give me an error, it just doesn't format the numbers. > > > Any ideas what could be wrong ? I searched the group for a solution > > for formatting numbers and didn't find a previous post on this matter > > > Thanks for your help > > >Franklin
[web2py] Numbers Format
In order to format numbers with thousands separator and custom number of decimals, I created the following function and included it in my "db.py" model so it could be accessed through the entire application. def number_format(num, places=0): return locale.format("%.*f", (places, num), True) I use it my views like: {{=number_format(x.vebamt,2)}} It works great in my development environment, but after migrating it to production (I am using a linode vps) the function doesn't work, I doesn't give me an error, it just doesn't format the numbers. Any ideas what could be wrong ? I searched the group for a solution for formatting numbers and didn't find a previous post on this matter Thanks for your help Franklin
[web2py] Re: Ajax sample function does not work on Update form
I solved the issue: if I enter the function on the 'onkeyup' event on the input text like this: onkeyup="ajax('my_function', ['argument'], 'target');" I get the error But if I used the full path ('/application_name/default/function') it works fine: onkeyup="ajax('/palitan/default/my_function', ['lastname'], 'target');" Thanks for your help, this got me for a few days On Oct 20, 4:25 pm, Anthony wrote: > Can you show some code? > > > > > > > > On Thursday, October 20, 2011 3:21:12 PM UTC-4, Franklin Freitas wrote: > > > I am using a form very similar to the Ajax sample on chapter 3 to > > search for customers and once you see the results, you click on the > > record you want so customer id and name are added to the form fields > > on my main processing form. This works fine on my "add new" records > > form. > > > I have another page to "update records", similar to the "add new > > records" page. On this form the Ajax doesn't work, when I call the > > Ajax function I get in the target div the content of the index page. > > After trying to see why it would only work in one page and the add and > > update records pages are similar I found the reason. On the update > > page there is an id on the url (to be read using request.args(0)) this > > causes the error, for some reason when there is an argument in that > > position the Ajax get confused and doesn't return the right results. > > > I tried adding a "/21" at the end of my "add new" page url and the > > Ajax also fails, this confirms that this is the cause of the error. I > > guess somehow the Ajax gets confused with this > > > Has anyone else experience this error ? > > > Thanks for your help
[web2py] Ajax sample function does not work on Update form
I am using a form very similar to the Ajax sample on chapter 3 to search for customers and once you see the results, you click on the record you want so customer id and name are added to the form fields on my main processing form. This works fine on my "add new" records form. I have another page to "update records", similar to the "add new records" page. On this form the Ajax doesn't work, when I call the Ajax function I get in the target div the content of the index page. After trying to see why it would only work in one page and the add and update records pages are similar I found the reason. On the update page there is an id on the url (to be read using request.args(0)) this causes the error, for some reason when there is an argument in that position the Ajax get confused and doesn't return the right results. I tried adding a "/21" at the end of my "add new" page url and the Ajax also fails, this confirms that this is the cause of the error. I guess somehow the Ajax gets confused with this Has anyone else experience this error ? Thanks for your help
[web2py] Re: connectionstring for mssql ? , DSN ?
Hi Stef, This is the way I've done it: db = DAL('mysql://username:password@dns_or_ip_of_server/ database_name') Hope it helps Regards Franklin On Feb 23, 3:43 pm, DenesL wrote: > According to the dal.py source you either supply > > mssql://dsn > > or > > mssql://username:password@host:port/dbname > > (port is optional) > > On Feb 23, 2:17 pm, Stef Mientki wrote:> hello, > > > i'm a little bit confused about how the connectionstring should look fro > > coupling a remote mssql > > database through odbc. > > > I was first searching for a odbc connecting string, > > and I'm finding that odbc is not considered as database engine but as a > > protocol ??? > > > Both the databasename and the DSN name in the ODBC definition is "test" > > > I can connect to the database with: > > conn = pyodbc.connect ( 'DSN=test; UID=z571117' ) > > print conn > > > Now with the DAL, I tried several constructs (the constructs below are also > > tried with the correct > > password), and none of them seem to work > > > Database_Name = r'mssql://z571117:@test/test' > > Database_Name = r'mssql://z571117:@test' > > Database_Name = r'mssql://z571117:@localhost/test' > > Database_Name = r'mssql://z571117:/test' > > My_DB = DAL ( Database_Name ) > > > What shpuld the connectionstring look like ? > > > Do I have to specify an alias in the ODBC manager or can I do without ? > > > thanks, > > Stef Mientki
[web2py] Re: Need help installing MySQLdb in Mac OSX
Hi Mart, Thanks for your detailed explanation. I had tried before with out any results. I tried it again anyway from scratch and here is the error I get when trying to import MySQLdb >>> import MySQLdb Traceback (most recent call last): File "", line 1, in File "build/bdist.macosx-10.6-universal/egg/MySQLdb/__init__.py", line 19, in File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 7, in File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 6, in __bootstrap__ ImportError: dlopen(/Users/ffreitas/.python-eggs/MySQL_python-1.2.3- py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.16.dylib Referenced from: /Users/ffreitas/.python-eggs/MySQL_python-1.2.3- py2.6-macosx-10.6-universal.egg-tmp/_mysql.so Reason: image not found >>> On Oct 18, 1:33 pm, mart wrote: > Yes, a little more involved that I remembered. So, to go through the > steps correctly, I started from scratch. This is what I did: > > 1) downloaded latest version of MySQLdb > formhttp://sourceforge.net/projects/mysql-python/ > 2) went to my default Python folder, and checked for any file or > folder with a reference to *MySQL* (remove if any) > 3) opened Vim in a terminal, opened setup_posix.py and made this > change (you may not have to do this if MySQL was already installed - > but i changed it anyways): > > <- changed this line > mysql_config.path = "mysql_config" > > --> to this > mysql_config.path = "/usr/local/mysql/bin/mysql_config" > > 4) ran these at the terminal: > python setup.py clean > python setup.py build > sudo python setup.py install > > 5) for good measure, did an export: export PATH=/usr/local/mysql/bin: > $PATH > > and there you have it. MyQSLdb is ready to be imported! > > good luck and feel free to ask, if you would like me to test a > different way of getting it insalled. > > Mart :) > > On Oct 18, 1:49 am, mart wrote: > > > > > > > > > hum.. let me check on my end to make sure I didn't miss mentioning > > something. It has been a little while... > > > On Oct 18, 12:40 am, Franklin Freitas > > wrote: > > > > Hi, the thing is that MySQLdb is not even working outside the Web2py > > > environment. I haven't been able to make it work in the regular Python > > > interpreter. I tried copying everything to the Web2py sites-packages > > > folder, but it didn't work > > > > Thanks > > > > Franklin > > > > On Oct 17, 8:03 pm, mart wrote: > > > > > you can throw in in the installed python/lib folder, or in site- > > > > packages folder (sibling to the applications folder of the web2py root > > > > dir, or do an export within your scripts (controller?),or my > > > > favorite, I usually do web2py stuff with Aptana,so, i throw of copy of > > > > all dependencies within my project and reference it there... so, many > > > > possibilities, depends how you prefer to reference it > > > > > Hope it helps, > > > > Mart :) > > > > > On Oct 17, 7:11 pm, Franklin Freitas > > > > wrote: > > > > > > Has anyone been able to install MySQLdb in Mac OSX ??? > > > > > > I want to use it with Web2py but haven't been able to make it work. > > > > > I've read a whole bunch of forums saying how hard it is, I've done > > > > > everything I've reead about it without any results. I even used > > > > > macports as recommended by my Web2py teacher but it didn't work > > > > > either. > > > > > > If anyone knows a sure way on how to achieve this I would appreciate > > > > > it. > > > > > > Thanks for your time
[web2py] Re: Need help installing MySQLdb in Mac OSX
Hi, the thing is that MySQLdb is not even working outside the Web2py environment. I haven't been able to make it work in the regular Python interpreter. I tried copying everything to the Web2py sites-packages folder, but it didn't work Thanks Franklin On Oct 17, 8:03 pm, mart wrote: > you can throw in in the installed python/lib folder, or in site- > packages folder (sibling to the applications folder of the web2py root > dir, or do an export within your scripts (controller?),or my > favorite, I usually do web2py stuff with Aptana,so, i throw of copy of > all dependencies within my project and reference it there... so, many > possibilities, depends how you prefer to reference it > > Hope it helps, > Mart :) > > On Oct 17, 7:11 pm, Franklin Freitas > wrote: > > > > > Has anyone been able to install MySQLdb in Mac OSX ??? > > > I want to use it with Web2py but haven't been able to make it work. > > I've read a whole bunch of forums saying how hard it is, I've done > > everything I've reead about it without any results. I even used > > macports as recommended by my Web2py teacher but it didn't work > > either. > > > If anyone knows a sure way on how to achieve this I would appreciate > > it. > > > Thanks for your time
[web2py] Need help installing MySQLdb in Mac OSX
Has anyone been able to install MySQLdb in Mac OSX ??? I want to use it with Web2py but haven't been able to make it work. I've read a whole bunch of forums saying how hard it is, I've done everything I've reead about it without any results. I even used macports as recommended by my Web2py teacher but it didn't work either. If anyone knows a sure way on how to achieve this I would appreciate it. Thanks for your time