Re: [web2py] powerTable.extrajs question

2011-02-01 Thread Johann Spies
Thanks. It helped a bit.  I see I had to use table.extra and not
table.extrajs as in the example I followed.

But my problems are not over :(

My controller:

def pwrtable():
"""
Generiese definisie vir plugin: powertable.
"""
powerTable = plugins.powerTable
powerTable.dtfeatures['sScrollY'] = '338'
powerTable.dtfeatures['sScrollX'] = '120%'
powerTable.headers = 'fieldname:capitalize'
powerTable.showkeycolumn = False
powerTable.uitheme = request.vars.get('theme','redmond')#'smoothness' /
'redmond' /'cupertino'
powerTable.dtfeatures['sPaginationType'] =
request.vars.get('pager','scrolling')
 powerTable.dtfeatures['bScrollCollapse'] = True
powerTable.dtfeatures['bScrollInfinite'] = True
powerTable.dtfeatures['iScrollLoadGap'] = 10
powerTable.dtfeatures['bAutoWidth'] = True
powerTable.dtfeatures['bLengthChange'] = True
powerTable.dtfeatures['bProcessing'] = True
powerTable.dtfeatures['iDisplayLength'] = 18
powerTable.dtfeatures['iDisplayStart'] = 0
powerTable.dtfeatures['asStripClasses'] = ['odd','even']
powerTable.columnsearch = False
return (powerTable)


def skrywerdetails():
"""
Receives:
'outeur' in tablename
'id' in fieldname'
the id value in value
column names in cols
"""
#Key Processing
art_id = None
art_id = request.vars['dt_1'].split('.')[-1]
print request.vars
print art_id

#create a DIV to wrap the return
obj = DIV()
obj.append(SQLTABLE(db((db.outeur_art_ekw.artikel == art_id)&
   (db.outeur.id ==
db.outeur_art_ekw.skrywer)).select(db.outeur.ALL)))


# return locals(), which has only one object 'obj'
return obj


@auth.requires_login()
def artikels():
  # some pagination stuff removed
   query = db.artikel.id > 0
powerTable = pwrtable()
powerTable.datasource = db(query).select(db.artikel.id,
 db.artikel.outeur_id,
 db.artikel.instansie_id,
 db.artikel.joernaal_id,
 db.artikel.titel,
 limitby=limitby)

powerTable.keycolumn = 'artikel.id'
powerTable.showkeycolumn = True
powerTable.extra = dict(autoresize={},
 tooltip={},

details={'detailscallback':URL('default','skrywerdetails')
 })

records = powerTable.create()


return dict(data = records, query=query, opskrif = opskrif,
total_found=total_found,page=page,
items_per_page=items_per_page,
pages=pages, add = add)


-- 
 May grace and peace be yours in abundance through the full knowledge of God
and of Jesus our Lord!  His divine power has given us everything we need for
life and godliness through the full knowledge of the one who called us by
his own glory and excellence.
2 Pet. 1:2b,3a


Re: [web2py] powerTable.extrajs question

2011-02-01 Thread Johann Spies
Apologies, I sent the email before it was completed.

It seems that only on artikel.id == 1 the function (skrywerdetails) is
called.  The print lines in that function print only the following content:

 (request.vars)
1 (art_id)

For all other rows in the table clickng on the + results in an empty table
opening up.

Regards
Johann
-- 
 May grace and peace be yours in abundance through the full knowledge of God
and of Jesus our Lord!  His divine power has given us everything we need for
life and godliness through the full knowledge of the one who called us by
his own glory and excellence.
2 Pet. 1:2b,3a


Re: [web2py] Pydiction - python autocomplete on VIM - web2py?

2011-02-01 Thread contatogilson...@gmail.com
I use Python Omni Completation. It's good:
http://www.vim.org/scripts/script.php?script_id=1542
_
*Gilson Filho*
*Web Developer
http://gilsondev.com*



2011/2/1 Bruno Rocha 

> Hi,
>
> I user Pydiction http://www.vim.org/scripts/script.php?script_id=850 to
> autocomplete Python code on VIM.
>
> I am playing with its complete-dict file, but I can' t find a way to
> include web2py keywords in there to have it autocompleted on VIM.
>
> I just want to add few web2py keywords as
>
> request. give me
> request.args(
> request.vars.
>
> db.
> db.define_table(
>
> Fie.
> Field(
>
> ret.
> return dict(
> return locals()
>
> Is there somebody who have this kind of stuff working for VIM ?
>
>
> --
> Bruno Rocha
> http://about.me/rochacbruno/bio
>


Re: [web2py] powerTable.extrajs question

2011-02-01 Thread rochacbruno
The problem is in 
art_id = request.vars['dt_1'].split('.')[-1]

For the first row it will be called dt_1 but for the second it will be dt_2 and 
so on. 

Another possibility is that when you call the second. It mess up the 
JavaScript. 

Can you pastebin your whole code or attach your w2p app?




Re: [web2py] Pydiction - python autocomplete on VIM - web2py?

2011-02-01 Thread Bruno Rocha
2011/2/1 contatogilson...@gmail.com 

> I use Python Omni Completation. It's good:
> http://www.vim.org/scripts/script.php?script_id=1542


It permits you to customize the keywords dictionary to include web2py
keywords? or it auto-detects web2py keywords?


[web2py] Re: host file

2011-02-01 Thread stargate
Anybody know how to do this?

On Jan 26, 7:22 am, stargate  wrote:
> Lets say in web2py  you create a new application called myapp.  What i
> want to do is when i type  www.myapp.com:8000it will go to that
> web2py installation how would you do this.
>
> I know in windows you need to edit
>
> C:\WINDOWS\system32\drivers\etc\hosts


Re: [web2py] Pydiction - python autocomplete on VIM - web2py?

2011-02-01 Thread contatogilson...@gmail.com
I do no know
_
*Gilson Filho*
*Web Developer
http://gilsondev.com*



2011/2/1 Bruno Rocha 

> 2011/2/1 contatogilson...@gmail.com 
>
>> I use Python Omni Completation. It's good:
>> http://www.vim.org/scripts/script.php?script_id=1542
>
>
> It permits you to customize the keywords dictionary to include web2py
> keywords? or it auto-detects web2py keywords?
>


Re: [web2py] Re: host file

2011-02-01 Thread w2padawan
rename your app as "init" or configure routes.py (search the book for this)

2011/2/1 stargate :
> Anybody know how to do this?
>
> On Jan 26, 7:22 am, stargate  wrote:
>> Lets say in web2py  you create a new application called myapp.  What i
>> want to do is when i type  www.myapp.com:8000it will go to that
>> web2py installation how would you do this.
>>
>> I know in windows you need to edit
>>
>> C:\WINDOWS\system32\drivers\etc\hosts


Re: [web2py] powerTable.extrajs question

2011-02-01 Thread Johann Spies
On 1 February 2011 13:17, rochacbruno  wrote:

> The problem is in
>
> art_id = request.vars['dt_1'].split('.')[-1]
>
> For the first row it will be called dt_1 but for the second it will be dt_2
> and so on.
>
>
Thanks.  Now I am beginning to understand your logic.  The following is
working now (adapting code from one of your examples):

  #Key Processing
key = None
cols = None
for k in request.vars.keys():
if k[:3] == 'dt_':
key = request.vars[k]

art_id = None
art_id = key.split('.')[-1]

Thanks for a fine product.  I am at the moment implementing pagination
before I call PowerTable because it takes too long to show a large number of
records.  I hope some time in future people with proper knowledge of
javascript like you will be able to combine pagination the way jqgrid from
the plugin_wiki does (using limitby in sql-queries) with the other powerfull
features to get the best of both sides.

Regards
Johann
-- 
 May grace and peace be yours in abundance through the full knowledge of God
and of Jesus our Lord!  His divine power has given us everything we need for
life and godliness through the full knowledge of the one who called us by
his own glory and excellence.
2 Pet. 1:2b,3a


Re: [web2py] powerTable.extrajs question

2011-02-01 Thread Bruno Rocha
2011/2/1 Johann Spies 

> I hope some time in future people with proper knowledge of javascript like
> you will be able to combine pagination the way jqgrid from the plugin_wiki
> does (using limitby in sql-queries) with the other powerfull features to get
> the best of both sides.


datatables.net has a full support to JSON and Xml datasources, with that we
can do server side processing in the same way jqgrid does, I am planning to
rewrite some parts of powerTable to implement it.

And I am counting the help of people who knows javascript and web2py, any
help, suggestion and report is very appreciated.

Thanks

Bruno.


Re: [web2py] cascading drop down list not working

2011-02-01 Thread w2padawan
I don't have any "require" in the model I posted. do you know how can
I get it work with the model I posted above?

2011/1/31 w2padawan :
> 2011/1/31 Alexandre Andrade :
>> It works fine to me, but it relies on default keys on db
>> subcategory table:
>> Field('category_id', db.category)
>> if it is like
>> Field('category_id', requires(db, db.category.id))
>> it will not work.
>
> Hi Alexandre, I don't fully understand your point. By "default keys on
> db" you mean using:
>
> Field('reference', db.othertable)
>
> in contrast of:
>
> Field('reference' type='reference othertable') ?
>
> It doesn't work in that way, neither. But as I said before, if I
> remove 'db.t_categoria' from
> line 110 in [2] (links posted in first post) the widget do work, and
> go wrong if I put db.t_categoria there again, but the keys seems to be
> in place as the code shows, so I still can't figure what i'm doing
> wrong.
>


[web2py] Case-insensitive autocomplete?

2011-02-01 Thread Johann Spies
How is it possible to get a case-insensitive autocomplete?

Having a database where there are inconsistencies in a field it will help a
lot if autocomplete can be told to work case-insensitive.

Regards
Johann

-- 
 May grace and peace be yours in abundance through the full knowledge of God
and of Jesus our Lord!  His divine power has given us everything we need for
life and godliness through the full knowledge of the one who called us by
his own glory and excellence.
2 Pet. 1:2b,3a


[web2py] Doubt, using the date field

2011-02-01 Thread Jan Palach
Hi everybody, 

I have a little problem. I have a table containing a date field in the format 
"% m-% d% Y"as shown below:

db.define_table('parcelas',
Field('numero', 'integer'),
Field('valor', 'double'),
Field('data_vencimento', 'date'),
Field('pago', 'boolean'),
Field('pagamento_id', db.pagamento)
)

db.parcelas.data_vencimento.requires=IS_DATE(format=T("%d-%m-%Y"), 
error_message=T("use dd-mm-"))


  In my form the corresponding inputs are using the class "date" see below 
for example:

 


  After saving the field is something strange in the management section of 
thedatabase object is not recovered, returning the following error:

   File "gluon / dal.py", line 1008, in select
   File "gluon / dal.py", line 1207, in parse
ValueError: day is out of range for month

I changed the web2py_ajax.html to use the format "% d-% m-% Y", but it seems 
not enough.


Should I convert the string to a form sent by type date before saving? Can 
anyone help me?


Sorry my english... :)

Re: [web2py] Re: Uncaught RangeError: Maximum call stack size exceeded

2011-02-01 Thread Anthony
On Tuesday, February 1, 2011 1:57:35 AM UTC-5, spyker wrote: 
>
> On 31 January 2011 21:52, Anthony  wrote:
>  
>>
>> Is that a Python error code? When I Google that error, all the references 
>> I see are to Javascript errors in particular browsers. Could the problem be 
>> on the client side?
>>
>
>
> I think you are on the right track.  The error message appeared when I used 
> Chrome.  When I try Firefox I get a popup:
> "A script on this page may be busy, or it may have stopped responding. You 
> can stop the script now, or you can continue to see if the script will 
> complete.
>
 
Yes, the references I found for that exact error message all mentioned 
Chrome or Safari (both use the WebKit engine) -- I think other browsers have 
slightly different error messages when the call stack size is exceeded. See 
http://www.javascriptrules.com/2009/06/30/limitation-on-call-stacks/.
 
Anthony


[web2py] Re: Can't deal with MemcachedKeyLengthError in caching selects

2011-02-01 Thread Massimo Di Pierro
I think have a solution in trunk. You will not need to specify length
and should work.

On Jan 31, 8:40 pm, kenji4569  wrote:
> When I run the following code:
>
> db(db.xxx.id==1).select(cache=(cache.memcache, 5))
>
> I got MemcachedKeyLengthError: Key length is > 250.
>
> Since xxx table has many fields, the sql used for the key readily
> reached the limit.
>
> I just want to specify the cache key, but I couldn't, given the
> dal.py:
>
> (cache_model, time_expire) = attributes['cache']
> del attributes['cache']
> key = self.uri + '/' + sql
> rows = cache_model(key, lambda: response(sql), time_expire)
>
> Please help.
> Thanks in advance, Kenji


[web2py] Re: has anyone managed to pickle the 'db' DAL reference?

2011-02-01 Thread Massimo Di Pierro
Yes, the data is there.

On Jan 31, 9:26 pm, mart  wrote:
> i see... so, if I understand, only the table definitions are missing
> (and I should know this), but I am hoping that this means just the
> tables,not the data? If something Commet could make that the tabel
> data available (maybe as a string), would it be possible to to :
>
>                  tables please?
> client  -> web2py Server (commet
> listener?)
>
>         < return "Models" as a
> string (I don't know the tornado size limitations)
>
> Now that I have the the model, i should be able to have that explicite
> define (with no data in the tables), then do dbRemote = DAL(... ?   Or
> maybe, this is silly...
>
> Maybe export/import is the best known solution?
>
> Thanks,
>
> mart :)
>
> On Jan 31, 9:09 pm, Massimo Di Pierro 
> wrote:
>
>
>
>
>
>
>
> > I see what you mean now. No you cannot do that.
>
> > If you do
>
> > python web2py.py -A app -M -N -R script.py
>
> > the script will be executed in an environment similar to a controller
> > and will see the stuff defined in the models.
>
> > There is no way (currently) for you to do db=DAL(...) and have
> > db.yourtable without an explicit db.define_table(..).
>
> > On Jan 31, 7:20 pm, mart  wrote:
>
> > > yes... that's what I meant... models ;) the models are invisible
>
> > > Thanks for that, I'll try that :) so with that, I can do something
> > > like:
>
> > > dbRemote = DAL(
>
> > > ?
>
> > > Mart :)
>
> > > On Jan 31, 3:47 pm, Massimo Di Pierro 
> > > wrote:
>
> > > > Not sure what you mean by invisible. web2py does not learn about
> > > > tables from the db. It learns about them from the models.
>
> > > > If you run a script with
>
> > > > python web2py.py -A app -M -N -R script.py
>
> > > > the script will see the models.
>
> > > > On Jan 31, 10:27 am, mart  wrote:
>
> > > > > right... ok, I get that.
>
> > > > > So, is there a way to connect a new network connection to an existing
> > > > > sqlite db? I tried some suggestion from a posting of a few weeks ago,
> > > > > and it seems to connect, but tables are 'invisible'.
>
> > > > > ** Note **
> > > > > some dbs are created from script (no web), still web2py (just no web,
> > > > > like __2py ;)) and others are created/maintained in a deployed web2py
> > > > > environment. Possible? can I for example have a script (DAL stand-
> > > > > alone), connect to a fully deployed web2py's DB? Actually, the
> > > > > scenario can be web2py app connects to another web2py app (on the same
> > > > > or different server), can also be stand alone DAL to stand-alone DAL,
> > > > > or stand-alone-DAL to web2py server, or web2py server to stand-alone
> > > > > DALs db
>
> > > > > Thanks,
> > > > > Mart:)
>
> > > > > On Jan 31, 9:24 am, Massimo Di Pierro 
> > > > > wrote:
>
> > > > > > Impossible. You cannot picke a network connection. It more than just
> > > > > > data.
>
> > > > > > On Jan 31, 5:30 am, mart  wrote:
>
> > > > > > > Hi,
>
> > > > > > > I'm looking to try something (again) that has not yet been too
> > > > > > > successful (but I still want to try)... Currently (with 
> > > > > > > stand-alone
> > > > > > > Dal) I am managing by passing 'db' around (or rather self.db) to 
> > > > > > > avoid
> > > > > > > having to create more instances than I have to. Now, to pick up 
> > > > > > > some
> > > > > > > processes where  they left off, I would like to try pickling 
> > > > > > > 'self.db'
> > > > > > > to a file, let sys.exit() happen, load the pickle, then debug
> > > > > > > exceptions, but without having to start from scratch ad rely on
> > > > > > > breakpoints to wake me up when I get to troublesome areas (the 
> > > > > > > wait
> > > > > > > can be as long as an hour sometimes).
>
> > > > > > > So, has anyone successfully pickled 'db'? Anything fancy that 
> > > > > > > need to
> > > > > > > be done the the attributes (even if only temporary).
>
> > > > > > > Thanks,
> > > > > > > Mart :)


[web2py] Re: background task error

2011-02-01 Thread Massimo Di Pierro
two things are wrong:

1) that line "import gluon.import_all" should be commented (has been
commented for at list six web2py versions) it is only used to build
py2exe
2) even if you uncomment, gluon/import_all.py should be there.

You may have a very old version of web2py and some missing files.

On Jan 31, 11:36 pm, pbreit  wrote:
> Trying to run a background task from MacOS command line and getting error:
>
> pbreit$ python web2py.py -S myapp -M -N -R
> applications/myapp/private/expire_items.py
> Traceback (most recent call last):
>   File "web2py.py", line 3, in 
>     import gluon.import_all
> ImportError: No module named gluon.import_all


[web2py] Re: Doubt, using the date field

2011-02-01 Thread Massimo Di Pierro
You should not change web2py_ajax. You should translate the string "%Y-
%m-%d" using the internationalization interface.

On Feb 1, 4:33 am, Jan Palach  wrote:
> Hi everybody,
>
> I have a little problem. I have a table containing a date field in the format 
> "% m-% d% Y"as shown below:
>
> db.define_table('parcelas',
>     Field('numero', 'integer'),
>     Field('valor', 'double'),
>     Field('data_vencimento', 'date'),
>     Field('pago', 'boolean'),
>     Field('pagamento_id', db.pagamento)
> )
>
> db.parcelas.data_vencimento.requires=IS_DATE(format=T("%d-%m-%Y"), 
> error_message=T("use dd-mm-"))
>
>       In my form the corresponding inputs are using the class "date" see 
> below for example:
>
>      
>
>       After saving the field is something strange in the management section 
> of thedatabase object is not recovered, returning the following error:
>
>    File "gluon / dal.py", line 1008, in select
>    File "gluon / dal.py", line 1207, in parse
> ValueError: day is out of range for month
>
> I changed the web2py_ajax.html to use the format "% d-% m-% Y", but it seems 
> not enough.
>
> Should I convert the string to a form sent by type date before saving? Can 
> anyone help me?
>
> Sorry my english... :)


[web2py] Re: Uncaught RangeError: Maximum call stack size exceeded

2011-02-01 Thread Massimo Di Pierro
The problem is that your app is trying to build a dropdown (..) with 102589 options.
This causes both the slowness and crashes the browser.



On Jan 31, 8:48 am, Johann Spies  wrote:
> Hallo Massimo,
>
> On 31 January 2011 16:23, Massimo Di Pierro wrote:
>
> > Never seen it before. What code/condition causes it?
>
> I have experimented and have determined that the following model definition
> is related:
>
>  Field("outeur_id", 'list:reference outeur'), # (see my other thread about
> the speeding up IS_IN_DB)
>
> The full model is in the other thread.  If I remove that line from the model
> the update/insert forms appear immediately when called - otherwise it takes
> about 70 seconds resulting in the error message in the subject line.
>
> The table referenced in this field contains 102589 records.
>
> I suspect list:reference should not be used here - which is a pity.
>
> Regards
> Johann
> --
>  May grace and peace be yours in abundance through the full knowledge of God
> and of Jesus our Lord!  His divine power has given us everything we need for
> life and godliness through the full knowledge of the one who called us by
> his own glory and excellence.
>                                                     2 Pet. 1:2b,3a


[web2py] Re: dynamic session variables

2011-02-01 Thread Francisco Costa
I want something like this:

if not session.id[page_id]:
session.id[page_id]=str(request.now)


but i get this error: KeyError: '74'


I want to validate if a dynamic variable exists.. if not I want to
create it and to get the time


On Feb 1, 4:17 am, Jason Brower  wrote:
> You can do that. At the top of the default.py or what ever you are using, 
> place something like...
> session.pages[request.page]  = True
> or how ever you want to do it. Just make sure because it is a dictionary that 
> you blank it or initialize it befor asigning anything to it.
>
>
>
>
>
>
>
> - Original message -
> > Hello,
> > I want to have dinamic session variables like this:
> >         session.id
> > where id is different from page to page..
>
> > I've tried
> >         id = variable
> >         session.id
>
> > and
> >         session.id['variable']
>
> > without any results.
>
> > I would like to be able to open different pages at the same time and
> > the browser could get all the session variables.


[web2py] Re: Is there a way to remove application name from URL()?

2011-02-01 Thread Wikus van de Merwe
Your routes do not work for internal links because the last rewriting rule 
from routes_in have to be also applied to routes_out.

routes_in = ( 
  ('/static/$anything', '/myapp/static/$anything'), 
  ('/appadmin/$anything', '/myapp/appadmin/$anything'), 
  ('/favicon.ico', '/myapp/static/favicon.ico'), 
  ('/robots.txt', '/myapp/static/robots.txt'), 
  ('/(.*))', r'/myapp/\1'), 
) 
routes_out = [(x, y) for (y, x) in routes_in[:-2]]+[('/myapp/(.*))', 
r'/\1')]



[web2py] adding tables instead of merging?

2011-02-01 Thread mart
Hi,

Say a process generates a DB and a set of tables, and say this process
is repeated multple times: Is it possible to add tables (as opposed to
merging) to an existing DB? Since once set of tables have the same
names as another, ideally the tables could live in a separate folder
(uniquely named)... I'm not too hopeful, but is something like this
possible?

thanks,
Mart :)


[web2py] Re: dynamic session variables

2011-02-01 Thread Massimo Di Pierro
session.id = session.id or {}
session.id[page_id]=session.id.get(page_id,str(request.now))


On Feb 1, 9:59 am, Francisco Costa  wrote:
> I want something like this:
>
>     if not session.id[page_id]:
>         session.id[page_id]=str(request.now)
>
> but i get this error: KeyError: '74'
>
> I want to validate if a dynamic variable exists.. if not I want to
> create it and to get the time
>
> On Feb 1, 4:17 am, Jason Brower  wrote:
>
>
>
> > You can do that. At the top of the default.py or what ever you are using, 
> > place something like...
> > session.pages[request.page]  = True
> > or how ever you want to do it. Just make sure because it is a dictionary 
> > that you blank it or initialize it befor asigning anything to it.
>
> > - Original message -
> > > Hello,
> > > I want to have dinamic session variables like this:
> > >         session.id
> > > where id is different from page to page..
>
> > > I've tried
> > >         id = variable
> > >         session.id
>
> > > and
> > >         session.id['variable']
>
> > > without any results.
>
> > > I would like to be able to open different pages at the same time and
> > > the browser could get all the session variables.- Hide quoted text -
>
> - Show quoted text -


[web2py] Log tickets

2011-02-01 Thread Jim Karsten
On my development server, I log errors to syslog so they are
accessible from a single location. Web2py tickets present a problem
since they are not logged. I could configure syslog to access errors
from the ticket error file, but it contains more information than I
need and the text isn't in a suitable format.

I added three lines to the RestrictedError class log() method in gluon/
restricted.py. The traceback message of a ticket is then logged quite
nicely.

def log(self, request):
...

ticket_storage = TicketStorage(db=request.tickets_db)
ticket_storage.store(request, f, d)
=>  for line in str(self.traceback).split("\n"):
=>  if len(line.strip()) > 1:
=>  logger.error(line.strip())
return '%s/%s' % (a, f)
except:
logger.error(self.traceback)
return None

Is there any interest in adding that to the source code?

Also, when I first tested this, I copied the
logger.error(self.traceback) line from the except clause to log the
ticket message. It only logged the first line. The message logged is:
"Traceback (most recent call last):" which isn't much use. Possibly a
for loop similar to what I used above would improve that.

Regards,
Jim Karsten


[web2py] insert into table where fields and values are in a dict

2011-02-01 Thread Ed Greenberg
If I call db.tablename.insert(...) it expects individual column-value
pairs.  I already have these in a dict (which has been pre-screened
for valid columns and types).

Is there a way to call insert with this dict, or to properly explode
the values into something I can pass to insert?

Thanks.


Re: [web2py] insert into table where fields and values are in a dict

2011-02-01 Thread Vasile Ermicioi
d = {k1=v1, k2=v2}
db.tablename.insert(**d)


Re: [web2py] insert into table where fields and values are in a dict

2011-02-01 Thread Vasile Ermicioi
d = dict(k1=v1, k2=v2)
db.tablename.insert(**d)


Re: [web2py] Re: Need help in standardizing my coding and naming schemes before I start my main project

2011-02-01 Thread Martin Barnard
General request for comments & corrections from the more experienced (than
me) programmers in this group please. I really don't want to be giving bad
advice. Anyway, on to the advice...

Rupesh,

In the end, it doesn't matter what scheme you use, as long as you find it
easy & your practices are consistent. If you are working on shared code
(i.e. working with somebody else), then you should both agree on a set of
coding practices.
If you are working on multiple applications within the same database, then
it makes sense to prefix application-specific tables with something which
easily describes it (in case you have to examine the back-end database, or
have to make cross-application queries).

That being said, I suggest that at the very least, you take a look at Python
PEP  guidelines, in order to
standardise your coding practice.

As far as database naming goes, if you are building applications from
scratch, try to ensure that you have memorable names (or ones which are
logical & easy to recreate). If there is the possibility of more than one
app being stored in your database backend, and the possibility exists for
table name collisions (tables called 'name' or 'address' are very common).
It is, in my opinion, good practice to prefix your application-specific
tables with something to separate them from the other applications tables.
Let's call your app *Contacts List.* We now have a nice, 2-prefix addition
to our table names: CL

# Storing our address types in a list as opposed to
# devoting a full table to them:
address_types=['permanent', 'temporary', 'postal', 'additional']
db.define_table('cl_contact',
  Field('name'),
)
db.define_table('cl_address',
  Field('contact', db.cl_contact),
  Field('address_type', 'string', requires=IS_IN_LIST(address_types))
  Field('
)

For small values of the list (i.e. less than a dozen items, which are
unlikely to change), you may as well store them in a list (as above) and let
web2py deal with the lookup. If you need a lookup table, then prefix it with
whatever is easy enough to remember. The important part (*and trust me on
this* :) is consistency.

At the end of the day, as long as your methodology is consistent, logical
and easy to follow, then just go with whatever's easiest for you.

Martin.


On 31 January 2011 21:58, Rupesh Pradhan  wrote:

> I am trying to standardize my naming schemes for my database, table and
> fields. I am trying to follow the one given below. Please share with me your
> scheme.
>
> Standard Database Table Naming Scheme
> =
> Table name:
> ---
> small caps with underscore
> look-up table prefixed with 'lu_'
> link table prefixed with 'lk_' (should i do this?)
>
>


> eg.
> contact
> lu_address_type
>
>
> Field names:
> 
> small caps with under score
> primary key suffixed with '_id'
>
> eg.
> name
> address_text
> contact_id
>
> Table Field access notation:
> ---
> table name DOT field name
>
> eg.
> contact.name
> contact.contact_id
> lu_address_type.name
> lu_address_type.address_type
>
>


[web2py] Re: background task error

2011-02-01 Thread pbreit
Here is web2py.py on a fresh MacOS install:

#!/usr/bin/env python2.5

import gluon.import_all
from gluon.widget import start
start()


Re: [web2py] Re: background task error

2011-02-01 Thread Martín Mulone
update web2py, import_all is commented since many versions ago...

2011/2/1 pbreit 

> Here is web2py.py on a fresh MacOS install:
>
> #!/usr/bin/env python2.5
>
> import gluon.import_all
> from gluon.widget import start
> start()
>



-- 
Pablo Martín Mulone (mar...@tecnodoc.com.ar)
http://www.tecnodoc.com.ar/
Paraná, Entre Ríos, Argentina (CP 3100).

My blog: http://martin.tecnodoc.com.ar
Expert4Solution Profile:
http://www.experts4solutions.com/e4s/default/expert/6


[web2py] migration from 1.88.2 to 1.91.6 problem

2011-02-01 Thread Richard Vézina
Hello,

I am not sure where it comes from the problem I face, but for sure it comes
from 1.91.6 because I dont have the probleme with the exact same app under
1.88.2.

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.

Traceback (most recent call last):
  File "/home/www-data/web2py/gluon/restricted.py", line 188, in restricted
exec ccode in environment
  File "/home/www-data/web2py/applications/init/controllers/test.py",
line 855, in 
  File "/home/www-data/web2py/gluon/globals.py", line 95, in 
self._caller = lambda f: f()
  File "/home/www-data/web2py/gluon/tools.py", line 2297, in f
return action(*a, **b)
  File "/home/www-data/web2py/applications/init/controllers/test.py",
line 410, in update
if form.accepts(request.vars, session):
  File "/home/www-data/web2py/gluon/sqlhtml.py", line 1091, in accepts
if self.table[fieldname].type == 'boolean' and self.vars[fieldname]==None:
KeyError: 'valid'


I have a field name "valid" in my models... May be it conflict with the new
DAL??

Thanks

Richard


[web2py] Re: background task error

2011-02-01 Thread pbreit
I noticed the source code version is quite a bit different:

http://code.google.com/p/web2py/source/browse/web2py.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys

if '__file__' in globals():
path = os.path.dirname(os.path.abspath(__file__))
os.chdir(path)
else:
path = os.getcwd() # Seems necessary for py2exe

sys.path = [path]+[p for p in sys.path if not p==path]

# import gluon.import_all # This should be uncommented for py2exe.py
import gluon.widget

# Start Web2py and Web2py cron service!
gluon.widget.start(cron=True)


[web2py] Re: has anyone managed to pickle the 'db' DAL reference?

2011-02-01 Thread mart
right, so I assume the answer was for "do the export/import"... k, got
it.


Thanks
Mart :)

On Feb 1, 9:38 am, Massimo Di Pierro 
wrote:
> Yes, the data is there.
>
> On Jan 31, 9:26 pm, mart  wrote:
>
>
>
>
>
>
>
> > i see... so, if I understand, only the table definitions are missing
> > (and I should know this), but I am hoping that this means just the
> > tables,not the data? If something Commet could make that the tabel
> > data available (maybe as a string), would it be possible to to :
>
> >                  tables please?
> > client  -> web2py Server (commet
> > listener?)
>
> >         < return "Models" as a
> > string (I don't know the tornado size limitations)
>
> > Now that I have the the model, i should be able to have that explicite
> > define (with no data in the tables), then do dbRemote = DAL(... ?   Or
> > maybe, this is silly...
>
> > Maybe export/import is the best known solution?
>
> > Thanks,
>
> > mart :)
>
> > On Jan 31, 9:09 pm, Massimo Di Pierro 
> > wrote:
>
> > > I see what you mean now. No you cannot do that.
>
> > > If you do
>
> > > python web2py.py -A app -M -N -R script.py
>
> > > the script will be executed in an environment similar to a controller
> > > and will see the stuff defined in the models.
>
> > > There is no way (currently) for you to do db=DAL(...) and have
> > > db.yourtable without an explicit db.define_table(..).
>
> > > On Jan 31, 7:20 pm, mart  wrote:
>
> > > > yes... that's what I meant... models ;) the models are invisible
>
> > > > Thanks for that, I'll try that :) so with that, I can do something
> > > > like:
>
> > > > dbRemote = DAL(
>
> > > > ?
>
> > > > Mart :)
>
> > > > On Jan 31, 3:47 pm, Massimo Di Pierro 
> > > > wrote:
>
> > > > > Not sure what you mean by invisible. web2py does not learn about
> > > > > tables from the db. It learns about them from the models.
>
> > > > > If you run a script with
>
> > > > > python web2py.py -A app -M -N -R script.py
>
> > > > > the script will see the models.
>
> > > > > On Jan 31, 10:27 am, mart  wrote:
>
> > > > > > right... ok, I get that.
>
> > > > > > So, is there a way to connect a new network connection to an 
> > > > > > existing
> > > > > > sqlite db? I tried some suggestion from a posting of a few weeks 
> > > > > > ago,
> > > > > > and it seems to connect, but tables are 'invisible'.
>
> > > > > > ** Note **
> > > > > > some dbs are created from script (no web), still web2py (just no 
> > > > > > web,
> > > > > > like __2py ;)) and others are created/maintained in a deployed 
> > > > > > web2py
> > > > > > environment. Possible? can I for example have a script (DAL stand-
> > > > > > alone), connect to a fully deployed web2py's DB? Actually, the
> > > > > > scenario can be web2py app connects to another web2py app (on the 
> > > > > > same
> > > > > > or different server), can also be stand alone DAL to stand-alone 
> > > > > > DAL,
> > > > > > or stand-alone-DAL to web2py server, or web2py server to stand-alone
> > > > > > DALs db
>
> > > > > > Thanks,
> > > > > > Mart:)
>
> > > > > > On Jan 31, 9:24 am, Massimo Di Pierro 
> > > > > > wrote:
>
> > > > > > > Impossible. You cannot picke a network connection. It more than 
> > > > > > > just
> > > > > > > data.
>
> > > > > > > On Jan 31, 5:30 am, mart  wrote:
>
> > > > > > > > Hi,
>
> > > > > > > > I'm looking to try something (again) that has not yet been too
> > > > > > > > successful (but I still want to try)... Currently (with 
> > > > > > > > stand-alone
> > > > > > > > Dal) I am managing by passing 'db' around (or rather self.db) 
> > > > > > > > to avoid
> > > > > > > > having to create more instances than I have to. Now, to pick up 
> > > > > > > > some
> > > > > > > > processes where  they left off, I would like to try pickling 
> > > > > > > > 'self.db'
> > > > > > > > to a file, let sys.exit() happen, load the pickle, then debug
> > > > > > > > exceptions, but without having to start from scratch ad rely on
> > > > > > > > breakpoints to wake me up when I get to troublesome areas (the 
> > > > > > > > wait
> > > > > > > > can be as long as an hour sometimes).
>
> > > > > > > > So, has anyone successfully pickled 'db'? Anything fancy that 
> > > > > > > > need to
> > > > > > > > be done the the attributes (even if only temporary).
>
> > > > > > > > Thanks,
> > > > > > > > Mart :)


[web2py] Search form in CRUD

2011-02-01 Thread Running Clam
Hi All,

If I call "search" from a controller like: -

def client_search():
return dict(form=crud.search(db.client))

...and get the expected form, but using: -

def data():
return dict(form=crud())

...at: -

[app]/crm/data/search/client

...I get a 404.

Am I missing something?

--

Cheers,

Clam


[web2py] GAE only issue extra status info as text on top of page

2011-02-01 Thread Terry
I am complete newbie to web based application design, and new to
web2py, so apologies if the answer is obvious.  I am doing a simple to
do list application as a learning exercise, and so far has been the
right balance between enough complexity to force learning a few things
without being overwhelming.

However, I have hit a small item and don't know how to address.  When
I run the app using the web2py server, all pages render fine.  When I
run the GAE development environment locally, all pages render fine.
When I upload to GAE, some of the pages include the following text at
the start of the page (rest of page renders fine) and some pages
render the same as they do in the other two environments.

The rendered page code (when a problem) looks like this:


Status: 200 OK
Set-Cookie:  session_id_todo="2001:ceba2b23-a490-44f2-86d0-
aa1c1c93b8e4"; Path=/
Expires: Tue, 01 Feb 2011 16:05:32 GMT
Content-Type: text/html; charset=utf-8
Pragma: no-cache
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-
check=0

http://www.w3.org/TR/html4/frameset.dtd";>
..


Could someone kindly point me in the right direction?


[web2py] Re: background task error

2011-02-01 Thread ron_m
I have had trouble with browser caching by just left clicking on the button 
on the downloads page on the web2py.com website. I now make a point of using 
a right click Save As or whatever your browser provides as the item in the 
pop up menu to save the file. The first clue the left click didn't actually 
download a file is the download went too fast but in todays multi-megabit 
link speeds that may be hard to detect. Also check the VERSION file in the 
top level web2py directory.

Ron



[web2py] Re: migration from 1.88.2 to 1.91.6 problem

2011-02-01 Thread Richard Vézina
Hello,

If I change erase those line (in red) in /gluon/sqlhtml.py

 if not self.ignore_rw and not self.table[fieldname].writable:
### this happens because FROM has no knowledge of writable
### and thinks that a missing boolean field is a None
if self.table[fieldname].type == 'boolean' and
self.vars[fieldname]==None:
del self.vars[fieldname]
continue

It solves the problem... But I don't have clue of what the impacts are on
web2py.


I use Postgres as backend...

I will try to write a demo app to reproduce de problem...

Richard




On Tue, Feb 1, 2011 at 12:49 PM, Richard Vézina  wrote:

> Hello,
>
> I am not sure where it comes from the problem I face, but for sure it comes
> from 1.91.6 because I dont have the probleme with the exact same app under
> 1.88.2.
>
>  1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
> 11.
> 12.
> 13.
> 14.
>
> Traceback (most recent call last):
>
>   File "/home/www-data/web2py/gluon/restricted.py", line 188, in restricted
>
> exec ccode in environment
>
>   File "/home/www-data/web2py/applications/init/controllers/test.py", line 
> 855, in 
>
>   File "/home/www-data/web2py/gluon/globals.py", line 95, in 
>
> self._caller = lambda f: f()
>
>   File "/home/www-data/web2py/gluon/tools.py", line 2297, in f
>
> return action(*a, **b)
>
>   File "/home/www-data/web2py/applications/init/controllers/test.py", line 
> 410, in update
>
> if form.accepts(request.vars, session):
>
>   File "/home/www-data/web2py/gluon/sqlhtml.py", line 1091, in accepts
>
> if self.table[fieldname].type == 'boolean' and self.vars[fieldname]==None:
> KeyError: 'valid'
>
>
> I have a field name "valid" in my models... May be it conflict with the new
> DAL??
>
> Thanks
>
> Richard
>


[web2py] Re: Log tickets

2011-02-01 Thread Massimo Di Pierro
I'd like to hear more pros and cons about this from other users.

massimo

On Feb 1, 11:19 am, Jim Karsten  wrote:
> On my development server, I log errors to syslog so they are
> accessible from a single location. Web2py tickets present a problem
> since they are not logged. I could configure syslog to access errors
> from the ticket error file, but it contains more information than I
> need and the text isn't in a suitable format.
>
> I added three lines to the RestrictedError class log() method in gluon/
> restricted.py. The traceback message of a ticket is then logged quite
> nicely.
>
>     def log(self, request):
>         ...
>
>             ticket_storage = TicketStorage(db=request.tickets_db)
>             ticket_storage.store(request, f, d)
> =>          for line in str(self.traceback).split("\n"):
> =>              if len(line.strip()) > 1:
> =>                  logger.error(line.strip())
>             return '%s/%s' % (a, f)
>         except:
>             logger.error(self.traceback)
>             return None
>
> Is there any interest in adding that to the source code?
>
> Also, when I first tested this, I copied the
> logger.error(self.traceback) line from the except clause to log the
> ticket message. It only logged the first line. The message logged is:
> "Traceback (most recent call last):" which isn't much use. Possibly a
> for loop similar to what I used above would improve that.
>
> Regards,
> Jim Karsten


Re: [web2py] Re: background task error

2011-02-01 Thread pbreit
I just downloaded web2py_osx.zip again and here is what I see:

VERSION
Version 1.91.6 (2011-01-03 17:55:14)

-- web2py/Contents/Resource/web2py.py --
#!/usr/bin/env python2.5

import gluon.import_all
from gluon.widget import start
start()


[web2py] Re: background task error

2011-02-01 Thread Massimo Di Pierro
hmmm. I think I know the problem now. Try comment that line. It should
work.

On Feb 1, 1:38 pm, pbreit  wrote:
> I just downloaded web2py_osx.zip again and here is what I see:
>
> VERSION
> Version 1.91.6 (2011-01-03 17:55:14)
>
> -- web2py/Contents/Resource/web2py.py --
> #!/usr/bin/env python2.5
>
> import gluon.import_all
> from gluon.widget import start
> start()


Re: [web2py] Re: Log tickets

2011-02-01 Thread Jonathan Lundell
On Feb 1, 2011, at 11:38 AM, Massimo Di Pierro wrote:
> 
> I'd like to hear more pros and cons about this from other users.

Good idea.

I'd make one change, though: define a separate ticket logger:

logger_ticket = logging.getLogger("web2py.ticket")

...and use it for this purpose. Perhaps add an explicit entry for it in 
logging.example.conf. That way ticket logging can be controlled independently 
of "real" web2py errors.

Is there a reason perhaps to log a little more information? The application, at 
least? That won't always be obvious from the traceback. Also the request URL is 
living somewhere in request.env (request.env.request_uri IIRC); might be useful.

> 
> massimo
> 
> On Feb 1, 11:19 am, Jim Karsten  wrote:
>> On my development server, I log errors to syslog so they are
>> accessible from a single location. Web2py tickets present a problem
>> since they are not logged. I could configure syslog to access errors
>> from the ticket error file, but it contains more information than I
>> need and the text isn't in a suitable format.
>> 
>> I added three lines to the RestrictedError class log() method in gluon/
>> restricted.py. The traceback message of a ticket is then logged quite
>> nicely.
>> 
>> def log(self, request):
>> ...
>> 
>> ticket_storage = TicketStorage(db=request.tickets_db)
>> ticket_storage.store(request, f, d)
>> =>  for line in str(self.traceback).split("\n"):
>> =>  if len(line.strip()) > 1:
>> =>  logger.error(line.strip())
>> return '%s/%s' % (a, f)
>> except:
>> logger.error(self.traceback)
>> return None
>> 
>> Is there any interest in adding that to the source code?
>> 
>> Also, when I first tested this, I copied the
>> logger.error(self.traceback) line from the except clause to log the
>> ticket message. It only logged the first line. The message logged is:
>> "Traceback (most recent call last):" which isn't much use. Possibly a
>> for loop similar to what I used above would improve that.
>> 
>> Regards,
>> Jim Karsten




[web2py] Re: dynamic session variables

2011-02-01 Thread Francisco Costa
the problem is when i open a second tab, it copies the session.id and
doesn't recognize the new page_id

basically what i want is a diferrent session.id[page_id] for each tab
i open

On Feb 1, 5:19 pm, Massimo Di Pierro 
wrote:
> session.id = session.id or {}
> session.id[page_id]=session.id.get(page_id,str(request.now))
>
> On Feb 1, 9:59 am, Francisco Costa  wrote:
>
>
>
>
>
>
>
> > I want something like this:
>
> >     if not session.id[page_id]:
> >         session.id[page_id]=str(request.now)
>
> > but i get this error: KeyError: '74'
>
> > I want to validate if a dynamic variable exists.. if not I want to
> > create it and to get the time
>
> > On Feb 1, 4:17 am, Jason Brower  wrote:
>
> > > You can do that. At the top of the default.py or what ever you are using, 
> > > place something like...
> > > session.pages[request.page]  = True
> > > or how ever you want to do it. Just make sure because it is a dictionary 
> > > that you blank it or initialize it befor asigning anything to it.
>
> > > - Original message -
> > > > Hello,
> > > > I want to have dinamic session variables like this:
> > > >         session.id
> > > > where id is different from page to page..
>
> > > > I've tried
> > > >         id = variable
> > > >         session.id
>
> > > > and
> > > >         session.id['variable']
>
> > > > without any results.
>
> > > > I would like to be able to open different pages at the same time and
> > > > the browser could get all the session variables.- Hide quoted text -
>
> > - Show quoted text -


[web2py] Re: GAE only issue extra status info as text on top of page

2011-02-01 Thread Terry
I had left a print statement in the code that I was using to debug an
issue.  When I removed the print statement, the application ran fine
on GAE.  I do not know if this was the root cause, or if there was
something about the deployment (used GAE SDK tool in both cases)

Can anyone share why (as I do not fully trust that I have found the
issue versus merely seeing coincidence)




On Feb 1, 11:26 am, Terry  wrote:
> I am complete newbie to web based application design, and new to
> web2py, so apologies if the answer is obvious.  I am doing a simple to
> do list application as a learning exercise, and so far has been the
> right balance between enough complexity to force learning a few things
> without being overwhelming.
>
> However, I have hit a small item and don't know how to address.  When
> I run the app using the web2py server, all pages render fine.  When I
> run the GAE development environment locally, all pages render fine.
> When I upload to GAE, some of the pages include the following text at
> the start of the page (rest of page renders fine) and some pages
> render the same as they do in the other two environments.
>
> The rendered page code (when a problem) looks like this:
>
> Status: 200 OK
> Set-Cookie:  session_id_todo="2001:ceba2b23-a490-44f2-86d0-
> aa1c1c93b8e4"; Path=/
> Expires: Tue, 01 Feb 2011 16:05:32 GMT
> Content-Type: text/html; charset=utf-8
> Pragma: no-cache
> Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-
> check=0
>
> 
> "http://www.w3.org/TR/html4/frameset.dtd";>
> ..
>
> Could someone kindly point me in the right direction?


[web2py] Re: tip of the day with a challenge

2011-02-01 Thread DenesL

I have been thinking about this.
How can one tell if the resulting records are going to have fields
from multiple tables?.


On Jan 30, 12:01 am, Massimo Di Pierro 
wrote:
> Immagine you have the following (suggested by user Nik):
>
> db.define_table('person',Field('name'),format='%(name)s')
> db.define_table('company', Field('name'),format='%(name)s')
> db.define_table('member',Field('person',db.Person),
> Field('company',db.company))
>
> and a new table
>
> db.define_table('manager', Field('member',db.member))
>
> Now you may want to a validator for managers with names of possible
> people who are members of the company.
> You can do it in this way (allowed):
>
>    db.manager.member.requires=IS_IN_DB(db,'member.id',lambda row: '%
> (name)s' % db.person[row.person])
>
> It would be nice to be able to also use this alternative syntax (not
> yet allowed):
>
> db.manager.member.requires=IS_IN_DB(db(db.member.person==db.person.id),'member.id','%
> (person.name)s')
>
> This is not yet possible but would be better because it would use a
> join instead of one select per option. Want to larn web2py? Try
> understand the IS_IN_DB validator in gluon/validators.py and implement
> the proposed syntax above.


Re: [web2py] Re: dynamic session variables

2011-02-01 Thread Jonathan Lundell
On Feb 1, 2011, at 11:54 AM, Francisco Costa wrote:
> 
> the problem is when i open a second tab, it copies the session.id and
> doesn't recognize the new page_id
> 
> basically what i want is a diferrent session.id[page_id] for each tab
> i open

where is page_id coming from? Perhaps the intended code is:

session.id = session.id or {}
session.id['page_id'] = session.id.get('page_id', str(request.now))

But yes, the problem with this is that you'll always get the same page id 
within a session.

I see a couple more problems as well. You don't actually see "pages" or "tabs"; 
you just see requests. So a reload of a page is indistinguishable from opening 
the same page in a new tab.

Also, you have no way of knowing when a page is closed. So if you keep a dict 
of open pages in your session, it'll grow indefinitely, which could result in a 
rather large session file.

What are you really trying to do?

> 
> On Feb 1, 5:19 pm, Massimo Di Pierro 
> wrote:
>> session.id = session.id or {}
>> session.id[page_id]=session.id.get(page_id,str(request.now))
>> 
>> On Feb 1, 9:59 am, Francisco Costa  wrote:
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> I want something like this:
>> 
>>> if not session.id[page_id]:
>>> session.id[page_id]=str(request.now)
>> 
>>> but i get this error: KeyError: '74'
>> 
>>> I want to validate if a dynamic variable exists.. if not I want to
>>> create it and to get the time
>> 
>>> On Feb 1, 4:17 am, Jason Brower  wrote:
>> 
 You can do that. At the top of the default.py or what ever you are using, 
 place something like...
 session.pages[request.page]  = True
 or how ever you want to do it. Just make sure because it is a dictionary 
 that you blank it or initialize it befor asigning anything to it.
>> 
 - Original message -
> Hello,
> I want to have dinamic session variables like this:
>  session.id
> where id is different from page to page..
>> 
> I've tried
>  id = variable
>  session.id
>> 
> and
>  session.id['variable']
>> 
> without any results.
>> 
> I would like to be able to open different pages at the same time and
> the browser could get all the session variables.- Hide quoted text -
>> 
>>> - Show quoted text -




[web2py] web2py exec in the new again

2011-02-01 Thread Massimo Di Pierro
>From the usual source:

http://lucumr.pocoo.org/2011/2/1/exec-in-python/

My answer:

Armin suggests exec'ing in an environment and not in the outer
environment. That is what web2py does and in fact we already follow
much of the advice he gives us about about how to use exec. We just do
not follow the advice not to use exec. ;-)

Performance is not an issue because 1) the time to bytecompile is
often small compared to the database IO time and because 2) web2py
allows you to bytecode compile apps anyway.

In web2py you cannot store instances of objects into session. While
Armin makes it tool like this is a web2py problem this is more complex
and general than that. In Python if you pickle and object that is
instance of a class defined in /path1/mymodule.py and then you
unpickle on a different installation where the class is defined in /
path2/mymodule.py you may run into problems. Because web2py does not
require installation (it is a feature) and has hot plug and play of
apps (another feature) we cannot pickle instances (the price we pay
for those features). To me it is worth it.

Once again Armin raises the issue of memory leaks. Unfortunately
CPython does not use a proper garbage collection but uses reference
counting. It suffers from memory leaks when circular references are
created. This is not a web2py specific problem. This is a problem with
any Python program. For example the following code

 class A: pass
 a=A()
 a.b=a

causes a memory leak in ANY python program.

I agree with Armin that in the case of exec (and web2py uses exec),
the self references are created whether you want them or not. That
means one should not define classes in Models and Controllers. I have
issued that warning already to our users and, I have never seen this
being a problem in practice.

Nothing in life is perfect and every design decision has a tradeoff.

What would really be useful to us is an example of how to overcome
that problem by showing how to break those implicit self references.

Massimo








[web2py] Re: tip of the day with a challenge

2011-02-01 Thread Massimo Di Pierro
You cannot tell easily from just looking at it.

On Feb 1, 2:05 pm, DenesL  wrote:
> I have been thinking about this.
> How can one tell if the resulting records are going to have fields
> from multiple tables?.
>
> On Jan 30, 12:01 am, Massimo Di Pierro 
> wrote:
>
>
>
>
>
>
>
> > Immagine you have the following (suggested by user Nik):
>
> > db.define_table('person',Field('name'),format='%(name)s')
> > db.define_table('company', Field('name'),format='%(name)s')
> > db.define_table('member',Field('person',db.Person),
> > Field('company',db.company))
>
> > and a new table
>
> > db.define_table('manager', Field('member',db.member))
>
> > Now you may want to a validator for managers with names of possible
> > people who are members of the company.
> > You can do it in this way (allowed):
>
> >    db.manager.member.requires=IS_IN_DB(db,'member.id',lambda row: '%
> > (name)s' % db.person[row.person])
>
> > It would be nice to be able to also use this alternative syntax (not
> > yet allowed):
>
> > db.manager.member.requires=IS_IN_DB(db(db.member.person==db.person.id),'mem 
> > ber.id','%
> > (person.name)s')
>
> > This is not yet possible but would be better because it would use a
> > join instead of one select per option. Want to larn web2py? Try
> > understand the IS_IN_DB validator in gluon/validators.py and implement
> > the proposed syntax above.


[web2py] Re: Can any help me with new dal in trunk?

2011-02-01 Thread Fran
I too have just been bitten by this.
>From r2950 to current trunk, all fieldnames in queries have been .lower()d
This breaks my code which uses the real fieldnames - things like maxExtent & 
maxResolution.
This code all worked fine before on MySQL, PotsgreSQL & sqlite.

In the spirit of not breaking backward compatibility, the not lower()ing 
should be the default.
If some cases want this lower()ing then they should be the ones who add an 
extra flag to get that behaviour, surely?

F


[web2py] Re: dynamic session variables

2011-02-01 Thread Francisco Costa
I'm trying to do a realtime commenting system.
I have this place for comments in posts, and I want the new comments
to display automatically in the comments area, with reloading the
page.

I have this that check if there are new posts after the page is loaded
every ten seconds:
setInterval("ajax('{{=URL(r=request, f='last_comments',
args=post_id)}}/{{=time()}}', ['comment'], ':eval');", 1);

I then use request.args(1) to query the db if there are post created
after the load.

But if it finds a new post, i have to save in the session the new time
for cheking..

It works well, but i need to have the post_id in the session variable,
because if the user as 2 posts loaded, I want the correct comments to
be displayed in the correct posts.

I don't know if this is the best way, if you any other option please
let me know.

On Feb 1, 8:15 pm, Jonathan Lundell  wrote:
> On Feb 1, 2011, at 11:54 AM, Francisco Costa wrote:
>
>
>
> > the problem is when i open a second tab, it copies the session.id and
> > doesn't recognize the new page_id
>
> > basically what i want is a diferrent session.id[page_id] for each tab
> > i open
>
> where is page_id coming from? Perhaps the intended code is:
>
> session.id = session.id or {}
> session.id['page_id'] = session.id.get('page_id', str(request.now))
>
> But yes, the problem with this is that you'll always get the same page id 
> within a session.
>
> I see a couple more problems as well. You don't actually see "pages" or 
> "tabs"; you just see requests. So a reload of a page is indistinguishable 
> from opening the same page in a new tab.
>
> Also, you have no way of knowing when a page is closed. So if you keep a dict 
> of open pages in your session, it'll grow indefinitely, which could result in 
> a rather large session file.
>
> What are you really trying to do?
>
>
>
>
>
>
>
>
>
> > On Feb 1, 5:19 pm, Massimo Di Pierro 
> > wrote:
> >> session.id = session.id or {}
> >> session.id[page_id]=session.id.get(page_id,str(request.now))
>
> >> On Feb 1, 9:59 am, Francisco Costa  wrote:
>
> >>> I want something like this:
>
> >>>     if not session.id[page_id]:
> >>>         session.id[page_id]=str(request.now)
>
> >>> but i get this error: KeyError: '74'
>
> >>> I want to validate if a dynamic variable exists.. if not I want to
> >>> create it and to get the time
>
> >>> On Feb 1, 4:17 am, Jason Brower  wrote:
>
>  You can do that. At the top of the default.py or what ever you are 
>  using, place something like...
>  session.pages[request.page]  = True
>  or how ever you want to do it. Just make sure because it is a dictionary 
>  that you blank it or initialize it befor asigning anything to it.
>
>  - Original message -
> > Hello,
> > I want to have dinamic session variables like this:
> >          session.id
> > where id is different from page to page..
>
> > I've tried
> >          id = variable
> >          session.id
>
> > and
> >          session.id['variable']
>
> > without any results.
>
> > I would like to be able to open different pages at the same time and
> > the browser could get all the session variables.- Hide quoted text -
>
> >>> - Show quoted text -


[web2py] SQLCustomType

2011-02-01 Thread Thadeus Burgess
Has this been deprecated?

If not, a refresher on how to make a simplejson type and perhaps a section
of the book devoted to custom types?

--
Thadeus


[web2py] pymysql gives Broken Pipe

2011-02-01 Thread Fran
I have been getting Broken Pipe issues with pymysql:
Traceback (most recent call last):
  File "/home/web2py/gluon/main.py", line 470, in wsgibase
BaseAdapter.close_all_instances('commit')
  File "/home/web2py/gluon/dal.py", line 272, in close_all_instances
getattr(instance,action)()
  File "/home/web2py/gluon/dal.py", line 1036, in commit
return self.connection.commit()
  File "/home/web2py/gluon/contrib/pymysql/connections.py", line 562, in 
commit
self.errorhandler(None, exc, value)
  File "/home/web2py/gluon/contrib/pymysql/connections.py", line 182, in 
defaulterrorhandler
raise Error(errorclass, errorvalue)
Error: (, error(32, 'Broken pipe'))

Everything is fine if I refresh the page, which I guess means that we 
establish a fresh MySQL connection rather than trying to reuse an old one 
(This is a quiet site)however tracebacks are horrible for users to face, 
so this really needs fixing.

I guess this has been happening ever since the move to pymysql, but I've not 
had production sites using it & generally my development is done on sqlite, 
so I hadn't noticed.
This is with pool_size = 30 & a default MySQL Debian Squeeze install.

I see someone else has experienced it occasionally:
https://groups.google.com/forum/?pli=1#!searchin/web2py/Broken$20pipe$20pymysql/web2py/W8xs1Vx38jo/Hz-BeQyMhfgJ

I suspect that this would best be fixed in pymysql, but we should at least 
be catching in web2py anyway.

I'm tempted by the same request as this user:
https://groups.google.com/d/msg/web2py/GXyyuBdrtyg/up0eZ1nkpQYJ
Portability of pymysql is kinda nice, but it's really no big deal to install 
the proven MySQLdb.

Many thanks,
Fran.


[web2py] Re: tip of the day with a challenge

2011-02-01 Thread DenesL
The processing of the records depends on that.
A short lived idea was to use dbset.query to get the info but since
the query can look like a tree full of ANDs and ORs its complicated.
So, no easy way out?.

On Feb 1, 3:17 pm, Massimo Di Pierro 
wrote:
> You cannot tell easily from just looking at it.
>
> On Feb 1, 2:05 pm, DenesL  wrote:
>
> > I have been thinking about this.
> > How can one tell if the resulting records are going to have fields
> > from multiple tables?.
>
> > On Jan 30, 12:01 am, Massimo Di Pierro 
> > wrote:
>
> > > Immagine you have the following (suggested by user Nik):
>
> > > db.define_table('person',Field('name'),format='%(name)s')
> > > db.define_table('company', Field('name'),format='%(name)s')
> > > db.define_table('member',Field('person',db.Person),
> > > Field('company',db.company))
>
> > > and a new table
>
> > > db.define_table('manager', Field('member',db.member))
>
> > > Now you may want to a validator for managers with names of possible
> > > people who are members of the company.
> > > You can do it in this way (allowed):
>
> > >    db.manager.member.requires=IS_IN_DB(db,'member.id',lambda row: '%
> > > (name)s' % db.person[row.person])
>
> > > It would be nice to be able to also use this alternative syntax (not
> > > yet allowed):
>
> > > db.manager.member.requires=IS_IN_DB(db(db.member.person==db.person.id),'mem
> > >  ber.id','%
> > > (person.name)s')
>
> > > This is not yet possible but would be better because it would use a
> > > join instead of one select per option. Want to larn web2py? Try
> > > understand the IS_IN_DB validator in gluon/validators.py and implement
> > > the proposed syntax above.
>
>


Re: [web2py] SQLCustomType

2011-02-01 Thread Art Zemon

On 02/01/2011 02:31 PM, Thadeus Burgess wrote:

Has this been deprecated?

If not, a refresher on how to make a simplejson type and perhaps a 
section of the book devoted to custom types?


I'd like to see this, too. I need to create an upload Field that stores 
the files in Rackspace Cloud Files. I had initially thought that I could 
do it with custom_store and custom_delete but realized that I would need 
custom_retrieve, too. So it is probably best to subclass Field or use 
SQLCustomType or something.


-- Art Z

--

Art Zemon, President
Hen's Teeth Network 
The source of reliable, secure e-commerce web hosting 


Phone: (866)HENS-NET or (636)447-3030 ext. 200



[web2py] Re: dynamic session variables

2011-02-01 Thread Francisco Costa
I've manage to use this solution:

firstcheck=datetime.fromtimestamp(float(request.args(1)))
session.id=session.id or {}
if not post_id in session.id:
session.id[post_id]=firstcheck
lastcheck=str(session.id[post_id])
if str(firstcheck) firstcheck

if returns any results:

session.id[post_id]=str(request.now)





On Feb 1, 8:27 pm, Francisco Costa  wrote:
> I'm trying to do a realtime commenting system.
> I have this place for comments in posts, and I want the new comments
> to display automatically in the comments area, with reloading the
> page.
>
> I have this that check if there are new posts after the page is loaded
> every ten seconds:
>     setInterval("ajax('{{=URL(r=request, f='last_comments',
> args=post_id)}}/{{=time()}}', ['comment'], ':eval');", 1);
>
> I then use request.args(1) to query the db if there are post created
> after the load.
>
> But if it finds a new post, i have to save in the session the new time
> for cheking..
>
> It works well, but i need to have the post_id in the session variable,
> because if the user as 2 posts loaded, I want the correct comments to
> be displayed in the correct posts.
>
> I don't know if this is the best way, if you any other option please
> let me know.
>
> On Feb 1, 8:15 pm, Jonathan Lundell  wrote:
>
>
>
>
>
>
>
> > On Feb 1, 2011, at 11:54 AM, Francisco Costa wrote:
>
> > > the problem is when i open a second tab, it copies the session.id and
> > > doesn't recognize the new page_id
>
> > > basically what i want is a diferrent session.id[page_id] for each tab
> > > i open
>
> > where is page_id coming from? Perhaps the intended code is:
>
> > session.id = session.id or {}
> > session.id['page_id'] = session.id.get('page_id', str(request.now))
>
> > But yes, the problem with this is that you'll always get the same page id 
> > within a session.
>
> > I see a couple more problems as well. You don't actually see "pages" or 
> > "tabs"; you just see requests. So a reload of a page is indistinguishable 
> > from opening the same page in a new tab.
>
> > Also, you have no way of knowing when a page is closed. So if you keep a 
> > dict of open pages in your session, it'll grow indefinitely, which could 
> > result in a rather large session file.
>
> > What are you really trying to do?
>
> > > On Feb 1, 5:19 pm, Massimo Di Pierro 
> > > wrote:
> > >> session.id = session.id or {}
> > >> session.id[page_id]=session.id.get(page_id,str(request.now))
>
> > >> On Feb 1, 9:59 am, Francisco Costa  wrote:
>
> > >>> I want something like this:
>
> > >>>     if not session.id[page_id]:
> > >>>         session.id[page_id]=str(request.now)
>
> > >>> but i get this error: KeyError: '74'
>
> > >>> I want to validate if a dynamic variable exists.. if not I want to
> > >>> create it and to get the time
>
> > >>> On Feb 1, 4:17 am, Jason Brower  wrote:
>
> >  You can do that. At the top of the default.py or what ever you are 
> >  using, place something like...
> >  session.pages[request.page]  = True
> >  or how ever you want to do it. Just make sure because it is a 
> >  dictionary that you blank it or initialize it befor asigning anything 
> >  to it.
>
> >  - Original message -
> > > Hello,
> > > I want to have dinamic session variables like this:
> > >          session.id
> > > where id is different from page to page..
>
> > > I've tried
> > >          id = variable
> > >          session.id
>
> > > and
> > >          session.id['variable']
>
> > > without any results.
>
> > > I would like to be able to open different pages at the same time and
> > > the browser could get all the session variables.- Hide quoted text -
>
> > >>> - Show quoted text -


[web2py] Re: GAE only issue extra status info as text on top of page

2011-02-01 Thread howesc
sounds like you got it right.  i have seen similar behavior on GAE with 
print statements.  they seem to show in the console on dev, but in the 
browser on production.  try using the logging package instead of print 
statements to avoid that problem.

cfh


[web2py] Re: adding tables instead of merging?

2011-02-01 Thread howesc
this sounds pretty database specific.  GAE uses namespaces for this, MySQL 
calls them 'databases', and postgres calls them schemas.  in all GAE and 
Postgres tables from one area cannot see tables in another area.  MySQL does 
permit querying data across 'databases'.


[web2py] Re: web2py exec in the new again

2011-02-01 Thread VP
One question:
If I define a class externally, and use local_import to import it into
controller or model, will it have these potential problems or not?


[web2py] Re: Need help in standardizing my coding and naming schemes before I start my main project

2011-02-01 Thread howesc
i try to use pythonic naming conventions in my database.

i prefer:
db.define_table('address_type',
Field('name'))

db.define_table('contact',
Field('name'))

db.define_table('address',
Field('contact', db.contact),
Field('type', db.address_type),
Field('text'))

but perhaps mainly because i don't like to type all those extra characters. 
:)


[web2py] Re: web2py and uploadify

2011-02-01 Thread Niphlod
bump 

On Jan 26, 9:42 pm, Niphlod  wrote:
> Hello, I'm working on integrating uploadify with web2py
> Unfortunately uploadify doesn't use cookies at all when posting the
> files so if I want to "assign" an user to an uploaded file I need to
> secure the "receiving" function somehow.
> Uploadify can definitely add a parameter on every POST it does on the
> receiving page  I'm not sure how to secure the access to that
> page. When uploadify is initalized the user is known in advance, so
> specifyng the parameter(s) is not a problem.
>
> I don't see any method to retrieve current "active" sessions (I did a
> quick look into gluon folder) ... but at least it comes to my mind
> that I can put the user password as it is stored on the database
> (hashed with the random key) as a parameter and then retrieve the user
> querying the auth_user table
> In this way I think the user is uniquely identified (or do I need to
> put also the username in the mix?) ... If he/she can upload a file
> forging a POST instead of accessing the site is a minor problem 
> if that can be fixed is a plus.
>
> Does anyone have a better idea ? Is that implementation secure ?
>
> a snippet is better than a thousand words 
>
> def receiver_page():
>     session.forget()
>     #user detection  fill the blanks
>     ...
>     ...
>     detected_user = x
>     #end user detection
>     db.uploaded_files.insert(content=db.uploaded_files.store(stream,
> filename),
>                                        user_id=detected_user)
>
> I know a session.forget() and wanting to know which user is accessing
> the page is kind of nonsense but nevertheless I'd like to do it :P


Re: [web2py] pymysql gives Broken Pipe

2011-02-01 Thread Vasile Ermicioi
I see no reason for you to use pool_size,
I think you will avoid this error by not using it,
and if you say that you have little traffic than I see almost no reason to
use pool_size


[web2py] Default Web2Py Application on GAE

2011-02-01 Thread Gary Bee
I have created an application for my business homepage.
When I run web2py locally by default it opens a link to the welcome
application. I have to edit the url to the application of my homepage.
This works fine for development purposes, I can also access the site
via the admin interface.
I have successfully uploaded this to GAE, but by default when I try to
access the application it sends me to welcome/default/index. However
in the yaml file I told GAE to ignore this app so I get an error:
http://www.rtplanb.com/welcome/default/index
My question is... how do I edit the default application that opens
when I run web2py/GAE?



[web2py] Favicon on GAE

2011-02-01 Thread Gary Bee
I have used a favicon (.png) to get a nice little icon for my website
in the browser. This works on my local web2py installation but now I
have uploaded it to GAE the favicon does not appear? Any ideas?


Re: [web2py] Favicon on GAE

2011-02-01 Thread contatogilson...@gmail.com
Insert with "link" tag in the :


   - http://www.quotes.co.uk/favicon.ico";
   type="image/x-icon">
   - http://www.quotes.co.uk/favicon.ico";
   type="image/x-icon">

_
*Gilson Filho*
*Web Developer
http://gilsondev.com*



2011/2/1 Gary Bee 

> I have used a favicon (.png) to get a nice little icon for my website
> in the browser. This works on my local web2py installation but now I
> have uploaded it to GAE the favicon does not appear? Any ideas?


[web2py] Re: Can any help me with new dal in trunk?

2011-02-01 Thread Massimo Di Pierro
The change in trunk is supposed to only affect internals. If it breaks
you code than is is a bug. Please provide an example of code that
breaks and I will fix trunk.

Massimo

On Feb 1, 2:22 pm, Fran  wrote:
> I too have just been bitten by this.
> From r2950 to current trunk, all fieldnames in queries have been .lower()d
> This breaks my code which uses the real fieldnames - things like maxExtent &
> maxResolution.
> This code all worked fine before on MySQL, PotsgreSQL & sqlite.
>
> In the spirit of not breaking backward compatibility, the not lower()ing
> should be the default.
> If some cases want this lower()ing then they should be the ones who add an
> extra flag to get that behaviour, surely?
>
> F


[web2py] Re: SQLCustomType

2011-02-01 Thread Massimo Di Pierro
It is not deprecated. It is just that I am not ready to promise
backward compatibility.
Nevertheless use it. If something better comes along, there will be
instructions for the transition.



On Feb 1, 2:46 pm, Art Zemon  wrote:
> On 02/01/2011 02:31 PM, Thadeus Burgess wrote:
>
> > Has this been deprecated?
>
> > If not, a refresher on how to make a simplejson type and perhaps a
> > section of the book devoted to custom types?
>
> I'd like to see this, too. I need to create an upload Field that stores
> the files in Rackspace Cloud Files. I had initially thought that I could
> do it with custom_store and custom_delete but realized that I would need
> custom_retrieve, too. So it is probably best to subclass Field or use
> SQLCustomType or something.
>
>      -- Art Z
>
> --
>
> Art Zemon, President
> Hen's Teeth Network 
> The source of reliable, secure e-commerce web hosting
> 
> Phone: (866)HENS-NET or (636)447-3030 ext. 200


[web2py] Re: web2py exec in the new again

2011-02-01 Thread Massimo Di Pierro
I run this test (following Armin's example):

# in file a.py
class Foo(object):
def __del__(self):
print 'Deleted'

#in file b.py
from a import A
foo=Foo()

#in file c.py
execfile('b.py', {})
execfile('b.py', {})
execfile('b.py', {})
import gc
gc.collect()

running c.py printes
Deleted
Deleted
Deleted

therefore there is NO memory leak.

On Feb 1, 3:08 pm, VP  wrote:
> One question:
> If I define a class externally, and use local_import to import it into
> controller or model, will it have these potential problems or not?


[web2py] Re: Default Web2Py Application on GAE

2011-02-01 Thread Massimo Di Pierro
call it "init".

On Feb 1, 3:08 pm, Gary Bee  wrote:
> I have created an application for my business homepage.
> When I run web2py locally by default it opens a link to the welcome
> application. I have to edit the url to the application of my homepage.
> This works fine for development purposes, I can also access the site
> via the admin interface.
> I have successfully uploaded this to GAE, but by default when I try to
> access the application it sends me to welcome/default/index. However
> in the yaml file I told GAE to ignore this app so I get an 
> error:http://www.rtplanb.com/welcome/default/index
> My question is... how do I edit the default application that opens
> when I run web2py/GAE?


[web2py] [SOLVED] Re: Default Web2Py Application on GAE

2011-02-01 Thread Gary Bee
I do apologize. I have found init.py and have edited it to my
satisfaction

On Feb 1, 9:08 pm, Gary Bee  wrote:
> I have created an application for my business homepage.
> When I run web2py locally by default it opens a link to the welcome
> application. I have to edit the url to the application of my homepage.
> This works fine for development purposes, I can also access the site
> via the admin interface.
> I have successfully uploaded this to GAE, but by default when I try to
> access the application it sends me to welcome/default/index. However
> in the yaml file I told GAE to ignore this app so I get an 
> error:http://www.rtplanb.com/welcome/default/index
> My question is... how do I edit the default application that opens
> when I run web2py/GAE?


[web2py] External Access to web2py (uWSGI + Cherokee)

2011-02-01 Thread greenpoise
Ok, I was able to deploy web2py using uWSGI & Cherokee. I can access it 
locally but not from the outside of the network. The connection basically 
times out when I try to access it. Any setting on cherokee that I am not 
aware of? I open the firewall to see if that was it but did not solved the 
problem. Ideas? leads?


Thanks

Dan


[web2py] Re: web2py exec in the new again

2011-02-01 Thread Anthony
But what if 'local_import' is used (instead of 'from a import Foo') -- does 
local_import work the same as regular Python imports?
 
On Tuesday, February 1, 2011 5:09:25 PM UTC-5, Massimo Di Pierro wrote:

> I run this test (following Armin's example): 
>
> # in file a.py 
> class Foo(object): 
> def __del__(self): 
> print 'Deleted' 
>
> #in file b.py 
> from a import A 
> foo=Foo() 
>
> #in file c.py 
> execfile('b.py', {}) 
> execfile('b.py', {}) 
> execfile('b.py', {}) 
> import gc 
> gc.collect() 
>
> running c.py printes 
> Deleted 
> Deleted 
> Deleted 
>
> therefore there is NO memory leak. 
>
> On Feb 1, 3:08 pm, VP  wrote: 
> > One question: 
> > If I define a class externally, and use local_import to import it into 
> > controller or model, will it have these potential problems or not?



[web2py] Re: Can any help me with new dal in trunk?

2011-02-01 Thread Fran
Cool, thanks :)

This function:
http://bazaar.launchpad.net/~flavour/sahana-eden/trunk/view/head:/modules/s3/s3gis.py#L381

maxResolution & maxExtent don't get copied into output as
maxresolution & maxextent are in the Rows...

The relevant model:
http://bazaar.launchpad.net/~flavour/sahana-eden/trunk/view/head:/models/03_gis.py#L88

F


Re: [web2py] pymysql gives Broken Pipe

2011-02-01 Thread Fran
Thanks - fine for this currently low-volume site now but we definitely want 
to take advantage of this feature for scalability (the site may suddenly 
start getting a lot of traffic):
http://www.web2py.com/book/default/chapter/06#Connection-Pooling

Also see:
http://www.web2py.com/book/default/chapter/06#Connection-Failures

The problem is known, but it seems web2py's retry mechanism isn't working 
any more...

F


[web2py] Re: web2py exec in the new again

2011-02-01 Thread VP
Maybe unnecessary, but here's another test:

+ In foo.py:
class Foo(object):
def __del__(self):
print 'Deleted'

def bar(self):
print "bar::"
b = Foo()

def f():
print "local_func::"
c = Foo()


+ In test.py:

from foo import *
a = Foo()
a.bar()
f()


+ Then, in interpreter:
>>> execfile('test.py',{})
bar::
Deleted
local_func::
Deleted
Deleted


==

It looks like all variables a, b, and c are properly destroyed.

Is this the pattern of usage in web2py?
(1) No class in controller.
(2) External classes are imported using local_import (does
local_import work exactly like import?).


If so, I think webp2y is okay with respect to memory leak.






[web2py] Re: web2py exec in the new again

2011-02-01 Thread Anthony


On Tuesday, February 1, 2011 3:16:12 PM UTC-5, Massimo Di Pierro wrote: 

> In web2py you cannot store instances of objects into session. While 
> Armin makes it tool like this is a web2py problem this is more complex 
> and general than that. In Python if you pickle and object that is 
> instance of a class defined in /path1/mymodule.py and then you 
> unpickle on a different installation where the class is defined in / 
> path2/mymodule.py you may run into problems. Because web2py does not 
> require installation (it is a feature) and has hot plug and play of 
> apps (another feature) we cannot pickle instances (the price we pay 
> for those features). To me it is worth it.
>
 
Is this limitation documented anywhere?
 

> I agree with Armin that in the case of exec (and web2py uses exec), 
> the self references are created whether you want them or not. That 
> means one should not define classes in Models and Controllers. I have 
> issued that warning already to our users and, I have never seen this 
> being a problem in practice.
>
 
My understanding is that with the recent fix (using gc), we can include 
classes in models and controllers, as long as they don't have a __del__ 
method (
https://groups.google.com/forum/#!msg/web2py/zE1cGK2x288/R6fTdEQjNOoJ). Is 
that right? That should be documented as well.
 

> Nothing in life is perfect and every design decision has a tradeoff.
>
 
A quote from Armin's post:

"Because one of the things we all have to keep in mind: if a Python 
developer starts his journeys in the twisted world of wrongly executed 
Python modules they will be very confused when they continue their travels 
in another Python environment. And having different semantics in different 
frameworks/modules/libraries is very hurtful for Python as a runtime and 
language."

He (and Jacob, and others) seems to be very concerned about following 
conventions. Of course, that's reasonable, as conventions can be very 
helpful, but there's always going to be some tension be convention and 
innovation. The above quote implies dire consequences if a few libraries and 
frameworks happen to buck this particular convention, but is there actual 
evidence of significant developer confusion or other supposed harm to 
Python? If we extend this logic, Python itself probably shouldn't exist 
because it violates conventions established by C and other earlier languages 
and might confuse developers as they move between environments.
 
Anyway, it's interesting that Armin didn't find arguments about the 
importance of convention so compelling when it came to creating an 
alternative to the Standard Library logging module: 
http://plumberjack.blogspot.com/2010/09/python-logging-functionality-facts-vs.html
 
Anthony 


[web2py] Re: web2py exec in the new again

2011-02-01 Thread VP
It's interesting to note that even the variable "c" in my example
above is properly destroyed with execfile('test.py', {}).


What does this mean?

I think this means that YES you can define classes inside a web2py
controller without memory leaks, as long as there are no global
(within the controller, i.e. foo.py) instances of Foo.





[web2py] Re: web2py exec in the new again

2011-02-01 Thread VP
If what I thought above is true, a warning like this sufficient:
"Global objects/variables in controllers might (will?) cause memory
leaks".

If this is what the criticism of web2py amounts to, I think it's a
storm in a tea cup.




[web2py] Re: migration from 1.88.2 to 1.91.6 problem

2011-02-01 Thread Massimo Di Pierro
Which ones are in red?

On Feb 1, 1:13 pm, Richard Vézina  wrote:
> Hello,
>
> If I change erase those line (in red) in /gluon/sqlhtml.py
>
>  if not self.ignore_rw and not self.table[fieldname].writable:
>                 ### this happens because FROM has no knowledge of writable
>                 ### and thinks that a missing boolean field is a None
>                 if self.table[fieldname].type == 'boolean' and
> self.vars[fieldname]==None:
>                     del self.vars[fieldname]
>                 continue
>
> It solves the problem... But I don't have clue of what the impacts are on
> web2py.
>
> I use Postgres as backend...
>
> I will try to write a demo app to reproduce de problem...
>
> Richard
>
> On Tue, Feb 1, 2011 at 12:49 PM, Richard Vézina 
>
>
>
>
>
>
> > wrote:
> > Hello,
>
> > I am not sure where it comes from the problem I face, but for sure it comes
> > from 1.91.6 because I dont have the probleme with the exact same app under
> > 1.88.2.
>
> >  1.
> > 2.
> > 3.
> > 4.
> > 5.
> > 6.
> > 7.
> > 8.
> > 9.
> > 10.
> > 11.
> > 12.
> > 13.
> > 14.
>
> > Traceback (most recent call last):
>
> >   File "/home/www-data/web2py/gluon/restricted.py", line 188, in restricted
>
> >     exec ccode in environment
>
> >   File "/home/www-data/web2py/applications/init/controllers/test.py", line 
> > 855, in 
>
> >   File "/home/www-data/web2py/gluon/globals.py", line 95, in 
>
> >     self._caller = lambda f: f()
>
> >   File "/home/www-data/web2py/gluon/tools.py", line 2297, in f
>
> >     return action(*a, **b)
>
> >   File "/home/www-data/web2py/applications/init/controllers/test.py", line 
> > 410, in update
>
> >     if form.accepts(request.vars, session):
>
> >   File "/home/www-data/web2py/gluon/sqlhtml.py", line 1091, in accepts
>
> >     if self.table[fieldname].type == 'boolean' and 
> > self.vars[fieldname]==None:
> > KeyError: 'valid'
>
> > I have a field name "valid" in my models... May be it conflict with the new
> > DAL??
>
> > Thanks
>
> > Richard


[web2py] Implement Share this Button of Facebook

2011-02-01 Thread Andrew Evans
How would you go about implemeting the "Share This" button of Facebook by
pulling out a query from a database table. for example: 

Thanks in Advance


Re: [web2py] web2py exec in the new again

2011-02-01 Thread Jonathan Lundell
On Feb 1, 2011, at 12:16 PM, Massimo Di Pierro wrote:
> 
> I agree with Armin that in the case of exec (and web2py uses exec),
> the self references are created whether you want them or not. That
> means one should not define classes in Models and Controllers. I have
> issued that warning already to our users and, I have never seen this
> being a problem in practice.
> 
> Nothing in life is perfect and every design decision has a tradeoff.
> 
> What would really be useful to us is an example of how to overcome
> that problem by showing how to break those implicit self references.

I agree. This is a subtle problem that isn't all that obvious to most of us, 
including me.

I've got classes defined in models (it's sort of the obvious place to define 
custom validators, for example), and I'd like to understand the implications 
better than I do.



[web2py] Re: External Access to web2py (uWSGI + Cherokee)

2011-02-01 Thread greenpoise
Ok..it was my ISP blocking port 80...apparently it is a common
practice by ISPs.


Worked fine after I changed the port..thanks

d




On Feb 1, 2:15 pm, greenpoise  wrote:
> Ok, I was able to deploy web2py using uWSGI & Cherokee. I can access it
> locally but not from the outside of the network. The connection basically
> times out when I try to access it. Any setting on cherokee that I am not
> aware of? I open the firewall to see if that was it but did not solved the
> problem. Ideas? leads?
>
> Thanks
>
> Dan


[web2py] Re: Can't deal with MemcachedKeyLengthError in caching selects

2011-02-01 Thread kenji4569
Thanks! That's the right way. It worked.

On 2月1日, 午後11:37, Massimo Di Pierro 
wrote:
> I think have a solution in trunk. You will not need to specify length
> and should work.
>
> On Jan 31, 8:40 pm, kenji4569  wrote:
>
> > When I run the following code:
>
> > db(db.xxx.id==1).select(cache=(cache.memcache, 5))
>
> > I got MemcachedKeyLengthError: Key length is > 250.
>
> > Since xxx table has many fields, the sql used for the key readily
> > reached the limit.
>
> > I just want to specify the cache key, but I couldn't, given the
> > dal.py:
>
> > (cache_model, time_expire) = attributes['cache']
> > del attributes['cache']
> > key = self.uri + '/' + sql
> > rows = cache_model(key, lambda: response(sql), time_expire)
>
> > Please help.
> > Thanks in advance, Kenji
>
>


[web2py] Re: adding tables instead of merging?

2011-02-01 Thread mart
interesting.. so may turn being a lack of planning on my part... I can
assue the SQLite fall in the group of those no being able to see
tables outside its own area...

So, given this problem (the need to collect the generated tables who
share the same names), would you have any suggestion? BTW, I am using
SQLite. I figure the fact that SQLite is light weight would prove
beneficial, but perhaps I was wrong?

Just seems that this & not being able to get remote scripts to connect
to the db  is appearing problematic...

ANyways, any suggestion around this would be greatly appreciated :)

Thanks,
Mart :)

On Feb 1, 4:07 pm, howesc  wrote:
> this sounds pretty database specific.  GAE uses namespaces for this, MySQL
> calls them 'databases', and postgres calls them schemas.  in all GAE and
> Postgres tables from one area cannot see tables in another area.  MySQL does
> permit querying data across 'databases'.


[web2py] Kudos for web2py!

2011-02-01 Thread mikech
This was unexpected!  I was reading thru a blog post on how wonderful 
Seaside - a Smalltalk web framework was, and lo and behold the author says 
about half way down: 
=
Now it’s time for a confession: the fastest-to-develop in, most 
prototype-friendly framework that I’ve had the pleasure to work with so far 
is not Seaside, nor is it Ruby on Rails
(which has other reasons to recommend it). It’s a relatively unknown (dare I 
say underdog?) Python framework called web2py, written by Massimo Di Pierro.

Enjoy!


[web2py] Re: Kudos for web2py!

2011-02-01 Thread mikech
Ok a link would be useful: 
http://smalltalkzen.wordpress.com/2011/02/01/a-secret-passion-and-your-choice-of-web-framework/


[web2py] Re: adding tables instead of merging?

2011-02-01 Thread villas
Hi Mart,
I thought you'd already solved that one in a previous thread named
'tables created dynamically'?
I am just reminding you of the thread in case you'd overlooked that
interesting answer by Massimo.
Sorry if that hasn't helped,  I do not know of any better answer.
Best regards,
David


On Feb 1, 5:14 pm, mart  wrote:
> Hi,
>
> Say a process generates a DB and a set of tables, and say this process
> is repeated multple times: Is it possible to add tables (as opposed to
> merging) to an existing DB? Since once set of tables have the same
> names as another, ideally the tables could live in a separate folder
> (uniquely named)... I'm not too hopeful, but is something like this
> possible?
>
> thanks,
> Mart :)


[web2py] Re: web2py exec in the new again

2011-02-01 Thread Massimo Di Pierro
You are correct. There ar no problems using trunk (and future web2py
versions) if classes have no __del__ method.

On Feb 1, 5:00 pm, Anthony  wrote:
> On Tuesday, February 1, 2011 3:16:12 PM UTC-5, Massimo Di Pierro wrote:
> > In web2py you cannot store instances of objects into session. While
> > Armin makes it tool like this is a web2py problem this is more complex
> > and general than that. In Python if you pickle and object that is
> > instance of a class defined in /path1/mymodule.py and then you
> > unpickle on a different installation where the class is defined in /
> > path2/mymodule.py you may run into problems. Because web2py does not
> > require installation (it is a feature) and has hot plug and play of
> > apps (another feature) we cannot pickle instances (the price we pay
> > for those features). To me it is worth it.
>
> Is this limitation documented anywhere?
>
> > I agree with Armin that in the case of exec (and web2py uses exec),
> > the self references are created whether you want them or not. That
> > means one should not define classes in Models and Controllers. I have
> > issued that warning already to our users and, I have never seen this
> > being a problem in practice.
>
> My understanding is that with the recent fix (using gc), we can include
> classes in models and controllers, as long as they don't have a __del__
> method 
> (https://groups.google.com/forum/#!msg/web2py/zE1cGK2x288/R6fTdEQjNOoJ). Is
> that right? That should be documented as well.
>
> > Nothing in life is perfect and every design decision has a tradeoff.
>
> A quote from Armin's post:
>
> "Because one of the things we all have to keep in mind: if a Python
> developer starts his journeys in the twisted world of wrongly executed
> Python modules they will be very confused when they continue their travels
> in another Python environment. And having different semantics in different
> frameworks/modules/libraries is very hurtful for Python as a runtime and
> language."
>
> He (and Jacob, and others) seems to be very concerned about following
> conventions. Of course, that's reasonable, as conventions can be very
> helpful, but there's always going to be some tension be convention and
> innovation. The above quote implies dire consequences if a few libraries and
> frameworks happen to buck this particular convention, but is there actual
> evidence of significant developer confusion or other supposed harm to
> Python? If we extend this logic, Python itself probably shouldn't exist
> because it violates conventions established by C and other earlier languages
> and might confuse developers as they move between environments.
>
> Anyway, it's interesting that Armin didn't find arguments about the
> importance of convention so compelling when it came to creating an
> alternative to the Standard Library logging 
> module:http://plumberjack.blogspot.com/2010/09/python-logging-functionality-...
>
> Anthony


[web2py] Re: web2py exec in the new again

2011-02-01 Thread Massimo Di Pierro
Not quite like that. It is more like (web2py specific):

"Do not declare classes with a __del__ method in web2py models or
controllers or instances of those classes will cause memory leaks"

AND (for any python program)

"Do not declare classes with a __del__ method in any Python program
unless you are sure there are no circular references"
Circular references are very easy to create accidentally in Python.


Massimo

On Feb 1, 5:08 pm, VP  wrote:
> If what I thought above is true, a warning like this sufficient:
> "Global objects/variables in controllers might (will?) cause memory
> leaks".
>
> If this is what the criticism of web2py amounts to, I think it's a
> storm in a tea cup.


[web2py] Re: web2py exec in the new again

2011-02-01 Thread Massimo Di Pierro
There is no problem if they have no __del__ method.


On Feb 1, 5:24 pm, Jonathan Lundell  wrote:
> On Feb 1, 2011, at 12:16 PM, Massimo Di Pierro wrote:
>
>
>
> > I agree with Armin that in the case of exec (and web2py uses exec),
> > the self references are created whether you want them or not. That
> > means one should not define classes in Models and Controllers. I have
> > issued that warning already to our users and, I have never seen this
> > being a problem in practice.
>
> > Nothing in life is perfect and every design decision has a tradeoff.
>
> > What would really be useful to us is an example of how to overcome
> > that problem by showing how to break those implicit self references.
>
> I agree. This is a subtle problem that isn't all that obvious to most of us, 
> including me.
>
> I've got classes defined in models (it's sort of the obvious place to define 
> custom validators, for example), and I'd like to understand the implications 
> better than I do.


[web2py] Re: Kudos for web2py!

2011-02-01 Thread Massimo Di Pierro
Thanks Mikech.
I think we removed "written by ..." from the web site because so many
people have contributed that my job is more that of fixing bugs and
rejecting backward incompatible patches. ;-)

Massimo

On Feb 1, 6:41 pm, mikech  wrote:
> This was unexpected!  I was reading thru a blog post on how wonderful
> Seaside - a Smalltalk web framework was, and lo and behold the author says
> about half way down:
> =
> Now it’s time for a confession: the fastest-to-develop in, most
> prototype-friendly framework that I’ve had the pleasure to work with so far
> is not Seaside, nor is it Ruby on Rails
> (which has other reasons to recommend it). It’s a relatively unknown (dare I
> say underdog?) Python framework called web2py, written by Massimo Di Pierro.
>
> Enjoy!


[web2py] Re: Returning the Row after insert;

2011-02-01 Thread KMax
Actualy do the same action, but select allow to choose columns

On 1 фев, 05:36, Vasile Ermicioi  wrote:
> db(db.auth_user.id=id).select() will give you a list of rows (of one element
> :) )
>
> easier is
>
> row = db.auth_user[form.vars.id]


[web2py] jQuery 1.5 released

2011-02-01 Thread ron_m
I was poking around and found jQuery 1.5 is released. They substantially 
improved the ajax portion of the library as well as big performance 
improvements when finding sibling DOM objects .prev(), .next(). Just thought 
I would mention it since web2py embeds jQuery.


Re: [web2py] jQuery 1.5 released

2011-02-01 Thread Bruno Rocha
Nice!

Lets test it with web2py welcome app.



2011/2/2 ron_m 

> I was poking around and found jQuery 1.5 is released. They substantially
> improved the ajax portion of the library as well as big performance
> improvements when finding sibling DOM objects .prev(), .next(). Just thought
> I would mention it since web2py embeds jQuery.
>


[web2py] web2py is running on dotCloud

2011-02-01 Thread Bruno Rocha
Take it a look:

http://www.web2py.dotcloud.com/welcome/default/index

definitely the 'heroku' for web2py

So easy


$dotcloud deploy -t python myweb2pyapp.www


$ln -s wsgihandler.py wsgi.py


$cd path/to/my/web2py


$dotcloud push myweb2pyapp.www


$...
rsync



and 
http://www.web2py.dotcloud.com


I am a little busy now, but I will try it with PostGreSQL tomorrow


--
Bruno Rocha
http://about.me/rochacbruno/bio


Re: [web2py] jQuery 1.5 released

2011-02-01 Thread ron_m
I took the min version and renamed it the same name as the 1.4.4 file in 
1.91.6 and tested both the welcome app and the video system controller I am 
writing. No noticeable differences that I could see. I also use jQueryUI but 
am back at 1.8.6, current is 1.8.9 and did not see anything broken.

I use a small amount of ajax to allow for user positioning of symbols on a 
map of the facility and when I drop a symbol the event makes an ajax call to 
a web2py controller to update the position of the symbol on the map into the 
database so it is drawn in the correct position next time.

>From my limited perspective the jQuery 1.5 release is perfect.


Re: [web2py] Re: Kudos for web2py!

2011-02-01 Thread Marco Mansilla
Agree on that, i used to work with django and turbogears (both
versions 1.5 and 2), last year a knew about web2py, and met Massimo on
October, since then i have improved my work a lot!, hopefully in a
short time i would be able to contribute with some apps and plugins.

Thanks Massimo!

> Ok a link would be useful: 
> http://smalltalkzen.wordpress.com/2011/02/01/a-secret-passion-and-your-choice-of-web-framework/


-- 
/* 
Marco Antonio Mansilla Gutierrez, alias "Big"
Medios de contacto adicionales:
Weblog: http://www.marcomansilla.com.ar
Jabber: conta...@marcomansilla.com.ar
Gtalk: conta...@marcomansilla.com.ar
MSN: conta...@marcomansilla.com.ar 

 http://www.saltalug.org.ar
 */


[web2py] Re: jQuery 1.5 released

2011-02-01 Thread Massimo Di Pierro
Usually there is a 1.X.1 a few days after...;-)

On Feb 1, 10:04 pm, ron_m  wrote:
> I took the min version and renamed it the same name as the 1.4.4 file in
> 1.91.6 and tested both the welcome app and the video system controller I am
> writing. No noticeable differences that I could see. I also use jQueryUI but
> am back at 1.8.6, current is 1.8.9 and did not see anything broken.
>
> I use a small amount of ajax to allow for user positioning of symbols on a
> map of the facility and when I drop a symbol the event makes an ajax call to
> a web2py controller to update the position of the symbol on the map into the
> database so it is drawn in the correct position next time.
>
> From my limited perspective the jQuery 1.5 release is perfect.


[web2py] Re: adding tables instead of merging?

2011-02-01 Thread mart
Hi Villas - you know it is quite possible i overlooked the obvious ;)

Ok, yeah had to check what I had asked back then. Yup, that was
great! and it still works great, no doubt about that. the thing is in
this case, we can create tables alright (even recreate them if need
be, or import them). The problem is, every identical process will have
the same tables and same names and I need to centralize them somehow
(especially, if we can't establish remote connections throuh script).
I am almost almost certain that if I say "yeah, it used to be in table
'changes', now its in table 'changesX'"... it will cause mass
confusion, like a meltdown ;)

so the hope would be to do something like this:

/databases/...product/branch//
TABLES_FOR_THAT_SPECIFIC_BUILD

the path would match the path to the same build on the file server
where the builds get stored.


Thanks for the reply :)


On Feb 1, 8:23 pm, villas  wrote:
> Hi Mart,
> I thought you'd already solved that one in a previous thread named
> 'tables created dynamically'?
> I am just reminding you of the thread in case you'd overlooked that
> interesting answer by Massimo.
> Sorry if that hasn't helped,  I do not know of any better answer.
> Best regards,
> David
>
> On Feb 1, 5:14 pm, mart  wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > Say a process generates a DB and a set of tables, and say this process
> > is repeated multple times: Is it possible to add tables (as opposed to
> > merging) to an existing DB? Since once set of tables have the same
> > names as another, ideally the tables could live in a separate folder
> > (uniquely named)... I'm not too hopeful, but is something like this
> > possible?
>
> > thanks,
> > Mart :)


Re: [web2py] Re: Need help in standardizing my coding and naming schemes before I start my main project

2011-02-01 Thread Martin Barnard
I'd be cautious about some of those field names. I'm not about to look them
up, but they look suspiciously like they may collide with reserved words.
I'm looking particularly hard at 'type' and 'text'. You may want to check
that.

Martin.

I don't mind typing the extra characters now that work bought me one of
these  :)



On 1 February 2011 23:08, howesc  wrote:

> i try to use pythonic naming conventions in my database.
>
> i prefer:
> db.define_table('address_type',
> Field('name'))
>
> db.define_table('contact',
> Field('name'))
>
> db.define_table('address',
> Field('contact', db.contact),
> Field('type', db.address_type),
> Field('text'))
>
> but perhaps mainly because i don't like to type all those extra characters.
> :)
>


[web2py] Re: web2py is running on dotCloud

2011-02-01 Thread Anthony
Cool. Thanks for putting up that demo.
 
Everyone, the DotCloud CEO recently offered folks on this list beta invites: 
https://groups.google.com/d/msg/web2py/eRARkDuYGn4/VJ9twwOA3-cJ
 
They also recently added a web2py setup tutorial to their documentation: 
http://docs.dotcloud.com/static/tutorials/web2py/. I emailed them to request 
they add the tutorial link to their main documentation page (which they 
did), and they said they were interested in feedback on the tutorial so they 
can improve it -- so try it out, and send them any feedback. Right now, 
Django is the only other Python framework with a tutorial there.
 
Anthony

On Tuesday, February 1, 2011 11:02:11 PM UTC-5, rochacbruno wrote:

> Take it a look: 
>
> http://www.web2py.dotcloud.com/welcome/default/index
>
> definitely the 'heroku' for web2py
>
> So easy
>
> $dotcloud deploy -t python myweb2pyapp.www
>
> $ln -s wsgihandler.py wsgi.py
>
> $cd path/to/my/web2py
>
> $dotcloud push myweb2pyapp.www
>
> $...
> rsync
>
>
>  
> and 
> http://www.web2py.dotcloud.com
>
>
> I am a little busy now, but I will try it with PostGreSQL tomorrow
>
>
> --
> Bruno Rocha
> http://about.me/rochacbruno/bio
>


[web2py] Creating subdomain on user registration

2011-02-01 Thread Prashanth
Im new to web2py .. I'm building an application which requires to
create subdomain which will be the username.. (like wordpress.com) .
So for example.. user1.mydomain.com  will be user1's area in my
website.

I have set the cname records for *.mydomain.com to point mydomain.com

Now my question is how can I make user1 part of the domain globally
available for all my controllers ( maybe in request.vars .. not
sure) .

Also user1 must be able to point user1.mydomain.com to his own domain
( custom domain feature) for the application interface. How can I
achieve this?


  1   2   >