Re: [web2py] Add gluon to global python path

2011-04-28 Thread José Luis Redrejo Rodríguez
2011/4/29 luckysmack :
> Pretty much like the title says. This is also for things like when i
> open up a i/b/python shell, it would be cool to just be able to run
> 'import gluon' or 'from gluon import foo'. Im sure this would also
> have other benefits as well, but im not sure. I tried doing 'import
> sys' and 'sys.path.append("/srv/sites/web2py/gluon")' but that didnt
> seem to work. i also tried it without the/gluon part. Is it worth it
> to do this? otherwise i can get the effect by opening a terminal and
> going to the web2py directory, opening the python shell and importing
> like that. This culd also be handy when running python scripts that
> are in different places on the system and wanting to be able to import
> something from gluon.


Using a Debian distribution (or any of its derivatives) you can
install the debian package python-gluon (
http://packages.qa.debian.org/w/web2py.html ) . When installing it,
gluon is available in the python path.

Regards.


[web2py] Add gluon to global python path

2011-04-28 Thread luckysmack
Pretty much like the title says. This is also for things like when i
open up a i/b/python shell, it would be cool to just be able to run
'import gluon' or 'from gluon import foo'. Im sure this would also
have other benefits as well, but im not sure. I tried doing 'import
sys' and 'sys.path.append("/srv/sites/web2py/gluon")' but that didnt
seem to work. i also tried it without the/gluon part. Is it worth it
to do this? otherwise i can get the effect by opening a terminal and
going to the web2py directory, opening the python shell and importing
like that. This culd also be handy when running python scripts that
are in different places on the system and wanting to be able to import
something from gluon.


[web2py] Re: db(...).delete()

2011-04-28 Thread mart
yup, that did it! AND... only those tables not in _tables! this is
great! Thanks Massimo! :)

Mart :)

if anyone interested, this empties tables NOT specified in a list:

def deleteRecords():
_tables=['auth_user',
'auth_group',
'auth_membership',
'auth_permisssion',
'auth_event',
'local_user',
'local_history']
for tbl in db.tables:
if not tbl in _tables:emptyTable(tbl)

def emptyTable(tbl):
for mTbl in db.tables:
if tbl in mTbl:
if mTbl.startswith(tbl):db[tbl].truncate()

On Apr 29, 12:12 am, Massimo Di Pierro 
wrote:
> Instead of
>
> db(db[tbl].id>0).delete()
>
> you can use
>
> db[tbl].truncate()
>
> which is faster but does not work on GAE.
>
> On Apr 28, 8:18 pm, mart  wrote:
>
>
>
>
>
>
>
> > Hi,
>
> >  I'm thinking this should work... its done through script. Should I be
> > doing it differently?
>
> > thanks,
> > Mart :)
>
> > def deleteRecords():
> >     _tables=['auth_user',
> >                         'auth_group',
> >                             'auth_membership',
> >                                 'auth_permisssion',
> >                                     'auth_event',
> >                                         'local_user',
> >                                             'local_history']
> >     for tbl in db.tables:
> >         if not tbl in _tables:
> >             db(db[tbl].id>0).delete()


[web2py] Re: help.. is this correct-auth_user

2011-04-28 Thread pbreit
Now that I'm looking at the code again, can you even do that?

Wouldn't you need to do something like:

user = db(db.Matworksheetdb.email==auth.user.email).select().first()
if user:
 ...

Or in your case:

user = db((
db.Matworksheeetdb.email==auth.user.email)&(db.Matworksheeetdb.mgp>session.mpg)).select().first()
if user:
user.update_record(...)

Regarding "and" and "&" I was confused since it didn't look like a query 
without the db().


Re: [web2py] Re: ajax didn't run passing var when put it on static js folder

2011-04-28 Thread Stifan Kristi
a, i c, thank you so much for your pointer, pbreintenbach.

On Fri, Apr 29, 2011 at 10:01 AM, pbreit  wrote:

> I think for this specific case you do need to put the 

Re: [web2py] Re: ajax & cache.ram

2011-04-28 Thread Stifan Kristi
a, i understand, it will be more simple, thank you so much for your advice,
pbreitenbach.

On Fri, Apr 29, 2011 at 9:59 AM, pbreit  wrote:

> The caching is likely the problem since that's exactly what caching does.
> It stores the results of the query for the time specified to avoid querying
> the database. Thus you won't see the new values. I would strongly discourage
> using cache unless/until you actually need it (which is rare). It can easily
> lead to unexpected behavior like this.
>
> Also, you can tighten up your code a lot which might make it easier to
> follow. For example:
>
> URL(request.application, request.controller, request.function, args =
> page.id))
>
> could be:
>
> URL(request.function, args = page.id))
>


[web2py] Re: db(...).delete()

2011-04-28 Thread Massimo Di Pierro
Instead of

db(db[tbl].id>0).delete()

you can use

db[tbl].truncate()

which is faster but does not work on GAE.

On Apr 28, 8:18 pm, mart  wrote:
> Hi,
>
>  I'm thinking this should work... its done through script. Should I be
> doing it differently?
>
> thanks,
> Mart :)
>
> def deleteRecords():
>     _tables=['auth_user',
>                         'auth_group',
>                             'auth_membership',
>                                 'auth_permisssion',
>                                     'auth_event',
>                                         'local_user',
>                                             'local_history']
>     for tbl in db.tables:
>         if not tbl in _tables:
>             db(db[tbl].id>0).delete()


[web2py] Re: help.. is this correct-auth_user

2011-04-28 Thread Massimo Di Pierro
Not sure I understand the context but there should be no "and" or "or"
in dal queries.

On Apr 28, 10:10 pm, pbreit  wrote:
> Try "and" instead of "&". I seem to recall that might be necessary. In fact,
> you could skip the first clause since it's redundant.


[web2py] Re: displaying a table in multiple columns

2011-04-28 Thread Massimo Di Pierro
BEAUTIFY is not smart enough

{{
  import random
  data = [(i,random.random()) for i in range(random.randint(100,200))]
  n=int((len(data)+2)/n)
  i=0
}}


{{for r in range(n):}}
  
  {{for c in range(3):}}
{{=data[i][0] if i
{{=data[i][1] if i
{{i=i+1}}{{pass}}
  
  {{pass}}


On Apr 28, 2:23 pm, mart  wrote:
> Hi,
>
> I have the db tables with only 2 or 3 fields (like name/value pairs),
> I was looking to  display the contents in a more condensed fashion,
> like maybe split the table in multiple columns. Maybe something like
> this :
>
> Column_1            column_2             column_3
> name | value        name | value       name | value
> name | value        name | value       name | value
> name | value        name | value       name | value
> name | value        name | value       name | value
> name | value        name | value       name | value
> name | value        name | value       name | value
>
> is there a quick and dirty way of doing that already? (can be
> plugin_wiki, or anything else, I'm not that fussy :) )
>
> any help would be appreciated!
>
> Thanks,
> Mart :)


[web2py] Re: Fake Tables

2011-04-28 Thread Massimo Di Pierro
Perhaps I do not understand enough of the problem but tables in memory
are a pain with web2py. The table will be re-created at each http-
request (unless you put the table in cache) and web2py will not create
the .table files for tables in memory because it knows they are not
persistent.


On Apr 28, 7:55 pm, KMax  wrote:
> Hello
>
>   I guess table creation files like
> 4d93272056dfca0a990325d869e079cd_auth_user.table
>   at database folder will arise.
>   What will happend next start?
>   Web2pyDAL will treat tables as created?
>   ...
>   And second question:
>   sqlite in memmory will be the fastest one, but what about concurent
> access in case of multithreaded instance?
>
> On 28 апр, 22:33, Bruno Rocha  wrote:
>
>
>
>
>
>
>
> > db = DAL('sqlite:memory') #you got an temp sqlinstance on memory


[web2py] Re: db(...).delete()

2011-04-28 Thread mart
hey,

nope, gave it a try, and a few other things and nothing so far... no
tables are being emptied... this is very strange. There must be a
trick somewhere ;)

thanks for the suggestion :)

On Apr 28, 9:49 pm, Vasile Ermicioi  wrote:
> def deleteRecords():
>    _tables=['auth_user',
>                        'auth_group',
>                            'auth_membership',
>                                'auth_permisssion',
>                                    'auth_event',
>                                        'local_user',
>                                            'local_history']
>    for tbl in db.tables:
>        if not tbl._tablename in _tables:
>            db(tbl).delete()
>
> important thing:  if not tbl._tablename in _tables
>
> this is just a shorter version: db(tbl).delete()


[web2py] debugging help. when trying to edit a record.

2011-04-28 Thread niknok
The following model and controller works fine when adding records, but
generates an error "('issuer')" when I try
to edit a record. Unfortunately for me, I couldn't understand what
that error actually means, or what I missed doing.

Could someone give me a nudge forward? Thanks.

/r
Nik

code is here: http://pastie.org/1845934


Re: [web2py] Fwd: Solved -- Problems with special characters and pyfpdf

2011-04-28 Thread Alexandre Andrade
The same can be converted to a function, to make it easier:

def lt(str):
return unicode(str,'utf-8').encode('iso-8859-1')


so just

pdf.cell(50,20,lt('Helló Wórld'), 0,2,'L')

2011/4/29 Christopher Steel 

>
> This solution works well. You will need to make a minor correction and
> remove the single quotes around 'txt' in the second line. The edited
> version looks like this:
>
>txt = 'Hélló wórld'
>utxt = unicode(txt, 'utf-8')
>stxt = utxt.encode('iso-8859-1')
>pdf.cell(50,20, stxt, 0, 2, 'L')
>
>
> Thanks for the hint Bernardo!
>
> C.
>
>
> -- Forwarded message --
> From: Bernardo 
> Date: Sep 25 2010, 7:35 am
> Subject: Solved -- Problems with special characters and pyfpdf
> To: web2py-users
>
>
> Hi all,
>
> When usingpyfpdfwhich comes with web2py framework, there are some
> issues withspecialcharacterssuch as accentedcharacters(á, é,
> í, ...). After some research, I found out thatpyfpdfjust understands
> 'iso-8859-1', and web2py gives him the strings in 'utf-8' format.
>
> So, as a solution, in your python code you just have to convert the
> string before passing it topyfpdf, like this:
>
> txt = 'Hélló wórld'
> utxt = unicode('txt', 'utf-8')
> stxt = utxt.encode('iso-8859-1')
> pdf.cell(50,20, stxt, 0, 2, 'L')
>
> If anyone has any doubts, just ask. I hope this can help someone...
>
> kind regards,
> Bernardo
>



-- 
Atenciosamente


Alexandre Andrade
Hipercenter.com Classificados Gratuitos


Re: [web2py] Re: help.. is this correct-auth_user

2011-04-28 Thread pbreit
Try "and" instead of "&". I seem to recall that might be necessary. In fact, 
you could skip the first clause since it's redundant.

[web2py] Fwd: Solved -- Problems with special characters and pyfpdf

2011-04-28 Thread Christopher Steel

This solution works well. You will need to make a minor correction and
remove the single quotes around 'txt' in the second line. The edited
version looks like this:

txt = 'Hélló wórld'
utxt = unicode(txt, 'utf-8')
stxt = utxt.encode('iso-8859-1')
pdf.cell(50,20, stxt, 0, 2, 'L')


Thanks for the hint Bernardo!

C.


-- Forwarded message --
From: Bernardo 
Date: Sep 25 2010, 7:35 am
Subject: Solved -- Problems with special characters and pyfpdf
To: web2py-users


Hi all,

When usingpyfpdfwhich comes with web2py framework, there are some
issues withspecialcharacterssuch as accentedcharacters(á, é,
í, ...). After some research, I found out thatpyfpdfjust understands
'iso-8859-1', and web2py gives him the strings in 'utf-8' format.

So, as a solution, in your python code you just have to convert the
string before passing it topyfpdf, like this:

txt = 'Hélló wórld'
utxt = unicode('txt', 'utf-8')
stxt = utxt.encode('iso-8859-1')
pdf.cell(50,20, stxt, 0, 2, 'L')

If anyone has any doubts, just ask. I hope this can help someone...

kind regards,
Bernardo


[web2py] Re: How to avoid computing a field when updating a record?

2011-04-28 Thread pbreit
A computed field is going to get re-computed every time the record is 
updated. If that's not the behavior you want, maybe use a default or virtual 
field (if I understand correctly).

[web2py] Re: displaying a table in multiple columns

2011-04-28 Thread pbreit
Maybe {{=BEAUTIFY(rows)}} ?

Re: [web2py] Re: ajax didn't run passing var when put it on static js folder

2011-04-28 Thread pbreit
I think for this specific case you do need to put the 

[web2py] Re: ajax & cache.ram

2011-04-28 Thread pbreit
The caching is likely the problem since that's exactly what caching does. It 
stores the results of the query for the time specified to avoid querying the 
database. Thus you won't see the new values. I would strongly discourage 
using cache unless/until you actually need it (which is rare). It can easily 
lead to unexpected behavior like this.

Also, you can tighten up your code a lot which might make it easier to 
follow. For example:

URL(request.application, request.controller, request.function, args = 
page.id))

could be:

URL(request.function, args = page.id)) 


Re: [web2py] Re: ajax didn't run passing var when put it on static js folder

2011-04-28 Thread Stifan Kristi
thank you so much for your pointer, pbreit, i've followed what u said, but
it still not working. currently, i put it on the views/default/index.html
not in the layout.html.

it seems that vars on ajax can't be passed to another file, because when i
put script on the same page, it can be run. because there are another
function that need the same ajax function, so that i put it on the
static/js/cart.js and then called the file on the views.

does anybody know how to fix it?
many thanks before

On Fri, Apr 29, 2011 at 9:27 AM, pbreit  wrote:

> Are you including the script in your layout.html or other page?
>
> I like to put a  tag in the  section of my layout.html:
>