[web2py] Re: auth_user.id == kenneth

2011-07-14 Thread Massimo Di Pierro
fields expect the type they have. references and integers expect
integers, double expects integer or float or double, date expects a
date, etc. Anyway because this is a current issue there is a shortcut:

user  = db.auth_user(request.args(0)) or redirect(URL('error'))

and even if request.args(0) is None or string you do not get an
exception but None



On Jul 14, 5:54 pm, Kenneth Lundström 
wrote:
> Thanks,
>
> logic error noted, in this case it woun t be a problem. Can t think of a
> fix without changing the idea behind this.
>
> I find it interesting that some fields expect a specific type. Is ID the
> only one?
>
> user = db(db.auth_user.id == request.args[0] if
> request.args[0].isdigit() else 0).select()
>
> This didn t work, it throws an error saying no table selected.
> But instead I did it like this:
>          if request.args[0].isdigit():
>              user = db(db.auth_user.id == str(request.args[0])).select()
>              if len(user):
>                  user_id = user[0].id
>              else:
>                  user_id = 0
>          else:
>              user = db(db.auth_user.username == request.args[0]).select()
>              if len(user):
>                  user_id = user[0].id
>              else:
>                  user_id = 0
>
> Kenneth
>
>
>
>
>
>
>
> > request.args always contain strings. str(request.args(0)) is
> > extraneous
>
> > There's a logic hole here: What if my username is "1" but my record's
> > id is 22. This code will return the record db.auth_user[1] when it's
> > supposed to return db.auth_user[22]
>
> > Anyway, ou get "invalid literal for int() with base 10" error because
> > auth_user.id expects integers and you're sending it a string,
> > "kenneth". Quick fix:
> > user = db(db.auth_user.id == request.args[0] if
> > request.args[0].isdigit() else 0).select()
>
> > That fixes the syntax error but not the logic error I pointed out
> > earlier.
>
> > On Jul 15, 5:06 am, Kenneth Lundstr m
> > wrote:
> >> Hello,
>
> >> why can t I do this:
> >> user = db(db.auth_user.id == 'kenneth').select()
>
> >> I know that this should result in len(user) = 0 but I m sending
> >> sometimes a text and sometimes a number and I m trying to do this:
> >>           user = db(db.auth_user.id == str(request.args[0])).select()
> >>           if len(user):
> >>               user_id = user[0].id
> >>           else:
> >>               user = db(db.auth_user.username == request.args[0]).select()
> >>               if len(user):
> >>                   user_id = user[0].id
> >>               else:
> >>                   user_id = 0
>
> >>      Error ticket for "kenneths"
>
> >>        Ticket ID
>
> >> 85.76.66.169.2011-07-15.00-45-45.b6793e0f-2144-4a02-802f-d7b8a45ec8a5
>
> >>        Version
>
> >> web2py^(TM)     Version 1.97.1 (2011-06-26 19:25:44)
> >> Python  Python 2.6.5: /usr/bin/python
>
> >>        Traceback
>
> >> 1.
> >> 2.
> >> 3.
> >> 4.
> >> 5.
> >> 6.
> >> 7.
> >> 8.
> >> 9.
> >> 10.
> >> 11.
> >> 12.
> >> 13.
> >> 14.
> >> 15.
> >> 16.
> >> 17.
> >> 18.
> >> 19.
> >> 20.
> >> 21.
> >> 22.
> >> 23.
> >> 24.
>
> >> Traceback(most recent call last):
> >>     File"/data/domains/web2py/gluon/restricted.py",line192,inrestricted
> >>       execccodeinenvironment
> >>     
> >> File"/data/domains/web2py/applications/kenneths/controllers/ticket.py",line43,in
> >>     File"/data/domains/web2py/gluon/globals.py",line137,in
> >>       self._caller=lambdaf:f()
> >>     
> >> File"/data/domains/web2py/applications/kenneths/controllers/ticket.py",line9,innew_ticket
> >>       user=db(db.auth_user.id=='kenneth').select()
> >>     File"/data/domains/web2py/gluon/dal.py",line5394,inselect
> >>       return self.db._adapter.select(self.query,fields,attributes)
> >>     File"/data/domains/web2py/gluon/dal.py",line1168,inselect
> >>       sql=self._select(query,fields,attributes)
> >>     File"/data/domains/web2py/gluon/dal.py",line1078,in_select
> >>       sql_w=' WHERE '+self.expand(query)
> >>     File"/data/domains/web2py/gluon/dal.py",line937,inexpand
> >>       returnexpression.op(expression.first,expression.second)
> >>     File"/data/domains/web2py/gluon/dal.py",line886,inEQ
> >>       return'(%s = %s)'% 
> >> (self.expand(first),self.expand(second,first.type))
> >>     File"/data/domains/web2py/gluon/dal.py",line943,inexpand
> >>       return self.represent(expression,field_type)
> >>     File"/data/domains/web2py/gluon/dal.py",line1280,inrepresent
> >>       returnstr(int(obj))
> >> ValueError:invalid literalforint()with base10:'kenneth'
>
> >>        Error snapshot
>
> >> |(invalid literal for int() with base 10:
> >> 'kenneth')|


[web2py] Re: shell tool used for videos

2011-07-14 Thread Massimo Di Pierro
It is not open source yet. I am still working on it. But it is very
close to playpiano for ipython and use osx "say" command for text to
speach

On Jul 14, 3:07 pm, Manu  wrote:
> Hi Massimo;
>   I was interested to know what is the tool you are using to script
> your presentation ( open web page; text2voice ...)
>
> Thx


[web2py] Re: We just hit 3000 members!

2011-07-14 Thread Massimo Di Pierro
Congratulations everybody for hitting 3000. Our 3000s member wins a
copy of the PDF book. Please claim it.

Massimo

On Jul 14, 3:34 pm, Anthony  wrote:
> Does member #3000 get a prize?
>
> 


[web2py] Message to the creator of Tenthrow regarding Paypal

2011-07-14 Thread Andrew Evans
Hello

I am having troubles integrating your code into even a simple example. I was
hoping you could help me by creating a working example of your code called
something like paypal_test and packing it into a web2py file so I can then
work on it in my own code.  As well as telling me how you generated the
certs needed to run it :-)

I would gladly pay 100 dollars for this. If you wanted money for your work

I understand if you don't have time. But this would be greatly appreciated
and I am sure would help others also

*cheers

The hopelessly confused

Andrew


[web2py] Re: Can't get linkto working in SQLFORM

2011-07-14 Thread tcab
I've been working through the book and have encountered exactly the
same problem.
The query has a spurious 'list_records' in front of it.

book is http://www.web2py.com/book/default/chapter/07?search=URL
web2py version is the latest 1.97.1
running under windows 7

-Andy

On Jul 12, 10:08 pm, jc  wrote:
> Hi,
> Trying to use linkto, so following example in web2py 
> book
>  first,
> to try to understand.
>
> I have copied the example with person and dog tables, in particular in def
> display_form(): I have
>
> link = URL('list_records')
> form = SQLFORM(db.person, record, deletable=True,
>                   upload=url, linkto=link, labels = {'dog.owner':"This
> person's dogs"})
>
> as described in the book.
>
> The books says the link generated will be
> "/test/default/list_records/dog?query=dog.owner%3D5" but in fact the link
> which appears when I visit /test/default/display_form/1 is
>  "/test/default/list_records/dog?query=list_records.dog.owner%3D%3D1", i.e.
> there is a spurious list.records and a spurious %3D. Not surprisingly the
> link doesn't work. Can anybody tell me what I am doing wrong?
>
> Thanks.


[web2py] Re: Can't get linkto working in SQLFORM

2011-07-14 Thread tcab
I get this too - a spurious "list_records." prepended to the query.
Latest web2py 1.97.1

-Andy

On Jul 12, 10:08 pm, jc  wrote:
> Hi,
> Trying to use linkto, so following example in web2py 
> book
>  first,
> to try to understand.
>
> I have copied the example with person and dog tables, in particular in def
> display_form(): I have
>
> link = URL('list_records')
> form = SQLFORM(db.person, record, deletable=True,
>                   upload=url, linkto=link, labels = {'dog.owner':"This
> person's dogs"})
>
> as described in the book.
>
> The books says the link generated will be
> "/test/default/list_records/dog?query=dog.owner%3D5" but in fact the link
> which appears when I visit /test/default/display_form/1 is
>  "/test/default/list_records/dog?query=list_records.dog.owner%3D%3D1", i.e.
> there is a spurious list.records and a spurious %3D. Not surprisingly the
> link doesn't work. Can anybody tell me what I am doing wrong?
>
> Thanks.


[web2py] Re: compute fields on update

2011-07-14 Thread niknok
I just tested this on v1.97.1 , and confirm that from the shell the
record doesn't appear to be updated even after a db.commit(). However,
using appadmin to check the database, the records were actually are
updated.

But if do it like this:
for i in db(db.item.id>0).select(): i.quantity, i.unit_price,
i.total_price

instead of like:
items =db(db.item.id>0).select()
for i in items: i.quantity, i.unit_price, i.total_price

You will see the record values are immediately updated.

So, I think this is a bug unless I'm very much mistaken.



On Jul 15, 12:17 pm, guruyaya  wrote:
> >>> db.commit()
> >>> db(db.item.id == 1).select()[0].total_price
> '9.95'
> >>> db(db.item.id == 1).select()[0]
>
>  at
> 0x17f1758>, 'unit_price': 3.0, 'id': 1, 'delete_record':   at 0x17f17d0>, 'quantity': 5}>
>
> On Jul 15, 12:54 am, niknok  wrote:
>
>
>
>
>
>
>
> > You're checking it from the shell. Do a db.commit() before checking
> > for total_price.
>
> > On Jul 15, 3:37 am, guruyaya  wrote:
>
> > > This is run on a web2py shell:
>
> > > >>> db.define_table('item',
>
> > > ...         Field('unit_price','double'),
> > > ...         Field('quantity','integer'),
> > > ...         Field('total_price',
> > > ...             compute=lambda r: r['unit_price']*r['quantity']))
> > > .
> > > .
> > > .
>
> > > >>> r = db.item.insert(unit_price=1.99, quantity=5)
> > > >>> r.total_price
> > > '9.95'
> > > >>> db(db.item.id == 1).select()[0]
>
> > >  at
> > > 0x17f10c8>, 'unit_price': 1.99, 'id': 1, 'delete_record':  > >  at 0x17f1230>, 'quantity': 5}>
>
> > > Till now, all is good.
>
> > > >>> db(db.item.id == 1).update(unit_price = 3)
> > > 1
> > > >>> db(db.item.id == 1).select()[0].total_price
> > > '9.95'
> > > >>> db(db.item.id == 1).select()[0].unit_price
>
> > > 3.0
>
> > > The web2py book said that
> > > """ When a new record is modified, including both insertions and
> > > *updates*, if a value for the field is not provided, web2py tries to
> > > compute from the other field values using the compute function """
>
> > > How come? shouldn't the compute field be recalculated?
>
> > > Now


[web2py] Re: compute fields on update

2011-07-14 Thread guruyaya
As for what you said, pbreit - this is acctually a copy paste of the
book. The version installed is 1.97.1

As for your your 2nd suggestion
>>> db.item.total_price.compute = lambda r: float(r['unit_price']) * 
>>> float(r['quantity'])
>>> r = db.item.insert(unit_price=1.99, quantity=3)
>>> r.total_price
'5.97'
>>> db.commit()
>>> r.id
2
>>> db(db.item.id>0).select();

>>> db(db.item.id>0).select()[1]
 at
0x17f1c80>, 'unit_price': 1.99, 'id': 2, 'delete_record':  at 0x17f1cf8>, 'quantity': 3}>
>>>
>>> db(db.item.id==2).select()[0];
 at
0x17f1b18>, 'unit_price': 1.99, 'id': 2, 'delete_record':  at 0x17f1d70>, 'quantity': 3}>
>>> db(db.item.id==2).update(quantity=12);
1
>>> db.commit()
>>> db(db.item.id>0).select()[1]
 at
0x17f1f50>,
 at
0x17f1f50>, 'unit_price': 1.99, 'id': 2, 'delete_record':  at 0x17f7050>, 'quantity': 12}>

So nothing yet...
On Jul 14, 11:18 pm, pbreit  wrote:
> That definitely looks like it should work according to the book.
>
> What do you get when you do it exactly like the book?
>
> >>> db.define_table('item',
>
>         Field 
> ('unit_price','double'),
>         Field 
> ('quantity','integer'),
>         Field ('total_price',
>             compute=lambda r: r['unit_price']*r['quantity']))
>
> >>> r = db.item.insert(unit_price=1.99, quantity=5)
> >>> print r.total_price
>
> What version of Web2py? Do you get different behavior if you pull the
> compute out of the table def?
>
> db.item.total_price.compute = lambda r: r['unit_price']*r['quantity']
>
> How about:
> db.item.total_price.compute = lambda r: float(r['unit_price']) *
> float(r['quantity'])


[web2py] Re: compute fields on update

2011-07-14 Thread guruyaya
>>> db.commit()
>>> db(db.item.id == 1).select()[0].total_price
'9.95'
>>> db(db.item.id == 1).select()[0]
 at
0x17f1758>, 'unit_price': 3.0, 'id': 1, 'delete_record':  at 0x17f17d0>, 'quantity': 5}>


On Jul 15, 12:54 am, niknok  wrote:
> You're checking it from the shell. Do a db.commit() before checking
> for total_price.
>
> On Jul 15, 3:37 am, guruyaya  wrote:
>
>
>
>
>
>
>
> > This is run on a web2py shell:
>
> > >>> db.define_table('item',
>
> > ...         Field('unit_price','double'),
> > ...         Field('quantity','integer'),
> > ...         Field('total_price',
> > ...             compute=lambda r: r['unit_price']*r['quantity']))
> > .
> > .
> > .
>
> > >>> r = db.item.insert(unit_price=1.99, quantity=5)
> > >>> r.total_price
> > '9.95'
> > >>> db(db.item.id == 1).select()[0]
>
> >  at
> > 0x17f10c8>, 'unit_price': 1.99, 'id': 1, 'delete_record':  >  at 0x17f1230>, 'quantity': 5}>
>
> > Till now, all is good.
>
> > >>> db(db.item.id == 1).update(unit_price = 3)
> > 1
> > >>> db(db.item.id == 1).select()[0].total_price
> > '9.95'
> > >>> db(db.item.id == 1).select()[0].unit_price
>
> > 3.0
>
> > The web2py book said that
> > """ When a new record is modified, including both insertions and
> > *updates*, if a value for the field is not provided, web2py tries to
> > compute from the other field values using the compute function """
>
> > How come? shouldn't the compute field be recalculated?
>
> > Now


Re: [web2py] Re: New Plugin: plugin_ckeditor

2011-07-14 Thread Tito Garrido
How to install it?

Regards,

Tito

On Sat, Jul 9, 2011 at 3:35 PM, cjrh  wrote:

> Very nice. I'm thinking how this is going to be immediately useful in a
> blog context for non-technical authors.




-- 

Linux User #387870
.
 _/_õ|__|
..º[ .-.___.-._| . . . .
.__( o)__( o).:___


[web2py] Re: slides of the San Francisco talk

2011-07-14 Thread weheh
Great slides.

On Jul 14, 2:33 pm, Massimo Di Pierro  wrote:
> http://www.scribd.com/doc/60038745/web2py-talk


[web2py] Re: auth_user.id == kenneth

2011-07-14 Thread niknok
As far as I know only with ID, which is always auto-magically created
for you.

On Jul 15, 6:54 am, Kenneth Lundström 
wrote:
> Thanks,
>
> logic error noted, in this case it woun t be a problem. Can t think of a
> fix without changing the idea behind this.
>
> I find it interesting that some fields expect a specific type. Is ID the
> only one?
>
> user = db(db.auth_user.id == request.args[0] if
> request.args[0].isdigit() else 0).select()
>
> This didn t work, it throws an error saying no table selected.
> But instead I did it like this:
>          if request.args[0].isdigit():
>              user = db(db.auth_user.id == str(request.args[0])).select()
>              if len(user):
>                  user_id = user[0].id
>              else:
>                  user_id = 0
>          else:
>              user = db(db.auth_user.username == request.args[0]).select()
>              if len(user):
>                  user_id = user[0].id
>              else:
>                  user_id = 0
>
> Kenneth
>
>
>
>
>
>
>
> > request.args always contain strings. str(request.args(0)) is
> > extraneous
>
> > There's a logic hole here: What if my username is "1" but my record's
> > id is 22. This code will return the record db.auth_user[1] when it's
> > supposed to return db.auth_user[22]
>
> > Anyway, ou get "invalid literal for int() with base 10" error because
> > auth_user.id expects integers and you're sending it a string,
> > "kenneth". Quick fix:
> > user = db(db.auth_user.id == request.args[0] if
> > request.args[0].isdigit() else 0).select()
>
> > That fixes the syntax error but not the logic error I pointed out
> > earlier.
>
> > On Jul 15, 5:06 am, Kenneth Lundstr m
> > wrote:
> >> Hello,
>
> >> why can t I do this:
> >> user = db(db.auth_user.id == 'kenneth').select()
>
> >> I know that this should result in len(user) = 0 but I m sending
> >> sometimes a text and sometimes a number and I m trying to do this:
> >>           user = db(db.auth_user.id == str(request.args[0])).select()
> >>           if len(user):
> >>               user_id = user[0].id
> >>           else:
> >>               user = db(db.auth_user.username == request.args[0]).select()
> >>               if len(user):
> >>                   user_id = user[0].id
> >>               else:
> >>                   user_id = 0
>
> >>      Error ticket for "kenneths"
>
> >>        Ticket ID
>
> >> 85.76.66.169.2011-07-15.00-45-45.b6793e0f-2144-4a02-802f-d7b8a45ec8a5
>
> >>        Version
>
> >> web2py^(TM)     Version 1.97.1 (2011-06-26 19:25:44)
> >> Python  Python 2.6.5: /usr/bin/python
>
> >>        Traceback
>
> >> 1.
> >> 2.
> >> 3.
> >> 4.
> >> 5.
> >> 6.
> >> 7.
> >> 8.
> >> 9.
> >> 10.
> >> 11.
> >> 12.
> >> 13.
> >> 14.
> >> 15.
> >> 16.
> >> 17.
> >> 18.
> >> 19.
> >> 20.
> >> 21.
> >> 22.
> >> 23.
> >> 24.
>
> >> Traceback(most recent call last):
> >>     File"/data/domains/web2py/gluon/restricted.py",line192,inrestricted
> >>       execccodeinenvironment
> >>     
> >> File"/data/domains/web2py/applications/kenneths/controllers/ticket.py",line43,in
> >>     File"/data/domains/web2py/gluon/globals.py",line137,in
> >>       self._caller=lambdaf:f()
> >>     
> >> File"/data/domains/web2py/applications/kenneths/controllers/ticket.py",line9,innew_ticket
> >>       user=db(db.auth_user.id=='kenneth').select()
> >>     File"/data/domains/web2py/gluon/dal.py",line5394,inselect
> >>       return self.db._adapter.select(self.query,fields,attributes)
> >>     File"/data/domains/web2py/gluon/dal.py",line1168,inselect
> >>       sql=self._select(query,fields,attributes)
> >>     File"/data/domains/web2py/gluon/dal.py",line1078,in_select
> >>       sql_w=' WHERE '+self.expand(query)
> >>     File"/data/domains/web2py/gluon/dal.py",line937,inexpand
> >>       returnexpression.op(expression.first,expression.second)
> >>     File"/data/domains/web2py/gluon/dal.py",line886,inEQ
> >>       return'(%s = %s)'% 
> >> (self.expand(first),self.expand(second,first.type))
> >>     File"/data/domains/web2py/gluon/dal.py",line943,inexpand
> >>       return self.represent(expression,field_type)
> >>     File"/data/domains/web2py/gluon/dal.py",line1280,inrepresent
> >>       returnstr(int(obj))
> >> ValueError:invalid literalforint()with base10:'kenneth'
>
> >>        Error snapshot
>
> >> |(invalid literal for int() with base 10:
> >> 'kenneth')|


[web2py] Re: auth_user.id == kenneth

2011-07-14 Thread niknok
In that case, this should work as well:

query = db.auth_user.id == request.args[0]).select() if
request.args[0].isdigit() else db.auth_user.username ==
request.args[0]
user_id = db(query).select()[0].id or 0




On Jul 15, 6:54 am, Kenneth Lundström 
wrote:
> Thanks,
>
> logic error noted, in this case it woun t be a problem. Can t think of a
> fix without changing the idea behind this.
>
> I find it interesting that some fields expect a specific type. Is ID the
> only one?
>
> user = db(db.auth_user.id == request.args[0] if
> request.args[0].isdigit() else 0).select()
>
> This didn t work, it throws an error saying no table selected.
> But instead I did it like this:
>          if request.args[0].isdigit():
>              user = db(db.auth_user.id == str(request.args[0])).select()
>              if len(user):
>                  user_id = user[0].id
>              else:
>                  user_id = 0
>          else:
>              user = db(db.auth_user.username == request.args[0]).select()
>              if len(user):
>                  user_id = user[0].id
>              else:
>                  user_id = 0
>
> Kenneth
>
>
>
>
>
>
>
> > request.args always contain strings. str(request.args(0)) is
> > extraneous
>
> > There's a logic hole here: What if my username is "1" but my record's
> > id is 22. This code will return the record db.auth_user[1] when it's
> > supposed to return db.auth_user[22]
>
> > Anyway, ou get "invalid literal for int() with base 10" error because
> > auth_user.id expects integers and you're sending it a string,
> > "kenneth". Quick fix:
> > user = db(db.auth_user.id == request.args[0] if
> > request.args[0].isdigit() else 0).select()
>
> > That fixes the syntax error but not the logic error I pointed out
> > earlier.
>
> > On Jul 15, 5:06 am, Kenneth Lundstr m
> > wrote:
> >> Hello,
>
> >> why can t I do this:
> >> user = db(db.auth_user.id == 'kenneth').select()
>
> >> I know that this should result in len(user) = 0 but I m sending
> >> sometimes a text and sometimes a number and I m trying to do this:
> >>           user = db(db.auth_user.id == str(request.args[0])).select()
> >>           if len(user):
> >>               user_id = user[0].id
> >>           else:
> >>               user = db(db.auth_user.username == request.args[0]).select()
> >>               if len(user):
> >>                   user_id = user[0].id
> >>               else:
> >>                   user_id = 0
>
> >>      Error ticket for "kenneths"
>
> >>        Ticket ID
>
> >> 85.76.66.169.2011-07-15.00-45-45.b6793e0f-2144-4a02-802f-d7b8a45ec8a5
>
> >>        Version
>
> >> web2py^(TM)     Version 1.97.1 (2011-06-26 19:25:44)
> >> Python  Python 2.6.5: /usr/bin/python
>
> >>        Traceback
>
> >> 1.
> >> 2.
> >> 3.
> >> 4.
> >> 5.
> >> 6.
> >> 7.
> >> 8.
> >> 9.
> >> 10.
> >> 11.
> >> 12.
> >> 13.
> >> 14.
> >> 15.
> >> 16.
> >> 17.
> >> 18.
> >> 19.
> >> 20.
> >> 21.
> >> 22.
> >> 23.
> >> 24.
>
> >> Traceback(most recent call last):
> >>     File"/data/domains/web2py/gluon/restricted.py",line192,inrestricted
> >>       execccodeinenvironment
> >>     
> >> File"/data/domains/web2py/applications/kenneths/controllers/ticket.py",line43,in
> >>     File"/data/domains/web2py/gluon/globals.py",line137,in
> >>       self._caller=lambdaf:f()
> >>     
> >> File"/data/domains/web2py/applications/kenneths/controllers/ticket.py",line9,innew_ticket
> >>       user=db(db.auth_user.id=='kenneth').select()
> >>     File"/data/domains/web2py/gluon/dal.py",line5394,inselect
> >>       return self.db._adapter.select(self.query,fields,attributes)
> >>     File"/data/domains/web2py/gluon/dal.py",line1168,inselect
> >>       sql=self._select(query,fields,attributes)
> >>     File"/data/domains/web2py/gluon/dal.py",line1078,in_select
> >>       sql_w=' WHERE '+self.expand(query)
> >>     File"/data/domains/web2py/gluon/dal.py",line937,inexpand
> >>       returnexpression.op(expression.first,expression.second)
> >>     File"/data/domains/web2py/gluon/dal.py",line886,inEQ
> >>       return'(%s = %s)'% 
> >> (self.expand(first),self.expand(second,first.type))
> >>     File"/data/domains/web2py/gluon/dal.py",line943,inexpand
> >>       return self.represent(expression,field_type)
> >>     File"/data/domains/web2py/gluon/dal.py",line1280,inrepresent
> >>       returnstr(int(obj))
> >> ValueError:invalid literalforint()with base10:'kenneth'
>
> >>        Error snapshot
>
> >> |(invalid literal for int() with base 10:
> >> 'kenneth')|


Re: [web2py] Re: auth_user.id == kenneth

2011-07-14 Thread Kenneth Lundström

Thanks,

logic error noted, in this case it woun´t be a problem. Can´t think of a 
fix without changing the idea behind this.


I find it interesting that some fields expect a specific type. Is ID the 
only one?


user = db(db.auth_user.id == request.args[0] if
request.args[0].isdigit() else 0).select()

This didn´t work, it throws an error saying no table selected.
But instead I did it like this:
if request.args[0].isdigit():
user = db(db.auth_user.id == str(request.args[0])).select()
if len(user):
user_id = user[0].id
else:
user_id = 0
else:
user = db(db.auth_user.username == request.args[0]).select()
if len(user):
user_id = user[0].id
else:
user_id = 0

Kenneth


request.args always contain strings. str(request.args(0)) is
extraneous

There's a logic hole here: What if my username is "1" but my record's
id is 22. This code will return the record db.auth_user[1] when it's
supposed to return db.auth_user[22]

Anyway, ou get "invalid literal for int() with base 10" error because
auth_user.id expects integers and you're sending it a string,
"kenneth". Quick fix:
user = db(db.auth_user.id == request.args[0] if
request.args[0].isdigit() else 0).select()

That fixes the syntax error but not the logic error I pointed out
earlier.



On Jul 15, 5:06 am, Kenneth Lundström
wrote:

Hello,

why can�t I do this:
user = db(db.auth_user.id == 'kenneth').select()

I know that this should result in len(user) = 0 but I�m sending
sometimes a text and sometimes a number and I�m trying to do this:
  user = db(db.auth_user.id == str(request.args[0])).select()
  if len(user):
  user_id = user[0].id
  else:
  user = db(db.auth_user.username == request.args[0]).select()
  if len(user):
  user_id = user[0].id
  else:
  user_id = 0

 Error ticket for "kenneths"

   Ticket ID

85.76.66.169.2011-07-15.00-45-45.b6793e0f-2144-4a02-802f-d7b8a45ec8a5

   Version

web2py^(TM) Version 1.97.1 (2011-06-26 19:25:44)
Python  Python 2.6.5: /usr/bin/python

   Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.

Traceback(most recent call last):
File"/data/domains/web2py/gluon/restricted.py",line192,inrestricted
  execccodeinenvironment

File"/data/domains/web2py/applications/kenneths/controllers/ticket.py",line43,in
File"/data/domains/web2py/gluon/globals.py",line137,in
  self._caller=lambdaf:f()

File"/data/domains/web2py/applications/kenneths/controllers/ticket.py",line9,innew_ticket
  user=db(db.auth_user.id=='kenneth').select()
File"/data/domains/web2py/gluon/dal.py",line5394,inselect
  return self.db._adapter.select(self.query,fields,attributes)
File"/data/domains/web2py/gluon/dal.py",line1168,inselect
  sql=self._select(query,fields,attributes)
File"/data/domains/web2py/gluon/dal.py",line1078,in_select
  sql_w=' WHERE '+self.expand(query)
File"/data/domains/web2py/gluon/dal.py",line937,inexpand
  returnexpression.op(expression.first,expression.second)
File"/data/domains/web2py/gluon/dal.py",line886,inEQ
  return'(%s = %s)'% (self.expand(first),self.expand(second,first.type))
File"/data/domains/web2py/gluon/dal.py",line943,inexpand
  return self.represent(expression,field_type)
File"/data/domains/web2py/gluon/dal.py",line1280,inrepresent
  returnstr(int(obj))
ValueError:invalid literalforint()with base10:'kenneth'

   Error snapshot

|(invalid literal for int() with base 10:
'kenneth')|




[web2py] Re: auth_user.id == kenneth

2011-07-14 Thread niknok
request.args always contain strings. str(request.args(0)) is
extraneous

There's a logic hole here: What if my username is "1" but my record's
id is 22. This code will return the record db.auth_user[1] when it's
supposed to return db.auth_user[22]

Anyway, ou get "invalid literal for int() with base 10" error because
auth_user.id expects integers and you're sending it a string,
"kenneth". Quick fix:
user = db(db.auth_user.id == request.args[0] if
request.args[0].isdigit() else 0).select()

That fixes the syntax error but not the logic error I pointed out
earlier.



On Jul 15, 5:06 am, Kenneth Lundström 
wrote:
> Hello,
>
> why can�t I do this:
> user = db(db.auth_user.id == 'kenneth').select()
>
> I know that this should result in len(user) = 0 but I�m sending
> sometimes a text and sometimes a number and I�m trying to do this:
>          user = db(db.auth_user.id == str(request.args[0])).select()
>          if len(user):
>              user_id = user[0].id
>          else:
>              user = db(db.auth_user.username == request.args[0]).select()
>              if len(user):
>                  user_id = user[0].id
>              else:
>                  user_id = 0
>
>     Error ticket for "kenneths"
>
>       Ticket ID
>
> 85.76.66.169.2011-07-15.00-45-45.b6793e0f-2144-4a02-802f-d7b8a45ec8a5
>
>       Version
>
> web2py^(TM)     Version 1.97.1 (2011-06-26 19:25:44)
> Python  Python 2.6.5: /usr/bin/python
>
>       Traceback
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
> 11.
> 12.
> 13.
> 14.
> 15.
> 16.
> 17.
> 18.
> 19.
> 20.
> 21.
> 22.
> 23.
> 24.
>
> Traceback(most recent call last):
>    File"/data/domains/web2py/gluon/restricted.py",line192,inrestricted
>      execccodeinenvironment
>    File"/data/domains/web2py/applications/kenneths/controllers/ticket.py"  
> ,line43,in
>    File"/data/domains/web2py/gluon/globals.py",line137,in
>      self._caller=lambdaf:f()
>    File"/data/domains/web2py/applications/kenneths/controllers/ticket.py"  
> ,line9,innew_ticket
>      user=db(db.auth_user.id=='kenneth').select()
>    File"/data/domains/web2py/gluon/dal.py",line5394,inselect
>      return self.db._adapter.select(self.query,fields,attributes)
>    File"/data/domains/web2py/gluon/dal.py",line1168,inselect
>      sql=self._select(query,fields,attributes)
>    File"/data/domains/web2py/gluon/dal.py",line1078,in_select
>      sql_w=' WHERE '+self.expand(query)
>    File"/data/domains/web2py/gluon/dal.py",line937,inexpand
>      returnexpression.op(expression.first,expression.second)
>    File"/data/domains/web2py/gluon/dal.py",line886,inEQ
>      return'(%s = %s)'% (self.expand(first),self.expand(second,first.type))
>    File"/data/domains/web2py/gluon/dal.py",line943,inexpand
>      return self.represent(expression,field_type)
>    File"/data/domains/web2py/gluon/dal.py",line1280,inrepresent
>      returnstr(int(obj))
> ValueError:invalid literalforint()with base10:'kenneth'
>
>       Error snapshot
>
> |(invalid literal for int() with base 10:
> 'kenneth')|


[web2py] Re: web2py with jquery mobile?

2011-07-14 Thread Anthony
http://web2py.com/plugins/plugin_jqmobile/about
 


[web2py] Re: compute fields on update

2011-07-14 Thread niknok
You're checking it from the shell. Do a db.commit() before checking
for total_price.

On Jul 15, 3:37 am, guruyaya  wrote:
> This is run on a web2py shell:
>
> >>> db.define_table('item',
>
> ...         Field('unit_price','double'),
> ...         Field('quantity','integer'),
> ...         Field('total_price',
> ...             compute=lambda r: r['unit_price']*r['quantity']))
> .
> .
> .
>
> >>> r = db.item.insert(unit_price=1.99, quantity=5)
> >>> r.total_price
> '9.95'
> >>> db(db.item.id == 1).select()[0]
>
>  at
> 0x17f10c8>, 'unit_price': 1.99, 'id': 1, 'delete_record':   at 0x17f1230>, 'quantity': 5}>
>
> Till now, all is good.
>
> >>> db(db.item.id == 1).update(unit_price = 3)
> 1
> >>> db(db.item.id == 1).select()[0].total_price
> '9.95'
> >>> db(db.item.id == 1).select()[0].unit_price
>
> 3.0
>
> The web2py book said that
> """ When a new record is modified, including both insertions and
> *updates*, if a value for the field is not provided, web2py tries to
> compute from the other field values using the compute function """
>
> How come? shouldn't the compute field be recalculated?
>
> Now


[web2py] web2py with jquery mobile?

2011-07-14 Thread António Ramos
hello, is there sample video showing how to use web2py and jquery mobile ?
maybe a an appliance to download from web2py.


thank you
Antonio


[web2py] auth_user.id == kenneth

2011-07-14 Thread Kenneth Lundström

Hello,

why can´t I do this:
user = db(db.auth_user.id == 'kenneth').select()

I know that this should result in len(user) = 0 but I´m sending 
sometimes a text and sometimes a number and I´m trying to do this:

user = db(db.auth_user.id == str(request.args[0])).select()
if len(user):
user_id = user[0].id
else:
user = db(db.auth_user.username == request.args[0]).select()
if len(user):
user_id = user[0].id
else:
user_id = 0


   Error ticket for "kenneths"


 Ticket ID

85.76.66.169.2011-07-15.00-45-45.b6793e0f-2144-4a02-802f-d7b8a45ec8a5


 Version

web2py^(TM) Version 1.97.1 (2011-06-26 19:25:44)
Python  Python 2.6.5: /usr/bin/python


 Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.



Traceback(most recent call last):
  File"/data/domains/web2py/gluon/restricted.py",line192,inrestricted
execccodeinenvironment
  File"/data/domains/web2py/applications/kenneths/controllers/ticket.py"  
,line43,in
  File"/data/domains/web2py/gluon/globals.py",line137,in
self._caller=lambdaf:f()
  File"/data/domains/web2py/applications/kenneths/controllers/ticket.py"  
,line9,innew_ticket
user=db(db.auth_user.id=='kenneth').select()
  File"/data/domains/web2py/gluon/dal.py",line5394,inselect
return self.db._adapter.select(self.query,fields,attributes)
  File"/data/domains/web2py/gluon/dal.py",line1168,inselect
sql=self._select(query,fields,attributes)
  File"/data/domains/web2py/gluon/dal.py",line1078,in_select
sql_w=' WHERE '+self.expand(query)
  File"/data/domains/web2py/gluon/dal.py",line937,inexpand
returnexpression.op(expression.first,expression.second)
  File"/data/domains/web2py/gluon/dal.py",line886,inEQ
return'(%s = %s)'% (self.expand(first),self.expand(second,first.type))
  File"/data/domains/web2py/gluon/dal.py",line943,inexpand
return self.represent(expression,field_type)
  File"/data/domains/web2py/gluon/dal.py",line1280,inrepresent
returnstr(int(obj))
ValueError:invalid literalforint()with base10:'kenneth'


 Error snapshot

|(invalid literal for int() with base 10: 
'kenneth')|





Re: [web2py] We just hit 3000 members!

2011-07-14 Thread Anthony
Sorry, didn't mean to be English-centric, though I assume there's a lot of 
overlap among the different groups:
 
3000: https://groups.google.com/group/web2py/about?hl=en&noredirect=true
81: 
https://groups.google.com/group/web2py-developers/about?hl=en&noredirect=true
243: 
https://groups.google.com/group/web2py-users-brazil/about?hl=en&noredirect=true
190: 
https://groups.google.com/group/web2py-usuarios/about?hl=en&noredirect=true
11: https://groups.google.com/group/web2py-fr/about?hl=en&noredirect=true
26: https://groups.google.com/group/web2py-japan/about?hl=en&noredirect=true
 
3000 <= Total <= 3551
 
So, I guess we now have a _minimum_ of 3000 members. :-)
 

On Thursday, July 14, 2011 4:44:24 PM UTC-4, rochacbruno wrote:

> 3243 
>
> http://awesomescreenshot.com/08agmmiad
>
>
>
> On Thu, Jul 14, 2011 at 5:34 PM, Anthony  wrote:
>
>> Does member #3000 get a prize?
>>  
>>
>>
>> 
>>  
>>
>
>
>
> -- 
>  
>
>
>  --
> Bruno Rocha
> [ About me: http://zerp.ly/rochacbruno ]
> [ Aprenda a programar: http://CursoDePython.com.br ] 
> [ O seu aliado nos cuidados com os animais: http://AnimalSystem.com.br ]
> [ Consultoria em desenvolvimento web: http://www.blouweb.com ]
>
>

Re: [web2py] We just hit 3000 members!

2011-07-14 Thread Bruno Rocha
3243

http://awesomescreenshot.com/08agmmiad



On Thu, Jul 14, 2011 at 5:34 PM, Anthony  wrote:

> Does member #3000 get a prize?
>
>
>
> 
>
>



-- 



--
Bruno Rocha
[ About me: http://zerp.ly/rochacbruno ]
[ Aprenda a programar: http://CursoDePython.com.br ]
[ O seu aliado nos cuidados com os animais: http://AnimalSystem.com.br ]
[ Consultoria em desenvolvimento web: http://www.blouweb.com ]
<>

[web2py] We just hit 3000 members!

2011-07-14 Thread Anthony
Does member #3000 get a prize?
 


 


[web2py] Re: Off topic: are Google Groups wires crossed?

2011-07-14 Thread Anthony
There's no problem when viewing the web2py user group. The problem is that 
many of our threads are also getting posted to other spam groups (as 
LightDot pointed out, probably because the email addresses of those spam 
groups are registered as members of our group, so any posts to our group get 
forwarded to those groups). For example:
 
https://groups.google.com/group/fameisfame?hl=en
https://groups.google.com/group/fametest?hl=en
https://groups.google.com/group/flutuberwachung?hl=en
 

On Thursday, July 14, 2011 4:21:22 PM UTC-4, pbreit wrote:

> I access the Group via the web and via the new interface and don't see any 
> problems: 
> https://groups.google.com/d/?fromgroups
>


[web2py] Re: Off topic: are Google Groups wires crossed?

2011-07-14 Thread pbreit
I access the Group via the web and via the new interface and don't see any 
problems:
https://groups.google.com/d/?fromgroups


[web2py] Re: compute fields on update

2011-07-14 Thread pbreit
That definitely looks like it should work according to the book.

What do you get when you do it exactly like the book?

>>> db.define_table('item',
Field 
('unit_price','double'),
Field 
('quantity','integer'),
Field ('total_price',
compute=lambda r: r['unit_price']*r['quantity']))
>>> r = db.item.insert(unit_price=1.99, quantity=5)
>>> print r.total_price


What version of Web2py? Do you get different behavior if you pull the 
compute out of the table def?

db.item.total_price.compute = lambda r: r['unit_price']*r['quantity']

How about: 
db.item.total_price.compute = lambda r: float(r['unit_price']) * 
float(r['quantity'])


[web2py] shell tool used for videos

2011-07-14 Thread Manu
Hi Massimo;
  I was interested to know what is the tool you are using to script
your presentation ( open web page; text2voice ...)

Thx


[web2py] Re: slides of the San Francisco talk

2011-07-14 Thread pbreit
Massimo's talk was well-received and I was happy to meet him in person for 
the first time.

Re: [web2py] Re: embedding html into python strings and getting them to render correctly

2011-07-14 Thread stephen_leaning


ok thanks v much for swift reply to all who replied, in particular
to Ross who proposed a solution and it works

good night from  luxembourg 

+

--

Re: [web2py] slides of the San Francisco talk

2011-07-14 Thread Martín Mulone
STOLEN!! jaja. It's a must read massimo, put in the main page.

2011/7/14 Bruno Rocha 

> On Thu, Jul 14, 2011 at 3:33 PM, Massimo Di Pierro <
> mdipie...@cs.depaul.edu> wrote:
>
>> http://www.scribd.com/doc/60038745/web2py-talk
>>
>
> I also gave a Talk about web2py on TheDevelopersConference 2011 (
> http://www.thedevelopersconference.com.br/tdc/2011/saopaulo/trilha-python#programacao
> )
>
> Coincidentally my Slides have some copies of yours (but no a copy, My talk
> was before)
>
> (all in Portuguese)
> Slides http://slidesha.re/nBnQpX
> One of the live demos I showed there: http://bit.ly/p2OLQB
>
> I prepared and showed comet_messaging, CAS, Plugins etc.. But people really
> liked the simple .json and .xml generic views.
>
>
>


-- 
 http://martin.tecnodoc.com.ar


[web2py] compute fields on update

2011-07-14 Thread guruyaya
This is run on a web2py shell:

>>> db.define_table('item',
... Field('unit_price','double'),
... Field('quantity','integer'),
... Field('total_price',
... compute=lambda r: r['unit_price']*r['quantity']))
.
.
.

>>> r = db.item.insert(unit_price=1.99, quantity=5)
>>> r.total_price
'9.95'
>>> db(db.item.id == 1).select()[0]
 at
0x17f10c8>, 'unit_price': 1.99, 'id': 1, 'delete_record':  at 0x17f1230>, 'quantity': 5}>

Till now, all is good.

>>> db(db.item.id == 1).update(unit_price = 3)
1
>>> db(db.item.id == 1).select()[0].total_price
'9.95'
>>> db(db.item.id == 1).select()[0].unit_price
3.0

The web2py book said that
""" When a new record is modified, including both insertions and
*updates*, if a value for the field is not provided, web2py tries to
compute from the other field values using the compute function """

How come? shouldn't the compute field be recalculated?



Now


[web2py] Re: embedding html into python strings and getting them to render correctly

2011-07-14 Thread Anthony
The XML object is documented here: 
http://web2py.com/book/default/chapter/05#XML. Just pass the string to XML() 
directly. In the example you found, variations[x].content was specific to 
that particular example (i.e., variations[x].content represented the string 
to be displayed).
 
Note, XML(..., sanitize=True) will do some sanitizing of the HTML (i.e., 
only allow particular tags and attributes in order to minimize the 
possibility of a security vulnerability).
 
Anthony

On Thursday, July 14, 2011 2:13:47 PM UTC-4, steveL wrote:

> In my web2py database I am storing strings with embedded html in. When 
> I try to render these records 
> in my views the html is not rendered (ie I get the string I put into 
> the database with all the embeded 
> html). On investigating this problem there was a similar problem some 
> 2/3  years ago and the solution 
> was given as use 
>
> {{=XML (variations[x].content)}} 
>
> where x is the  string containing the embeded html. 
>
> However when I use this solution I get 
>
> NameError: name 'variations' is not defined 
>
> Now the original solution is over 2 years old - has something 
> changed? 
>
> Thanks in advance 
>
> Steve 
>
> + 
>
>

[web2py] Re: slides of the San Francisco talk

2011-07-14 Thread Stefaan Himpe

http://www.scribd.com/doc/60038745/web2py-talk


The slides are stunningly informative and beautiful.



Re: [web2py] slides of the San Francisco talk

2011-07-14 Thread Bruno Rocha
I almost forgot...

Congrats, very nice slides!

I will copy some slides to use with my students and maybe in PyConBrasil


Re: [web2py] slides of the San Francisco talk

2011-07-14 Thread Bruno Rocha
On Thu, Jul 14, 2011 at 3:33 PM, Massimo Di Pierro
wrote:

> http://www.scribd.com/doc/60038745/web2py-talk
>

I also gave a Talk about web2py on TheDevelopersConference 2011 (
http://www.thedevelopersconference.com.br/tdc/2011/saopaulo/trilha-python#programacao
)

Coincidentally my Slides have some copies of yours (but no a copy, My talk
was before)

(all in Portuguese)
Slides http://slidesha.re/nBnQpX
One of the live demos I showed there: http://bit.ly/p2OLQB

I prepared and showed comet_messaging, CAS, Plugins etc.. But people really
liked the simple .json and .xml generic views.


[web2py] Re: embedding html into python strings and getting them to render correctly

2011-07-14 Thread Ross Peoples
Not sure where the variations variable is coming from, but putting 
pre-formatted HTML into a view is simple. In your controller, you have to 
include the html as an item in the dict() that is returned.

Here is an example controller:

def test():
html = 'Hello World'
return dict(html=html)

Then in your view:

{{extend 'layout.html'}}
{{=XML(html)}}

You could also have your controller return the wrapped XML object as well:

def test():
html = XML('Hello World')
return dict(html=html)

Then in your view:

{{extend 'layout.html'}}
{{=html}}

I do this sort of thing all the time to generate the required HTML, 
JavaScript, and CSS for the plugins I create.


[web2py] slides of the San Francisco talk

2011-07-14 Thread Massimo Di Pierro
http://www.scribd.com/doc/60038745/web2py-talk

[web2py] embedding html into python strings and getting them to render correctly

2011-07-14 Thread steveL
In my web2py database I am storing strings with embedded html in. When
I try to render these records
in my views the html is not rendered (ie I get the string I put into
the database with all the embeded
html). On investigating this problem there was a similar problem some
2/3  years ago and the solution
was given as use

{{=XML (variations[x].content)}}

where x is the  string containing the embeded html.

However when I use this solution I get

NameError: name 'variations' is not defined

Now the original solution is over 2 years old - has something
changed?

Thanks in advance

Steve

+



[web2py] date internationalization in view (solved)

2011-07-14 Thread andrej burja
it works, thank you
but it is hardcoded

this is better
TD(row.date.strftime(str(T('%Y-%m-%d')))


andrej


[web2py] Re: Off topic: are Google Groups wires crossed?

2011-07-14 Thread Massimo Di Pierro
Is there anybody on this list who works for google and can advice on
which action to take?

Massimo

On Jul 13, 5:11 pm, Anthony  wrote:
> Yes, I pointed this out a couple months ago. It appears that entire web2py
> threads are completely reposted within other groups 
> (e.g.,https://groups.google.com/forum/#!topic/fameisfame/Og_-6Z86DfE). The 
> content
> of these other groups generally appears to be spam. I have no idea how this
> happens.
>
> Anthony
>
>
>
>
>
>
>
> On Wednesday, July 13, 2011 4:30:56 PM UTC-4, DenesL wrote:
>
> > The recent activity of a group user can be viewed by clicking on the
> > "view profile" link on any post made by him/her, but I am seeing
> > activity in groups that I have never even heard about, let alone
> > become a member of, and the posts certainly belong to this group.
>
> > Maybe that could explain why some post have been "disappearing" from
> > our group.
>
> > I can see this happening not only on my profile but on other group
> > user profiles as well.
>
> > Comments? Suggestions?. (besides contacting Google I mean).


[web2py] Recurly with web2py

2011-07-14 Thread Carl
just a flag in the ground

I've taken the python library from recurly.com (for their credit-card
payment system) and it works just fine locally, on dev_appserver and
on GAE.

recurly.py (<300 lines) makes use of import base64, import types,
import re, import urllib, import urllib2.

nice to have something slip in so smoothly.

separately... had my head down when the 3rd edition of the Web2py book
came out... have just ordered it.


[web2py] hack doc: web2py's handling of incoming URLs

2011-07-14 Thread Jonathan Lundell
I don't think that this is actually documented anywhere, so here's a crack at 
it. Not authoritative. This doesn't document the routes.py-based rewriting, 
just the "normal" handling of incoming URLs.


main.wsgibase:

web2py expects its incoming URL to be in environ['PATH_INFO'] and 
environ['QUERY_STRING']. If PATH_INFO is not set, we try to set it and 
QUERY_STRING from REQUEST_URI.

Likewise, if HTTP_HOST is not set, we try to set it from SERVER_NAME and 
SERVER_PORT.

We then call rewrite.url_in to do all the work (regardless of whether routes.py 
exists).


rewrite.url_in:

If routes.py exists and contains a parametric router ('routers', a dict), we 
invoke rewrite.map_url_in to do the work; otherwise rewrite.regex_url_in does 
the work (including when routes.py does not exist).


rewrite.regex_url_in:

rewrite.regex_select determines the application. This is needed in case we're 
using app-specific routing.

If routes.py exists, call rewrite.regex_filter_in to rewrite the URL.

For each item in environ, create a copy with the key in lower case, with dots 
(in the key) replaced with underscores.

In request.path_info, convert backslashes to slashes.

Use regex_static to detect URLs of static files; return static files at this 
point, with spaces converted to underscores, where by 'spaces' we mean any 
white space, '+', or '%20'.

Otherwise, replace '%20' with ' ' (space).

Test path against regex_url; if it doesn't match, raise an invalid-request 
exception.

Set request.application, controller, function from the first three elements of 
the path, converting spaces (and +) to underscores. Use /init/default/index as 
the defaults, unless overridden in routes.py.

Set request.raw_extension to the extension, if any.

Set request.extension to the extension, or 'html' if None.

Set request.raw_args to the remainder of the path.

If the app is in routes_apps_raw, set request.args = None.

Otherwise replace spaces (but not +) with underscore and validate against 
regex_args, raising a 400 exception if no match, and split the result (on /) 
into the List request.args.



Re: [web2py] Re: URL() args encoding

2011-07-14 Thread Anthony
On Thursday, July 14, 2011 10:32:49 AM UTC-4, Jonathan Lundell wrote: 
>
>  On Jul 14, 2011, at 5:17 AM, Anthony wrote:
>
> I cannot reproduce this problem. For me, 'laa%20poo' is converted to 'laa 
> poo' (i.e., the '%20' is properly converted to a space, not an underscore). 
> What version of web2py are you using? Are you using the built-in Rocket 
> server?
>
>
> Are you (Anthony) using the parametric router? The standard handling of 
> incoming URLs (with no router or the pattern-based router) converts spaces 
> to underscores. The parametric router does not.
>
 
Oops, yes, I'm using the parametric router. Thanks for clearing that up.
 
Anthony


Re: [web2py] Re: URL() args encoding

2011-07-14 Thread Jonathan Lundell
On Jul 14, 2011, at 5:17 AM, Anthony wrote:
> I cannot reproduce this problem. For me, 'laa%20poo' is converted to 'laa 
> poo' (i.e., the '%20' is properly converted to a space, not an underscore). 
> What version of web2py are you using? Are you using the built-in Rocket 
> server?

Are you (Anthony) using the parametric router? The standard handling of 
incoming URLs (with no router or the pattern-based router) converts spaces to 
underscores. The parametric router does not.

If you're not using the parametric router, you'll find the untranslated args in 
request.raw_args, a single string that you'll need to split. 

If you're not using the parametric router and you want to take complete 
responsibility for dealing with args (this, importantly, includes validating 
them, because normal validation is bypassed), you can add your app name to 
routes_apps_raw.

My recommendation: use the parametric router (see router.example.py), even if 
you disable rewriting.

>  
> Anthony
> 
> On Thursday, July 14, 2011 6:27:09 AM UTC-4, (m) wrote:
> Awesome and thanx. I got that working and am able to generate URLs of 
> the form I wanted. 
> 
> But I've now discovered that web2py seems to be doing some additional 
> URL processing that I can't isolate. 
> 
> Assume a controller: 
> 
> def baz(): 
> orb = request.args[0] 
> return dict(orb=orb) 
> 
> With a view that just renders orb: 
> 
> {{extend 'layout.html'}} 
> Baz 
> {{=orb}} 
> 
> When I type in a URL of the form: 
> 
> http://localhost:8000/simple_app/default/baz/laa%20poo 
> 
> the value of orb that gets passed to the view appears to be 
> 
> laa_poo 
> 
> In other words, the encoded space got converted to an underscore 
> somewhere. 
> 
> Who is doing this and where are its rules documented? (I'm guessing 
> it's part of a security measure to prevent arbitrary stuff being 
> passed as args -- is this right?) 
> 
> 
> On Jul 14, 2:31 am, Anthony  wrote: 
> > If you've got keys and values in a dictionary that you want to convert to a 
> > query string, you would use urllib.urlencode (which is what the web2py URL 
> > function uses for vars). To quote just a plain string (like an arg), you 
> > can 
> > use urllib.quote() or urllib.quote_plus() (the latter converts each space 
> > to 
> > a '+' instead of a '%20'). If you want to convert back, you can use 
> > urllib.unquote() or urllib.unquote_plus() (though I think that will be 
> > handled automatically anyway). 
> > 
> > Anthony 
> > 
> > On Wednesday, July 13, 2011 5:55:49 PM UTC-4, (m) wrote: 
> > > My Web-programming and Python noobs continues to show. Thanks for 
> > > bearing with me. 
> > 
> > > I have a view with a fragment along the lines of the following to 
> > > generates a list of links. foos has been generated in the controller. 
> > 
> > > {{for foo in foos:}} 
> > > {{=foo.name}} 
> > > {{pass}} 
> > 
> > > This works fine until foo.name has spaces and/or other URL-unfriendly 
> > > chars in it. So the questions are: 
> > 
> > > * Does web2py have its own mechanism for encoding/decoding URLs that 
> > > is useful here? 
> > > * If not, what is the preferred Python lib for doing URL encoding/ 
> > > decoding? 
> > 
> > > (P.S. I am aware that there are other ways of addressing this issue: 
> > > e.g., use vars (which web2py seems to automatically encode) instead of 
> > > args, or use args=foo.id instead or args=foo.name. In any event, it'd 
> > > be good to know the web2py way to encode/decode URLs.) 
> > 
> >




[web2py] Good jQuery UI Library

2011-07-14 Thread stargate
I loved using the following library

http://flowplayer.org/tools/index.html

because it was light-weight but I think the developer is MIA. What is
a good jQuery library that will work with web2py and is light
weight.

I am not impressed with jquery UI I think its to bloated.


Re: [web2py] date internationalization in view

2011-07-14 Thread Bruno Rocha
TD(row.date.strftime('%y-%m-%d'))

http://zerp.ly/rochacbruno
Em 14/07/2011 09:23, "andrej burja"  escreveu:
> in model i have
> T.force('sl-si')
>
> and
> db.course.date.requires = IS_DATE(T('%Y-%m-%d'))
>
> in language fiel i have
> %Y-%m-%d
> %d %m %y
>
> in SQLFORM (od crud) and also the calendar widget it si ok
>
> but how can i display date in right format in view where i have
> for row in 
> TD(row.date)
>
> andrej


[web2py] Re: multiselect with part of a table

2011-07-14 Thread Anthony
The default validator for a list:reference field is 
IS_IN_DB(db,'.id',multiple=True). Instead of db, you can pass a DAL 
Set to that validator to filter the returned list -- something like:
 
db.audienceInstances.instances.requires=IS_IN_DB(db(db.instance.type==current_profile.type),'instance.id',multiple=True)
 
 
 
See http://web2py.com/book/default/chapter/06#DAL,-Table,-Field and 
http://web2py.com/book/default/chapter/07#Database-Validators.
 
Anthony
 
On Wednesday, July 13, 2011 2:39:50 PM UTC-4, Nico Palumbo wrote:

> I have currently this multiselect generated by list:references: 
>
> db.py: 
>
>
> db.define_table('instance',Field('app',db.application),Field('server',db.server),Field('type','string'),format=lambda
> r: '%s %s' %(db.application[r.app].name,db.server[r.server].hostname))
> ...
> db.define_table('audienceInstances', Field('instances','list:reference
> instance'),Field('user',db.auth_user,writable=False, readable=False)) 
>
> default.py: 
>
> monitoredInstances = db.audienceInstances(db.audienceInstances.user ==
> auth.user.id)
> #Generates a form for the updation of the list of monitored instances
> instancesForm = SQLFORM(db.audienceInstances, monitoredInstances,
> submit_button='Update', showid=False)
> if instancesForm.accepts(request.vars, session):
> response.flash = 'list updated'
> elif instancesForm.errors:
> response.flash = 'form has errors' 
>
> That shows a list select among all instances. But what if I'd like to
> show a subset of that list, I mean I added a type field in instance
> table, and like to get the instances of the type the user has selected
> in its profile. 
>
> The only way I can think of is creating a separate audienceInstances
> table for each type. Is there any othere way? 
>
> Thanks,
> Nico
>
>   

[web2py] Re: Database connection to Google Datastor in appengine

2011-07-14 Thread stargate
Thanks for the info I will try that.

On Jul 14, 8:09 am, Anthony  wrote:
> On Thursday, July 14, 2011 7:48:40 AM UTC-4, stargate wrote:
>
> > I am having trouble finding the connection string example to connect
> > to a Google Datastor database.
>
> Seehttp://code.google.com/p/web2py/source/browse/applications/welcome/mo
> According to the book, you can just use DAL('gae').
>
> >   Also what is the best method if you
> > are working on your web2py application locally how would you connect
> > to a Google Datastor database.
>
> Maybe use the 
> SDK:http://code.google.com/appengine/docs/python/gettingstarted/devenviro...
> .
>
> Anthony


[web2py] Re: multiselect with part of a table

2011-07-14 Thread Nicolas Palumbo
any alternatives?

On Wed, Jul 13, 2011 at 3:39 PM, Nicolas Palumbo  wrote:
> I have currently this multiselect generated by list:references:
>
> db.py:
>
> db.define_table('instance',Field('app',db.application),Field('server',db.server),Field('type','string'),format=lambda
> r: '%s %s' %(db.application[r.app].name,db.server[r.server].hostname))
> ...
> db.define_table('audienceInstances', Field('instances','list:reference
> instance'),Field('user',db.auth_user,writable=False, readable=False))
>
> default.py:
>
> monitoredInstances = db.audienceInstances(db.audienceInstances.user ==
> auth.user.id)
>    #Generates a form for the updation of the list of monitored instances
>    instancesForm = SQLFORM(db.audienceInstances, monitoredInstances,
> submit_button='Update', showid=False)
>    if instancesForm.accepts(request.vars, session):
>        response.flash = 'list updated'
>    elif instancesForm.errors:
>        response.flash = 'form has errors'
>
> That shows a list select among all instances. But what if I'd like to
> show a subset of that list, I mean I added a type field in instance
> table, and like to get the instances of the type the user has selected
> in its profile.
>
> The only way I can think of is creating a separate audienceInstances
> table for each type. Is there any othere way?
>
> Thanks,
> Nico
>


[web2py] Re: how to get user name before login is completed

2011-07-14 Thread Anthony
On Thursday, July 14, 2011 1:03:24 AM UTC-4, weheh wrote: 
>
> How would one get auth.messages.logged_in to be something like 
> "Welcome Massimo"upon login? auth.user_id is None at the time the 
> auth.messages.logged_in is evaluated.

 
There may be a better way, but maybe something like this:
 
def dynamic_logged_in_message(form):
session.flash='Welcome %s' % auth.user.first_name
auth.settings.login_onaccept = dynamic_logged_in_message
 
 
Anthony


[web2py] date internationalization in view

2011-07-14 Thread andrej burja
in model i have
T.force('sl-si')

and
db.course.date.requires = IS_DATE(T('%Y-%m-%d'))

in language fiel i have
%Y-%m-%d
%d %m %y

in SQLFORM (od crud) and also the calendar widget it si ok

but how can i display date in right format in view where i have
for row in 
TD(row.date)

andrej


[web2py] Re: URL() args encoding

2011-07-14 Thread Anthony
I cannot reproduce this problem. For me, 'laa%20poo' is converted to 'laa 
poo' (i.e., the '%20' is properly converted to a space, not an underscore). 
What version of web2py are you using? Are you using the built-in Rocket 
server?
 
Anthony

On Thursday, July 14, 2011 6:27:09 AM UTC-4, (m) wrote:

> Awesome and thanx. I got that working and am able to generate URLs of 
> the form I wanted. 
>
> But I've now discovered that web2py seems to be doing some additional 
> URL processing that I can't isolate. 
>
> Assume a controller: 
>
> def baz(): 
> orb = request.args[0] 
> return dict(orb=orb) 
>
> With a view that just renders orb: 
>
> {{extend 'layout.html'}} 
> Baz 
> {{=orb}} 
>
> When I type in a URL of the form: 
>
> http://localhost:8000/simple_app/default/baz/laa%20poo 
>
> the value of orb that gets passed to the view appears to be 
>
> laa_poo 
>
> In other words, the encoded space got converted to an underscore 
> somewhere. 
>
> Who is doing this and where are its rules documented? (I'm guessing 
> it's part of a security measure to prevent arbitrary stuff being 
> passed as args -- is this right?) 
>
>
> On Jul 14, 2:31 am, Anthony  wrote: 
> > If you've got keys and values in a dictionary that you want to convert to 
> a 
> > query string, you would use urllib.urlencode (which is what the web2py 
> URL 
> > function uses for vars). To quote just a plain string (like an arg), you 
> can 
> > use urllib.quote() or urllib.quote_plus() (the latter converts each space 
> to 
> > a '+' instead of a '%20'). If you want to convert back, you can use 
> > urllib.unquote() or urllib.unquote_plus() (though I think that will be 
> > handled automatically anyway). 
> > 
> > Anthony 
> > 
> > On Wednesday, July 13, 2011 5:55:49 PM UTC-4, (m) wrote: 
> > > My Web-programming and Python noobs continues to show. Thanks for 
> > > bearing with me. 
> > 
> > > I have a view with a fragment along the lines of the following to 
> > > generates a list of links. foos has been generated in the controller. 
> > 
> > > {{for foo in foos:}} 
> > > {{=foo.name}} 
> > > {{pass}} 
> > 
> > > This works fine until foo.name has spaces and/or other URL-unfriendly 
> > > chars in it. So the questions are: 
> > 
> > > * Does web2py have its own mechanism for encoding/decoding URLs that 
> > > is useful here? 
> > > * If not, what is the preferred Python lib for doing URL encoding/ 
> > > decoding? 
> > 
> > > (P.S. I am aware that there are other ways of addressing this issue: 
> > > e.g., use vars (which web2py seems to automatically encode) instead of 
> > > args, or use args=foo.id instead or args=foo.name. In any event, it'd 
> > > be good to know the web2py way to encode/decode URLs.) 
> > 
> >



[web2py] Re: Database connection to Google Datastor in appengine

2011-07-14 Thread Anthony
On Thursday, July 14, 2011 7:48:40 AM UTC-4, stargate wrote: 
>
> I am having trouble finding the connection string example to connect 
> to a Google Datastor database.

 
See 
http://code.google.com/p/web2py/source/browse/applications/welcome/models/db.py#8.
 
According to the book, you can just use DAL('gae').
 

>   Also what is the best method if you 
> are working on your web2py application locally how would you connect 
> to a Google Datastor database.

 
Maybe use the SDK: 
http://code.google.com/appengine/docs/python/gettingstarted/devenvironment.html
.
 
Anthony


[web2py] Database connection to Google Datastor in appengine

2011-07-14 Thread stargate
I am having trouble finding the connection string example to connect
to a Google Datastor database.  Also what is the best method if you
are working on your web2py application locally how would you connect
to a Google Datastor database.


[web2py] Re: URL() args encoding

2011-07-14 Thread (m)
Awesome and thanx. I got that working and am able to generate URLs of
the form I wanted.

But I've now discovered that web2py seems to be doing some additional
URL processing that I can't isolate.

Assume a controller:

def baz():
orb = request.args[0]
return dict(orb=orb)

With a view that just renders orb:

{{extend 'layout.html'}}
Baz
{{=orb}}

When I type in a URL of the form:

http://localhost:8000/simple_app/default/baz/laa%20poo

the value of orb that gets passed to the view appears to be

laa_poo

In other words, the encoded space got converted to an underscore
somewhere.

Who is doing this and where are its rules documented? (I'm guessing
it's part of a security measure to prevent arbitrary stuff being
passed as args -- is this right?)


On Jul 14, 2:31 am, Anthony  wrote:
> If you've got keys and values in a dictionary that you want to convert to a
> query string, you would use urllib.urlencode (which is what the web2py URL
> function uses for vars). To quote just a plain string (like an arg), you can
> use urllib.quote() or urllib.quote_plus() (the latter converts each space to
> a '+' instead of a '%20'). If you want to convert back, you can use
> urllib.unquote() or urllib.unquote_plus() (though I think that will be
> handled automatically anyway).
>
> Anthony
>
> On Wednesday, July 13, 2011 5:55:49 PM UTC-4, (m) wrote:
> > My Web-programming and Python noobs continues to show. Thanks for
> > bearing with me.
>
> > I have a view with a fragment along the lines of the following to
> > generates a list of links. foos has been generated in the controller.
>
> > {{for foo in foos:}}
> > {{=foo.name}}
> > {{pass}}
>
> > This works fine until foo.name has spaces and/or other URL-unfriendly
> > chars in it. So the questions are:
>
> > * Does web2py have its own mechanism for encoding/decoding URLs that
> > is useful here?
> > * If not, what is the preferred Python lib for doing URL encoding/
> > decoding?
>
> > (P.S. I am aware that there are other ways of addressing this issue:
> > e.g., use vars (which web2py seems to automatically encode) instead of
> > args, or use args=foo.id instead or args=foo.name. In any event, it'd
> > be good to know the web2py way to encode/decode URLs.)
>
>


[web2py] Re: Off topic: are Google Groups wires crossed?

2011-07-14 Thread LightDot
Well, two possibilities come to mind:

- a spam group's e-mail address is registered a member of web2py-users
- a third party e-mail address is registered as a member of web2py-users and 
is then set up to redirect all e-mail to this spam group.

Why is this done is beyond me... some way of harvesting e-mail addresses? I 
see I need to Google a bit about Google group spamming/hacking to come up to 
speed with these criminals


Re: [web2py] Re: how to use contrib/login_methods/linkedin_account.py

2011-07-14 Thread Carl Roach
Using web2py's sample classes as a reference and a lot of code written
by Ozgur Vatansever I have written code to OAuth into LinkedIn (built
on gluon.contrib.login_methods.oauth10a_account)

This enables access to a contact's name, job title, photo & company as
well as details about their connections. It can also send messages to
their LinkedIn account.

Alas I find LinkedIn's account quite limiting as it's aimed at
enhancing the experience of LinkedIn users during their own sessions
and not for providing services when they are not logged in.

You're right that no access is given to any of the email addresses of
a user but LinkedIn are doing well to protect the value of the service
- and as I user I appreciate I can't be spammed.




On 14 July 2011 04:32, Luis Goncalves  wrote:
> I didn't.
>
> But by doing the authentication manually (that is, in an interactive shell),
> I was able to connect to linked in.  I realized that I wouldn't be able to
> get the information that I wanted though (email address - never provided by
> linkedin!), so I gave up.
>
> But the web2py linked-in auth is broken, as far as I can tell.
>
> The same thing with facebook.  I think there are some steps that are just
> missing in the web2py implementation.   I have a simple script that works
> with facebook auth (I can get all the info from a person and their graph on
> facebook) -- but I don't know how to integrate that with the web2py auth.
>
> If you, or anyone else, wants my facebook login script, I can post it.
>
> Luis.
>