[web2py] Re: Issue with defaultdict(list)

2018-05-20 Thread Ricardo Cárdenas
Hi Drew and all,

I saw the same exact problem Drew saw with *defaultdict(list)*. For the 
benefit of any future debuggers, I thought I'd document what went wrong in 
our case.

One of the functions in the controller was inappropriately named *list()*, 
thus overriding the definition of *list()* itself. By the time the model 
code was called -- *g = defaultdict(list)* and then 
*g['foo'].append('someValue')* -- it raised the *AttributeError: 'dict' 
object has no attribute 'append'* exception that Drew saw.

This problem would not occur if the controller was not involved - i.e. from 
the Python interpreter.

warm regards,


On Friday, March 16, 2018 at 8:22:06 PM UTC-5, Drew Howell wrote:
>
> After taking a break and working on another section, I finally found what 
> was causing the issue. There was, indeed, an error elsewhere within that 
> controller, which was causing me all the headache. I appreciate your guys' 
> help! Thanks.
>
> On Sunday, March 11, 2018 at 11:14:27 PM UTC-4, Drew Howell wrote:
>>
>> I seem to be having issues getting defaultdict to work within Web2Py. I 
>> am using Web2Py version 2.16.1 (Python 2.7.11).
>>
>> Here is the code in my controller:
>> from collections import defaultdict
>> g = defaultdict(list)
>> g['someKey'].append('someValue')
>>
>> Here is the error I'm getting:
>>
>> File "D:/web2py/applications/fpr/controllers/students.py" 
>> , line 
>> 14, in view
>>  g['someKey'].append('someValue')
>> AttributeError: 'dict' object has no attribute 'append'
>>
>> If I do the same thing in the Python Interpreter, I don't seem to get the 
>> issue.
>>
>> >>> from collections import defaultdict
>> >>> g = defaultdict(list)
>> >>> g['k'].append('v')
>> >>> print g['k']
>> ['v']
>>
>> Am I implementing this wrong or is there some sort of issue with using 
>> defaultdict(list) in Web2Py?
>>
>>

-- 
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.


Re: [web2py] web2py conference - online talks

2014-05-19 Thread Ricardo Cárdenas
Kudos to everyone involved in the web2py conference!

I'm having trouble watching the videos - maybe it's my connection, but 
often the video stops and the pointer resets to the beginning of the video. 
I'm having to refresh the browser and start over.

I don't know if others are having these problems, but it would be great if 
an offline solution was available.

thanks -Ricardo


On Monday, May 5, 2014 10:09:05 PM UTC-5, Massimo Di Pierro wrote:
>
> I do not think so.
>
> On Monday, 5 May 2014 10:38:17 UTC-5, marco mansilla wrote:
>>
>> Is there any chance to download this videos to watch offline?, that 
>> would be awesome. 
>>
>> Marco. 
>>
>> > Please find below the links to the video of the first web2py 
>> > conference. Videos are not broken into talks. 
>> > There is no audio for the first 2minutes but no talk either, only 
>> > service announcements. 
>> > 
>> > 
>> > *Part #1 (from start to lunch break)* 
>> > 
>> > 
>> https://colflash.cdm.depaul.edu/colflashweb/COLFlashPlayer.aspx?ID=183272 
>> > 
>> > 10:00-10:10! Conference Opening 
>> > 
>> > 10:10-10:20! “What's New with the PSF” by Brian Curtin 
>> > 
>> > 10:20-11:00! “History of web2py” by Massimo Di Pierro 
>> > 
>> > 11:00-11:40! "Learn web2py the Really Hard Way" by Anthony Bastardi 
>> > 11:40-12:20! "Stereodose" by Mark Li 
>> > 
>> > 12:20-12:30! "Planet Host" by Jason Burosh 
>> > 
>> > *Part #2 (from tutorial to coffee break)* 
>> > 
>> > 
>> https://colflash.cdm.depaul.edu/colflashweb/COLFlashPlayer.aspx?ID=183273 
>> > 
>> > 13:00:13:40! "hands-on web2py tutorial" by Clifford Williams 
>> > 
>> > 13:40-14:20! "Angular and web2py" by Amber Doctor 
>> > 
>> > 14:20-14:40 ! "Stitching together the tree of life with web2py" by 
>> > Richard Ree 1 
>> > 
>> > 4:40-15:00! "ShipElf: Automated Fulfillment with Web2Py" by Peter 
>> > Szczepanski 
>> > 
>> > 15:00-15:20! "MyIRE - What is Open Source Science?" by Mark Graves 
>> > 
>> > 15:20-15:40! "Introduction to Mongodb" by Marco Chou 
>> > 
>> > *Part #3 (from coffee break to end)* 
>> > 
>> > 
>> https://colflash.cdm.depaul.edu/colflashweb/COLFlashPlayer.aspx?ID=183274 
>> > 
>> > 16:00-16:20! "Introduction to OpenShift" by Craig Brott 
>> > 
>> > 16:20-16:40! "Introduction to Hypermedia API" by Bryan Barnard 
>> > 
>> > 16:40-17:00! "web2py and the Semantic web" by Chris Baron 
>> > 
>> > 17:00-17-20! "Teaching an old dog new tricks" by Don O'Hara 
>> > 
>> > 17:20-17:30! Conference Closing 
>> > 
>>
>

-- 
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: Help with production deployment on virtual server

2013-10-22 Thread Ricardo Cárdenas
Hello curious,

I'l assume you're using web2py 2.6 (you reference the handlers/ directory, 
which is new). Please review handlers/README. wsgihandler.py (all handlers 
in fact) is meant to be copied to web2py's root directory. Hope this helps, 
please report back...

best regards -Ricardo


On Tuesday, October 22, 2013 8:54:48 PM UTC-5, curiouslearn wrote:
>
> Niphlod,
>
> Thanks again. Is uwsgi faster/safer? Anyhow, I tried doing what you said. 
> But instead of following the difficult instructions in the web2py book, I 
> used the instructions in uwsgi documentation. I have attached three files:
>
> (1) My nginx configuration. (mysite_nginxconf.com)
> (2) uwsgi configuration (wsgiconf.ini)
> (3) The console output when I run uwsgi directly (now there is some output 
> and it gives some idea about the error). When I try to visit the site I get 
> "Internal server error" message. (uwsgi_consoleLog.txt)
>
> One problem I see is that ImportError: No module named wsgihandler
>
> But I see wsgihandler.py in the web2py/handlers folder. Should it not read 
> it from there? Do I have to install it separately, or give path to it 
> somehow?
>
> Really appreciate your help. Difficulty to deploying python apps is 
> frustrating and despite all the great things web2py offers, the difficulty 
> in deployment might otherwise require me to use something else.
>
>
>
>
> On Tuesday, October 22, 2013 5:41:38 PM UTC-4, Niphlod wrote:
>>
>> low performances vs running web2py on uwsgi.
>>
>> PS: try running uwsgi directly pointing to that config file (i.e. no 
>> emperor mode with upstart, so you get a chance to see any logged error that 
>> may pop up)
>>
>> On Tuesday, October 22, 2013 10:15:16 PM UTC+2, curiouslearn wrote:
>>>
>>> While some helpful soul helps me understand how to setup web2py to work 
>>> with nginx and uwsgi, I had another question. 
>>>
>>> Is there anything wrong, or problematic in using the following for 
>>> deployment
>>>
>>> Run web2py using 
>>>
>>> python web2py.py -a mypasswd -i 0.0.0.0 -p 9001
>>>
>>> and then use nginx to direct traffic from http://mydomain.com to this 
>>> running instance. 
>>>
>>> This seems an easy way to do it. What I am risking by doing this?
>>>
>>> Thank you.
>>>
>>> On Tuesday, October 22, 2013 3:28:21 PM UTC-4, curiouslearn wrote:

 Niphlod,

 Thanks for getting back to me. There is no file that has uwsgi-emperor 
 in its name in /var/log/upstart.

 Anything else I can do to find what is the problem? 

 On Tuesday, October 22, 2013 1:03:37 PM UTC-4, Niphlod wrote:
>
> every upstart job logs something into 
>  /var/log/upstart/name_of_the_service.log
>
> check if you have something on /var/log/upstart/uwsgi-emperor.log
>
> On Tuesday, October 22, 2013 6:48:42 PM UTC+2, curiouslearn wrote:
>>
>> I want to get web2py running on a Digital Ocean virtual server with 
>> nginx and uWSGI. I followed the instructions on deployment recipes in 
>> Web2py book, but things are not working. The following are the 
>> differences 
>> between the instructions given in the book and my specific case. 
>>
>> *Differences from instructions given in web2py deployment recipes*
>> (1) I have web2py installed in "/home/username/web_apps/web2py" instead 
>> of in "/home/www-data/web2py"
>> (2) The configuration file is called "/etc/nginx/sites-available/
>> myconfig.org" instead of "/etc/nginx/sites-available/web2py"
>> (3) For now I am ignoring settings related to ssl since I am just 
>> trying to get this to work.
>>
>> *The configuration I am using:*
>>
>> *1.* In the nginx file I have the following. Since I have other 
>> non-web2py apps running I don't want to listen on 80:
>>
>> *server {*
>> *
>> *
>> *server_name $hostname;*
>> *listen 9001; *
>> *access_log /var/log/nginx/me.log;*
>> *
>> *
>> *location / {*
>> *uwsgi_pass unix:///tmp/web2py.socket;*
>> *include uwsgi_params;*
>> *uwsgi_param UWSGI_SCHEME $scheme;*
>> *uwsgi_param SERVER_SOFTWARE nginx/$nginx_version;*
>> *}*
>> *}*
>>
>> *
>> *
>> *2.* In the /etc/uwsgi/web2py.xml file I have:
>>
>> **
>> */tmp/web2py.socket   *
>> */home/username/web_apps/web2py/*
>> */=wsgihandler:application  *
>> *  *
>> *1   *
>> *60*
>> *8 *
>> *1 *
>> */tmp/stats.socket   *
>> *2000  *
>> *512   *
>> *256   *
>> *192 *
>> *web_apps*
>> *web_apps*
>> *  *
>> **
>>
>>
>> 3. The uwsgi-emperor.conf is identical to that in the instructions.
>>
>> When I run sudo start uwsgi-emperor I ge

[web2py] contributing patches

2013-09-27 Thread Ricardo Cárdenas
(Apologies if this has been asked before.)

Kudos for web2py and for this community; happy to have found you. Web2py's 
very useful for my projects; even enjoyable!

I'd like to pay it back, starting with minor patches that I think could be 
useful to others. I can fork and watch on github, and generate PRs, but... Is 
there a document with guidelines on doing so? (I don't mean github 
instructions, more like "what you are looking for in good PRs") I saw 
reference to an agreement that should be signed? Mailing lists one can join 
to get the hang of etiquette and how the devs currently manage the process?

best regards -Ricardo

-- 
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.


Re: [web2py] Re: batch script - best way to reopen a closed database connection?

2013-09-26 Thread Ricardo Cárdenas
@michele, @niphlod, @Derek

My solution oddly turned out to be a combination of all of your 
suggestions! :)

On Postgres, Michele's snippet below works for me too. On MySQL it works, 
but then raises an exception (attached below). Apparently, upon exit web2py 
tries to close the dead MySQL connection, and MySQL complains (even though 
the connection had no outstanding transactions). The PostgreSQL behavior 
seems different; web2py is silent when trying to close a dead connection 
with no outstanding transactions.

So I tried db._adapter.close() right after the db.commit(). That eliminated 
the MySQL exception. In fact, if there are no pending transactions, 
db._adapter.close() is all that is needed.

Problem solved for me. But I wonder whether the dev's might consider 
exposing an explicit db.close() and db.open() to avoid calling 
db._adapter.close() 
and then DAL(...auto_import=True), for the use case where a script does a 
lot of processing sans database, and then resumes database use.

Sorry if this was TL;DR for most people... best regards -Ricardo



Traceback (most recent call last):
  File "/home/rcardenas/web2py/gluon/shell.py", line 231, in run
BaseAdapter.close_all_instances('commit')
  File "/home/rcardenas/web2py/gluon/dal.py", line 560, in 
close_all_instances
db._adapter.close(action)
  File "/home/rcardenas/web2py/gluon/dal.py", line 540, in close
getattr(self, action)()
  File "/home/rcardenas/web2py/gluon/dal.py", line 1740, in commit
if self.connection: return self.connection.commit()
OperationalError: (2013, 'Lost connection to MySQL server during query')

Traceback (most recent call last):
  File "web2py.py", line 33, in 
gluon.widget.start(cron=True)
  File "/home/rcardenas/web2py/gluon/widget.py", line 1120, in start
import_models=options.import_models, startfile=options.run)
  File "/home/rcardenas/web2py/gluon/shell.py", line 235, in run
BaseAdapter.close_all_instances('rollback')
  File "/home/rcardenas/web2py/gluon/dal.py", line 560, in 
close_all_instances
db._adapter.close(action)
  File "/home/rcardenas/web2py/gluon/dal.py", line 540, in close
getattr(self, action)()
  File "/home/rcardenas/web2py/gluon/dal.py", line 1743, in rollback
if self.connection: return self.connection.rollback()
_mysql_exceptions.OperationalError: (2006, 'MySQL server has gone away')



On Wednesday, September 25, 2013 8:36:01 AM UTC-5, Michele Comitini wrote:
>
>  
>
> -- Forwarded message ------
> From: Michele Comitini >
> Date: 2013/9/25
> Subject: Re: [web2py] Re: batch script - best way to reopen a closed 
> database connection?
> To: Ricardo Cárdenas 
>
> Try using the auto_import
>
> see the following:
>
> db.commit()
> sleep(20) # <-- here I stop and restart the postgresql service
> db=DAL('postgres://script:script@localhost/script',pool_size=1, 
> check_reserved=['all'], auto_import=True)
> print db(db.people).count()
>
>
>
> 2013/9/25 Ricardo Cárdenas >
>
>> Hi Michele, you're right, it's better to instantiate the connection when 
>> needed.
>>
>>  Since I have all the DAL() and define_tables() calls in db.py, I 
>> shouldn't have to rewrite the code elsewhere. I tried "import db" after the 
>> wait, but I guess it's not possible to import models/* because I got an 
>> import error. How do you suggest I implement your suggestion?
>>
>> thanks -Ricardo
>>
>> On Wednesday, September 25, 2013 4:50:38 AM UTC-5, Michele Comitini wrote:
>>
>>> Yes, but the connection in the pool will get dropped anyway.  After some 
>>> thought IMHO the correct way for you to fix the problem is:
>>> 
>>> ...wait...wait...
>>> db = DAL(...) 
>>> 
>>> db.commit() #<- commit or rollback as soon as possible
>>> ...wait...wait...
>>> db = DAL(...) 
>>> 
>>> db.commit() #<- commit or rollback as soon as possible
>>> 
>>>
>>> i.e. init the db instance right before using it.  This should avoid 
>>> timing out connections, with consequent data loss.  
>>> It fixes also the problem that keeping transactions open for such a long 
>>> time is no good for anything else trying to work on that database it could 
>>> cause all other connections/applications to stop until the transaction is 
>>> closed or timedout!
>>>
>>>
>>> 2013/9/25 Ricardo Cárdenas 
>>>
>>> @michele - No, I'm not doing a db.commit() -- because I don't use the db 
>>>> connection at all, until many minutes later, when

Re: [web2py] Re: batch script - best way to reopen a closed database connection?

2013-09-25 Thread Ricardo Cárdenas
@michele, @niphlod

I tried db.commit() and then waiting for more than wait_timeout (300 
seconds). I also tried db._adapter.reconnect(). Neither worked for me: 
MySQL on PA still raises OperationalError: (2013, 'Lost connection to MySQL 
server during query') after the wait. (If I wait just under 300 seconds, it 
works fine.) Any ideas? Could it be a problem with the MySQL adapter? My 
test code:


import time

def insert_user():
db.auth_user.insert(email='t...@test.com')

def user_count():
return db(db.auth_user.id<50).count()

wait = 320

insert_user()
db.commit()

print "Sleeping for {} seconds.".format(wait)
time.sleep(wait)

db._adapter.reconnect()
print "{} users found".format(user_count())

thanks and best regards -Ricardo


On Tuesday, September 24, 2013 5:16:20 PM UTC-5, Michele Comitini wrote:
>
> Did you remember to do a commit at each round?
>
> A long running script / daemon can do:
>
> db=DAL...
> 
>
> while True:
>
>db.commit()
>sleep(1000) # <- just for exampl i.e. don't do anything for a long time
>
> The DAL pushes the connection "back to sleep in the pool" [ :-) ] when 
> there is a commit.
> When one starts operating on the DAL instance (db) a connection is  taken 
> from the pool and *tested* for being functioning.
> If the connection is dead it's replaced by a new one.  Then a transaction 
> is started on that connection.
>
>  mic
>
>
> 2013/9/24 Ricardo Cárdenas >
>
>> Derek, thanks for your suggestion. Which is the preferred way to reopen 
>> the connection and define the tables?
>>
>> My db.py contains
>>
>> db = DAL(connection_string, options...)
>> db.define_table('table1', Field('f1' ...), Field('f2'...))
>> db.define_table(...)
>> db.define_table(...)
>> ...
>>
>> So ideally I wouldn't have to repeat this code in my script. Is it best I 
>> break out the DAL/define_tables calls into a file that I import both in my 
>> db.py and in my script.py?
>>
>>
>>
>> On Tuesday, September 24, 2013 4:45:09 PM UTC-5, Derek wrote:
>>>
>>> Each time you need to do work, you should open a new connection. You'd 
>>> think there is a large overhead in creating a connection, but there isn't.
>>>
>>> On Tuesday, September 24, 2013 2:33:24 PM UTC-7, Ricardo Cárdenas wrote:
>>>>
>>>> I have a web2py app running fine on pythonanywhere. I have a minor 
>>>> problem - I think I understand why it is happening, but would seek your 
>>>> advice as to how best to fix it.
>>>>
>>>> The app itself works fine. But I also run a scheduled task using PA's 
>>>> scheduler, by executing "python web2py.py -S appname -M -R 
>>>> appname/private/myscript.py". The script does some processing for a few 
>>>> minutes, and only then starts writing to the MySQL database.
>>>>
>>>> PA's MySQL database has wait_timeout set to 120 seconds. If my initial 
>>>> processing is less than wait_timeout, everything works fine. But when 
>>>> my initial processing exceeds wait_timeout, I get a 'Lost Connection 
>>>> to MySQL' error when my code tries to write to the database. I am 
>>>> using connection pooling in the call to the DAL, but I guess the 
>>>> connection 
>>>> instantiated by db.py file is not automatically kept warm nor is it 
>>>> automatically replaced by another good connection when it expires.
>>>>
>>>> What's the best practice here:
>>>>
>>>>- Is there a preferred way to ping the database every once in a 
>>>>while?
>>>>- Is there a preferred way to detect an expired DAL connection, and 
>>>>to request another one? 
>>>>
>>>> Thanks for any suggestions or pointers. Sorry if this is in the docs, 
>>>> couldn't find it. warm regards -Ricardo
>>>>
>>>>  -- 
>> 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 .
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>

-- 
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: batch script - best way to reopen a closed database connection?

2013-09-24 Thread Ricardo Cárdenas
@Derek - makes sense - I'll try this. thanks again.


On Tuesday, September 24, 2013 5:14:28 PM UTC-5, Derek wrote:
>
> import db.py  always, that should be your first line of a function.
>
> On Tuesday, September 24, 2013 2:55:21 PM UTC-7, Ricardo Cárdenas wrote:
>>
>> Derek, thanks for your suggestion. Which is the preferred way to reopen 
>> the connection and define the tables?
>>
>> My db.py contains
>>
>> db = DAL(connection_string, options...)
>> db.define_table('table1', Field('f1' ...), Field('f2'...))
>> db.define_table(...)
>> db.define_table(...)
>> ...
>>
>> So ideally I wouldn't have to repeat this code in my script. Is it best I 
>> break out the DAL/define_tables calls into a file that I import both in my 
>> db.py and in my script.py?
>>
>>
>>
>> On Tuesday, September 24, 2013 4:45:09 PM UTC-5, Derek wrote:
>>>
>>> Each time you need to do work, you should open a new connection. You'd 
>>> think there is a large overhead in creating a connection, but there isn't.
>>>
>>> On Tuesday, September 24, 2013 2:33:24 PM UTC-7, Ricardo Cárdenas wrote:
>>>>
>>>> I have a web2py app running fine on pythonanywhere. I have a minor 
>>>> problem - I think I understand why it is happening, but would seek your 
>>>> advice as to how best to fix it.
>>>>
>>>> The app itself works fine. But I also run a scheduled task using PA's 
>>>> scheduler, by executing "python web2py.py -S appname -M -R 
>>>> appname/private/myscript.py". The script does some processing for a few 
>>>> minutes, and only then starts writing to the MySQL database.
>>>>
>>>> PA's MySQL database has wait_timeout set to 120 seconds. If my initial 
>>>> processing is less than wait_timeout, everything works fine. But when 
>>>> my initial processing exceeds wait_timeout, I get a 'Lost Connection 
>>>> to MySQL' error when my code tries to write to the database. I am 
>>>> using connection pooling in the call to the DAL, but I guess the 
>>>> connection 
>>>> instantiated by db.py file is not automatically kept warm nor is it 
>>>> automatically replaced by another good connection when it expires.
>>>>
>>>> What's the best practice here:
>>>>
>>>>- Is there a preferred way to ping the database every once in a 
>>>>while?
>>>>- Is there a preferred way to detect an expired DAL connection, and 
>>>>to request another one?
>>>>
>>>> Thanks for any suggestions or pointers. Sorry if this is in the docs, 
>>>> couldn't find it. warm regards -Ricardo
>>>>
>>>>

-- 
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: batch script - best way to reopen a closed database connection?

2013-09-24 Thread Ricardo Cárdenas
@niphlod - db.reconnect() method does not exist, but 
db._adapter.reconnect() does. I'll try it now - though I'm a little 
reluctant to use an underscore_attribute that was probably meant to be 
private :)


On Tuesday, September 24, 2013 5:23:31 PM UTC-5, Niphlod wrote:
>
> if I'm not mistaken a simple db.reconnect() should do the trick.  or 
> db._adapter.reconnect() . But mcm has a point.
>

-- 
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.


Re: [web2py] Re: batch script - best way to reopen a closed database connection?

2013-09-24 Thread Ricardo Cárdenas
@michele - No, I'm not doing a db.commit() -- because I don't use the db 
connection at all, until many minutes later, when it fails.

However, you bring up an interesting point. Does this mean that if I 
db.commit() at the very beginning of my script (even if there is no 
outstanding transaction), I will in effect be pushing a connection to sleep?

Ricardo


On Tuesday, September 24, 2013 5:16:20 PM UTC-5, Michele Comitini wrote:
>
> Did you remember to do a commit at each round?
>
> A long running script / daemon can do:
>
> db=DAL...
> 
>
> while True:
>
>db.commit()
>sleep(1000) # <- just for exampl i.e. don't do anything for a long time
>
> The DAL pushes the connection "back to sleep in the pool" [ :-) ] when 
> there is a commit.
> When one starts operating on the DAL instance (db) a connection is  taken 
> from the pool and *tested* for being functioning.
> If the connection is dead it's replaced by a new one.  Then a transaction 
> is started on that connection.
>
>  mic
>
>
> 2013/9/24 Ricardo Cárdenas >
>
>> Derek, thanks for your suggestion. Which is the preferred way to reopen 
>> the connection and define the tables?
>>
>> My db.py contains
>>
>> db = DAL(connection_string, options...)
>> db.define_table('table1', Field('f1' ...), Field('f2'...))
>> db.define_table(...)
>> db.define_table(...)
>> ...
>>
>> So ideally I wouldn't have to repeat this code in my script. Is it best I 
>> break out the DAL/define_tables calls into a file that I import both in my 
>> db.py and in my script.py?
>>
>>
>>
>> On Tuesday, September 24, 2013 4:45:09 PM UTC-5, Derek wrote:
>>>
>>> Each time you need to do work, you should open a new connection. You'd 
>>> think there is a large overhead in creating a connection, but there isn't.
>>>
>>> On Tuesday, September 24, 2013 2:33:24 PM UTC-7, Ricardo Cárdenas wrote:
>>>>
>>>> I have a web2py app running fine on pythonanywhere. I have a minor 
>>>> problem - I think I understand why it is happening, but would seek your 
>>>> advice as to how best to fix it.
>>>>
>>>> The app itself works fine. But I also run a scheduled task using PA's 
>>>> scheduler, by executing "python web2py.py -S appname -M -R 
>>>> appname/private/myscript.py". The script does some processing for a few 
>>>> minutes, and only then starts writing to the MySQL database.
>>>>
>>>> PA's MySQL database has wait_timeout set to 120 seconds. If my initial 
>>>> processing is less than wait_timeout, everything works fine. But when 
>>>> my initial processing exceeds wait_timeout, I get a 'Lost Connection 
>>>> to MySQL' error when my code tries to write to the database. I am 
>>>> using connection pooling in the call to the DAL, but I guess the 
>>>> connection 
>>>> instantiated by db.py file is not automatically kept warm nor is it 
>>>> automatically replaced by another good connection when it expires.
>>>>
>>>> What's the best practice here:
>>>>
>>>>- Is there a preferred way to ping the database every once in a 
>>>>while?
>>>>- Is there a preferred way to detect an expired DAL connection, and 
>>>>to request another one? 
>>>>
>>>> Thanks for any suggestions or pointers. Sorry if this is in the docs, 
>>>> couldn't find it. warm regards -Ricardo
>>>>
>>>>  -- 
>> 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 .
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>

-- 
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: batch script - best way to reopen a closed database connection?

2013-09-24 Thread Ricardo Cárdenas
Derek, thanks for your suggestion. Which is the preferred way to reopen the 
connection and define the tables?

My db.py contains

db = DAL(connection_string, options...)
db.define_table('table1', Field('f1' ...), Field('f2'...))
db.define_table(...)
db.define_table(...)
...

So ideally I wouldn't have to repeat this code in my script. Is it best I 
break out the DAL/define_tables calls into a file that I import both in my 
db.py and in my script.py?



On Tuesday, September 24, 2013 4:45:09 PM UTC-5, Derek wrote:
>
> Each time you need to do work, you should open a new connection. You'd 
> think there is a large overhead in creating a connection, but there isn't.
>
> On Tuesday, September 24, 2013 2:33:24 PM UTC-7, Ricardo Cárdenas wrote:
>>
>> I have a web2py app running fine on pythonanywhere. I have a minor 
>> problem - I think I understand why it is happening, but would seek your 
>> advice as to how best to fix it.
>>
>> The app itself works fine. But I also run a scheduled task using PA's 
>> scheduler, by executing "python web2py.py -S appname -M -R 
>> appname/private/myscript.py". The script does some processing for a few 
>> minutes, and only then starts writing to the MySQL database.
>>
>> PA's MySQL database has wait_timeout set to 120 seconds. If my initial 
>> processing is less than wait_timeout, everything works fine. But when my 
>> initial processing exceeds wait_timeout, I get a 'Lost Connection to 
>> MySQL' error when my code tries to write to the database. I am using 
>> connection pooling in the call to the DAL, but I guess the connection 
>> instantiated by db.py file is not automatically kept warm nor is it 
>> automatically replaced by another good connection when it expires.
>>
>> What's the best practice here:
>>
>>- Is there a preferred way to ping the database every once in a while?
>>- Is there a preferred way to detect an expired DAL connection, and 
>>to request another one?
>>
>> Thanks for any suggestions or pointers. Sorry if this is in the docs, 
>> couldn't find it. warm regards -Ricardo
>>
>>

-- 
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] batch script - best way to reopen a closed database connection?

2013-09-24 Thread Ricardo Cárdenas
I have a web2py app running fine on pythonanywhere. I have a minor problem 
- I think I understand why it is happening, but would seek your advice as 
to how best to fix it.

The app itself works fine. But I also run a scheduled task using PA's 
scheduler, by executing "python web2py.py -S appname -M -R 
appname/private/myscript.py". The script does some processing for a few 
minutes, and only then starts writing to the MySQL database.

PA's MySQL database has wait_timeout set to 120 seconds. If my initial 
processing is less than wait_timeout, everything works fine. But when my 
initial processing exceeds wait_timeout, I get a 'Lost Connection to MySQL' 
error when my code tries to write to the database. I am using connection 
pooling in the call to the DAL, but I guess the connection instantiated by 
db.py file is not automatically kept warm nor is it automatically replaced 
by another good connection when it expires.

What's the best practice here:

   - Is there a preferred way to ping the database every once in a while?
   - Is there a preferred way to detect an expired DAL connection, and to 
   request another one?

Thanks for any suggestions or pointers. Sorry if this is in the docs, 
couldn't find it. warm regards -Ricardo

-- 
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.


Re: [web2py] geocode() return value

2013-09-24 Thread Ricardo Cárdenas
Hi Manuele,

Thanks for your email. (0,0) in effect represents two possible outcomes: "*I 
could not geocode this address*" and also "*please try again later*". How 
can I know if it makes sense to retry later?

best regards -Ricardo



On Tuesday, September 24, 2013 8:26:38 AM UTC-5, Manuele wrote:
>
>  Il 24/09/13 15:13, Ricardo Cárdenas ha scritto:
>  
> The gluon.tools geocode() function is great.
>
>  A minor suggestion. Right now it returns (0,0) on any execption. It 
> would be nice if the function distinguished between *unable to geocode 
> this address* and other problems (such as quota reached).
>
> why can't you consider (0,0) as the output for exception? :)
> If you prefer you can use assert to raise exception when geocode return 
> exactly (0,0)
>
> M.
>  

-- 
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] geocode() return value

2013-09-24 Thread Ricardo Cárdenas

Hi,

The gluon.tools geocode() function is great.

A minor suggestion. Right now it returns (0,0) on any execption. It would 
be nice if the function distinguished between *unable to geocode this 
address* and other problems (such as quota reached). Use case: I geocode 
addresses as they come in and store the resulting location in the database. 
If an address is un-geocodable, I'd like to mark it for no more retries; 
but with (0,0) I can't be sure if it's un-geocodable, or if we hit a 
network/quota/throttling/other problem.

warm regards -Ricardo

ps. Admiring web2py more every day. :)

ps2. When posting to this group via web, you are offered a list of tags. 
Would it make sense to add a "gluon" tag?

-- 
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: how to use last()?

2013-08-26 Thread Ricardo Cárdenas
Hello Dave,

You're almost there actually. You are correct that last() gives you a row 
object instead of a rows object. Then, the as_dict() converts the row 
object to a Python dict 
object, 
an object which maps keys (the field names) to values (the field values).

In your view, your for loop iterates over the keys, but prints the keys 
instead of the values. If you change the LI line to

{{=LI(logs[log])}}

you'll see the field values you are expecting. -Ricardo


On Monday, August 26, 2013 7:56:13 PM UTC-5, Dave S wrote:
>
> After reading 
> http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#first-and-last,
>  
> I was trying to use
>
> def my_ctlr:
> results = db().select(db.logtable.ALL, orderby=db.logtable.field1)
> logs = results.last().as_dict()
> return dict(logs = logs)
>
>
>
> with a view using this
> {{extend 'layout.html'}}
> Hi
>
>
> 
> {{for log in logs:}}
> {{=LI(log)}}
> {{pass}}
> 
>
>
> and was expecting to get a row object (if I remove the .last(), I get a 
> bunch of row objects).  Instead, I get several li items displayed that 
> apparently strings, and happen to match the field names.  Since they are 
> strings, I can't apply .values() or .items().
>
> If I replace the loop with 
> {{=BEAUTIFY(response._vars)}}
>
> (as in generic.html)
> I get the fieldnames and their values displayed in the programmer-friendly 
> format of the BEAUTIFY operator.
>
> It is obvious that I don't know what I'm doing, especially in regards to 
> the last() operator.  How can I get to having the values display as the LI 
> contents?
>
> Version is 2.5.1-stable+timestamp.2013.06.06.15.39.19
> (Running on Rocket 1.2.6)
>
> Thanks.
>
> /dps
>
>

-- 

--- 
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.


Re: [web2py] Re: database shootout

2013-05-28 Thread Ricardo Cárdenas
Just got email from a PA developer saying they're hoping to have Postgres
9.2 out next month. Good news!


On Tue, May 28, 2013 at 8:23 AM, Cliff Kachinske  wrote:

> They [PythonAnywhere] list Psycopg2 among the installed gadgets.  This
> will definitely push me in their direction.

-- 

--- 
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.




Re: [web2py] Re: hiding a column in smartgrid

2013-05-27 Thread Ricardo Cárdenas
Thanks Calvin! Exactly what I needed.

Is there be a way to hide it at the grid level, but let it be readable when
viewing the record detail? (I can do without it -- just curious really.)
best regards


On Mon, May 27, 2013 at 1:21 PM, Calvin  wrote:

> before the call to SQLFORM.smartgrid, add
>
> db.tablename.linkfield.readable=False
>
>
> On Monday, 27 May 2013 23:57:31 UTC+8, Ricardo Cárdenas wrote:
>>
>> Hi,
>>
>> My model contains a URL field, and I'm displaying the model in a
>> SQLFORM.smartgrid. I don't want to show the whole URL, but I do want the
>> user to be able to visit the URL directly from the grid. So I use the
>> 'links' parameter to SQLFORM.smartgrid. It works very nicely:
>>
>> links=[dict(header="Link", body=lambda row: A("Go", 
>> _href=row.linkfield,_target
>> ="_blank"))]
>>
>>
>> But it doesn't work if I remove 'linkfield' from the 'fields' parameter
>> to SQLFORM.smartgrid. That's because, according to the 
>> documentation<http://web2py.com/books/default/chapter/29/07#SQLFORM.grid-and-SQLFORM.smartgrid>
>> :
>>
>> *'fields' is a list of fields to be fetched from the database. It is
>>> also used to determine which fields to be shown in the grid view.*
>>
>>
>> In my use case, I want the field to be fetched, but not shown. Is there a
>> "smart" (pun intended :) way to do this?
>>
>> best regards -Ricardo
>>
>> ps. I'd prefer not to mess around with jquery, and anyway it seems the
>>  does not have a CSS class or id that would allow me to hide an
>> undesired column.
>>
>  --
>
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/wKKlDWIuA3U/unsubscribe?hl=en.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
<http://alum.mit.edu/www/rcardenas> Ricardo Cárdenas|
http://alum.mit.edu/www/rcardenas | Perú: (+51) 96176-3092 | USA: +1 650
395-7772 | México: +52 (155) 2691-9958

-- 

--- 
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.




Re: [web2py] database shootout

2013-05-27 Thread Ricardo Cárdenas
Among RDBMSs, I personally prefer Postgres too, for many of the reasons 
mentioned - quality of build and add-ons, platform availability, SQL 
compliance, optional commercial support, Oracle compatibility.

But another factor to consider is deployment on IaaS/PaaS options. Heroku 
and OpenShift can provision Postgres and MySQL; Google App Engine and 
PythonAnywhere only provide MySQL.

PythonAnywhere is a terrific option; I'm a bit surprised they don't offer 
Postgres. Maybe someone with influence on the PythonAnywhere folks can give 
them a nudge? Could push many projects their way.



On Thursday, March 7, 2013 4:36:29 PM UTC-5, Richard wrote:
>
> Also you should consider that DAL adapter are not all equal on quality, 
> quality for a given adapter is "correlated" to the user base for a given 
> (my interpretation) and since Postgres is largely used it adapter is really 
> good. Notice that there is two adapter for postgres psycopg2 and pg8000 the 
> former is much better then the latter that is still experimental I think.
>
> Richard
>
>
> On Thu, Mar 7, 2013 at 4:15 PM, BlueShadow 
> > wrote:
>
>> Thanks Richard. 
>> Postgres 
>> Pros: Many User in web2py, open source
>> Cons: Speed
>>
>> MySQL
>> Pros: Speed
>>
>>
>> On Thursday, March 7, 2013 9:57:48 PM UTC+1, Richard wrote:
>>
>>> Postgres, full open source, supported by a consortium, commercial 
>>> support available (ex.: Enterprise DB), build-in Foreing key constraint, PL 
>>> SQL (so you can migrate to Oracle), Still with commercial build you are 
>>> still at one/ten the price of Oracle DB...
>>>
>>> Also, I think many serious web2py user here are using Postgres.
>>>
>>> You will have Cons about speed... And Pros for MySQL for the inverse 
>>> (MySQL speedier).
>>>
>>> The rule of thumd is, if you need speed on retreiving information (you 
>>> mostly do select query) go with MySQL. It is reputed faster on select.
>>>
>>> Richard
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Thu, Mar 7, 2013 at 3:41 PM, BlueShadow  wrote:
>>>
 Hi guys so I learned that using SQLlite for me wasn't a great 
 choice(thanks Niphlod). But since I started using databases when I started 
 to use web2py. I got no clue what database to use. I used sqllite because 
 it was in the welcome app and it worked while having my site offline and 
 with me being the only user. I know the choice is mostly personal 
 prefrence 
 but I thought give it a trail and ask you guys why you chose your 
 particular database.
 It would be really nice if you could tell me a few pros and cons.
 I researched a little on PostgreSQL, MySQL and SQLite the informations 
 I got were sometimes contradicting.
 I got about 2 times a writing command per page per visit. (keeping 
 track of views for articles) but apparently thats already too much for 
 SQLite.

  -- 
  
 --- 
 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.

 For more options, visit 
 https://groups.google.com/**groups/opt_out
 .
  
  

>>>
>>>  -- 
>>  
>> --- 
>> 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 .
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

-- 

--- 
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] hiding a column in smartgrid

2013-05-27 Thread Ricardo Cárdenas
Hi,

My model contains a URL field, and I'm displaying the model in a 
SQLFORM.smartgrid. I don't want to show the whole URL, but I do want the 
user to be able to visit the URL directly from the grid. So I use the 
'links' parameter to SQLFORM.smartgrid. It works very nicely:

links=[dict(header="Link", body=lambda row: A("Go", _href=row.linkfield,_target
="_blank"))]


But it doesn't work if I remove 'linkfield' from the 'fields' parameter to 
SQLFORM.smartgrid. That's because, according to the 
documentation
:

*'fields' is a list of fields to be fetched from the database. It is also 
> used to determine which fields to be shown in the grid view.*


In my use case, I want the field to be fetched, but not shown. Is there a 
"smart" (pun intended :) way to do this?

best regards -Ricardo

ps. I'd prefer not to mess around with jquery, and anyway it seems the  
does not have a CSS class or id that would allow me to hide an undesired 
column.

-- 

--- 
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: upgrade to 2.4.6 breaks existing code. function replace in psycopg2

2013-04-15 Thread Ricardo Cárdenas
Hello Massimo,

I have psql 9.1.8; a quick console test shows replace() working fine. My 
read of the error is that the replace function is being handed incorrect 
types. Notice the following fragment in the SQL generated from the DAL 
(posted below):

REPLACE(my_group.id,'%','%%')

The first argument is an integer. I assume replace() cannot handle that. 
best regards -Ricardo


On Monday, April 15, 2013 9:56:53 AM UTC-5, Massimo Di Pierro wrote:
>
> Which postgresql version are you using? It is complain there is not 
> replace function but there should be:
>
> http://www.postgresql.org/docs/8.1/static/functions-string.html
>
> On Saturday, 13 April 2013 15:23:04 UTC-5, Ricardo Cárdenas wrote:
>>
>> Hi niphlod, here's the code:
>>
>> p = db.my_post
>> g = db.my_group
>> m = db.my_membership
>> query = ((m.my_user == auth.user.id) &
>> (m.my_group == g.id) &
>> (p.groups.contains(g.id)))
>> rows= db(query).select(p.id, p.status, orderby=~p.creation_date,distinct
>> =True)
>>
>> The SQL generated is:
>>
>> SELECT DISTINCT my_post.id, my_post.status FROM my_post, 
>> my_membership,my_group WHERE 
>> (((my_membership.my_user = 1) AND (my_membership.my_group = my_group.id))AND 
>> (CAST(my_post.groups AS CHAR(512)) LIKE (('%|' || (REPLACE((REPLACE(
>> my_group.id,'%','%%')),'|','||')) || '|%' ORDER BY my_post.creation_date 
>> DESC;
>>
>> and the error again:
>>
>>  function replace(integer, unknown, 
>> unknown) does not exist LINE 1: ...ost.groups AS CHAR(512)) LIKE (('%|' || 
>> (REPLACE((REPLACE(me... ^ HINT: No function matches the given name and 
>> argument types. You might need to add explicit type casts.
>>
>> Thanks and best regards -Ricardo
>>
>>
>> On Saturday, April 13, 2013 10:42:52 AM UTC-5, Niphlod wrote:
>>>
>>> can you post the code that generates the error and the query generated 
>>> bu the DAL ( i.e. print db(..)._select() with the underscore) ?
>>>
>>> On Saturday, April 13, 2013 4:28:55 PM UTC+2, Ricardo Cárdenas wrote:
>>>>
>>>> Just upgraded to 2.4.6-stable+timestamp.2013.04.12.23.32.51.
>>>>
>>>> Code that worked in my prior version (I think trunk 2013.04.02? sorry 
>>>> don't have the exact version on-hand) now breaks. I get the following 
>>>> error:
>>>>
>>>>  function replace(integer, unknown, 
>>>> unknown) does not exist LINE 1: ...ost.groups AS CHAR(512)) LIKE (('%|' || 
>>>> (REPLACE((REPLACE(me... ^ HINT: No function matches the given name and 
>>>> argument types. You might need to add explicit type casts
>>>>
>>>> The ticket comes from a 3-table query on PostgreSQL that uses 
>>>> .CONTAINS. (Perhaps related to this 
>>>> issue<https://groups.google.com/forum/?fromgroups=#!searchin/web2py/contains/web2py/WKmzK6prO20/SRkZ2SF5YlwJ>.)
>>>>  
>>>> When I simplify the query to a simple db(table).select(), the code works 
>>>> (though of course it doesn't bring back the results I am looking for).
>>>>
>>>> I just thought I'd throw it out there in case someone has worked on 
>>>> that code recently..
>>>>
>>>> best regards -Ricardo
>>>>
>>>

-- 

--- 
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: upgrade to 2.4.6 breaks existing code. function replace in psycopg2

2013-04-13 Thread Ricardo Cárdenas
Hi niphlod, here's the code:

p = db.my_post
g = db.my_group
m = db.my_membership
query = ((m.my_user == auth.user.id) &
(m.my_group == g.id) &
(p.groups.contains(g.id)))
rows= db(query).select(p.id, p.status, orderby=~p.creation_date,distinct
=True)

The SQL generated is:

SELECT DISTINCT my_post.id, my_post.status FROM my_post, my_membership,my_group 
WHERE 
(((my_membership.my_user = 1) AND (my_membership.my_group = my_group.id))AND 
(CAST(my_post.groups AS CHAR(512)) LIKE (('%|' || (REPLACE((REPLACE(my_group
.id,'%','%%')),'|','||')) || '|%' ORDER BY my_post.creation_date DESC;

and the error again:

 function replace(integer, unknown, 
unknown) does not exist LINE 1: ...ost.groups AS CHAR(512)) LIKE (('%|' || 
(REPLACE((REPLACE(me... ^ HINT: No function matches the given name and 
argument types. You might need to add explicit type casts.

Thanks and best regards -Ricardo


On Saturday, April 13, 2013 10:42:52 AM UTC-5, Niphlod wrote:
>
> can you post the code that generates the error and the query generated bu 
> the DAL ( i.e. print db(..)._select() with the underscore) ?
>
> On Saturday, April 13, 2013 4:28:55 PM UTC+2, Ricardo Cárdenas wrote:
>>
>> Just upgraded to 2.4.6-stable+timestamp.2013.04.12.23.32.51.
>>
>> Code that worked in my prior version (I think trunk 2013.04.02? sorry 
>> don't have the exact version on-hand) now breaks. I get the following error:
>>
>>  function replace(integer, unknown, 
>> unknown) does not exist LINE 1: ...ost.groups AS CHAR(512)) LIKE (('%|' || 
>> (REPLACE((REPLACE(me... ^ HINT: No function matches the given name and 
>> argument types. You might need to add explicit type casts
>>
>> The ticket comes from a 3-table query on PostgreSQL that uses .CONTAINS. 
>> (Perhaps related to this 
>> issue<https://groups.google.com/forum/?fromgroups=#!searchin/web2py/contains/web2py/WKmzK6prO20/SRkZ2SF5YlwJ>.)
>>  
>> When I simplify the query to a simple db(table).select(), the code works 
>> (though of course it doesn't bring back the results I am looking for).
>>
>> I just thought I'd throw it out there in case someone has worked on that 
>> code recently..
>>
>> best regards -Ricardo
>>
>

-- 

--- 
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] upgrade to 2.4.6 breaks existing code. function replace in psycopg2

2013-04-13 Thread Ricardo Cárdenas
Just upgraded to 2.4.6-stable+timestamp.2013.04.12.23.32.51.

Code that worked in my prior version (I think trunk 2013.04.02? sorry don't 
have the exact version on-hand) now breaks. I get the following error:

 function replace(integer, unknown, 
unknown) does not exist LINE 1: ...ost.groups AS CHAR(512)) LIKE (('%|' || 
(REPLACE((REPLACE(me... ^ HINT: No function matches the given name and 
argument types. You might need to add explicit type casts

The ticket comes from a 3-table query on PostgreSQL that uses .CONTAINS. 
(Perhaps related to this 
issue.)
 
When I simplify the query to a simple db(table).select(), the code works 
(though of course it doesn't bring back the results I am looking for).

I just thought I'd throw it out there in case someone has worked on that 
code recently..

best regards -Ricardo

-- 

--- 
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: 'list:reference', contains, Mysql, instr

2013-04-03 Thread Ricardo Cárdenas
Massimo,

Yes, it works. The DAL now generates the following SQL, which does bring 
back the results I was expecting:



I should mention that when I tested this model with the default SQLite 
driver, I got an error ticket. It is probably unrelated to this commit, but 
here it is just in case:

 no such function: CONCAT

Traceback (most recent call last):
  File "/home/ricardo/src/web2py/gluon/restricted.py", line 212, in 
restricted
exec ccode in environment
  File 
"/home/ricardo/src/web2py/applications/welcome/controllers/default.py", 
line 85, in 
  File "/home/ricardo/src/web2py/gluon/globals.py", line 194, in 
self._caller = lambda f: f()
  File 
"/home/ricardo/src/web2py/applications/welcome/controllers/default.py", 
line 29, in myinterestingmovies
rows = db(query).select(db.movie.name, distinct=True)
  File "/home/ricardo/src/web2py/gluon/dal.py", line 9865, in select
return adapter.select(self.query,fields,attributes)
  File "/home/ricardo/src/web2py/gluon/dal.py", line 2226, in select
return super(SQLiteAdapter, self).select(query, fields, attributes)
  File "/home/ricardo/src/web2py/gluon/dal.py", line 1684, in select
return self._select_aux(sql,fields,attributes)
  File "/home/ricardo/src/web2py/gluon/dal.py", line 1649, in _select_aux
self.execute(sql)
  File "/home/ricardo/src/web2py/gluon/dal.py", line 1762, in execute
return self.log_execute(*a, **b)
  File "/home/ricardo/src/web2py/gluon/dal.py", line 1756, in log_execute
ret = self.cursor.execute(*a, **b)
OperationalError: no such function: CONCAT

thanks for your time. best regards -Ricardo


On Monday, April 1, 2013 9:31:59 AM UTC-5, Massimo Di Pierro wrote:
>
> Fixed in trunk. Please check it out.
>
> On Monday, 1 April 2013 08:59:20 UTC-5, Ricardo Cárdenas wrote:
>>
>> Hi, I think I've run into this problem too (Web2py 2.4.5-stable, 
>> PostgreSQL 9.1.8.).
>>
>> I have a list of movies; each may be tagged with one or more genres. Each 
>> user in the system may show interest in one or more genres:
>>
>> db.define_table('genre', Field('name'), format='%(name)s')
>> db.define_table('movie', Field('name'), Field('genres', 'list:reference 
>> genre'))
>> db.define_table('interest',
>> Field('spectator', 'reference auth_user'), Field('genre', 'reference 
>> genre'))
>>
>> I would have expected this query to return all movies tagged with genres 
>> the user is interested in:
>>
>> def myinterestingmovies():
>> query = (
>> (db.interest.spectator == auth.user.id) &
>> (db.interest.genre == db.genre.id) &
>> (db.movie.genres.contains(db.genre.id)))
>> rows = db(query).select(db.movie.name, distinct=True)
>> return locals()
>>
>> But no rows are returned. The SQL generated by the DAL is:
>>
>> SELECT DISTINCT movie.name FROM genre, movie, interest WHERE 
>> (((interest.spectator 
>> = 2) AND (interest.genre = genre.id)) AND (CAST(movie.genres AS CHAR(512
>> )) LIKE '%|genre.id|%'));
>>
>> The column name is inserted within the LIKE literal. In PostgreSQL, the 
>> following does yield the expected list of movies:
>>
>> SELECT DISTINCT movie.name FROM interest, genre, movie WHERE 
>> (((interest.spectator 
>> = 1) AND (interest.genre = genre.id)) AND (CAST(movie.genres AS CHAR(512
>> )) LIKE '%|' || genre.id || '|%'));
>>
>> Would that be a good solution to rewrite CONTAINS, or is there a better 
>> way to rewrite my query? best regards -Ricardo
>>
>>
>> On Monday, January 21, 2013 9:55:40 AM UTC-5, pablo@uam.es wrote:
>>>
>>>   Hello:
>>>   I was getting incorrect SQL from statements like:
>>>
>>> db(db.paper.authors.contains(person.id)).select()
>>>
>>> where
>>>
>>> db.define_table('paper',
>>> Field('title'),
>>> Field('authors', 'list:reference person'),
>>> )
>>>
>>>
>>>   so I rewrote dal.MySQLAdapter.CONTAINS from:
>>>
>>> def CONTAINS(self, first, second):
>>> if first.type in ('string', 'text'):
>>> key = '%'+str(second).replace('%','%%')+'%'
>>> elif first.type.startswith('list:'):
>>> key = 
>>> '%|'+str(second).replace('|',&#x

[web2py] Re: 'list:reference', contains, Mysql, instr

2013-04-01 Thread Ricardo Cárdenas
@niphlod - indeed, the use of expressions rather than values is not 
mentioned specifically in Ch. 
6<http://web2py.com/books/default/chapter/29/06#list:,-and-contains>, 
though it is also not discounted. The added functionality would seem useful 
in many situations, while retaining the use of fixed values as well... 
thanks -Ricardo


On Monday, April 1, 2013 9:38:50 AM UTC-5, Niphlod wrote:
>
> @ricardo: this is done under the assumption that contains() takes a field 
>  it's nowhere documented in the book that this should work.
> contains() (just a few moments before the latest commit by Massimo) was 
> supposed to take a "fixed" value, not a column.
>
>
> On Monday, April 1, 2013 4:31:59 PM UTC+2, Massimo Di Pierro wrote:
>>
>> Fixed in trunk. Please check it out.
>>
>> On Monday, 1 April 2013 08:59:20 UTC-5, Ricardo Cárdenas wrote:
>>>
>>> Hi, I think I've run into this problem too (Web2py 2.4.5-stable, 
>>> PostgreSQL 9.1.8.).
>>>
>>> I have a list of movies; each may be tagged with one or more genres. 
>>> Each user in the system may show interest in one or more genres:
>>>
>>> db.define_table('genre', Field('name'), format='%(name)s')
>>> db.define_table('movie', Field('name'), Field('genres', 'list:reference 
>>> genre'))
>>> db.define_table('interest',
>>> Field('spectator', 'reference auth_user'), Field('genre', 'reference 
>>> genre'))
>>>
>>> I would have expected this query to return all movies tagged with genres 
>>> the user is interested in:
>>>
>>> def myinterestingmovies():
>>> query = (
>>> (db.interest.spectator == auth.user.id) &
>>> (db.interest.genre == db.genre.id) &
>>> (db.movie.genres.contains(db.genre.id)))
>>> rows = db(query).select(db.movie.name, distinct=True)
>>> return locals()
>>>
>>> But no rows are returned. The SQL generated by the DAL is:
>>>
>>> SELECT DISTINCT movie.name FROM genre, movie, interest WHERE (((interest
>>> .spectator = 2) AND (interest.genre = genre.id)) AND (CAST(movie.genres 
>>> AS CHAR(512)) LIKE '%|genre.id|%'));
>>>
>>> The column name is inserted within the LIKE literal. In PostgreSQL, the 
>>> following does yield the expected list of movies:
>>>
>>> SELECT DISTINCT movie.name FROM interest, genre, movie WHERE (((interest
>>> .spectator = 1) AND (interest.genre = genre.id)) AND (CAST(movie.genres 
>>> AS CHAR(512)) LIKE '%|' || genre.id || '|%'));
>>>
>>> Would that be a good solution to rewrite CONTAINS, or is there a better 
>>> way to rewrite my query? best regards -Ricardo
>>>
>>>
>>> On Monday, January 21, 2013 9:55:40 AM UTC-5, pablo@uam.es wrote:
>>>>
>>>>   Hello:
>>>>   I was getting incorrect SQL from statements like:
>>>>
>>>> db(db.paper.authors.contains(person.id)).select()
>>>>
>>>> where
>>>>
>>>> db.define_table('paper',
>>>> Field('title'),
>>>> Field('authors', 'list:reference person'),
>>>> )
>>>>
>>>>
>>>>   so I rewrote dal.MySQLAdapter.CONTAINS from:
>>>>
>>>> def CONTAINS(self, first, second):
>>>> if first.type in ('string', 'text'):
>>>> key = '%'+str(second).replace('%','%%')+'%'
>>>> elif first.type.startswith('list:'):
>>>> key = 
>>>> '%|'+str(second).replace('|','||').replace('%','%%')+'|%'
>>>> return '(%s LIKE %s)' % 
>>>> (self.expand(first),self.expand(key,'string'))
>>>>
>>>> into:
>>>>
>>>> def CONTAINS(self, first, second):
>>>> if first.type in ('string', 'text'):
>>>> key = '%'+str(second).replace('%','%%')+'%'
>>>> elif first.type.startswith('list:reference'):
>>>> return 'INSTR(%s, %s)'%(first, str(second))
>>>> elif first.type.startswith('list:'):
>>>> key = 
>>>> '%|'+str(second).replace('|','||').replace('%','%%')+'|%'
>>>> return '(%s LIKE %s)' % 
>>>> (self.expand(first),self.expand(key,'string'))
>>>>
>>>> now the above query works, but that's in MySQL, not SQLite, which 
>>>> apparently does not have  a INSTR operation, despite the fact that it is 
>>>> advertised!
>>>>
>>>> https://www.sqlite.org/lang_corefunc.html
>>>>
>>>> Can anybody think of a solution that works in more databases
>>>>
>>>

-- 

--- 
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: 'list:reference', contains, Mysql, instr

2013-04-01 Thread Ricardo Cárdenas
Hi, I think I've run into this problem too (Web2py 2.4.5-stable, PostgreSQL 
9.1.8.).

I have a list of movies; each may be tagged with one or more genres. Each 
user in the system may show interest in one or more genres:

db.define_table('genre', Field('name'), format='%(name)s')
db.define_table('movie', Field('name'), Field('genres', 'list:reference 
genre'))
db.define_table('interest',
Field('spectator', 'reference auth_user'), Field('genre', 'reference 
genre'))

I would have expected this query to return all movies tagged with genres 
the user is interested in:

def myinterestingmovies():
query = (
(db.interest.spectator == auth.user.id) &
(db.interest.genre == db.genre.id) &
(db.movie.genres.contains(db.genre.id)))
rows = db(query).select(db.movie.name, distinct=True)
return locals()

But no rows are returned. The SQL generated by the DAL is:

SELECT DISTINCT movie.name FROM genre, movie, interest WHERE 
(((interest.spectator 
= 2) AND (interest.genre = genre.id)) AND (CAST(movie.genres AS CHAR(512))LIKE 
'%|genre.id|%'));

The column name is inserted within the LIKE literal. In PostgreSQL, the 
following does yield the expected list of movies:

SELECT DISTINCT movie.name FROM interest, genre, movie WHERE 
(((interest.spectator 
= 1) AND (interest.genre = genre.id)) AND (CAST(movie.genres AS CHAR(512))LIKE 
'%|' || genre.id || '|%'));

Would that be a good solution to rewrite CONTAINS, or is there a better way 
to rewrite my query? best regards -Ricardo


On Monday, January 21, 2013 9:55:40 AM UTC-5, pablo@uam.es wrote:
>
>   Hello:
>   I was getting incorrect SQL from statements like:
>
> db(db.paper.authors.contains(person.id)).select()
>
> where
>
> db.define_table('paper',
> Field('title'),
> Field('authors', 'list:reference person'),
> )
>
>
>   so I rewrote dal.MySQLAdapter.CONTAINS from:
>
> def CONTAINS(self, first, second):
> if first.type in ('string', 'text'):
> key = '%'+str(second).replace('%','%%')+'%'
> elif first.type.startswith('list:'):
> key = '%|'+str(second).replace('|','||').replace('%','%%')+'|%'
> return '(%s LIKE %s)' % 
> (self.expand(first),self.expand(key,'string'))
>
> into:
>
> def CONTAINS(self, first, second):
> if first.type in ('string', 'text'):
> key = '%'+str(second).replace('%','%%')+'%'
> elif first.type.startswith('list:reference'):
> return 'INSTR(%s, %s)'%(first, str(second))
> elif first.type.startswith('list:'):
> key = '%|'+str(second).replace('|','||').replace('%','%%')+'|%'
> return '(%s LIKE %s)' % 
> (self.expand(first),self.expand(key,'string'))
>
> now the above query works, but that's in MySQL, not SQLite, which 
> apparently does not have  a INSTR operation, despite the fact that it is 
> advertised!
>
> https://www.sqlite.org/lang_corefunc.html
>
> Can anybody think of a solution that works in more databases
>

-- 

--- 
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: "4 minutes ago"

2013-03-22 Thread Ricardo Cárdenas
Got it - thanks.

On Friday, March 22, 2013 8:27:32 PM UTC-5, Ricardo Cárdenas wrote:
>
> My google-fu has not helped me come up with an answer...
>
> Django has a set of template filters they call "humanize" which will add a 
> nice touch to data. (Java also has a lib called PrettyTime.) For example it 
> will convert "Fri Mar 22, 20:23" into "4 minutes ago", or "Fri Mar 21" into 
> "yesterday". Is there something similar in web2py?
>
> best regards -Ricardo
>

-- 

--- 
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] "4 minutes ago"

2013-03-22 Thread Ricardo Cárdenas
My google-fu has not helped me come up with an answer...

Django has a set of template filters they call "humanize" which will add a 
nice touch to data. (Java also has a lib called PrettyTime.) For example it 
will convert "Fri Mar 22, 20:23" into "4 minutes ago", or "Fri Mar 21" into 
"yesterday". Is there something similar in web2py?

best regards -Ricardo

-- 

--- 
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] list:reference widget depends on order of define_table statements

2013-03-20 Thread Ricardo Cárdenas
I define two tables: category and product. Product can belong in multiple 
categories; M:M relationship expressed thus:

db.define_table('category', Field('name'))
db.define_table('product', Field('name'), Field('categories', 'list:reference 
category'))

When I define the controller for adding a product to the database:

def new():
form = SQLFORM(db.product)
return dict(form=form)

It works fine. I get my Multiple Selection widget on the Product form. I 
can select multiple categories, as expected.

But if I switch the order of the two define_tables statements, such that 
the product table is defined prior to the category table, I don't get the 
widget I expected -- just an empty input field. Is this expected behavior, 
or am I missing something? Is it better practice to rearrange my table 
definitions, or perhaps to explicit any widgets/requires after all table 
definitions? (I couldn't find a reference to this in chapter 6 of the book.)

In my simplistic example, it's no big deal, but in other cases it would be 
less appealing to rearrange the table definitions. For example, if I wanted 
to base an M:M relationship off the auth_user table, I'd have to place the 
auth.define_tables after my define_tables.

best regards -Ricardo

-- 

--- 
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.