[web2py] Re: cpdb errors

2013-01-08 Thread mart
Hi Simon,

Thanks for the update! This is interesting. One question, are you making 
use of cache.py? I had huge memory problems a while ago and I didn't have 
time to debug. A colleague was testing on windows and each time it crapped 
out his system where he was forced to do a hard reboot (but seemed to work 
fine on Linux). I ended up pulling it out until such time as I could 
upgrade to a later web2py release (I believe Massimo had made a fix in a 
later release than I was using that addressed the memory leak issue (but I 
can't remember any more details on this, so I may be out of my tree :) ). 
Anyways, I was just wondering if you were using an older web2py version ?

Thanks,
Mart :)



On Monday, January 7, 2013 8:01:01 PM UTC-8, Simon Ashley wrote:

 Thanks Mart,

 That gives me some clues and a renewed focus. Issue may be with postgres 
 (at least the install I had - has been deleted and will be installed). Will 
 also try ubuntu environment. Will report back ...

  ... confirmed the memory leak with postgres (eventually absorbs all 
 available memory) under win7. The same csv file imports fine under SQLite 
 and mySQL. Connection strings are:

 db = DAL('sqlite://storage.sqlite', lazy_tables=True, 
 migrate=True,fake_migrate
 =False, check_reserved=['all','mysql', 'postgres', 'postgres_nonreserved'
 ])
 db = DAL('postgres://postgres:xx@localhost:5433/yyy', lazy_tables=True
 , migrate=True, fake_migrate=False, check_reserved=['all','mysql', 
 'postgres', 'postgres_nonreserved'])
 db = DAL('mysql://root:xx@localhost:3306/zzz', lazy_tables=True,migrate
 =True, fake_migrate=False, check_reserved=['all','mysql', 'postgres', 
 'postgres_nonreserved'])



-- 





Re: [web2py] Re: anyone tried jQuery svg?

2013-01-08 Thread Jonas Fredriksson
Thanks for the replies. d3js looks very interesting, I will look into that.

On Tue, Jan 8, 2013 at 3:56 AM, Andrew W awillima...@gmail.com wrote:
 I haven't either, but I'd recommend a look at d3js.org, if you want to use
 svg.

 I've done something similar to this one, using a web2py generated json data
 feed - data driven layout !

 http://mbostock.github.com/d3/talk/2016/bundle.html






 On Monday, January 7, 2013 7:29:10 AM UTC+13, villas wrote:

 Look at what he does here:

 http://keith-wood.name/svgBasics.html

 See the drawInitial function.
 You need to load it, put it into a document.ready function or something.


 On Sunday, January 6, 2013 2:14:13 PM UTC, jonas wrote:

 Hi.

 Has anyone here tried the jQuery svg lib http://keith-wood.name/svg.html?

 I tried to use it in web2py but with no success.

 the necessary lib was imported: script
 src={{=URL('static','js/jquery/jquery.svg.js')}}/script
 but is seems that the svg function is not present :

 div class=testsvg should be here/div

 script

 $('.test').svg();

 var svg=$('.test').svg('get');
 svg.circle(130, 75, 50, {fill: 'none', stroke: 'red', strokeWidth: 3});

 /script

 the above snippet doesn't work. anyone tried this?

 --




-- 





Re: [web2py] Re: self join on postgres

2013-01-08 Thread paolo.vall...@gmail.com
Thanks for this explanations! To add more info, I can say that the elements
on left column are naturally ordered, I have thousands of
records(~5000record/day) for each station but only a few
station_id(~5-10stations totally).
Instead of making a complex query, a cleaner approach would be to run the
query with only the join and then do a loop in python to remove the
unnecessary lines.

Moreover, right now, the worst think is that since I switched to postgres
the initial query (the one with only the leftjoin) is taking minutes to be
executed (almost 4m) against just few seconds on sqlite. I set an index on
the mac field through pgAdmin and the results are really better,
unfortunately this hack is not portable, is there a way to define indexes
from web2py?

Paolo


2013/1/8 Niphlod niph...@gmail.com

 after a full day at work I may lack the usual fantasy, but what you're
 trying to do can't be even achieved by a relatively simple windowed
 function
 What you're trying to do is recursing. way out of DAL reach (if you
 want to do it in a single query)
 Trying to explain better

 Real data helps.
 For every station_id record with the same mac address you want to find the
 min gathered_on record from the same table (with another station_id) and
 subtract it for every next possible match.

 One thing is requiring

 2013-01-21 11:23:35;a;127167;2013-01-21 11:23:45;a;127168
 2013-01-21 11:23:00;a;127169;2013-01-21 11:23:45;a;127168
 That can be accomplished by something like this

 select * from (
 selectstart_point.gathered_on,start_point.mac,start_point.id,
 end_point.gathered_on,end_point.mac,end_point.id,
 row_number() over (partition by start_point.id order by end_point.
 gathered_on) as filter_field
 from record as start_point
 inner join
 record as end_point
 on start_point.mac = end_point.mac
 and start_point.gathered_on = end_point.gathered_on
 where start_point.station_id = 13
 and end_point.station_id = 14
 ) as q
 where q.filter_field = 1

 because for the record 127167 the next record with another station_id is
 127168, but then for the 127169 you don't want the 127168, you want 127170
 because 127168 has been booked before by 127169.

 Honestly, (beware of the lack of fantasy :P) I'd do a loop in python
 instead of using recursing in the db itself unless you have zillions of
 windows (i.e. you have 1000 station_id = 13 and 1000 station_id = 14, and
 1000 distinct station_id), just because it's more readable than what it
 would be needed in raw sql

 --







-- 
 Paolo

-- 





[web2py] Re: cpdb errors

2013-01-08 Thread Simon Ashley
That's a negative on cache.py. 
It's from a nightly build pulled about 5 days ago.
The csv in question is about 150k records. 
(have pruned it down to a test of 10 records, and they import OK).
Has about 140 fields, quite a few nulls, and have compensated for the 
adapter's postgres decimal precision issue.
(its the largest table in the app, and others appear to import OK)

Still building a u12.10 environment under vmware to test 
(linux skills are rusty but coming back)

-- 





[web2py] Re: Web2Py on AWS Elastic Beanstalk

2013-01-08 Thread Simon Ashley
Isaac, if you do a search on this group, you'll find a bit more info. 
Failing that, we may need to do the same in the next few days  ... 

-- 





[web2py] How to write a script that inserts data into a web2py database table

2013-01-08 Thread sasogeek
I have a database table shown below:

db=DAL(sqlite://storage.sqlite)

db.define_table('content',
Field('author'),
Field('time', 'datetime', update=request.now),
Field('text', 'text'),
Field('picture', readable=False),


Question is, how do I connect to the database via a script, and what is the 
syntax for inserting data into a web2py database table via a script? I want 
to know this because I'll be looping through a list and inserting data from 
the list to the database as I loop through...

-- 





[web2py] Re: Bar encoded text fields

2013-01-08 Thread Alan Etkin
El martes, 8 de enero de 2013 01:25:02 UTC-3, howesc escribió:

 shouldn't non-list data types not accept list input?  this sounds like an 
 un-expected side effect to me.


I don't know, does web2py restrict input strictly by default in other cases 
(raising exceptions, etc)? The behavior should be consistent. For example, 
on insert/update, DAL tries to adapt values casting different types for 
compatibility.

Since bar encoded data is used only for list:type I think it is safe to 
change the way it handles other field type input, raising exceptions or 
casting to a conventional field default type.

-- 





Re: [web2py] geodal

2013-01-08 Thread Paolo valleri
Hi all, I have a simple problem, how I can extract values of a single point?
I found that there are the functions ST_X, and ST_Y.
Please find attached a patch that add them to dal and to the postgres 
adapter, I haven't put them neither to MSSQLAdapter nor to 
SQLITESpatiaLiteAdapter because I don't have those db to run tests.
Now you can do something like:
print db(db.city).select(db.city.latlng,
 db.city.latlng.st_x(), 
 db.city.latlng.st_y())

city.latlng,ST_X(city.latlng),ST_Y(city.latlng)
POINT(51.507335 -0.127683),51.507335,-0.127683
POINT(41.901514 12.460774),41.901514,12.460774
POINT(40.851775 14.268124),40.851775,14.268124
The geometry field MUST contain only point otherwise it raises an error.

Hope it helps

Paolo



On Sunday, January 6, 2013 5:29:52 PM UTC+1, Paolo valleri wrote:

 Hi Massimo, I found an other strange behavior. I tried to capitalize the 
 name of a field, as follows:
 db.define_table('test_geo', 
 Field('loc_Test','geometry()'),
 )
 and I get this error:

 Traceback (most recent call last):
   File /home/paolo/Dropbox/git/web2py/gluon/restricted.py, line 212, in 
 restricted
 exec ccode in environment
   File /home/paolo/Dropbox/git/web2py/applications/bikend/models/db.py 
 http://127.0.0.1:8000/admin/default/edit/bikend/models/db.py, line 585, in 
 module
 db.test_geo.insert(loc_Test=geoPoint(45.89096,11.0401399))
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 7977, in insert
 ret =  self._db._adapter.insert(self,self._listify(fields))
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1175, in insert
 raise e
 ProgrammingError: column loc_test of relation test_geo does not exist
 LINE 1: INSERT INTO test_geo(loc_Test) VALUES (ST_GeomFromText('POIN...

 and so I tried to insert without the capitalize and I get this error:

 Traceback (most recent call last):
   File /home/paolo/Dropbox/git/web2py/gluon/restricted.py, line 212, in 
 restricted
 exec ccode in environment
   File /home/paolo/Dropbox/git/web2py/applications/bikend/models/db.py 
 http://127.0.0.1:8000/admin/default/edit/bikend/models/db.py, line 585, in 
 module
 db.test_geo.insert(loc_test=geoPoint(45.89096,11.0401399))
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 7977, in insert
 ret =  self._db._adapter.insert(self,self._listify(fields))
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 7915, in _listify
 'Field %s does not belong to the table' % name)
 SyntaxError: Field loc_test does not belong to the table


 finally, I redefined the table as was before, (without any capital latter) 
 and I get this:

 Traceback (most recent call last):
   File /home/paolo/Dropbox/git/web2py/gluon/restricted.py, line 212, in 
 restricted
 exec ccode in environment
   File /home/paolo/Dropbox/git/web2py/applications/bikend/models/db.py 
 http://127.0.0.1:8000/admin/default/edit/bikend/models/db.py, line 583, in 
 module
 db.test_geo.insert(Name='paolo')
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 7313, in 
 __getattr__
 return self.lazy_define_table(tablename,*fields,**args)
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 7281, in 
 lazy_define_table
 polymodel=polymodel)
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 965, in 
 create_table
 fake_migrate=fake_migrate)
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1068, in 
 migrate_table
 self.execute(sub_query)
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1714, in execute
 return self.log_execute(*a, **b)
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1708, in 
 log_execute
 ret = self.cursor.execute(*a, **b)
 ProgrammingError: syntax error at or near SELECT
 LINE 1: ALTER TABLE test_geo ADD loc_test__tmp SELECT AddGeometryCol...



 Hope it helps,
 Paolo






 I changed the name of the field:


 On Sunday, January 6, 2013 5:01:32 PM UTC+1, Paolo valleri wrote:

 well done! All the former tests worked. I will investigate more the 
 others functions as soon as possible.

 Paolo


 On Sunday, January 6, 2013 4:28:13 PM UTC+1, Massimo Di Pierro wrote:

 One more try please. 

 On Sunday, 6 January 2013 02:11:09 UTC-6, Paolo valleri wrote:

 Hi Massimo, I've tried the same 3 tests.
 The first one failed, it was working before though, the ticket:

 Traceback (most recent call last):
   File /home/paolo/Dropbox/git/web2py/gluon/restricted.py, line 212, in 
 restricted
 exec ccode in environment
   File /home/paolo/Dropbox/git/web2py/applications/bikend/models/db.py 
 http://127.0.0.1:8000/admin/default/edit/bikend/models/db.py, line 586, 
 in module
 print db(query)._select(db.test_geo.id, db.test_geo.loc_test)
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 8928, in _select
 return adapter._select(self.query,fields,attributes)
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1478, in _select
 sql_f = ', 

[web2py] Re: Bar encoded text fields

2013-01-08 Thread Alan Etkin
 For example, on insert/update, DAL tries to adapt values casting 
different types for compatibility.

Sorry, the above is wrong. Some adapters in dal.py have that behavior, not 
the DAL class

-- 





[web2py] Can i do this select db(db.table1.id in [1,2,3]).select() ?

2013-01-08 Thread António Ramos
Can i do this  select db(db.table1.id in [1,2,3]).select() ?

thank you
António

-- 





[web2py] Re: Maintain Attendance details of students

2013-01-08 Thread Cler
Thank you,
  That was very helpful...
But I am unable to display the way u specified the SQL form. But I got ur 
method of maintaining the database.

On Monday, January 7, 2013 4:38:42 AM UTC+5:30, Alan Etkin wrote:

 El domingo, 6 de enero de 2013 13:32:49 UTC-3, Cler escribió:

 Hello,
   Is there any way to maintain attendance records of students using 
 web2py?


 Let me know if this helped:

 http://www.web2pyslices.com/slice/show/1582/a-chart-with-db-io-for-class-attendance-check


-- 





[web2py] Logging user login

2013-01-08 Thread António Ramos
hello
how do i log each time a user logs in?

thank you

António

-- 





[web2py] Re: Can i do this select db(db.table1.id in [1,2,3]).select() ?

2013-01-08 Thread villas
Try:
db(db.table1.id.belongs([1,2,3])).select() 

You can always print the SQL to your console so you can check it is what 
you expect...
db(db.table1.id.belongs([1,2,3]))._select() 

(Note the underline:  _select)


On Tuesday, January 8, 2013 11:44:28 AM UTC, Ramos wrote:

 Can i do this  select db(db.table1.id in [1,2,3]).select() ?

 thank you
 António


-- 





Re: [web2py] Re: app about page

2013-01-08 Thread António Ramos
Its nice to see this graph. Pleas add labels in the graph.

Its not documented but i think it is worth it.
Now i can see that my app started 20 days ago and i have about 300 lines of
code.
When i report my app to my boss i can tell him this just for statistics
sake.
Thank you
António

2013/1/5 Massimo Di Pierro massimo.dipie...@gmail.com

 It counts the lines of lines in the code (.html and .py files only). I use
 it to monitor when my students work on projects.


 On Friday, 4 January 2013 04:36:28 UTC-6, Ramos wrote:

 hello.
 what does it mean the graph in the about page under Project progress?


 Thank you
 António

  --





-- 





[web2py] Re: Can i do this select db(db.table1.id in [1,2,3]).select() ?

2013-01-08 Thread Anthony
http://web2py.com/books/default/chapter/29/06#belongs

On Tuesday, January 8, 2013 6:44:28 AM UTC-5, Ramos wrote:
 Can i do this  select db(db.table1.id in [1,2,3]).select() ?
 
 
 thank you
 António

-- 





[web2py] Re: Associate a db record with a logged in user

2013-01-08 Thread Dave Cenker
Thank you very much! I knew it had to be simple. I just didn't infer that 
information from the way the book explained it. Your help is much 
appreciated!
 

On Monday, January 7, 2013 3:31:33 PM UTC-5, Dave Cenker wrote:

 This seems so elementary, but I can't seem to find out how to do it in the 
 book or googling the group ...
  
 I have several users defined and when that user is logged in and is 
 creating a db record that is specific to that user, I want it to be 
 automatically assigned to him/her.
  
 For example, given a model that defines a checking account,
  
 db.define_table('account',
   Field('type'),
   Field('balance'),
   Field('user', db.auth_user))
  
 How can I use the crud.create forms to automatically assign the value of 
 the user field on the account model to the currently logged in user?
  
 Thanks,
 Dave
  


-- 





[web2py] Re: Logging user login

2013-01-08 Thread Niphlod
if you dind't change the default settings, you can find already a line for 
every log-in action into the auth_event table.

Il giorno martedì 8 gennaio 2013 12:53:16 UTC+1, Ramos ha scritto:

 hello
 how do i log each time a user logs in?

 thank you

 António


-- 





[web2py] Re: How to write a script that inserts data into a web2py database table

2013-01-08 Thread Massimo Di Pierro
You can do

begin script.py
from gluon import DAL, Field
db=DAL(sqlite://storage.sqlite, path='/path/to/app/databases')
db.define_table('content',
Field('author'),
Field('time', 'datetime', update=request.now),
Field('text', 'text'))
db.content.insert()
/end
$ pyhton script.py 

or 

begin script.py
db.content.insert()
/end
$ pyhton web2py.py -S yourapp -M -R script.py 


On Tuesday, 8 January 2013 05:07:08 UTC-6, sasogeek wrote:

 I have a database table shown below:

 db=DAL(sqlite://storage.sqlite)

 db.define_table('content',
 Field('author'),
 Field('time', 'datetime', update=request.now),
 Field('text', 'text'))

 Question is, how do I connect to the database via a script, and what is 
 the syntax for inserting data into a web2py database table via a script? I 
 want to know this because I'll be looping through a list and inserting data 
 from the list to the database as I loop through...


-- 





Re: [web2py] geodal

2013-01-08 Thread Massimo Di Pierro
In trunk. How about the previous issue? Is that still open? If so, can you 
please open a ticket? Thanks.

On Tuesday, 8 January 2013 05:31:28 UTC-6, Paolo valleri wrote:

 Hi all, I have a simple problem, how I can extract values of a single 
 point?
 I found that there are the functions ST_X, and ST_Y.
 Please find attached a patch that add them to dal and to the postgres 
 adapter, I haven't put them neither to MSSQLAdapter nor to 
 SQLITESpatiaLiteAdapter because I don't have those db to run tests.
 Now you can do something like:
 print db(db.city).select(db.city.latlng,
  db.city.latlng.st_x(), 
  db.city.latlng.st_y())

 city.latlng,ST_X(city.latlng),ST_Y(city.latlng)
 POINT(51.507335 -0.127683),51.507335,-0.127683
 POINT(41.901514 12.460774),41.901514,12.460774
 POINT(40.851775 14.268124),40.851775,14.268124
 The geometry field MUST contain only point otherwise it raises an error.

 Hope it helps

 Paolo



 On Sunday, January 6, 2013 5:29:52 PM UTC+1, Paolo valleri wrote:

 Hi Massimo, I found an other strange behavior. I tried to capitalize the 
 name of a field, as follows:
 db.define_table('test_geo', 
 Field('loc_Test','geometry()'),
 )
 and I get this error:

 Traceback (most recent call last):
   File /home/paolo/Dropbox/git/web2py/gluon/restricted.py, line 212, in 
 restricted
 exec ccode in environment
   File /home/paolo/Dropbox/git/web2py/applications/bikend/models/db.py 
 http://127.0.0.1:8000/admin/default/edit/bikend/models/db.py, line 585, in 
 module
 db.test_geo.insert(loc_Test=geoPoint(45.89096,11.0401399))
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 7977, in insert
 ret =  self._db._adapter.insert(self,self._listify(fields))
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1175, in insert
 raise e
 ProgrammingError: column loc_test of relation test_geo does not exist
 LINE 1: INSERT INTO test_geo(loc_Test) VALUES (ST_GeomFromText('POIN...

 and so I tried to insert without the capitalize and I get this error:

 Traceback (most recent call last):
   File /home/paolo/Dropbox/git/web2py/gluon/restricted.py, line 212, in 
 restricted
 exec ccode in environment
   File /home/paolo/Dropbox/git/web2py/applications/bikend/models/db.py 
 http://127.0.0.1:8000/admin/default/edit/bikend/models/db.py, line 585, in 
 module
 db.test_geo.insert(loc_test=geoPoint(45.89096,11.0401399))
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 7977, in insert
 ret =  self._db._adapter.insert(self,self._listify(fields))
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 7915, in _listify
 'Field %s does not belong to the table' % name)
 SyntaxError: Field loc_test does not belong to the table


 finally, I redefined the table as was before, (without any capital 
 latter) and I get this:

 Traceback (most recent call last):
   File /home/paolo/Dropbox/git/web2py/gluon/restricted.py, line 212, in 
 restricted
 exec ccode in environment
   File /home/paolo/Dropbox/git/web2py/applications/bikend/models/db.py 
 http://127.0.0.1:8000/admin/default/edit/bikend/models/db.py, line 583, in 
 module
 db.test_geo.insert(Name='paolo')
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 7313, in 
 __getattr__
 return self.lazy_define_table(tablename,*fields,**args)
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 7281, in 
 lazy_define_table
 polymodel=polymodel)
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 965, in 
 create_table
 fake_migrate=fake_migrate)
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1068, in 
 migrate_table
 self.execute(sub_query)
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1714, in execute
 return self.log_execute(*a, **b)
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1708, in 
 log_execute
 ret = self.cursor.execute(*a, **b)
 ProgrammingError: syntax error at or near SELECT
 LINE 1: ALTER TABLE test_geo ADD loc_test__tmp SELECT AddGeometryCol...



 Hope it helps,
 Paolo






 I changed the name of the field:


 On Sunday, January 6, 2013 5:01:32 PM UTC+1, Paolo valleri wrote:

 well done! All the former tests worked. I will investigate more the 
 others functions as soon as possible.

 Paolo


 On Sunday, January 6, 2013 4:28:13 PM UTC+1, Massimo Di Pierro wrote:

 One more try please. 

 On Sunday, 6 January 2013 02:11:09 UTC-6, Paolo valleri wrote:

 Hi Massimo, I've tried the same 3 tests.
 The first one failed, it was working before though, the ticket:

 Traceback (most recent call last):
   File /home/paolo/Dropbox/git/web2py/gluon/restricted.py, line 212, in 
 restricted
 exec ccode in environment
   File /home/paolo/Dropbox/git/web2py/applications/bikend/models/db.py 
 http://127.0.0.1:8000/admin/default/edit/bikend/models/db.py, line 586, 
 in module
 print db(query)._select(db.test_geo.id, db.test_geo.loc_test)
   File 

Re: [web2py] Re: Logging user login

2013-01-08 Thread António Ramos
great!
thk

2013/1/8 Niphlod niph...@gmail.com

 if you dind't change the default settings, you can find already a line for
 every log-in action into the auth_event table.

 Il giorno martedì 8 gennaio 2013 12:53:16 UTC+1, Ramos ha scritto:

 hello
 how do i log each time a user logs in?

 thank you

 António

  --





-- 





[web2py] Re: Associate a db record with a logged in user

2013-01-08 Thread Massimo Di Pierro
You can do:

Field('user', db.auth_user, default=auth.user_id, writable=False))

Anyway, type and user are not valid field names. They work with sqlite 
but will break with postgresql and other databases.

On Monday, 7 January 2013 14:31:33 UTC-6, Dave Cenker wrote:

 This seems so elementary, but I can't seem to find out how to do it in the 
 book or googling the group ...
  
 I have several users defined and when that user is logged in and is 
 creating a db record that is specific to that user, I want it to be 
 automatically assigned to him/her.
  
 For example, given a model that defines a checking account,
  
 db.define_table('account',
   Field('type'),
   Field('balance'),
   Field('user', db.auth_user))
  
 How can I use the crud.create forms to automatically assign the value of 
 the user field on the account model to the currently logged in user?
  
 Thanks,
 Dave
  


-- 





Re: [web2py] geodal

2013-01-08 Thread Paolo valleri
Hi Massimo, good to know that the patch is in trunk but I it is only for 
the postgres adapter, I can try to define the same functions for the other 
adapter but then someone has to check if they works or not.

For what concern the other issue I will open I ticket, the main problem is 
that web2py makes all the common fields name lower while it store the 'gis' 
fields as is. I have just tried this:
db.define_table('test_geo1_name', 
Field('name_P', 'string'),
Field('location_P','geometry()'),
)
In the db I have the field *name_p* and *location_P* respectively. To fix 
it, I added in dal.py .lower() at line 832:
ftype = ftype % dict(schema=schema,
 tablename=tablename,
 fieldname=field_name.lower(), srid=srid,
 dimension=dimension)
And now in the db I have the field *name_p* and *location_p* respectively

Paolo





On Tuesday, January 8, 2013 3:48:56 PM UTC+1, Massimo Di Pierro wrote:

 In trunk. How about the previous issue? Is that still open? If so, can you 
 please open a ticket? Thanks.

 On Tuesday, 8 January 2013 05:31:28 UTC-6, Paolo valleri wrote:

 Hi all, I have a simple problem, how I can extract values of a single 
 point?
 I found that there are the functions ST_X, and ST_Y.
 Please find attached a patch that add them to dal and to the postgres 
 adapter, I haven't put them neither to MSSQLAdapter nor to 
 SQLITESpatiaLiteAdapter because I don't have those db to run tests.
 Now you can do something like:
 print db(db.city).select(db.city.latlng,
  db.city.latlng.st_x(), 
  db.city.latlng.st_y())

 city.latlng,ST_X(city.latlng),ST_Y(city.latlng)
 POINT(51.507335 -0.127683),51.507335,-0.127683
 POINT(41.901514 12.460774),41.901514,12.460774
 POINT(40.851775 14.268124),40.851775,14.268124
 The geometry field MUST contain only point otherwise it raises an error.

 Hope it helps

 Paolo



 On Sunday, January 6, 2013 5:29:52 PM UTC+1, Paolo valleri wrote:

 Hi Massimo, I found an other strange behavior. I tried to capitalize the 
 name of a field, as follows:
 db.define_table('test_geo', 
 Field('loc_Test','geometry()'),
 )
 and I get this error:

 Traceback (most recent call last):
   File /home/paolo/Dropbox/git/web2py/gluon/restricted.py, line 212, in 
 restricted
 exec ccode in environment
   File /home/paolo/Dropbox/git/web2py/applications/bikend/models/db.py 
 http://127.0.0.1:8000/admin/default/edit/bikend/models/db.py, line 585, 
 in module
 db.test_geo.insert(loc_Test=geoPoint(45.89096,11.0401399))
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 7977, in insert
 ret =  self._db._adapter.insert(self,self._listify(fields))
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1175, in insert
 raise e
 ProgrammingError: column loc_test of relation test_geo does not exist
 LINE 1: INSERT INTO test_geo(loc_Test) VALUES (ST_GeomFromText('POIN...

 and so I tried to insert without the capitalize and I get this error:

 Traceback (most recent call last):
   File /home/paolo/Dropbox/git/web2py/gluon/restricted.py, line 212, in 
 restricted
 exec ccode in environment
   File /home/paolo/Dropbox/git/web2py/applications/bikend/models/db.py 
 http://127.0.0.1:8000/admin/default/edit/bikend/models/db.py, line 585, 
 in module
 db.test_geo.insert(loc_test=geoPoint(45.89096,11.0401399))
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 7977, in insert
 ret =  self._db._adapter.insert(self,self._listify(fields))
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 7915, in _listify
 'Field %s does not belong to the table' % name)
 SyntaxError: Field loc_test does not belong to the table


 finally, I redefined the table as was before, (without any capital 
 latter) and I get this:

 Traceback (most recent call last):
   File /home/paolo/Dropbox/git/web2py/gluon/restricted.py, line 212, in 
 restricted
 exec ccode in environment
   File /home/paolo/Dropbox/git/web2py/applications/bikend/models/db.py 
 http://127.0.0.1:8000/admin/default/edit/bikend/models/db.py, line 583, 
 in module
 db.test_geo.insert(Name='paolo')
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 7313, in 
 __getattr__
 return self.lazy_define_table(tablename,*fields,**args)
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 7281, in 
 lazy_define_table
 polymodel=polymodel)
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 965, in 
 create_table
 fake_migrate=fake_migrate)
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1068, in 
 migrate_table
 self.execute(sub_query)
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1714, in execute
 return self.log_execute(*a, **b)
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1708, in 
 log_execute
 ret = self.cursor.execute(*a, **b)
 ProgrammingError: syntax error at or near SELECT
 LINE 1: ALTER TABLE test_geo ADD 

[web2py] Re: Question about multiple OAuth (Twitter or Facebook) Problem.

2013-01-08 Thread Ahmed Janim
I'm also facing this issue, can anyone help !
Thanks

-- 





[web2py] how to prevent delete processing from ondelete callback?

2013-01-08 Thread Michael Schoonover
How can I prevent the SQLFORM from deleting a record?  I have an ondelete 
callback that I want to do the deletion, and I don't want the form to 
subsequently attempt to delete the same record upon return from the 
callback.

Thanks in advance,
Mike Schoonover

-- 





[web2py] Re: subforms / formsets / form cloning imprementation

2013-01-08 Thread Henrique Pantarotto
I've been researching about this since my last post, and just to be clear, 
this is exactly what I need to 
do: http://railscasts.com/episodes/196-nested-model-form-part-1 (please 
watch minute 1:00 of this video).

So I wonder if it is possible to use web2py to create nested forms such as 
django's formsets 
(https://docs.djangoproject.com/en/dev/topics/forms/formsets/) or Ruby on 
Rail's Active Record Nested Attributes 
(http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html)?


Thanks

On Monday, January 7, 2013 5:02:01 AM UTC-2, Henrique Pantarotto wrote:

 Hello everybody!

 I'm quite new to Python and web2py, but I consumed all of web2py's 
 wonderful documentation at the last few days and I'm quite amazed at this 
 wonderful framework. But there's a feature that I need that I couldn't find 
 a way to easily implement it.

 The application that I'm developing requires extensive use of form cloning 
 within a single web page, done dynamically at the client side.  I'm not 
 really sure how to call this technique, so I found a bit hard to find 
 information regarding this at this mailing list's archive.

 What I want to accomplish can be easily understood viewing the screenshots 
 from this tool: http://www.mdelrosso.com/sheepit/

 I already have my own (ugly) jquery code to create the forms dynamically, 
 and of course I could validate it manually on web2py's side, but I was 
 looking into an easier implementation using something like FORM or SQLFORM. 
 Like I said, I'm very new to web2py and python, and I have no idea how 
 django works, but I think I need to accomplish something similar to this: 
 https://docs.djangoproject.com/en/dev/topics/forms/formsets/

 I tried searching this mailing list archive and I found a couple of 
 discussions from people trying to do the same thing, but I didn't find a 
 solution.

 https://groups.google.com/forum/#!topic/web2py/ssaSj6v9Wu8/discussion
 https://groups.google.com/d/topic/web2py/UK8NZ1VMlNk/discussion

 But these are threads from 2011

 There's also this guy asking something similar a couple of months ago: 
 https://groups.google.com/d/topic/web2py/IPMz4FylT2k/discussion and 
 http://stackoverflow.com/questions/13215902/web2py-possible-to-submit-multiple-forms-with-a-single-submit-button/13215926#13215926but
  the solution presented didn't seem very elegant.

 Anyway, I would really appreciate any help on this.


 Thanks, Henrique.



-- 





[web2py] Custom authentication provider

2013-01-08 Thread Ignacio Ocampo
Hi,

I'm working with my own authentication provider as: *
auth.settings.login_form=MyAuth()*, all *works correctly*.

I need an additional field from default auth_user table definition, I used: 
*auth.settings.extra_fields['auth_user'] = [Field('**employee_id**', 
'text')]*, works correctly (the value of this field is provided by MyAuth() 
to reference another system, ergo, in web2py it's would be treated as a 
simple text).

The final schema is:

CREATE TABLE auth_user(
id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name CHAR(128),
last_name CHAR(128),
email CHAR(512),
password CHAR(512),
registration_key CHAR(512),
reset_password_key CHAR(512),
registration_id CHAR(512)
, *employee_id* TEXT);

In MyAuth() class, I have the method get_user(self), which web2py call in 
the login process to get user details. At the end of this method, I return:

user = dict(first_name=response['attributes']['cn'][0], 
last_name=response['attributes']['cn'][0], 
username=response['attributes']['uid'][0], 
registration_id=response['attributes']['uid'][0], *employee_id*
=response['attributes']['*employee_id*'][0])

All fields are updated correctly, except the *employee_id*, that is the 
additional field.

*Hypothesis 1*: I don't know if web2py is updating only default fields from 
the auth_user table (and because employee_id are not default field, it's no 
updated).
*Hypothesis 2*: The name of the additional field *employee_id* is malformed 
(because the last part _id is used to reference another table and 
commonly is INT type and web2py don't know how to handle this, since there 
is no the *employee* table).

Thank you.

-- 





[web2py] Re: how to prevent delete processing from ondelete callback?

2013-01-08 Thread Derek
From the 
bookhttp://web2py.com/books/default/chapter/29/06#before-and-after-callbacks
:
The return values of these callback should be None or False. If any of the 
_before_* callback returns a True value it will abort the actual 
insert/update/delete operation.

I'm guessing the 'return true' would break the chain, same as it does in 
the 'before' - but i'm not sure.

On Tuesday, January 8, 2013 9:00:41 AM UTC-7, Michael Schoonover wrote:

 How can I prevent the SQLFORM from deleting a record?  I have an ondelete 
 callback that I want to do the deletion, and I don't want the form to 
 subsequently attempt to delete the same record upon return from the 
 callback.

 Thanks in advance,
 Mike Schoonover


-- 





[web2py] Re: Custom authentication provider

2013-01-08 Thread Niphlod
hypothesis 2 is off the table

BTW: saying that you have a method that returns a dict and stating that 
that method doesn't update a field lacks of the key point.. 
*Who*writes/updates the auth_user table in your custom class ?

On Tuesday, January 8, 2013 5:36:39 PM UTC+1, Ignacio Ocampo wrote:

 Hi,

 I'm working with my own authentication provider as: *
 auth.settings.login_form=MyAuth()*, all *works correctly*.

 I need an additional field from default auth_user table definition, I 
 used: *auth.settings.extra_fields['auth_user'] = [Field('**employee_id**', 
 'text')]*, works correctly (the value of this field is provided by 
 MyAuth() to reference another system, ergo, in web2py it's would be treated 
 as a simple text).

 The final schema is:

 CREATE TABLE auth_user(
 id INTEGER PRIMARY KEY AUTOINCREMENT,
 first_name CHAR(128),
 last_name CHAR(128),
 email CHAR(512),
 password CHAR(512),
 registration_key CHAR(512),
 reset_password_key CHAR(512),
 registration_id CHAR(512)
 , *employee_id* TEXT);

 In MyAuth() class, I have the method get_user(self), which web2py call in 
 the login process to get user details. At the end of this method, I return:

 user = dict(first_name=response['attributes']['cn'][0], 
 last_name=response['attributes']['cn'][0], 
 username=response['attributes']['uid'][0], 
 registration_id=response['attributes']['uid'][0], *employee_id*
 =response['attributes']['*employee_id*'][0])

 All fields are updated correctly, except the *employee_id*, that is the 
 additional field.

 *Hypothesis 1*: I don't know if web2py is updating only default fields 
 from the auth_user table (and because employee_id are not default field, 
 it's no updated).
 *Hypothesis 2*: The name of the additional field *employee_id* is 
 malformed (because the last part _id is used to reference another table 
 and commonly is INT type and web2py don't know how to handle this, since 
 there is no the *employee* table).

 Thank you.


-- 





Re: [web2py] Re: self join on postgres

2013-01-08 Thread Derek
No way to set an index... perhaps you could use caching.

On Tuesday, January 8, 2013 1:27:46 AM UTC-7, Paolo valleri wrote:

 Thanks for this explanations! To add more info, I can say that the 
 elements on left column are naturally ordered, I have thousands of 
 records(~5000record/day) for each station but only a few 
 station_id(~5-10stations totally). 
 Instead of making a complex query, a cleaner approach would be to run the 
 query with only the join and then do a loop in python to remove the 
 unnecessary lines.

 Moreover, right now, the worst think is that since I switched to postgres 
 the initial query (the one with only the leftjoin) is taking minutes to be 
 executed (almost 4m) against just few seconds on sqlite. I set an index on 
 the mac field through pgAdmin and the results are really better, 
 unfortunately this hack is not portable, is there a way to define indexes 
 from web2py?

 Paolo


 2013/1/8 Niphlod nip...@gmail.com javascript:

 after a full day at work I may lack the usual fantasy, but what you're 
 trying to do can't be even achieved by a relatively simple windowed 
 function
 What you're trying to do is recursing. way out of DAL reach (if you 
 want to do it in a single query)
 Trying to explain better

 Real data helps.
 For every station_id record with the same mac address you want to find 
 the min gathered_on record from the same table (with another station_id) 
 and subtract it for every next possible match.

 One thing is requiring

 2013-01-21 11:23:35;a;127167;2013-01-21 11:23:45;a;127168
 2013-01-21 11:23:00;a;127169;2013-01-21 11:23:45;a;127168
 That can be accomplished by something like this

 select * from (
 selectstart_point.gathered_on,start_point.mac,start_point.id,
 end_point.gathered_on,end_point.mac,end_point.id, 
 row_number() over (partition by start_point.id order by end_point.
 gathered_on) as filter_field
 from record as start_point
 inner join
 record as end_point
 on start_point.mac = end_point.mac
 and start_point.gathered_on = end_point.gathered_on
 where start_point.station_id = 13
 and end_point.station_id = 14
 ) as q
 where q.filter_field = 1

 because for the record 127167 the next record with another station_id is 
 127168, but then for the 127169 you don't want the 127168, you want 127170 
 because 127168 has been booked before by 127169. 

 Honestly, (beware of the lack of fantasy :P) I'd do a loop in python 
 instead of using recursing in the db itself unless you have zillions of 
 windows (i.e. you have 1000 station_id = 13 and 1000 station_id = 14, and 
 1000 distinct station_id), just because it's more readable than what it 
 would be needed in raw sql

 -- 
  
  
  




 -- 
  Paolo 


-- 





[web2py] Re: Custom authentication provider

2013-01-08 Thread Ignacio Ocampo
I only return a dict in the get_user, web2py does all the work.

web2py call the get_user method, and web2py update the auth_user table with 
the dict values.

I don't write/update the auth_user table in my custom class.

On Tuesday, January 8, 2013 11:05:04 AM UTC-6, Niphlod wrote:

 hypothesis 2 is off the table

 BTW: saying that you have a method that returns a dict and stating that 
 that method doesn't update a field lacks of the key point.. 
 *Who*writes/updates the auth_user table in your custom class ?

 On Tuesday, January 8, 2013 5:36:39 PM UTC+1, Ignacio Ocampo wrote:

 Hi,

 I'm working with my own authentication provider as: *
 auth.settings.login_form=MyAuth()*, all *works correctly*.

 I need an additional field from default auth_user table definition, I 
 used: *auth.settings.extra_fields['auth_user'] = [Field('**employee_id**', 
 'text')]*, works correctly (the value of this field is provided by 
 MyAuth() to reference another system, ergo, in web2py it's would be treated 
 as a simple text).

 The final schema is:

 CREATE TABLE auth_user(
 id INTEGER PRIMARY KEY AUTOINCREMENT,
 first_name CHAR(128),
 last_name CHAR(128),
 email CHAR(512),
 password CHAR(512),
 registration_key CHAR(512),
 reset_password_key CHAR(512),
 registration_id CHAR(512)
 , *employee_id* TEXT);

 In MyAuth() class, I have the method get_user(self), which web2py call in 
 the login process to get user details. At the end of this method, I return:

 user = dict(first_name=response['attributes']['cn'][0], 
 last_name=response['attributes']['cn'][0], 
 username=response['attributes']['uid'][0], 
 registration_id=response['attributes']['uid'][0], *employee_id*
 =response['attributes']['*employee_id*'][0])

 All fields are updated correctly, except the *employee_id*, that is the 
 additional field.

 *Hypothesis 1*: I don't know if web2py is updating only default fields 
 from the auth_user table (and because employee_id are not default field, 
 it's no updated).
 *Hypothesis 2*: The name of the additional field *employee_id* is 
 malformed (because the last part _id is used to reference another table 
 and commonly is INT type and web2py don't know how to handle this, since 
 there is no the *employee* table).

 Thank you.



-- 





[web2py] Re: Custom authentication provider

2013-01-08 Thread Ignacio Ocampo
I see that only the first time that user login, web2py saves the 
employee_id.

If I logout and login, and I change the employee_id value (I write this in 
external file to see the value), web2py does not update the field.

On Tuesday, January 8, 2013 11:08:34 AM UTC-6, Ignacio Ocampo wrote:

 I only return a dict in the get_user, web2py does all the work.

 web2py call the get_user method, and web2py update the auth_user table 
 with the dict values.

 I don't write/update the auth_user table in my custom class.

 On Tuesday, January 8, 2013 11:05:04 AM UTC-6, Niphlod wrote:

 hypothesis 2 is off the table

 BTW: saying that you have a method that returns a dict and stating that 
 that method doesn't update a field lacks of the key point.. 
 *Who*writes/updates the auth_user table in your custom class ?

 On Tuesday, January 8, 2013 5:36:39 PM UTC+1, Ignacio Ocampo wrote:

 Hi,

 I'm working with my own authentication provider as: *
 auth.settings.login_form=MyAuth()*, all *works correctly*.

 I need an additional field from default auth_user table definition, I 
 used: *auth.settings.extra_fields['auth_user'] = [Field('**employee_id**', 
 'text')]*, works correctly (the value of this field is provided by 
 MyAuth() to reference another system, ergo, in web2py it's would be treated 
 as a simple text).

 The final schema is:

 CREATE TABLE auth_user(
 id INTEGER PRIMARY KEY AUTOINCREMENT,
 first_name CHAR(128),
 last_name CHAR(128),
 email CHAR(512),
 password CHAR(512),
 registration_key CHAR(512),
 reset_password_key CHAR(512),
 registration_id CHAR(512)
 , *employee_id* TEXT);

 In MyAuth() class, I have the method get_user(self), which web2py call 
 in the login process to get user details. At the end of this method, I 
 return:

 user = dict(first_name=response['attributes']['cn'][0], 
 last_name=response['attributes']['cn'][0], 
 username=response['attributes']['uid'][0], 
 registration_id=response['attributes']['uid'][0], *employee_id*
 =response['attributes']['*employee_id*'][0])

 All fields are updated correctly, except the *employee_id*, that is the 
 additional field.

 *Hypothesis 1*: I don't know if web2py is updating only default fields 
 from the auth_user table (and because employee_id are not default field, 
 it's no updated).
 *Hypothesis 2*: The name of the additional field *employee_id* is 
 malformed (because the last part _id is used to reference another table 
 and commonly is INT type and web2py don't know how to handle this, since 
 there is no the *employee* table).

 Thank you.



-- 





[web2py] Re: Question about multiple OAuth (Twitter or Facebook) Problem.

2013-01-08 Thread Massimo Di Pierro
Did you look into:

gluon/contrib/login_methods/extended_login_form.py

On Wednesday, August 29, 2012 11:56:37 AM UTC-5, JungHyun Kim wrote:

 Hello,

 I am trying multiple login methods- Twitter or Facebook.
 I want to know the best practice to support multiple login methods 
 (multiple OAuth).

 Currently, I got a problem.
 I can redirect to login form of facebook or twitter. 
 But after I successfully logged in the OAuth providers, I can't log in my 
 service.

 Here is my code.

 In db.py, I defined two classes TwitterAccount and FacebookAccount

 from gluon.contrib.login_methods.oauth20_account import OAuthAccount

 class FaceBookAccount(OAuthAccount):
 OAuth impl for Facebook
 AUTH_URL=https://graph.facebook.com/oauth/authorize;
 TOKEN_URL=https://graph.facebook.com/oauth/access_token;
 user = None
 graph = None
 def __init__(self, g=globals()):
 OAuthAccount.__init__(self, g,
   FACEBOOK_CLIENT_ID,
   FACEBOOK_CLIENT_SECRET,
   self.AUTH_URL,
   self.TOKEN_URL)
 self.graph = None

 def get_user(self):
 if not self.accessToken():
 return None
 
 if not self.graph:
 self.graph = GraphAPI((self.accessToken()))
 
 if not self.user:
 try:
 self.user = self.graph.get_object(me)
 except GraphAPIError:
 return None
 
 return self.user
 



 import oauth2 as oauth
 from gluon.contrib.login_methods.oauth10a_account import OAuthAccount as 
 OAuthAccount10a

 class TwitterAccount(OAuthAccount10a):
 AUTH_URL = http://twitter.com/oauth/authorize;
 TOKEN_URL = https://twitter.com/oauth/request_token;
 ACCESS_TOKEN_URL = http://twitter.com/oauth/access_token;
 def __init__(self, g=globals()):
 OAuthAccount10a.__init__(self, g,
   consumer_key,
   consumer_secret,
   self.AUTH_URL,
   self.TOKEN_URL,
   self.ACCESS_TOKEN_URL)
   
 def get_user(self):
 if self.accessToken() is not None:
 client = oauth.Client(self.consumer, self.accessToken())
 resp, content = client.request('
 http://api.twitter.com/1/account/verify_credentials.json')
 if resp['status'] != '200':
 # cannot get user info. should check status
 return None
 u = json.loads(content)
 return dict(username=u['screen_name'], name=u['name'], 
 registration_id=str(u['id']))



 and then, make two instances

 # TWITTER
 twitter_login = TwitterAccount(globals())

 # FACEBOOK
 facebook_login = FaceBookAccount(globals())

 # set
 crud.settings.auth = None  # =auth to enforce 
 authorization on crud

 auth.settings.actions_disabled=['register','change_password','request_reset_password','profile']
 auth.define_tables()



 In controller, 
 def user():
 
 if len(request.args)  1:
 if request.args[0] == 'login' and request.args[1] == 'facebook':
 auth.settings.login_form=facebook_login
 elif request.args[0] == 'login' and request.args[1] == 'twitter':
 auth.settings.login_form=twitter_login

 return dict(form=auth())



 But it seems that I need to set 'auth_settings.login_form' in db.py before 
 calling auth.define_tables()


 If I set

 auth.settings.login_form=twitter_login
 auth.define_tables()

 or 

 auth.settings.login_form=facebook_login
 auth.define_tables()

 in db.py, each works well.


 Is there any way to set auth.settings.login_form dynamically in controller?

 I think it may impossible, because auth creates tables before knowing 
 proper fileds (like username).

 Then, how can I set multiple login form?

 Or right way to support multiple login? (except janrain)


 Thank you very much.



-- 





Re: [web2py] geodal

2013-01-08 Thread Massimo Di Pierro
Please open a ticket so I will look into it asap. I would add the st_x/y to 
all GIS adapters.

On Tuesday, January 8, 2013 9:36:57 AM UTC-6, Paolo valleri wrote:

 Hi Massimo, good to know that the patch is in trunk but I it is only for 
 the postgres adapter, I can try to define the same functions for the other 
 adapter but then someone has to check if they works or not.

 For what concern the other issue I will open I ticket, the main problem is 
 that web2py makes all the common fields name lower while it store the 'gis' 
 fields as is. I have just tried this:
 db.define_table('test_geo1_name', 
 Field('name_P', 'string'),
 Field('location_P','geometry()'),
 )
 In the db I have the field *name_p* and *location_P* respectively. To fix 
 it, I added in dal.py .lower() at line 832:
 ftype = ftype % dict(schema=schema,
  tablename=tablename,
  fieldname=field_name.lower(), srid=srid,
  dimension=dimension)
 And now in the db I have the field *name_p* and *location_p* respectively

 Paolo





 On Tuesday, January 8, 2013 3:48:56 PM UTC+1, Massimo Di Pierro wrote:

 In trunk. How about the previous issue? Is that still open? If so, can 
 you please open a ticket? Thanks.

 On Tuesday, 8 January 2013 05:31:28 UTC-6, Paolo valleri wrote:

 Hi all, I have a simple problem, how I can extract values of a single 
 point?
 I found that there are the functions ST_X, and ST_Y.
 Please find attached a patch that add them to dal and to the postgres 
 adapter, I haven't put them neither to MSSQLAdapter nor to 
 SQLITESpatiaLiteAdapter because I don't have those db to run tests.
 Now you can do something like:
 print db(db.city).select(db.city.latlng,
  db.city.latlng.st_x(), 
  db.city.latlng.st_y())

 city.latlng,ST_X(city.latlng),ST_Y(city.latlng)
 POINT(51.507335 -0.127683),51.507335,-0.127683
 POINT(41.901514 12.460774),41.901514,12.460774
 POINT(40.851775 14.268124),40.851775,14.268124
 The geometry field MUST contain only point otherwise it raises an error.

 Hope it helps

 Paolo



 On Sunday, January 6, 2013 5:29:52 PM UTC+1, Paolo valleri wrote:

 Hi Massimo, I found an other strange behavior. I tried to capitalize 
 the name of a field, as follows:
 db.define_table('test_geo', 
 Field('loc_Test','geometry()'),
 )
 and I get this error:

 Traceback (most recent call last):
   File /home/paolo/Dropbox/git/web2py/gluon/restricted.py, line 212, in 
 restricted
 exec ccode in environment
   File /home/paolo/Dropbox/git/web2py/applications/bikend/models/db.py 
 http://127.0.0.1:8000/admin/default/edit/bikend/models/db.py, line 585, 
 in module
 db.test_geo.insert(loc_Test=geoPoint(45.89096,11.0401399))
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 7977, in insert
 ret =  self._db._adapter.insert(self,self._listify(fields))
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1175, in insert
 raise e
 ProgrammingError: column loc_test of relation test_geo does not exist
 LINE 1: INSERT INTO test_geo(loc_Test) VALUES (ST_GeomFromText('POIN...

 and so I tried to insert without the capitalize and I get this error:

 Traceback (most recent call last):
   File /home/paolo/Dropbox/git/web2py/gluon/restricted.py, line 212, in 
 restricted
 exec ccode in environment
   File /home/paolo/Dropbox/git/web2py/applications/bikend/models/db.py 
 http://127.0.0.1:8000/admin/default/edit/bikend/models/db.py, line 585, 
 in module
 db.test_geo.insert(loc_test=geoPoint(45.89096,11.0401399))
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 7977, in insert
 ret =  self._db._adapter.insert(self,self._listify(fields))
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 7915, in 
 _listify
 'Field %s does not belong to the table' % name)
 SyntaxError: Field loc_test does not belong to the table


 finally, I redefined the table as was before, (without any capital 
 latter) and I get this:

 Traceback (most recent call last):
   File /home/paolo/Dropbox/git/web2py/gluon/restricted.py, line 212, in 
 restricted
 exec ccode in environment
   File /home/paolo/Dropbox/git/web2py/applications/bikend/models/db.py 
 http://127.0.0.1:8000/admin/default/edit/bikend/models/db.py, line 583, 
 in module
 db.test_geo.insert(Name='paolo')
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 7313, in 
 __getattr__
 return self.lazy_define_table(tablename,*fields,**args)
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 7281, in 
 lazy_define_table
 polymodel=polymodel)
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 965, in 
 create_table
 fake_migrate=fake_migrate)
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1068, in 
 migrate_table
 self.execute(sub_query)
   File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1714, in execute
 return self.log_execute(*a, **b)
   File 

[web2py] Re: drop table cascade

2013-01-08 Thread Massimo Di Pierro
What do you get? An error? What error?

On Friday, January 4, 2013 3:18:32 AM UTC-6, Liang wrote:

 drop('cascade') seems not working.

 On Wednesday, 4 February 2009 14:17:14 UTC+8, mdipierro wrote:

 give this a try. In trunk 

 db.table.drop('cascade') 

 On Feb 3, 11:40 pm, Baron richar...@gmail.com wrote: 
  thanks Massimo. 
  
  On Feb 4, 3:28 pm, mdipierro mdipie...@cs.depaul.edu wrote: 
  
   sorry, for now you have to do it manually 
  
   db.executesql('DROP TABLE tablename CASCADE;') 
  
   perhaps I can add an option to drop/truncate. 
  
   Massimo 
  
   On Feb 3, 9:01 pm, Baron richar...@gmail.com wrote: 
  
When I try to drop or truncate a table I get this error: 
  
ProgrammingError: cannot drop table dump because other objects 
 depend 
on it 
HINT:  Use DROP ... CASCADE to drop the dependent objects too. 
  
Deleting from the table works fine because the deletions cascade. 
 Is 
there a way to truncate or drop tables through the DAL that have 
foreign key dependencies? 
  
Baron



-- 





Re: [web2py] geodal

2013-01-08 Thread paolo.vall...@gmail.com
Done,
http://code.google.com/p/web2py/issues/detail?id=1259thanks=1259ts=1357666735
Thanks

Paolo


2013/1/8 Massimo Di Pierro massimo.dipie...@gmail.com

 Please open a ticket so I will look into it asap. I would add the st_x/y
 to all GIS adapters.


 On Tuesday, January 8, 2013 9:36:57 AM UTC-6, Paolo valleri wrote:

 Hi Massimo, good to know that the patch is in trunk but I it is only for
 the postgres adapter, I can try to define the same functions for the other
 adapter but then someone has to check if they works or not.

 For what concern the other issue I will open I ticket, the main problem
 is that web2py makes all the common fields name lower while it store the
 'gis' fields as is. I have just tried this:
 db.define_table('test_geo1_**name',
 Field('name_P', 'string'),
 Field('location_P','geometry()**'),
 )
 In the db I have the field *name_p* and *location_P* respectively. To
 fix it, I added in dal.py .lower() at line 832:
 ftype = ftype % dict(schema=schema,
  tablename=tablename,
  fieldname=field_name.lower(), srid=srid,
  dimension=dimension)
 And now in the db I have the field *name_p* and *location_p* respectively

 Paolo





 On Tuesday, January 8, 2013 3:48:56 PM UTC+1, Massimo Di Pierro wrote:

 In trunk. How about the previous issue? Is that still open? If so, can
 you please open a ticket? Thanks.

 On Tuesday, 8 January 2013 05:31:28 UTC-6, Paolo valleri wrote:

 Hi all, I have a simple problem, how I can extract values of a single
 point?
 I found that there are the functions ST_X, and ST_Y.
 Please find attached a patch that add them to dal and to the postgres
 adapter, I haven't put them neither to MSSQLAdapter nor to
 SQLITESpatiaLiteAdapter because I don't have those db to run tests.
 Now you can do something like:
 print db(db.city).select(db.city.lat**lng,
  db.city.latlng.st_x(),
  db.city.latlng.st_y())

 city.latlng,ST_X(city.latlng),**ST_Y(city.latlng)
 POINT(51.507335 -0.127683),51.507335,-0.127683
 POINT(41.901514 12.460774),41.901514,12.460774
 POINT(40.851775 14.268124),40.851775,14.268124
 The geometry field MUST contain only point otherwise it raises an error.

 Hope it helps

 Paolo



 On Sunday, January 6, 2013 5:29:52 PM UTC+1, Paolo valleri wrote:

 Hi Massimo, I found an other strange behavior. I tried to capitalize
 the name of a field, as follows:
 db.define_table('test_geo',
 Field('loc_Test','geometry()')**,
 )
 and I get this error:

 Traceback (most recent call last):

   File /home/paolo/Dropbox/git/**web2py/gluon/restricted.py, line 212, 
 in restricted

 exec ccode in environment

   File 
 /home/paolo/Dropbox/git/**web2py/applications/bikend/**models/db.py 
 http://127.0.0.1:8000/admin/default/edit/bikend/models/db.py, line 585, 
 in module

 db.test_geo.insert(loc_Test=ge**oPoint(45.89096,11.0401399))

   File /home/paolo/Dropbox/git/**web2py/gluon/dal.py, line 7977, in 
 insert

 ret =  self._db._adapter.insert(self**,self._listify(fields))

   File /home/paolo/Dropbox/git/**web2py/gluon/dal.py, line 1175, in 
 insert

 raise e
 ProgrammingError: column loc_test of relation test_geo does not exist

 LINE 1: INSERT INTO test_geo(loc_Test) VALUES (ST_GeomFromText('POIN...

 and so I tried to insert without the capitalize and I get this error:

 Traceback (most recent call last):

   File /home/paolo/Dropbox/git/**web2py/gluon/restricted.py, line 212, 
 in restricted

 exec ccode in environment

   File 
 /home/paolo/Dropbox/git/**web2py/applications/bikend/**models/db.py 
 http://127.0.0.1:8000/admin/default/edit/bikend/models/db.py, line 585, 
 in module

 db.test_geo.insert(loc_test=ge**oPoint(45.89096,11.0401399))

   File /home/paolo/Dropbox/git/**web2py/gluon/dal.py, line 7977, in 
 insert

 ret =  self._db._adapter.insert(self**,self._listify(fields))

   File /home/paolo/Dropbox/git/**web2py/gluon/dal.py, line 7915, in 
 _listify

 'Field %s does not belong to the table' % name)
 SyntaxError: Field loc_test does not belong to the table


 finally, I redefined the table as was before, (without any capital
 latter) and I get this:

 Traceback (most recent call last):

   File /home/paolo/Dropbox/git/**web2py/gluon/restricted.py, line 212, 
 in restricted

 exec ccode in environment

   File 
 /home/paolo/Dropbox/git/**web2py/applications/bikend/**models/db.py 
 http://127.0.0.1:8000/admin/default/edit/bikend/models/db.py, line 583, 
 in module

 db.test_geo.insert(Name='**paolo')

   File /home/paolo/Dropbox/git/**web2py/gluon/dal.py, line 7313, in 
 __getattr__

 return self.lazy_define_table(tablena**me,*fields,**args)

   File /home/paolo/Dropbox/git/**web2py/gluon/dal.py, line 7281, in 
 lazy_define_table

 polymodel=polymodel)
   File /home/paolo/Dropbox/git/**web2py/gluon/dal.py, line 965, in 
 create_table

 fake_migrate=fake_migrate)
   File 

[web2py] Re: Custom authentication provider

2013-01-08 Thread Anthony
On Tuesday, January 8, 2013 12:08:34 PM UTC-5, Ignacio Ocampo wrote:

 I only return a dict in the get_user, web2py does all the work.

 web2py call the get_user method, and web2py update the auth_user table 
 with the dict values.



Yes, but where are you telling web2py to update the auth_user table? Can 
you show the code?

Anthony

-- 





[web2py] Auto populate form

2013-01-08 Thread Saba
hello,
 
I have a table like this:
 
db.define_table('host',
Field('host_name', requires=IS_NOT_EMPTY()),
Field('host_ip', requires=IS_NOT_EMPTY())
)

i'm using SQLFORM.grid to display/edit the data in the table. When a user 
inputs a host_name field, I would like to automatically populate the 
host_ip field by doing an nslookup of the host_name. Is there a way to do 
this. Any suggestions please?
 
thanks,
Saba
 

-- 





[web2py] Re: Maintain Attendance details of students

2013-01-08 Thread Alan Etkin


 Thank you,
   That was very helpful...
 But I am unable to display the way u specified the SQL form. But I got ur 
 method of maintaining the database.


You mean it doesn't fit with your app layout? The form imitates those 
sheets used in schools for course attendance. Maybe it is too wide for a 
computer display.

-- 





[web2py] Re: Custom authentication provider

2013-01-08 Thread Ignacio Ocampo
Yes,

I only uses:

auth.settings.login_form=MyAuth(
   param1=value1,
   param2=value
)

It's all, I never call and writes/update in the auth_user anywhere.

In gluon/tools.py login function, web2py check if they would use their 
login form or from a central source (line 1955)

At line 2068 web2py determined that central authentication would be used.

At line 2075 web2py call: user = 
self.get_or_create_user(table_user._filter_fields(cas_user))

At line 1724, within get_or_create_user function, after that web2py 
determine that the user exists:

*update_keys = dict(registration_id=keys['registration_id']) #here is the 
BUG*

I solved it with:

*update_keys = dict(registration_id=keys['registration_id'], 
employee_id=keys['employee_id'])*

So, I think that we need to update the gluon/tools.py file, to improve the 
update of external fields.

On Tuesday, January 8, 2013 11:43:44 AM UTC-6, Anthony wrote:

 On Tuesday, January 8, 2013 12:08:34 PM UTC-5, Ignacio Ocampo wrote:

 I only return a dict in the get_user, web2py does all the work.

 web2py call the get_user method, and web2py update the auth_user table 
 with the dict values.



 Yes, but where are you telling web2py to update the auth_user table? Can 
 you show the code?

 Anthony


-- 





[web2py] Re: Auto populate form

2013-01-08 Thread Leonel Câmara
I'd just add javascript to the view to do it.

Attach to the change event on the name field and do ajax requests from the 
server for dns resolution. If successful fill in the host_ip field.

Terça-feira, 8 de Janeiro de 2013 17:46:04 UTC, Saba escreveu:

 hello,
  
 I have a table like this:
  
 db.define_table('host',
 Field('host_name', requires=IS_NOT_EMPTY()),
 Field('host_ip', requires=IS_NOT_EMPTY())
 )

 i'm using SQLFORM.grid to display/edit the data in the table. When a user 
 inputs a host_name field, I would like to automatically populate the 
 host_ip field by doing an nslookup of the host_name. Is there a way to do 
 this. Any suggestions please?
  
 thanks,
 Saba
  


-- 





[web2py] Re: GAE + Cloud SQL: Tickets

2013-01-08 Thread Felipe Meirelles
Well, the real problem is I'm using GAE with Google Cloud SQL, so I have 
the migrations problem but here is the fix:

On restricted.py line 72:

def _get_table(self, db, tablename, app):
tablename = tablename + '_' + app
try:
table = db[tablename]
except:
db.rollback()   # not necessary but one day
# any app may store tickets on DB
table = db.define_table(
tablename,
db.Field('ticket_id', length=100),
db.Field('ticket_data', 'text'),
db.Field('created_datetime', 'datetime'),
)
logging.info(table)
return table

The problem is web2py was trying to create the table in every request, even 
when it already exists (don't know why, but with lazy tables 
db.get(tablename, None) was returning none always). So I swaped to 
db[tablename] and added a exception handling for it. Seem to work just fine 
now. 

Can you take a look and see if this dosen't conflicts with another DBs to 
move it to trunk? Thanks!

Thanks.

On Friday, January 4, 2013 10:58:07 PM UTC-2, Massimo Di Pierro wrote:

 Admin is readonly on GAE and by default not deployed. 

 On Friday, 4 January 2013 17:10:56 UTC-6, Alan Etkin wrote:

 El jueves, 3 de enero de 2013 11:31:45 UTC-3, Felipe Meirelles escribió:

 Well, the problem is when the ticket is saved, self.db points to DAL 
 uri=google:sql://**:novello-solutionworkshop:novello-solutionworkshop/novello_test
  
 but when load() is called, it points to DAL uri=gae.


 AFAIK admin is db less. It uses the db of the app it manages. Besides, 
 wasn't admin disabled for GAE?



-- 





[web2py] Re: Question about multiple OAuth (Twitter or Facebook) Problem.

2013-01-08 Thread samuel bonilla
look :
http://web2py.com/books/default/chapter/29/09#Integration-with-OpenID,-Facebook,-etc.

www.janrain.com/

-- 





[web2py] Re: Auto populate form

2013-01-08 Thread Derek
You'd probably want to have a javascript that calls a special function on 
your controller that returns the results from gethostbyname().

On Tuesday, January 8, 2013 10:46:04 AM UTC-7, Saba wrote:

 hello,
  
 I have a table like this:
  
 db.define_table('host',
 Field('host_name', requires=IS_NOT_EMPTY()),
 Field('host_ip', requires=IS_NOT_EMPTY())
 )

 i'm using SQLFORM.grid to display/edit the data in the table. When a user 
 inputs a host_name field, I would like to automatically populate the 
 host_ip field by doing an nslookup of the host_name. Is there a way to do 
 this. Any suggestions please?
  
 thanks,
 Saba
  


-- 





[web2py] emailing From: full name

2013-01-08 Thread Jonathan Lundell
I tried to persuade the web2py emailer to use a full name (like: 'My Name 
mym...@mail.com') in the From: header by setting it in the headers argument, 
but it didn't work: From continued to be set to the value of sender (the bare 
email address).

As I read the code, From is initialized to the value of sender, but should be 
overridden by headers. And for reference, if I set 'X-From' instead, that did 
end up in the headers as I would have expected.

The Python smtplib suggests that it doesn't mess with the embedded headers. I 
suppose it could be happening farther down the line, and eventually I'll do 
some experimentation, but I thought I'd see whether anyone on the list has 
solved the problem first.

-- 





[web2py] Re: GAE + Cloud SQL: Tickets

2013-01-08 Thread Felipe Meirelles
Never mind, this solution just worked the first time, when I need to define 
the table, the second time it fails too...

On Tuesday, January 8, 2013 4:21:01 PM UTC-2, Felipe Meirelles wrote:

 Well, the real problem is I'm using GAE with Google Cloud SQL, so I have 
 the migrations problem but here is the fix:

 On restricted.py line 72:

 def _get_table(self, db, tablename, app):
 tablename = tablename + '_' + app
 try:
 table = db[tablename]
 except:
 db.rollback()   # not necessary but one day
 # any app may store tickets on DB
 table = db.define_table(
 tablename,
 db.Field('ticket_id', length=100),
 db.Field('ticket_data', 'text'),
 db.Field('created_datetime', 'datetime'),
 )
 logging.info(table)
 return table

 The problem is web2py was trying to create the table in every request, 
 even when it already exists (don't know why, but with lazy tables 
 db.get(tablename, None) was returning none always). So I swaped to 
 db[tablename] and added a exception handling for it. Seem to work just fine 
 now. 

 Can you take a look and see if this dosen't conflicts with another DBs to 
 move it to trunk? Thanks!

 Thanks.

 On Friday, January 4, 2013 10:58:07 PM UTC-2, Massimo Di Pierro wrote:

 Admin is readonly on GAE and by default not deployed. 

 On Friday, 4 January 2013 17:10:56 UTC-6, Alan Etkin wrote:

 El jueves, 3 de enero de 2013 11:31:45 UTC-3, Felipe Meirelles escribió:

 Well, the problem is when the ticket is saved, self.db points to DAL 
 uri=google:sql://**:novello-solutionworkshop:novello-solutionworkshop/novello_test
  
 but when load() is called, it points to DAL uri=gae.


 AFAIK admin is db less. It uses the db of the app it manages. Besides, 
 wasn't admin disabled for GAE?



-- 





[web2py] Re: GAE + Cloud SQL: Tickets

2013-01-08 Thread Felipe Meirelles
Now its working for all requests, but the solution is a little odd:
First try to get the table, then try to define it for the first time and if 
it fails, try to just define the table, with no migrate. Is this OK?

def _get_table(self, db, tablename, app):
tablename = tablename + '_' + app
logging.info(tablename)
table = None
try:
table = db[tablename]
except:
db.rollback()   # not necessary but one day
# any app may store tickets on DB
logging.info(Trying to create)
try:
db.define_table(
tablename,
db.Field('ticket_id', length=100),
db.Field('ticket_data', 'text'),
db.Field('created_datetime', 'datetime'),
)
table = db[tablename]
except:
try:
db.define_table(
tablename,
db.Field('ticket_id', length=100),
db.Field('ticket_data', 'text'),
db.Field('created_datetime', 'datetime'),
migrate=False
)
table = db[tablename]
except:
pass
return table

On Tuesday, January 8, 2013 4:34:39 PM UTC-2, Felipe Meirelles wrote:

 Never mind, this solution just worked the first time, when I need to 
 define the table, the second time it fails too...

 On Tuesday, January 8, 2013 4:21:01 PM UTC-2, Felipe Meirelles wrote:

 Well, the real problem is I'm using GAE with Google Cloud SQL, so I have 
 the migrations problem but here is the fix:

 On restricted.py line 72:

 def _get_table(self, db, tablename, app):
 tablename = tablename + '_' + app
 try:
 table = db[tablename]
 except:
 db.rollback()   # not necessary but one day
 # any app may store tickets on DB
 table = db.define_table(
 tablename,
 db.Field('ticket_id', length=100),
 db.Field('ticket_data', 'text'),
 db.Field('created_datetime', 'datetime'),
 )
 logging.info(table)
 return table

 The problem is web2py was trying to create the table in every request, 
 even when it already exists (don't know why, but with lazy tables 
 db.get(tablename, None) was returning none always). So I swaped to 
 db[tablename] and added a exception handling for it. Seem to work just fine 
 now. 

 Can you take a look and see if this dosen't conflicts with another DBs to 
 move it to trunk? Thanks!

 Thanks.

 On Friday, January 4, 2013 10:58:07 PM UTC-2, Massimo Di Pierro wrote:

 Admin is readonly on GAE and by default not deployed. 

 On Friday, 4 January 2013 17:10:56 UTC-6, Alan Etkin wrote:

 El jueves, 3 de enero de 2013 11:31:45 UTC-3, Felipe Meirelles escribió:

 Well, the problem is when the ticket is saved, self.db points to DAL 
 uri=google:sql://**:novello-solutionworkshop:novello-solutionworkshop/novello_test
  
 but when load() is called, it points to DAL uri=gae.


 AFAIK admin is db less. It uses the db of the app it manages. Besides, 
 wasn't admin disabled for GAE?



-- 





[web2py] Resizing a user uploaded image

2013-01-08 Thread Daniele
How can i make it so that when a user uploads an image, it automatically 
gets resized to a specified dimension?

Thanks!

-- 





[web2py] Re: tab separated csv file

2013-01-08 Thread Derek
in sqlhtml there is a TSV exporter though...

On Wednesday, March 11, 2009 9:08:27 AM UTC-7, mdipierro wrote:

 There is no configuration parameter to do so. You mat create your own 
 csv serializer. look into the python csv module. 

 On Mar 11, 10:01 am, Marco Prosperi marcoprosperi...@gmail.com 
 wrote: 
  hello everybody, 
  how can I change the following function (defined in appadmin.py 
  controller) so that the downloaded file has tab separated values 
  instead of comma separated? Or do I have to change some settings 
  somewhere? 
  
  thanks in advance, 
  Marco 
  
  def csv(): 
  import gluon.contenttype 
  response.headers['Content-Type'] = \ 
  gluon.contenttype.contenttype('.csv') 
  db = get_database(request) 
  query = get_query(request) 
  if not query: 
  return None 
  response.headers['Content-disposition'] = \ 
  'attachment; filename=%s_%s.csv'\ 
   % tuple(request.vars.query.split('.')[:2]) 
  return str(db(query).select())

-- 





[web2py] Re: subforms / formsets / form cloning imprementation

2013-01-08 Thread Henrique Pantarotto
Hi Christian, thanks for your reply!  Your approach sounds interesting and 
it seems to be one of the best options with what's possible as for this 
moment.

I have this page already implemented and working in php/javascript, but I'm 
searching for a new full featured framework exactly to avoid these kinds 
of ugly workarounds. I guess I'll either wait until web2py implements this, 
or I guess I'll have to decide between rails or django for this project. 
I'm not a python or ruby programmer (I program mostly in C/Perl/shell and 
php), so it doesn't really matter much to me.

I read all of web2py's documentation and created a few demo projects and I 
enjoyed it very much. I wish I had the programming experience and knowledge 
to help web2py developers to implement this feature, as it seems lots of 
other people also need this (I've found MANY threads from people asking the 
same thing on this mailing list).

Thanks again!

On Tuesday, January 8, 2013 2:17:05 AM UTC-2, howesc wrote:

 i have an (untested) idea...plugging together a few things i have used 
 before

  - you could create templates of field sets using handlebars: 
 http://handlebarsjs.com/  then you can via JS add them to the page based 
 on user interaction.
  - you can use hidden fields to provide some meta data on the form.
  - remembering that in your controller you define your SQLFORM *before* 
 you process it, you could check for the presence of your hidden fields in 
 request.vars, and based on their values initialize your SQLFORM to match 
 the sub-forms that were added to the form.  then when you call .process it 
 will check all those fields as well.

 i don't know if that is a great idea or not (we recently solved this 
 problem at my workplace but i think ended up using handlebars and manual 
 form processing)it's a thought we considered and still might try!

 christian

 On Sunday, January 6, 2013 11:02:01 PM UTC-8, Henrique Pantarotto wrote:

 Hello everybody!

 I'm quite new to Python and web2py, but I consumed all of web2py's 
 wonderful documentation at the last few days and I'm quite amazed at this 
 wonderful framework. But there's a feature that I need that I couldn't find 
 a way to easily implement it.

 The application that I'm developing requires extensive use of form 
 cloning within a single web page, done dynamically at the client side.  I'm 
 not really sure how to call this technique, so I found a bit hard to find 
 information regarding this at this mailing list's archive.

 What I want to accomplish can be easily understood viewing the 
 screenshots from this tool: http://www.mdelrosso.com/sheepit/

 I already have my own (ugly) jquery code to create the forms dynamically, 
 and of course I could validate it manually on web2py's side, but I was 
 looking into an easier implementation using something like FORM or SQLFORM. 
 Like I said, I'm very new to web2py and python, and I have no idea how 
 django works, but I think I need to accomplish something similar to this: 
 https://docs.djangoproject.com/en/dev/topics/forms/formsets/

 I tried searching this mailing list archive and I found a couple of 
 discussions from people trying to do the same thing, but I didn't find a 
 solution.

 https://groups.google.com/forum/#!topic/web2py/ssaSj6v9Wu8/discussion
 https://groups.google.com/d/topic/web2py/UK8NZ1VMlNk/discussion

 But these are threads from 2011

 There's also this guy asking something similar a couple of months ago: 
 https://groups.google.com/d/topic/web2py/IPMz4FylT2k/discussion and 
 http://stackoverflow.com/questions/13215902/web2py-possible-to-submit-multiple-forms-with-a-single-submit-button/13215926#13215926but
  the solution presented didn't seem very elegant.

 Anyway, I would really appreciate any help on this.


 Thanks, Henrique.



-- 





[web2py] Re: tab separated csv file

2013-01-08 Thread Derek
You could monkey-patch the dal 'rows' object __str__ by making it export as 
a TSV.

On Wednesday, March 11, 2009 8:01:42 AM UTC-7, Marco Prosperi wrote:

 hello everybody, 
 how can I change the following function (defined in appadmin.py 
 controller) so that the downloaded file has tab separated values 
 instead of comma separated? Or do I have to change some settings 
 somewhere? 

 thanks in advance, 
 Marco 

 def csv(): 
 import gluon.contenttype 
 response.headers['Content-Type'] = \ 
 gluon.contenttype.contenttype('.csv') 
 db = get_database(request) 
 query = get_query(request) 
 if not query: 
 return None 
 response.headers['Content-disposition'] = \ 
 'attachment; filename=%s_%s.csv'\ 
  % tuple(request.vars.query.split('.')[:2]) 
 return str(db(query).select())

-- 





[web2py] Re: subforms / formsets / form cloning imprementation

2013-01-08 Thread Derek
Perhaps it would be a nice feature to add to the smartgrid - in place ajax 
update / addition.
So you'd just add a smartgrid to your form, and you can click 'add' and 
right in place you can add a new record to the grid / db.


On Tuesday, January 8, 2013 11:43:31 AM UTC-7, Henrique Pantarotto wrote:

 Hi Christian, thanks for your reply!  Your approach sounds interesting and 
 it seems to be one of the best options with what's possible as for this 
 moment.

 I have this page already implemented and working in php/javascript, but 
 I'm searching for a new full featured framework exactly to avoid these 
 kinds of ugly workarounds. I guess I'll either wait until web2py implements 
 this, or I guess I'll have to decide between rails or django for this 
 project. I'm not a python or ruby programmer (I program mostly in 
 C/Perl/shell and php), so it doesn't really matter much to me.

 I read all of web2py's documentation and created a few demo projects and I 
 enjoyed it very much. I wish I had the programming experience and knowledge 
 to help web2py developers to implement this feature, as it seems lots of 
 other people also need this (I've found MANY threads from people asking the 
 same thing on this mailing list).

 Thanks again!

 On Tuesday, January 8, 2013 2:17:05 AM UTC-2, howesc wrote:

 i have an (untested) idea...plugging together a few things i have used 
 before

  - you could create templates of field sets using handlebars: 
 http://handlebarsjs.com/  then you can via JS add them to the page based 
 on user interaction.
  - you can use hidden fields to provide some meta data on the form.
  - remembering that in your controller you define your SQLFORM *before* 
 you process it, you could check for the presence of your hidden fields in 
 request.vars, and based on their values initialize your SQLFORM to match 
 the sub-forms that were added to the form.  then when you call .process it 
 will check all those fields as well.

 i don't know if that is a great idea or not (we recently solved this 
 problem at my workplace but i think ended up using handlebars and manual 
 form processing)it's a thought we considered and still might try!

 christian

 On Sunday, January 6, 2013 11:02:01 PM UTC-8, Henrique Pantarotto wrote:

 Hello everybody!

 I'm quite new to Python and web2py, but I consumed all of web2py's 
 wonderful documentation at the last few days and I'm quite amazed at this 
 wonderful framework. But there's a feature that I need that I couldn't find 
 a way to easily implement it.

 The application that I'm developing requires extensive use of form 
 cloning within a single web page, done dynamically at the client side.  I'm 
 not really sure how to call this technique, so I found a bit hard to find 
 information regarding this at this mailing list's archive.

 What I want to accomplish can be easily understood viewing the 
 screenshots from this tool: http://www.mdelrosso.com/sheepit/

 I already have my own (ugly) jquery code to create the forms 
 dynamically, and of course I could validate it manually on web2py's side, 
 but I was looking into an easier implementation using something like FORM 
 or SQLFORM. Like I said, I'm very new to web2py and python, and I have no 
 idea how django works, but I think I need to accomplish something similar 
 to this: https://docs.djangoproject.com/en/dev/topics/forms/formsets/

 I tried searching this mailing list archive and I found a couple of 
 discussions from people trying to do the same thing, but I didn't find a 
 solution.

 https://groups.google.com/forum/#!topic/web2py/ssaSj6v9Wu8/discussion
 https://groups.google.com/d/topic/web2py/UK8NZ1VMlNk/discussion

 But these are threads from 2011

 There's also this guy asking something similar a couple of months ago: 
 https://groups.google.com/d/topic/web2py/IPMz4FylT2k/discussion and 
 http://stackoverflow.com/questions/13215902/web2py-possible-to-submit-multiple-forms-with-a-single-submit-button/13215926#13215926but
  the solution presented didn't seem very elegant.

 Anyway, I would really appreciate any help on this.


 Thanks, Henrique.



-- 





[web2py] Re: subforms / formsets / form cloning imprementation

2013-01-08 Thread Derek
Take a look at this - maybe it's similar to what you need...

http://www.web2pyslices.com/slice/show/1432/insert-and-delete-ajax-show-process

On Monday, January 7, 2013 12:02:01 AM UTC-7, Henrique Pantarotto wrote:

 Hello everybody!

 I'm quite new to Python and web2py, but I consumed all of web2py's 
 wonderful documentation at the last few days and I'm quite amazed at this 
 wonderful framework. But there's a feature that I need that I couldn't find 
 a way to easily implement it.

 The application that I'm developing requires extensive use of form cloning 
 within a single web page, done dynamically at the client side.  I'm not 
 really sure how to call this technique, so I found a bit hard to find 
 information regarding this at this mailing list's archive.

 What I want to accomplish can be easily understood viewing the screenshots 
 from this tool: http://www.mdelrosso.com/sheepit/

 I already have my own (ugly) jquery code to create the forms dynamically, 
 and of course I could validate it manually on web2py's side, but I was 
 looking into an easier implementation using something like FORM or SQLFORM. 
 Like I said, I'm very new to web2py and python, and I have no idea how 
 django works, but I think I need to accomplish something similar to this: 
 https://docs.djangoproject.com/en/dev/topics/forms/formsets/

 I tried searching this mailing list archive and I found a couple of 
 discussions from people trying to do the same thing, but I didn't find a 
 solution.

 https://groups.google.com/forum/#!topic/web2py/ssaSj6v9Wu8/discussion
 https://groups.google.com/d/topic/web2py/UK8NZ1VMlNk/discussion

 But these are threads from 2011

 There's also this guy asking something similar a couple of months ago: 
 https://groups.google.com/d/topic/web2py/IPMz4FylT2k/discussion and 
 http://stackoverflow.com/questions/13215902/web2py-possible-to-submit-multiple-forms-with-a-single-submit-button/13215926#13215926but
  the solution presented didn't seem very elegant.

 Anyway, I would really appreciate any help on this.


 Thanks, Henrique.



-- 





[web2py] Re: Resizing a user uploaded image

2013-01-08 Thread Derek
Take a look here for a somewhat similar example...

http://www.web2pyslices.com/slice/show/1387/upload-image-and-make-a-thumbnail

You'll need the PIL (python image library) installed.

On Tuesday, January 8, 2013 11:43:36 AM UTC-7, Daniele wrote:

 How can i make it so that when a user uploads an image, it automatically 
 gets resized to a specified dimension?

 Thanks!


-- 





[web2py] Re: Resizing a user uploaded image

2013-01-08 Thread Derek
They made it even simpler now... (look at contrib/imageutils.py)
#
# Put this file in yourapp/modules/images.py
#
# Given the model
#
# db.define_table(table_name, Field(picture, upload), 
Field(thumbnail, upload))
#
# # to resize the picture on upload
#
# from images import RESIZE
#
# db.table_name.picture.requires = RESIZE(200, 200)
#
# # to store original image in picture and create a thumbnail in 
'thumbnail' field
#
# from images import THUMB
# db.table_name.thumbnail.compute = lambda row: THUMB(row.picture, 200, 200)


On Tuesday, January 8, 2013 12:03:37 PM UTC-7, Derek wrote:

 Take a look here for a somewhat similar example...


 http://www.web2pyslices.com/slice/show/1387/upload-image-and-make-a-thumbnail

 You'll need the PIL (python image library) installed.

 On Tuesday, January 8, 2013 11:43:36 AM UTC-7, Daniele wrote:

 How can i make it so that when a user uploads an image, it automatically 
 gets resized to a specified dimension?

 Thanks!



-- 





[web2py] Re: Custom authentication provider

2013-01-08 Thread Massimo Di Pierro
Perhaps I misunderstand the workflow. The solution cannot be to change an 
Auth function to handle a specific custom field.

The proper signature for the function is 

  get_or_create_user(self, keys, update_fields=['email'])

so if you want to pass employee_id to keys and expect it to update the 
record in case it is found you need to pass

  get_or_create_user(self, keys, update_fields=['email', 'employee_id'])

There are two options here:
1) allow some auth.settings.update_fields to be specified so the function 
is called with right parameters
2) change it so that update_fields defaults to keys.keys()

2) would solve the problem automatically but it may break something. Not 
sure.

Please open a ticket: http://code.google.com/p/web2py/issues/list
but let's discuss it some more.

Massimo




On Tuesday, 8 January 2013 12:09:09 UTC-6, Ignacio Ocampo wrote:

 Yes,

 I only uses:

 auth.settings.login_form=MyAuth(
param1=value1,
param2=value
 )

 It's all, I never call and writes/update in the auth_user anywhere.

 In gluon/tools.py login function, web2py check if they would use their 
 login form or from a central source (line 1955)

 At line 2068 web2py determined that central authentication would be used.

 At line 2075 web2py call: user = 
 self.get_or_create_user(table_user._filter_fields(cas_user))

 At line 1724, within get_or_create_user function, after that web2py 
 determine that the user exists:

 *update_keys = dict(registration_id=keys['registration_id']) #here is the 
 BUG*

 I solved it with:

 *update_keys = dict(registration_id=keys['registration_id'], 
 employee_id=keys['employee_id'])*

 So, I think that we need to update the gluon/tools.py file, to improve the 
 update of external fields.

 On Tuesday, January 8, 2013 11:43:44 AM UTC-6, Anthony wrote:

 On Tuesday, January 8, 2013 12:08:34 PM UTC-5, Ignacio Ocampo wrote:

 I only return a dict in the get_user, web2py does all the work.

 web2py call the get_user method, and web2py update the auth_user table 
 with the dict values.



 Yes, but where are you telling web2py to update the auth_user table? Can 
 you show the code?

 Anthony



-- 





[web2py] Re: tab separated csv file

2013-01-08 Thread Massimo Di Pierro
Nooo. This would break other apps in the same server.

I would take a patch to pass the parameter around or use the grid exporter 
in appadmin.

On Tuesday, 8 January 2013 12:52:38 UTC-6, Derek wrote:

 You could monkey-patch the dal 'rows' object __str__ by making it export 
 as a TSV.

 On Wednesday, March 11, 2009 8:01:42 AM UTC-7, Marco Prosperi wrote:

 hello everybody, 
 how can I change the following function (defined in appadmin.py 
 controller) so that the downloaded file has tab separated values 
 instead of comma separated? Or do I have to change some settings 
 somewhere? 

 thanks in advance, 
 Marco 

 def csv(): 
 import gluon.contenttype 
 response.headers['Content-Type'] = \ 
 gluon.contenttype.contenttype('.csv') 
 db = get_database(request) 
 query = get_query(request) 
 if not query: 
 return None 
 response.headers['Content-disposition'] = \ 
 'attachment; filename=%s_%s.csv'\ 
  % tuple(request.vars.query.split('.')[:2]) 
 return str(db(query).select())



-- 





[web2py] Re: emailing From: full name

2013-01-08 Thread Adi
Hi Jonathan,
Mine is putting properly company name in front of the address, by using:  
mail.settings.sender = 'Company', but knowing that you are a guru here, may 
not be at all what you are looking for... If you wanted I could send you a 
sample email privately to see if that's what you needed?

Adnan




On Tuesday, January 8, 2013 1:32:23 PM UTC-5, Jonathan Lundell wrote:

 I tried to persuade the web2py emailer to use a full name (like: 'My Name 
 mym...@mail.com javascript:') in the From: header by setting it in the 
 headers argument, but it didn't work: From continued to be set to the value 
 of sender (the bare email address). 

 As I read the code, From is initialized to the value of sender, but should 
 be overridden by headers. And for reference, if I set 'X-From' instead, 
 that did end up in the headers as I would have expected. 

 The Python smtplib suggests that it doesn't mess with the embedded 
 headers. I suppose it could be happening farther down the line, and 
 eventually I'll do some experimentation, but I thought I'd see whether 
 anyone on the list has solved the problem first. 



-- 





Re: [web2py] Re: emailing From: full name

2013-01-08 Thread Jonathan Lundell
On 8 Jan 2013, at 11:40 AM, Adi adnan.smajlo...@gmail.com wrote:
 Hi Jonathan,
 Mine is putting properly company name in front of the address, by using:  
 mail.settings.sender = 'Company', but knowing that you are a guru here, may 
 not be at all what you are looking for... If you wanted I could send you a 
 sample email privately to see if that's what you needed?

I'd appreciate it, thanks. 

 
 Adnan
 
 
 
 
 On Tuesday, January 8, 2013 1:32:23 PM UTC-5, Jonathan Lundell wrote:
 I tried to persuade the web2py emailer to use a full name (like: 'My Name 
 mym...@mail.com') in the From: header by setting it in the headers 
 argument, but it didn't work: From continued to be set to the value of sender 
 (the bare email address). 
 
 As I read the code, From is initialized to the value of sender, but should be 
 overridden by headers. And for reference, if I set 'X-From' instead, that did 
 end up in the headers as I would have expected. 
 
 The Python smtplib suggests that it doesn't mess with the embedded headers. I 
 suppose it could be happening farther down the line, and eventually I'll do 
 some experimentation, but I thought I'd see whether anyone on the list has 
 solved the problem first. 
 
 
 -- 
  
  
  


-- 





[web2py] Re: Auto populate form

2013-01-08 Thread Niphlod
or use a computed field ?

On Tuesday, January 8, 2013 7:24:36 PM UTC+1, Derek wrote:

 You'd probably want to have a javascript that calls a special function on 
 your controller that returns the results from gethostbyname().

 On Tuesday, January 8, 2013 10:46:04 AM UTC-7, Saba wrote:

 hello,
  
 I have a table like this:
  
 db.define_table('host',
 Field('host_name', requires=IS_NOT_EMPTY()),
 Field('host_ip', requires=IS_NOT_EMPTY())
 )

 i'm using SQLFORM.grid to display/edit the data in the table. When a user 
 inputs a host_name field, I would like to automatically populate the 
 host_ip field by doing an nslookup of the host_name. Is there a way to do 
 this. Any suggestions please?
  
 thanks,
 Saba
  



-- 





[web2py] Re: Custom authentication provider

2013-01-08 Thread Ignacio Ocampo
I only change the Auth function to solve this problem and to know how 
web2py works.

I see that get_or_create_user have a second parameter with fields that will 
be updated.

I think that if the developer uses web2py default Auth function, would be 
nice allow update fields through auth.settings.update_fields configuration.

Is viable? To open a new ticket.

Ignacio Ocampo

On Tuesday, January 8, 2013 1:23:45 PM UTC-6, Massimo Di Pierro wrote:

 Perhaps I misunderstand the workflow. The solution cannot be to change an 
 Auth function to handle a specific custom field.

 The proper signature for the function is 

   get_or_create_user(self, keys, update_fields=['email'])

 so if you want to pass employee_id to keys and expect it to update the 
 record in case it is found you need to pass

   get_or_create_user(self, keys, update_fields=['email', 'employee_id'])

 There are two options here:
 1) allow some auth.settings.update_fields to be specified so the function 
 is called with right parameters
 2) change it so that update_fields defaults to keys.keys()

 2) would solve the problem automatically but it may break something. Not 
 sure.

 Please open a ticket: http://code.google.com/p/web2py/issues/list
 but let's discuss it some more.

 Massimo




 On Tuesday, 8 January 2013 12:09:09 UTC-6, Ignacio Ocampo wrote:

 Yes,

 I only uses:

 auth.settings.login_form=MyAuth(
param1=value1,
param2=value
 )

 It's all, I never call and writes/update in the auth_user anywhere.

 In gluon/tools.py login function, web2py check if they would use their 
 login form or from a central source (line 1955)

 At line 2068 web2py determined that central authentication would be used.

 At line 2075 web2py call: user = 
 self.get_or_create_user(table_user._filter_fields(cas_user))

 At line 1724, within get_or_create_user function, after that web2py 
 determine that the user exists:

 *update_keys = dict(registration_id=keys['registration_id']) #here is 
 the BUG*

 I solved it with:

 *update_keys = dict(registration_id=keys['registration_id'], 
 employee_id=keys['employee_id'])*

 So, I think that we need to update the gluon/tools.py file, to improve 
 the update of external fields.

 On Tuesday, January 8, 2013 11:43:44 AM UTC-6, Anthony wrote:

 On Tuesday, January 8, 2013 12:08:34 PM UTC-5, Ignacio Ocampo wrote:

 I only return a dict in the get_user, web2py does all the work.

 web2py call the get_user method, and web2py update the auth_user table 
 with the dict values.



 Yes, but where are you telling web2py to update the auth_user table? Can 
 you show the code?

 Anthony



-- 





Re: [web2py] Re: Resizing a user uploaded image

2013-01-08 Thread Bruno Rocha
I am using this recipe:

http://www.web2pyslices.com/slice/show/1522/generate-a-thumbnail-that-fits-in-a-box

I have plans to integrate it with a JavaScript Cropper plugin to get the
dimensions.

-- 





[web2py] Re: Custom authentication provider

2013-01-08 Thread Ignacio Ocampo
I open a ticket http://code.google.com/p/web2py/issues/detail?id=1260

On Tuesday, January 8, 2013 1:23:45 PM UTC-6, Massimo Di Pierro wrote:

 Perhaps I misunderstand the workflow. The solution cannot be to change an 
 Auth function to handle a specific custom field.

 The proper signature for the function is 

   get_or_create_user(self, keys, update_fields=['email'])

 so if you want to pass employee_id to keys and expect it to update the 
 record in case it is found you need to pass

   get_or_create_user(self, keys, update_fields=['email', 'employee_id'])

 There are two options here:
 1) allow some auth.settings.update_fields to be specified so the function 
 is called with right parameters
 2) change it so that update_fields defaults to keys.keys()

 2) would solve the problem automatically but it may break something. Not 
 sure.

 Please open a ticket: http://code.google.com/p/web2py/issues/list
 but let's discuss it some more.

 Massimo




 On Tuesday, 8 January 2013 12:09:09 UTC-6, Ignacio Ocampo wrote:

 Yes,

 I only uses:

 auth.settings.login_form=MyAuth(
param1=value1,
param2=value
 )

 It's all, I never call and writes/update in the auth_user anywhere.

 In gluon/tools.py login function, web2py check if they would use their 
 login form or from a central source (line 1955)

 At line 2068 web2py determined that central authentication would be used.

 At line 2075 web2py call: user = 
 self.get_or_create_user(table_user._filter_fields(cas_user))

 At line 1724, within get_or_create_user function, after that web2py 
 determine that the user exists:

 *update_keys = dict(registration_id=keys['registration_id']) #here is 
 the BUG*

 I solved it with:

 *update_keys = dict(registration_id=keys['registration_id'], 
 employee_id=keys['employee_id'])*

 So, I think that we need to update the gluon/tools.py file, to improve 
 the update of external fields.

 On Tuesday, January 8, 2013 11:43:44 AM UTC-6, Anthony wrote:

 On Tuesday, January 8, 2013 12:08:34 PM UTC-5, Ignacio Ocampo wrote:

 I only return a dict in the get_user, web2py does all the work.

 web2py call the get_user method, and web2py update the auth_user table 
 with the dict values.



 Yes, but where are you telling web2py to update the auth_user table? Can 
 you show the code?

 Anthony


On Tuesday, January 8, 2013 1:23:45 PM UTC-6, Massimo Di Pierro wrote:

 Perhaps I misunderstand the workflow. The solution cannot be to change an 
 Auth function to handle a specific custom field.

 The proper signature for the function is 

   get_or_create_user(self, keys, update_fields=['email'])

 so if you want to pass employee_id to keys and expect it to update the 
 record in case it is found you need to pass

   get_or_create_user(self, keys, update_fields=['email', 'employee_id'])

 There are two options here:
 1) allow some auth.settings.update_fields to be specified so the function 
 is called with right parameters
 2) change it so that update_fields defaults to keys.keys()

 2) would solve the problem automatically but it may break something. Not 
 sure.

 Please open a ticket: http://code.google.com/p/web2py/issues/list
 but let's discuss it some more.

 Massimo




 On Tuesday, 8 January 2013 12:09:09 UTC-6, Ignacio Ocampo wrote:

 Yes,

 I only uses:

 auth.settings.login_form=MyAuth(
param1=value1,
param2=value
 )

 It's all, I never call and writes/update in the auth_user anywhere.

 In gluon/tools.py login function, web2py check if they would use their 
 login form or from a central source (line 1955)

 At line 2068 web2py determined that central authentication would be used.

 At line 2075 web2py call: user = 
 self.get_or_create_user(table_user._filter_fields(cas_user))

 At line 1724, within get_or_create_user function, after that web2py 
 determine that the user exists:

 *update_keys = dict(registration_id=keys['registration_id']) #here is 
 the BUG*

 I solved it with:

 *update_keys = dict(registration_id=keys['registration_id'], 
 employee_id=keys['employee_id'])*

 So, I think that we need to update the gluon/tools.py file, to improve 
 the update of external fields.

 On Tuesday, January 8, 2013 11:43:44 AM UTC-6, Anthony wrote:

 On Tuesday, January 8, 2013 12:08:34 PM UTC-5, Ignacio Ocampo wrote:

 I only return a dict in the get_user, web2py does all the work.

 web2py call the get_user method, and web2py update the auth_user table 
 with the dict values.



 Yes, but where are you telling web2py to update the auth_user table? Can 
 you show the code?

 Anthony


On Tuesday, January 8, 2013 1:23:45 PM UTC-6, Massimo Di Pierro wrote:

 Perhaps I misunderstand the workflow. The solution cannot be to change an 
 Auth function to handle a specific custom field.

 The proper signature for the function is 

   get_or_create_user(self, keys, update_fields=['email'])

 so if you want to pass employee_id to keys and expect it to update the 
 record in case it is found you need to pass

   

Re: [web2py] Re: Resizing a user uploaded image

2013-01-08 Thread Michele Comitini
I use wand for the task: http://pypi.python.org/pypi/Wand/0.1.10
there are many other bindings on the impressive *magick libraries, but
this one being a ctypes implementation is light and fast enough..

mic


2013/1/8 Bruno Rocha rochacbr...@gmail.com:
 I am using this recipe:

 http://www.web2pyslices.com/slice/show/1522/generate-a-thumbnail-that-fits-in-a-box

 I have plans to integrate it with a JavaScript Cropper plugin to get the
 dimensions.

 --




-- 





[web2py] Re: Auto populate form

2013-01-08 Thread Saba

thank you all... i'll try your suggestions (need to do study 
javascript/ajax..)

-- 





[web2py] SQLFORM Next Item in Database

2013-01-08 Thread D.P.
I'm using solidtable to pull a selection from a database and display that 
selection (with the ability to edit the db entry) to the user.  I added an 
extra column with the code:

extracolumns = [{'label': A('Edit', _href='#'),
 'content': lambda row, rc: A('Edit', _href=
'display_database/%s' % row.id)}
]

which calls the function using sqlform

def display_database():
record = db.studentGrades(request.args(0)) or redirect(URL('back_home'))
form = SQLFORM(db.studentGrades, record)
if form.process().accepted:
response.flash = 'Updated Student Record'
redirect(URL(r=request, f='back_home'))
elif form.errors:
response.flash = 'Form has errors!'
return dict(form=form)



It would be much easier for the user if they could click a next button to 
scroll through the selection.  Is there functionality in sqlform or some 
other way to allow users to scroll through only a selection within a 
database?  So instead of returning to the solidtable view, the user could 
just edit the next row in the database selection.

dp

-- 





[web2py] Re: SQLFORM Next Item in Database

2013-01-08 Thread Derek
It seems to me that you could add a 'next' button on that page, which would 
take request.args(0)+1 and formulate your HREF that way.

On Tuesday, January 8, 2013 2:43:46 PM UTC-7, D.P. wrote:

 I'm using solidtable to pull a selection from a database and display that 
 selection (with the ability to edit the db entry) to the user.  I added an 
 extra column with the code:

 extracolumns = [{'label': A('Edit', _href='#'),
  'content': lambda row, rc: A('Edit', _href=
 'display_database/%s' % row.id)}
 ]

 which calls the function using sqlform

 def display_database():
 record = db.studentGrades(request.args(0)) or redirect(URL('back_home'
 ))
 form = SQLFORM(db.studentGrades, record)
 if form.process().accepted:
 response.flash = 'Updated Student Record'
 redirect(URL(r=request, f='back_home'))
 elif form.errors:
 response.flash = 'Form has errors!'
 return dict(form=form)



 It would be much easier for the user if they could click a next button 
 to scroll through the selection.  Is there functionality in sqlform or some 
 other way to allow users to scroll through only a selection within a 
 database?  So instead of returning to the solidtable view, the user could 
 just edit the next row in the database selection.

 dp


-- 





Re: [web2py] Delete a user

2013-01-08 Thread puercoespin
I think the right way is digitally signed urls. In the book: 
http://web2py.com/books/default/chapter/29/04?search=signature

-- 





[web2py] equivalent PHP $_SERVER['REMOTE_ADDR']

2013-01-08 Thread José Eloy
Hello!

Is there an equivalent to PHP variable $_SERVER['REMOTE_ADDR']?
I need to get the IP of the clients that are visiting my page to implement 
a counter page.

Thanks

-- 





Re: [web2py] equivalent PHP $_SERVER['REMOTE_ADDR']

2013-01-08 Thread Vinicius Assef
request.client or request.env.remote_addr

On Tue, Jan 8, 2013 at 8:55 PM, José Eloy pepe.e...@gmail.com wrote:
 Hello!

 Is there an equivalent to PHP variable $_SERVER['REMOTE_ADDR']?
 I need to get the IP of the clients that are visiting my page to implement a
 counter page.

 Thanks

 --




-- 





Re: [web2py] Re: Resizing a user uploaded image

2013-01-08 Thread Daniele Pestilli
I put imageutils in my app's modules directory, then I added:
Field(thumbnail, upload, uploadfolder=os.path.join(request.folder,
'uploads', 'profiles', 'thumbs')),
to the appropriate database table, and below that, in the same file (db.py)
I wrote:

from imageutils import THUMB
db.tutor.thumbnail.compute = lambda row: THUMB(row.picture, 200, 200)

but the resizing doesn't seem to work. Am I doing something wrong?


On Tue, Jan 8, 2013 at 9:29 PM, Michele Comitini michele.comit...@gmail.com
 wrote:

 I use wand for the task: http://pypi.python.org/pypi/Wand/0.1.10
 there are many other bindings on the impressive *magick libraries, but
 this one being a ctypes implementation is light and fast enough..

 mic


 2013/1/8 Bruno Rocha rochacbr...@gmail.com:
  I am using this recipe:
 
 
 http://www.web2pyslices.com/slice/show/1522/generate-a-thumbnail-that-fits-in-a-box
 
  I have plans to integrate it with a JavaScript Cropper plugin to get the
  dimensions.
 
  --
 
 
 

 --





-- 





Re: [web2py] Re: preferred solution for parsing {xht,ht,x}ml

2013-01-08 Thread Michele Comitini
IMHO beautifulsoup is simpler hence faster to implement than other
solutions, very  tolerant on bad markup...



2013/1/8 rh richard_hubb...@lavabit.com:
 On Mon, 7 Jan 2013 10:55:39 +0200
 Vasile Ermicioi elff...@gmail.com wrote:

 lxml, beautifulsoup

 Thanks, but too much code for my simple needs. I would hesitate to install
 so much software onto a production machine.  See the recent moinmoin
 exploit for an example of possible risks from 3rd party software.

 The HTMLParser in python will do fine.

 FWIW for python 3.3 it is now called html.parser
 sgmllib does not exist in 3.3

 The scope of parsing markup is deep and wide I have discovered. And I find
 there lots and lots of ways to do so in python.


 --





 --


 --




-- 





[web2py] problem with multiple processes with uwsgi and web2py

2013-01-08 Thread VP
My set up is nginx, uwsgi, web2py, and I am trying unsucessfully to 
configure so that there are multiple uwsgi processes serving web2py.

I used the script to install nginx, uwsgi.  I configured 8 processes.

$cat /etc/uwsgi/apps-enabled/web2py.xml 
uwsgi
pluginpython/plugin
socket/run/uwsgi/app/web2py/web2py.socket/socket
pythonpath/home/www-data/web2py//pythonpath
app mountpoint=/
scriptwsgihandler/script
/app
master/
processes8/processes
harakiri60/harakiri 
reload-mercy8/reload-mercy
cpu-affinity1/cpu-affinity
stats/tmp/stats.socket/stats
max-requests2000/max-requests
limit-as512/limit-as
reload-on-as256/reload-on-as
reload-on-rss192/reload-on-rss
no-orphans/
vacuum/
/uwsgi






But top says that only 3 uwsgi processes running.  



Also, it isn't working properly.   The way I expect this to work is that a 
request comes in after a slow still-running request still gets served. But 
this isn't the case.  It was like there was only one web2py process:   
other requests have to wait for the long-running request to finish.

I think there is a problem with the web2py and uwsgi set up.









-- 





[web2py] Re: problem with multiple processes with uwsgi and web2py

2013-01-08 Thread VP
I also test uwsgi serving a Bottle app.  I run from the command line, 
uwsgi, the bottle app with 8 processes.


This works as I expect.   Requests are served by unbusy processes while 
long-running requests are still being run.


So something about the web2py configuration that doesn't tell uwsgi to run 
with multiple processes.

Does anyone have any clue?

Thanks.

-- 





[web2py] Re: problem with multiple processes with uwsgi and web2py

2013-01-08 Thread Alan Etkin
El martes, 8 de enero de 2013 20:58:10 UTC-3, VP escribió:

 I also test uwsgi serving a Bottle app.  I run from the command line, 
 uwsgi, the bottle app with 8 processes.


Is that the file created by the script?. uwsgi can take options in 
different ways. Make sure it is actually reading the options from there. 
For example, the CentOS script creates a .conf file

-- 





[web2py] Re: problem with multiple processes with uwsgi and web2py

2013-01-08 Thread VP
Alan,
No.  From the command line, I told uwsgi to run with 8 processes (for the 
Bottle app).  Here's the command:

uwsgi --http 127.0.0.1:8080 -p 8 --plugins python --module=app:application



On Tuesday, January 8, 2013 6:09:07 PM UTC-6, Alan Etkin wrote:

 El martes, 8 de enero de 2013 20:58:10 UTC-3, VP escribió:

 I also test uwsgi serving a Bottle app.  I run from the command line, 
 uwsgi, the bottle app with 8 processes.


 Is that the file created by the script?. uwsgi can take options in 
 different ways. Make sure it is actually reading the options from there. 
 For example, the CentOS script creates a .conf file



-- 





Re: [web2py] Re: Resizing a user uploaded image

2013-01-08 Thread Bruno Rocha
Yeah it is a problem in THUMB function, thumb function looks for files
under /uploads and you are defining another folder.

change the imageutils module replacing /uploads with /uploads/profile

On Tue, Jan 8, 2013 at 9:30 PM, Daniele Pestilli byakugan...@gmail.comwrote:

 I put imageutils in my app's modules directory, then I added:
 Field(thumbnail, upload, uploadfolder=os.path.join(request.folder,
 'uploads', 'profiles', 'thumbs')),
 to the appropriate database table, and below that, in the same file
 (db.py) I wrote:

 from imageutils import THUMB
 db.tutor.thumbnail.compute = lambda row: THUMB(row.picture, 200, 200)

 but the resizing doesn't seem to work. Am I doing something wrong?


 On Tue, Jan 8, 2013 at 9:29 PM, Michele Comitini 
 michele.comit...@gmail.com wrote:

 I use wand for the task: http://pypi.python.org/pypi/Wand/0.1.10
 there are many other bindings on the impressive *magick libraries, but
 this one being a ctypes implementation is light and fast enough..

 mic


 2013/1/8 Bruno Rocha rochacbr...@gmail.com:
  I am using this recipe:
 
 
 http://www.web2pyslices.com/slice/show/1522/generate-a-thumbnail-that-fits-in-a-box
 
  I have plans to integrate it with a JavaScript Cropper plugin to get the
  dimensions.
 
  --
 
 
 

 --




  --





-- 





[web2py] Re: problem with multiple processes with uwsgi and web2py

2013-01-08 Thread VP
Those who are running nginx, uwsgi, web2py, can you do a quick check to see 
if uwsgi reads your web2py config file properly?

The default config has 4 processes.  If you do a top -u www-data, you 
should see 5 uwsgi processes (4 + 1 master).

If you see a different number (may be 3?), then there might be a problem.

Thanks.

-- 





Re: [web2py] Re: problem with multiple processes with uwsgi and web2py

2013-01-08 Thread Bruno Rocha
I have a single server, ubuntu 12.04 running 3 web2py instances + 2 php
wordpress websites

Php runs with fcgi - web2py runs with uwsgi, because of that I have 12
nginx workers running

I am not an expert on this, but this solution is working well for me.


That is what I have in top


*TOP*
top - 22:54:55 up 78 days,  4:24,  1 user,  load average: 0.05, 0.13, 0.13
Tasks: 111 total,   1 running, 110 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.1%us,  0.2%sy,  0.0%ni, 98.2%id,  1.5%wa,  0.0%hi,  0.1%si,
0.0%st
Mem:   1012860k total,   934292k used,78568k free,27148k buffers
Swap:   524284k total,   343908k used,   180376k free,   258680k cached

  PID USER  PR  NI  VIRT  RES  SHR S %CPU %MEMTIME+
COMMAND
 1123 www-data  20   0  396m  41m  14m S0  4.2   7:40.82
php5-fpm
 3738 www-data  20   0  160m 1512 1472 S0  0.1   5:00.87
uwsgi-core
 3901 www-data  20   0  160m 1512 1472 S0  0.1   5:04.47
uwsgi-core
 4730 www-data  20   0  397m  43m  15m S0  4.4   9:45.87
php5-fpm
 4731 www-data  20   0  397m  42m  15m S0  4.3   9:41.48
php5-fpm
 4732 www-data  20   0  392m  37m  14m S0  3.8   9:32.35
php5-fpm
 4734 www-data  20   0  393m  38m  15m S0  3.9   9:58.31
php5-fpm
 5113 www-data  20   0  208m  36m 3824 S0  3.7   0:56.18
uwsgi
 8993 www-data  20   0  240m  94m 4504 S0  9.5   0:20.76
uwsgi
 9409 www-data  20   0  217m 2188 2184 S0  0.2   1:34.40
uwsgi-core
 9410 www-data  20   0  217m 4388 2180 S0  0.4   0:51.60
uwsgi-core
 9457 www-data  20   0  214m  65m 4840 S0  6.7   0:08.62
uwsgi
15463 www-data  20   0 79460 3356 1664 S0  0.3   5:56.76
nginx
15464 www-data  20   0 79108 3476 1712 S0  0.3   5:56.79
nginx
15465 www-data  20   0 79632 3480 1656 S0  0.3   5:59.49
nginx
15466 www-data  20   0 79468 3392 1652 S0  0.3   5:54.69
nginx
15467 www-data  20   0 79184 3244 1660 S0  0.3   5:49.36
nginx
15468 www-data  20   0 79460 3380 1668 S0  0.3   5:39.78
nginx
15469 www-data  20   0 79604 3860 1672 S0  0.4   5:46.62
nginx
15470 www-data  20   0 79488 3368 1680 S0  0.3   5:55.42
nginx
15471 www-data  20   0 79604 3280 1656 S0  0.3   5:52.24
nginx
15472 www-data  20   0 79444 3468 1688 S0  0.3   5:59.96
nginx
15473 www-data  20   0 79440 3452 1684 S0  0.3   5:54.13
nginx
15474 www-data  20   0 79476 3516 1692 S0  0.3   5:49.28
nginx
16040 www-data  20   0  193m  47m 3884 S0  4.8   2:49.74
uwsgi
22482 www-data  20   0  153m 2384 2144 S0  0.2   2:41.56
uwsgi
22651 www-data  20   0  160m 4864 2208 S0  0.5   2:42.54
uwsgi
22818 www-data  20   0  160m 5532 2220 S0  0.5   3:01.67
uwsgi
28847 www-data  20   0  192m  46m 3588 S0  4.7   2:18.97
uwsgi
29885 www-data  20   0  208m  37m 4052 S0  3.8   0:34.50
uwsgi
29914 www-data  20   0  222m 2192 2188 S0  0.2   0:11.24
uwsgi-core
30403 www-data  20   0  205m 2208 2176 S0  0.2   0:05.77
uwsgi-core


*uwsgitop*

uwsgi-1.0.3-debian - Tue Jan  8 23:01:58 2013 - req: 1110940 - lq: 0 - tx:
22786619414
node: li284-252 - cwd: /home/www-data/web2py - uid: 33 - gid: 33 -
masterpid: 22818
 WID%   PID REQ EXC SIG STATUS  AVG RSS
VSZ TX  RunT
 1  71.03   10199   789111  0   0   idle162ms   76M
222M15494M  3912m
 2  28.97   10171   321829  0   0   idle246ms   60M
205M6236M   1776m



*UWSGI FILE* ( Ihave the same file for other 2 apps, but other apps have no
master tag )

uwsgi
pluginpython/plugin
socket/run/uwsgi/app/web2py/web2py.socket/socket
pythonpath/home/www-data/web2py//pythonpath
app mountpoint=/
scriptwsgihandler/script
/app
master/
processes4/processes
harakiri60/harakiri
reload-mercy8/reload-mercy
cpu-affinity1/cpu-affinity
stats/tmp/stats.socket/stats
max-requests2000/max-requests
limit-as512/limit-as
reload-on-as256/reload-on-as
reload-on-rss192/reload-on-rss
no-orphans/
vacuum/
/uwsgi


*NGINX FILE*

server {
server_name x.com.br;

rewrite ^/(.*) http://www.xx.com.br/$1 permanent;
   }


server {
client_max_body_size 10M;
listen  80;
server_name wwwcom.br;


if ( $http_referer ~*
(babes|forsale|girl|jewelry|love|nudit|poker|porn|sex|teen) )
{
 # return 404;
 return 403;
}

if ($request_method !~ ^(GET|HEAD|POST)$ ) {
 return 444;
}

location ~ \.(aspx|php|jsp|asp|cgi)$ {
   return 410;
}

if ($http_user_agent ~* LWP::Simple|BBBike|wget) {
return 403;
}

if ($http_user_agent ~*
msnbot|scrapbot|WebCopier|AhrefsBot|Baidu|Yandex|baiduspider|yandexspider )
{
return 403;
}

location ~* /(\w+)/static/ {
   root /home/www-data/web2py/applications/;
}

   location ~ ^/download/(.*)$ {
   alias 

Re: [web2py] equivalent PHP $_SERVER['REMOTE_ADDR']

2013-01-08 Thread José Eloy
Thanks


-- 





Re: [web2py] Re: Resizing a user uploaded image

2013-01-08 Thread Daniele Pestilli
Hmm still not working.
I'm wondering if this is the problem:
uploadfolder=os.path.join(request.folder, 'uploads', 'profiles', 'thumbs')
should it be
uploadfolder=os.path.join(request.folder, 'uploads', 'profiles/thumbs')  or
something?


On Wed, Jan 9, 2013 at 12:43 AM, Bruno Rocha rochacbr...@gmail.com wrote:

 Yeah it is a problem in THUMB function, thumb function looks for files
 under /uploads and you are defining another folder.

 change the imageutils module replacing /uploads with /uploads/profile

 On Tue, Jan 8, 2013 at 9:30 PM, Daniele Pestilli byakugan...@gmail.comwrote:

 I put imageutils in my app's modules directory, then I added:
 Field(thumbnail, upload, uploadfolder=os.path.join(request.folder,
 'uploads', 'profiles', 'thumbs')),
 to the appropriate database table, and below that, in the same file
 (db.py) I wrote:

 from imageutils import THUMB
 db.tutor.thumbnail.compute = lambda row: THUMB(row.picture, 200, 200)

 but the resizing doesn't seem to work. Am I doing something wrong?


 On Tue, Jan 8, 2013 at 9:29 PM, Michele Comitini 
 michele.comit...@gmail.com wrote:

 I use wand for the task: http://pypi.python.org/pypi/Wand/0.1.10
 there are many other bindings on the impressive *magick libraries, but
 this one being a ctypes implementation is light and fast enough..

 mic


 2013/1/8 Bruno Rocha rochacbr...@gmail.com:
  I am using this recipe:
 
 
 http://www.web2pyslices.com/slice/show/1522/generate-a-thumbnail-that-fits-in-a-box
 
  I have plans to integrate it with a JavaScript Cropper plugin to get
 the
  dimensions.
 
  --
 
 
 

 --




  --





  --





-- 





Re: [web2py] Re: Resizing a user uploaded image

2013-01-08 Thread Daniele Pestilli
It seems to be uploading the full-sized image properly but for the thumb it
says 'thumbnail': None where thumbnail is the field name in the db.py file.


On Wed, Jan 9, 2013 at 1:06 AM, Daniele Pestilli byakugan...@gmail.comwrote:

 Hmm still not working.
 I'm wondering if this is the problem:

 uploadfolder=os.path.join(request.folder, 'uploads', 'profiles', 'thumbs')
 should it be
 uploadfolder=os.path.join(request.folder, 'uploads', 'profiles/thumbs')
 or something?


 On Wed, Jan 9, 2013 at 12:43 AM, Bruno Rocha rochacbr...@gmail.comwrote:

 Yeah it is a problem in THUMB function, thumb function looks for files
 under /uploads and you are defining another folder.

 change the imageutils module replacing /uploads with /uploads/profile

 On Tue, Jan 8, 2013 at 9:30 PM, Daniele Pestilli 
 byakugan...@gmail.comwrote:

 I put imageutils in my app's modules directory, then I added:
 Field(thumbnail, upload, uploadfolder=os.path.join(request.folder,
 'uploads', 'profiles', 'thumbs')),
 to the appropriate database table, and below that, in the same file
 (db.py) I wrote:

 from imageutils import THUMB
 db.tutor.thumbnail.compute = lambda row: THUMB(row.picture, 200, 200)

 but the resizing doesn't seem to work. Am I doing something wrong?


 On Tue, Jan 8, 2013 at 9:29 PM, Michele Comitini 
 michele.comit...@gmail.com wrote:

 I use wand for the task: http://pypi.python.org/pypi/Wand/0.1.10
 there are many other bindings on the impressive *magick libraries, but
 this one being a ctypes implementation is light and fast enough..

 mic


 2013/1/8 Bruno Rocha rochacbr...@gmail.com:
  I am using this recipe:
 
 
 http://www.web2pyslices.com/slice/show/1522/generate-a-thumbnail-that-fits-in-a-box
 
  I have plans to integrate it with a JavaScript Cropper plugin to get
 the
  dimensions.
 
  --
 
 
 

 --




  --





  --







-- 





Re: [web2py] Re: problem with multiple processes with uwsgi and web2py

2013-01-08 Thread VP
Thanks Bruno.

Okay, I figured it out.  I'm not sure if I used an out-of-date 
web2py/uwsgi/ngninx install script, but that script does not mention 
another file /usr/share/uwsgi/conf/default.ini 

This file sets the number of workers to 2 and it overwrites the web2py 
configuration file /etc/uwsgi/apps-available/web2py.xml 


-- 





Re: [web2py] Re: problem with multiple processes with uwsgi and web2py

2013-01-08 Thread Bruno Rocha
and youi delete or comment that file?

-- 





Re: [web2py] Re: problem with multiple processes with uwsgi and web2py

2013-01-08 Thread VP
yeah.  I commented off the worker=2 setting in that file.  Consequently, 
the number of workers was exactly what the web2py configure file says.



On Tuesday, January 8, 2013 7:36:01 PM UTC-6, rochacbruno wrote:

 and youi delete or comment that file?


-- 





Re: [web2py] Re: problem with multiple processes with uwsgi and web2py

2013-01-08 Thread Bruno Rocha
Ok, but just read this

# User-made changes in this file will be silently lost, as it is silently
# rewrited with upgrade of uwsgi package.
#
# If you want to change default options of uWSGI daemon, then:
# * copy this file somewhere
# * add/remove/change options in copied file
# * edit /etc/default/uwsgi and change location of inherited configuration
#   file to path to copied file

-- 





Re: [web2py] Re: Resizing a user uploaded image

2013-01-08 Thread Bruno Rocha
are you running on Google App Engine?

-- 





Re: [web2py] equivalent PHP $_SERVER['REMOTE_ADDR']

2013-01-08 Thread Vasile Ermicioi
request.env.remote_addr

--