[web2py] Email as username

2011-01-30 Thread Kenneth Lundström

Hello list,

I have an old application build two years ago and it uses email adress 
as the username, so you don´t need a different username.


Now I´d like to do the same on a new application but I don´t know what 
to change to do this.


Any ideas?


Kenneth



Re: [web2py] Re: Fwd: web2py basic auth

2011-01-30 Thread Miguel Lopes
You got me in the right direction.
Txs.
I'll be starting a separate thread on what I'm trying to achieve, so
far without success.


On Sat, Jan 29, 2011 at 8:13 PM, Niphlod niph...@gmail.com wrote:
 sorry, my mistake!

 On Jan 29, 4:01 pm, Miguel Lopes mig.e.lo...@gmail.com wrote:
 gluons/tools.py

 Txs,
 Miguel

 On Sat, Jan 29, 2011 at 12:29 AM, Niphlod niph...@gmail.com wrote:
  call_or_redirect() is the real addition here  you can use both a
  URL or a function to manage on_failed_authentication and
  on_failed_authorization ... take a look in gluon/utils.py

  On Jan 28, 1:48 am, miguel mig.e.lo...@gmail.com wrote:
   I suppose this is mentioned in the Change Log by:
   on_failed_authorization can be a function, thanks Niphold

   How is this used? could the function be a lambda, does it take params,
   is it an action (i.e. a controller function)?

   Also, is it possible to allow the usual login redirection in case it
   is not a service call? I'm thinking in these lines:

   def theFunction():
       if request.function == 'call':
           # return case forservice call
       else:
           # redirect to login form

   This would be useful for publishing the same service both for browsers
   and for other apps, like it is mentioned in p://
 www.web2pyslices.com/main/slices/take_slice/48
   (see Authentication). This solution would also be useful for other
   non-browser-based clients. Would it work? How is the function used?

   Txs,
   Miguel

   -- Forwarded message --
   From: mdipierro mdipie...@cs.depaul.edu
   Date: Sep 23 2010, 2:34 pm
   Subject: web2py basic auth
   To: web2py-users

   Against trunk please. It is ok if you just send me a replacement file.
   I will diff and study it.

   On Sep 23, 8:52 am, Niphlod niph...@gmail.com wrote:

Never done a patch before, but I think in the night (here are 3PM) I
can manage to have a first draft.

I'd have to test it out, but for the beginning .. What wuold be the
patch against ? tools.py in trunk or tools.py in 1.85.3?

On 23 Set, 14:52, mdipierro mdipie...@cs.depaul.edu wrote:

 You are right. That would be best. Want to send me a patch?

 On Sep 23, 2:26 am, Niphlod niph...@gmail.com wrote:




[web2py] Re: Email as username

2011-01-30 Thread hcvst
Hi Kenneth,

remove the 'username' field from the auth_user table. Also see Chapter
8
http://web2py.com/book/default/chapter/08 on custom tables.

I think in the past w2p only used email by default. The new app wizard
appears to include it now.

Regards,
HC

On Jan 30, 11:13 am, Kenneth Lundström kenneth.t.lundst...@gmail.com
wrote:
 Hello list,

 I have an old application build two years ago and it uses email adress
 as the username, so you don t need a different username.

 Now I d like to do the same on a new application but I don t know what
 to change to do this.

 Any ideas?

 Kenneth


[web2py] Re: Email as username

2011-01-30 Thread hcvst
Even easier - as I only saw now (always worthwhile to reread the book
every so often)

 (w2p book Ch 8)

To start using Auth, you need at least this code in a model file,
which is also provided with the web2py welcome application and
assumes a db connection object:

from gluon.tools import Auth
auth = Auth(globals(), db)
auth.define_tables(username=False)

Set username=True if you want auth to user username for login instead
of email.



On Jan 30, 11:55 am, hcvst hcv...@googlemail.com wrote:
 Hi Kenneth,

 remove the 'username' field from the auth_user table. Also see Chapter
 8http://web2py.com/book/default/chapter/08on custom tables.

 I think in the past w2p only used email by default. The new app wizard
 appears to include it now.

 Regards,
 HC

 On Jan 30, 11:13 am, Kenneth Lundström kenneth.t.lundst...@gmail.com
 wrote:







  Hello list,

  I have an old application build two years ago and it uses email adress
  as the username, so you don t need a different username.

  Now I d like to do the same on a new application but I don t know what
  to change to do this.

  Any ideas?

  Kenneth


[web2py] problems with conditional login redirection on on_failed_authorization

2011-01-30 Thread Miguel Lopes
on_failed_authorization can be a URL or a function.
I'm think I could use this to achieve conditional login redirection.
A use case would be service calls returning a simple string (or a JSON
or an XML reply to non-validated requests), while still allowing for
regular (non-service requests) to be redirected to a login page.
This is useful for command-line clients (as a recent post argues) and
desktops clients, but also to browser based RIA apps (e.g. Pyjamas
based, Flex,...) where session expiration could lead to wanted
redirections (as is mentioned in
http://www.web2pyslices.com/main/slices/take_slice/48 ).

I would see this as something as simple as:

[in models/db.py]
private_service = Service(globals())   # PRIVATE - for json,
xml, jsonrpc, xmlrpc, amfrpc
public_service = Service(globals())# PUBLIC - for json,
xml, jsonrpc, xmlrpc, amfrpc
...
auth.settings.allow_basic_login = True
def failedAuthHandler():
   if request.function == 'private_call':
   redirect(URL(f='public_call', args='failed_login'))
   else:
   redirect(URL(request))
auth.settings.on_failed_authorization = failedAuthHandlerandler

[in controllers/default]
@private_service.jsonrpc
def jsoncount():
return dict(response=response.session_id_name, now=request.now)

@public_service.jsonrpc
def failed_login():
return dict(error='Failed login')

def public_call():
return public_service()

@auth.requires_login()
def private_call():
return private_service()

However, I'm unable to make this code work.
From the command line, if I issue a call with basic auth, with good
credentials, such as:
 import jsonrpc
 sv = 
 jsonrpc.ServiceProxy(http://GOOD_USER:GOOD_PASS@127.0.0.1:8080/json_auth_test/default/private_call/jsonrpc;)
 sv.jsoncount()
 {'now': '2011-01-30 10:31:21', 'response': 'session_id_json_auth_test'}

But bad credentials don't work as expected:
 import jsonrpc
 sv = 
 jsonrpc.ServiceProxy(http://GOOD_USER:BAD_PASS@127.0.0.1:8080/json_auth_test/default/private_call/jsonrpc;)
 sv.jsoncount()
Traceback (most recent call last):
  File stdin, line 1, in module
  File 
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/jsonrpc/proxy.py,
line 43, in __call__
resp = loads(respdata)
  File 
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/jsonrpc/json.py,
line 211, in loads
raise JSONDecodeException('Expected []{}, or Number, Null, False or True')
jsonrpc.json.JSONDecodeException: Expected []{}, or Number, Null, False or True


From the browser using an url with or without credentials, for both:
.../default/private_call/jsoncount
.../default/public_call/failed_login

I get:
Object does not exist with a Status 404 content header

Am I on the right track?
How could this be achieved?
Txs,
Miguel


Re: [web2py] Forcing SSL on certain requests;

2011-01-30 Thread David J.

Philip;

Yes; I suppose that would work;

Thanks for the advice;

It is appreciated.

Have a good day.



On 1/30/11 2:41 AM, Philip Kilner wrote:

Hi David,

On 30/01/2011 01:02, David J. wrote:

Is there a utility available to force requests to SSL? (ex: Login,
Register, etc..)



Are you behind a web server? That may be a better place to manage that 
than on the web2py side, depending on you needs of course.


You can do this with an Apache rewrite rule, see: -

http://www.whoopis.com/howtos/apache-rewrite.html

...for some examples.

HTH






[web2py] table field with reference to other in read-only mode doesn't appear right

2011-01-30 Thread szimszon
I wonder if somebody could help me.

Here is my Field:

Field( 'updated_by', db.auth_user,
writable = False  )

CRUD rendered it in form None but the record has a value 1 and I
have user in auth_user.id=1

If I modify the Field to:

Field( 'updated_by', db.auth_user,
writable = False ,
requires = IS_EMPTY_OR( IS_IN_DB( db, 
db.auth_user.id, '%
(first_name)s' ) ) )

The result is 1 and not the first_name value.

If I modify the Field to:

Field( 'updated_by', db.auth_user)

The result is a list with all the auth_user rows :-o

With the Field like this:

Field( 'updated_by', db.auth_user,
requires = IS_EMPTY_OR( IS_IN_DB( db, 
db.auth_user.id, '%
(first_name)s' ) ) )

There is a result list with all the first_name values...

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


[web2py] table field with reference to other in read-only mode doesn't appear right

2011-01-30 Thread szimszon
I wonder if somebody could help me.

Here is my Field:

Field( 'updated_by', db.auth_user,
writable = False  )

CRUD rendered it in form None but the record has a value 1 and I
have user in auth_user.id=1

If I modify the Field to:

Field( 'updated_by', db.auth_user,
writable = False ,
requires = IS_EMPTY_OR( IS_IN_DB( db, 
db.auth_user.id, '%
(first_name)s' ) ) )

The result is 1 and not the first_name value.

If I modify the Field to:

Field( 'updated_by', db.auth_user)

The result is a list with all the auth_user rows :-o

With the Field like this:

Field( 'updated_by', db.auth_user,
requires = IS_EMPTY_OR( IS_IN_DB( db, 
db.auth_user.id, '%
(first_name)s' ) ) )

There is a result list with all the first_name values...

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


Re: [web2py] Re: web2py and gae : Delete everything in the datastore

2011-01-30 Thread Nathan VanHoudnos
It worked. :)

On Sat, Jan 29, 2011 at 6:03 PM, devGS vitali@geniestills.com wrote:

 Great than. From my experience with that future, it takes time to
 delete in bulk and the process is is splitted into hours in order to
 save your CPU time. You can track the process through your datastore
 panels, task queue, etc. That's all I can comment about. Hopping to
 hear about your experience.

 On Jan 29, 7:16 pm, Nathan VanHoudnos nathan...@gmail.com wrote:
  Yes, I am doing something wrong. I needed to navigate to 'Datastore
 Admin'
  instead of 'Datastore Viewer'. The admin pages allows you to delete
  everything quickly. The viewer page only allows you to delete in chunks
 of
  20.
 
  From:
 http://code.google.com/appengine/docs/python/datastore/entities.html
 
  Deleting Entities in Bulk via the Admin Console
  You can use the Datastore Admin tab of the Admin Console to delete all
  entities of a kind, or all entities of all kinds, in the default
 namespace.
  To enable this feature, simply include the datastore_admin builtin
 handler
  in app.yaml:
 
  builtins:
  - datastore_admin: on
 
  Adding this builtin enables the Datastore Admin screen in the Data
 section
  of the Admin Console. From this screen, you can select the entity kind(s)
 to
  delete individually or in bulk, and delete them using the Delete Entities
  button.
 
  Warning! Deleting entities in bulk happens within your application, and
 thus
  counts against your quota.
 
  This feature is currently experimental. We believe this feature is
 currently
  the fastest way to bulk-delete data, but it is not yet stable and you may
  encounter occasional bugs.
 
  Thanks for the help guys!
 
  Cheers,
 
  Nathan
 
  On Sat, Jan 29, 2011 at 9:23 AM, Nathan VanHoudnos nathan...@gmail.com
 wrote:
 
 
 
 
 
 
 
 
 
   I tried that again this morning, but it only lets me delete 20 at a
 time.
   Am I doing something wrong?
 
   (I have hundreds of entries to delete.)
 
   Cheers,
 
   Nathan
 
   On Fri, Jan 28, 2011 at 5:35 PM, howesc how...@umich.edu wrote:
 
   if i remember correctly the bulk delete was google's christmas present
 to
   us - in the decemeber release, so it's a new feature, but quite handy!
 
   --
   Nathan VanHoudnos
   |- Statistics  Public Policy PhD student
   |- Program for Interdisciplinary Education Research (PIER) Fellowship
   |- Carnegie Mellon University
   |-http://www.andrew.cmu.edu/user/nmv
 
   Neglect of mathematics works injury to all knowledge,
since he who is ignorant of it cannot know the other
sciences or the things of this world. -- Roger Bacon
 
  --
  Nathan VanHoudnos
  |- Statistics  Public Policy PhD student
  |- Program for Interdisciplinary Education Research (PIER) Fellowship
  |- Carnegie Mellon University
  |-http://www.andrew.cmu.edu/user/nmv
 
  Neglect of mathematics works injury to all knowledge,
   since he who is ignorant of it cannot know the other
   sciences or the things of this world. -- Roger Bacon




-- 
Nathan VanHoudnos
|- Statistics  Public Policy PhD student
|- Program for Interdisciplinary Education Research (PIER) Fellowship
|- Carnegie Mellon University
|- http://www.andrew.cmu.edu/user/nmv

Neglect of mathematics works injury to all knowledge,
 since he who is ignorant of it cannot know the other
 sciences or the things of this world. -- Roger Bacon


Re: [web2py] Re: Email as username

2011-01-30 Thread Kenneth Lundström

Thanks HC.

The book holds a lot of information, not allways so easy to find. :=)


Kenneth


Even easier - as I only saw now (always worthwhile to reread the book
every so often)

 (w2p book Ch 8)

To start using Auth, you need at least this code in a model file,
which is also provided with the web2py welcome application and
assumes a db connection object:

from gluon.tools import Auth
auth = Auth(globals(), db)
auth.define_tables(username=False)

Set username=True if you want auth to user username for login instead
of email.



On Jan 30, 11:55 am, hcvsthcv...@googlemail.com  wrote:

Hi Kenneth,

remove the 'username' field from the auth_user table. Also see Chapter
8http://web2py.com/book/default/chapter/08on custom tables.

I think in the past w2p only used email by default. The new app wizard
appears to include it now.

Regards,
HC

On Jan 30, 11:13 am, Kenneth Lundströmkenneth.t.lundst...@gmail.com
wrote:








Hello list,
I have an old application build two years ago and it uses email adress
as the username, so you don t need a different username.
Now I d like to do the same on a new application but I don t know what
to change to do this.
Any ideas?
Kenneth




[web2py] Re: table field with reference to other in read-only mode doesn't appear right

2011-01-30 Thread Massimo Di Pierro
This should be fixed in trunk (and nightly build).Please give it a try
and confirm.

Massimo

On Jan 30, 7:46 am, szimszon szims...@gmail.com wrote:
 I wonder if somebody could help me.

 Here is my Field:

     Field( 'updated_by', db.auth_user,
                                         writable = False  )

 CRUD rendered it in form None but the record has a value 1 and I
 have user in auth_user.id=1

 If I modify the Field to:

     Field( 'updated_by', db.auth_user,
                                         writable = False ,
                                         requires = IS_EMPTY_OR( IS_IN_DB( db, 
 db.auth_user.id, '%
 (first_name)s' ) ) )

 The result is 1 and not the first_name value.

 If I modify the Field to:

     Field( 'updated_by', db.auth_user)

 The result is a list with all the auth_user rows :-o

 With the Field like this:

     Field( 'updated_by', db.auth_user,
                                         requires = IS_EMPTY_OR( IS_IN_DB( db, 
 db.auth_user.id, '%
 (first_name)s' ) ) )

 There is a result list with all the first_name values...

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


[web2py] Re: Deployment Confusion

2011-01-30 Thread g...@rtplanb.com
Thank you for the advice, but as I already have a years domain and
hosting with godaddy I was hoping for some specific advice regarding
setup using that service.
godaddy support suggest that I simply upload all the files from my
web2py application but I asssume this will not give me admin interface
access?
I have really enjoyed using web2py but if the deployment isnt simple I
may have to change to something supported by my hosting provider, like
wordpress, joomla or drupal.


[web2py] Is Web2py the right choice for me?

2011-01-30 Thread Panupat
I just discovered web2py. I'm wondering if web2py is the right choice
for me.

Would greatly appreciate any input :)

A little background is that I'm a PHP user and a 3D artist. So Python
has always been on the top of the to-learn list because it can be used
with MAX and MAYA. I recently was given an assignment to create a
website for internal use across our LAN network. I'm given a HUGE
amount of time so I am using this opportunity to eventually learn
Python.

Here are some of the specifications of my current assignment and I
really would really love to know if web2py provides functionality to
make them happen without much fuss.

- username and password will be authenticated against Windows Acrive
Directory

- User group also determines by Active Directory groups.

- Everything else will be in MySQL.

- A lot of real time drag-and-drop using javascript on the front end.
The back end will have to be able to respond to a lot of small
requests and update database accordingly.

Everything else are generic web stuff so my main concern is only the 4
specs mentioned above.

Thank you very much!

best regards,
Panupat.

:)


[web2py] deploying one app to different regions in the world

2011-01-30 Thread VP
I have never configured an app like this so I have no idea how this is
done.  So, any help or pointer is greatly appreciated.

Basically, I have an app.  If it is hosted in the US, then access in
Asia will be slow.  And conversely, if it is hosted in Asia, US access
will be slow.  So, I think the best strategy is to host it both in
Asia and the US.

Ideally, this will be transparent to users.  The simplest
configuration I can think of this having 2 domains: domain1.com and
domain2.com; each being hosted in US and Asia, respectively.   And
depending on users' geolocation based on IP addresses, they will be
redirected to either domain.

Two problems:

1. the appearance of domain1.com and domain2.com is not transparent
enough.  Is there a better way?

2. maintaining consistency between the 2 databases.  Does web2py have
support for replications of one app like this?

Thanks.



[web2py] inconsistency ? == and belongs

2011-01-30 Thread Stef Mientki
hello,

I thought the DAL was ment to be Pythonic.
Writing a query to search for a records with some specific id,
I have to use the Pythonic == instead of the SQL-like =

Rows = DB ( DB.Excel_List.id == 3 ).select()

Writing a query to search for a records with some a range of id's,
I have to use the SQL-like belongs
Rows = DB ( DB.Excel_List.id.belongs((3,4))).select()

instead of the Pythonic in
Rows = DB ( DB.Excel_List.id in (3,4) ).select()

Why is that ?

thanks,
Stef Mientki


[web2py] Re: Is Web2py the right choice for me?

2011-01-30 Thread Massimo Di Pierro
Welcome Panupat
Other users may have more to say on this issue, anyway ...

web2py has pluggable login methods. One is gluon/contrib/login_methods/
ldap_auth.py. It contains an example of how to use it. It will allow
you to login using Active Directory using LDAP.

More complex is the issue with groups. Web2py has its own mechanism
for creating groups and checking membership.

There is a third party  python module to get Active Directory groups
and membership (http://timgolden.me.uk/python/
ad_cookbook.html#find_a_user_quick).

Somehow you need to put the two together.

One option is to extend the class Auth in gluon/tools.py and overload
methods add_group, del_group, add_membership, del_membership,
has_membership to use the active directory APIs internally.

Another option is to use Auth as it is an periodically runs a
background script that syncs the web2py database with the ative
directory once.

I am sorry but if there is a simpler solution I have not seen one.

Massimo





On Jan 30, 4:25 am, Panupat panup...@gmail.com wrote:
 I just discovered web2py. I'm wondering if web2py is the right choice
 for me.

 Would greatly appreciate any input :)

 A little background is that I'm a PHP user and a 3D artist. So Python
 has always been on the top of the to-learn list because it can be used
 with MAX and MAYA. I recently was given an assignment to create a
 website for internal use across our LAN network. I'm given a HUGE
 amount of time so I am using this opportunity to eventually learn
 Python.

 Here are some of the specifications of my current assignment and I
 really would really love to know if web2py provides functionality to
 make them happen without much fuss.

 - username and password will be authenticated against Windows Acrive
 Directory

 - User group also determines by Active Directory groups.

 - Everything else will be in MySQL.

 - A lot of real time drag-and-drop using javascript on the front end.
 The back end will have to be able to respond to a lot of small
 requests and update database accordingly.

 Everything else are generic web stuff so my main concern is only the 4
 specs mentioned above.

 Thank you very much!

 best regards,
 Panupat.

 :)


Re: [web2py] Re: Deployment Confusion

2011-01-30 Thread Bruno Rocha
AS I said,I know only two host options where you can simply put the files
there and everything runs without the need of configuration. ['Google App
Engine', 'webfaction']

In other shared hosts you need to follow some deployment instruction:

I guess this slice works for godaddy
http://www.web2pyslices.com/main/slices/take_slice/76

or if you have a VPS you can use deployment script on /scripts folder, or
follow this slices (deppending on your VM setup)
http://web2pyslices.com/main/slices/take_slice/110
http://web2pyslices.com/main/slices/take_slice/98

Here in Brazil, we have a shared host (kinghost.com.br) that has 'One Click
Install for web2py' in control panel, but I dont know any other.

In the book http://web2py.com/book/default/chapter/11 you can find
information needed to setup web2py with wsgi, mod_wsgi and mod_python.

Python web apps (indepent of teh framework you are using) works in a
different way of PHP or ASP applications.

Do you know exactly what is the setup provided by GoDaddy? Python Version,
Linux Distro?


[web2py] Field custom_store and custom_delete

2011-01-30 Thread Art Zemon

Massimo, et al,

I want to extend Field type upload to store in Rackspace Cloud Files (or 
anywhere, for that matter). The custom_store attribute of the Field 
class gives me half of what I need. Is there some reason why 
custom_delete has not been implemented?


I'll be glad to do it and contribute the code back to web2py. Would you 
like to see this as patches to the existing codebase or what? It looks 
like I just need to add the new attribute to Field and add a couple of 
lines to Set.delete_uploaded_files.


-- Art Z.

--

Art Zemon, President
Hen's Teeth Network http://www.hens-teeth.net/
The source of reliable, secure e-commerce web hosting 
http://www.hens-teeth.net/html/hosting/ecommerce_hosting.php

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



[web2py] Re: GAE belongs (how to map long list)

2011-01-30 Thread Arun K.Rajeevan
No it doesn't. 

I deployed application using belongs in GAE, because it worked for me with 
python sdk for appengine using dev_appserver.py

But it didn't when I upload it to appengine. 
I lost two days wondering. 
Nothing is logged on appengine logs.

Then I changed it to manually selecting each element in the list (using 
reduce() and map() ) and then site started to work.

So, what I understood is it's not working. 
I'm using Web2py Version 1.91.6 (2011-01-04 15:55:30)
google_appengine sdk: release: 1.4.1



[web2py] Re: GAE belongs (how to map long list)

2011-01-30 Thread Arun K.Rajeevan
I know it's an old post Christian, but when time comes I need it to save me.

[web2py] Re: table field with reference to other in read-only mode doesn't appear right

2011-01-30 Thread szimszon
Now, there is a programming error in nightly build (source version)
[pgsql]:


Traceback (most recent call last):
  File /home/szimszon_nfs/web2py/gluon/restricted.py, line 188, in
restricted
exec ccode in environment
  File /home/szimszon_nfs/web2py/applications/raktar/controllers/
default.py, line 77, in module
  File /home/szimszon_nfs/web2py/gluon/globals.py, line 95, in
lambda
self._caller = lambda f: f()
  File /home/szimszon_nfs/web2py/applications/raktar/controllers/
default.py, line 52, in user
return dict( form = auth() )
  File /home/szimszon_nfs/web2py/gluon/tools.py, line 1034, in
__call__
return self.login()
  File /home/szimszon_nfs/web2py/gluon/tools.py, line 1527, in login
self.log_event(log % self.user)
  File /home/szimszon_nfs/web2py/gluon/tools.py, line 1277, in
log_event
origin=origin, user_id=user_id)
  File /home/szimszon_nfs/web2py/gluon/dal.py, line 3934, in insert
return self._db._adapter.insert(self,self._listify(fields))
  File /home/szimszon_nfs/web2py/gluon/dal.py, line 707, in insert
raise e
ProgrammingError: column origin specified more than once
LINE
1: ...t(origin,user_id,description,time_stamp,client_ip,origin,des...
 ^

Error snapshot help

class 'psycopg2.ProgrammingError'(column origin specified more
than once LINE
1: ...t(origin,user_id,description,time_stamp,client_ip,origin,des...
^ )


On jan. 30, 16:08, Massimo Di Pierro massimo.dipie...@gmail.com
wrote:
 This should be fixed in trunk (and nightly build).Please give it a try
 and confirm.

 Massimo

 On Jan 30, 7:46 am, szimszon szims...@gmail.com wrote:







  I wonder if somebody could help me.

  Here is my Field:

      Field( 'updated_by', db.auth_user,
                                          writable = False  )

  CRUD rendered it in form None but the record has a value 1 and I
  have user in auth_user.id=1

  If I modify the Field to:

      Field( 'updated_by', db.auth_user,
                                          writable = False ,
                                          requires = IS_EMPTY_OR( IS_IN_DB( 
  db, db.auth_user.id, '%
  (first_name)s' ) ) )

  The result is 1 and not the first_name value.

  If I modify the Field to:

      Field( 'updated_by', db.auth_user)

  The result is a list with all the auth_user rows :-o

  With the Field like this:

      Field( 'updated_by', db.auth_user,
                                          requires = IS_EMPTY_OR( IS_IN_DB( 
  db, db.auth_user.id, '%
  (first_name)s' ) ) )

  There is a result list with all the first_name values...

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


[web2py] crud.create next= syntax

2011-01-30 Thread Art Zemon

I'm tangled up in the syntax for crud.create. I have written

   form = crud.create(db.assets, message=T('Asset Created'),
   next=URL(f=show, args=([id])))

But the URL being generated is

   .../show/%3Cbuilt-in%20function%20id%3E

How should I write this? Or do I need to drop back to using a SQLFORM?

Thanks,
-- Art Z.

--

Art Zemon, President
Hen's Teeth Network http://www.hens-teeth.net/
The source of reliable, secure e-commerce web hosting 
http://www.hens-teeth.net/html/hosting/ecommerce_hosting.php

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



[web2py] Re: Login form (remember for 30 days not working)

2011-01-30 Thread Arun K.Rajeevan
I see in gae admin interface, we can set cookie expiry time.
We have 3 options, 1day, 1week, 2week.

In that case, even though the label reads keeps logged in for 30days it'll 
be in effect for 15 days.

How, should I change the label to keep logged in for 15days.


[web2py] Re: deploying one app to different regions in the world

2011-01-30 Thread Massimo Di Pierro
About 1 I am sure Jonathan has something to day because of the new
routing features.

About 2. Make sure your database tables have a UUID field. When
exporting/importing web2py will use it to rebuild references (the ids
will not be synced but you can write a simple program to fix
references given the UUIDs).

It is on my todo list to improve support for this type of issues.

Massimo




On Jan 30, 10:33 am, VP vtp2...@gmail.com wrote:
 I have never configured an app like this so I have no idea how this is
 done.  So, any help or pointer is greatly appreciated.

 Basically, I have an app.  If it is hosted in the US, then access in
 Asia will be slow.  And conversely, if it is hosted in Asia, US access
 will be slow.  So, I think the best strategy is to host it both in
 Asia and the US.

 Ideally, this will be transparent to users.  The simplest
 configuration I can think of this having 2 domains: domain1.com and
 domain2.com; each being hosted in US and Asia, respectively.   And
 depending on users' geolocation based on IP addresses, they will be
 redirected to either domain.

 Two problems:

 1. the appearance of domain1.com and domain2.com is not transparent
 enough.  Is there a better way?

 2. maintaining consistency between the 2 databases.  Does web2py have
 support for replications of one app like this?

 Thanks.


[web2py] Re: Change in URL args handling

2011-01-30 Thread villas
 I don't think that they'll be any cleaner or shorter either way. The only way 
 you'll get trailing slashes (if we end up supporting them) is by asking for a 
 URL with empty trailing args. If you don't want trailing slashes, then don't 
 add empty args.

Hi, I was mainly thinking of incoming urls being appended with slashes
externally and that we could ignore them, but as it has been pointed
out, a trailing slash already gives an empty arg, so I suppose we have
to keep that. Anyhow,  it sounds like your thought process has covered
all the bases!  :)
Thanks.  D


[web2py] Re: inconsistency ? == and belongs

2011-01-30 Thread Massimo Di Pierro
because the meaning of in, and and or cannot be overloaded in
python.

This expression:

   DB.Excel_List.id in (3,4)

would always return false because the left hand side is an object and
the object is not contained in the right.
Because it cannot be overloaded, we canot change its meaning.

Massimo



On Jan 30, 10:36 am, Stef Mientki stef.mien...@gmail.com wrote:
 hello,

 I thought the DAL was ment to be Pythonic.
 Writing a query to search for a records with some specific id,
 I have to use the Pythonic == instead of the SQL-like =

 Rows = DB ( DB.Excel_List.id == 3 ).select()

 Writing a query to search for a records with some a range of id's,
 I have to use the SQL-like belongs
 Rows = DB ( DB.Excel_List.id.belongs((3,4))).select()

 instead of the Pythonic in
 Rows = DB ( DB.Excel_List.id in (3,4) ).select()

 Why is that ?

 thanks,
 Stef Mientki


[web2py] Re: Field custom_store and custom_delete

2011-01-30 Thread Massimo Di Pierro
Good point. There should be a custom delete. I will add it to my todo
list.

massimo

On Jan 30, 11:04 am, Art Zemon a...@hens-teeth.net wrote:
 Massimo, et al,

 I want to extend Field type upload to store in Rackspace Cloud Files (or
 anywhere, for that matter). The custom_store attribute of the Field
 class gives me half of what I need. Is there some reason why
 custom_delete has not been implemented?

 I'll be glad to do it and contribute the code back to web2py. Would you
 like to see this as patches to the existing codebase or what? It looks
 like I just need to add the new attribute to Field and add a couple of
 lines to Set.delete_uploaded_files.

      -- Art Z.

 --

 Art Zemon, President
 Hen's Teeth Network http://www.hens-teeth.net/
 The source of reliable, secure e-commerce web hosting
 http://www.hens-teeth.net/html/hosting/ecommerce_hosting.php
 Phone: (866)HENS-NET or (636)447-3030 ext. 200


[web2py] Re: table field with reference to other in read-only mode doesn't appear right

2011-01-30 Thread Massimo Di Pierro
do you have a custom auth_user table? How does it look like?

On Jan 30, 11:29 am, szimszon szims...@gmail.com wrote:
 Now, there is a programming error in nightly build (source version)
 [pgsql]:

 Traceback (most recent call last):
   File /home/szimszon_nfs/web2py/gluon/restricted.py, line 188, in
 restricted
     exec ccode in environment
   File /home/szimszon_nfs/web2py/applications/raktar/controllers/
 default.py, line 77, in module
   File /home/szimszon_nfs/web2py/gluon/globals.py, line 95, in
 lambda
     self._caller = lambda f: f()
   File /home/szimszon_nfs/web2py/applications/raktar/controllers/
 default.py, line 52, in user
     return dict( form = auth() )
   File /home/szimszon_nfs/web2py/gluon/tools.py, line 1034, in
 __call__
     return self.login()
   File /home/szimszon_nfs/web2py/gluon/tools.py, line 1527, in login
     self.log_event(log % self.user)
   File /home/szimszon_nfs/web2py/gluon/tools.py, line 1277, in
 log_event
     origin=origin, user_id=user_id)
   File /home/szimszon_nfs/web2py/gluon/dal.py, line 3934, in insert
     return self._db._adapter.insert(self,self._listify(fields))
   File /home/szimszon_nfs/web2py/gluon/dal.py, line 707, in insert
     raise e
 ProgrammingError: column origin specified more than once
 LINE
 1: ...t(origin,user_id,description,time_stamp,client_ip,origin,des...
                                                              ^

 Error snapshot help

 class 'psycopg2.ProgrammingError'(column origin specified more
 than once LINE
 1: ...t(origin,user_id,description,time_stamp,client_ip,origin,des...
 ^ )

 On jan. 30, 16:08, Massimo Di Pierro massimo.dipie...@gmail.com
 wrote:







  This should be fixed in trunk (and nightly build).Please give it a try
  and confirm.

  Massimo

  On Jan 30, 7:46 am, szimszon szims...@gmail.com wrote:

   I wonder if somebody could help me.

   Here is my Field:

       Field( 'updated_by', db.auth_user,
                                           writable = False  )

   CRUD rendered it in form None but the record has a value 1 and I
   have user in auth_user.id=1

   If I modify the Field to:

       Field( 'updated_by', db.auth_user,
                                           writable = False ,
                                           requires = IS_EMPTY_OR( IS_IN_DB( 
   db, db.auth_user.id, '%
   (first_name)s' ) ) )

   The result is 1 and not the first_name value.

   If I modify the Field to:

       Field( 'updated_by', db.auth_user)

   The result is a list with all the auth_user rows :-o

   With the Field like this:

       Field( 'updated_by', db.auth_user,
                                           requires = IS_EMPTY_OR( IS_IN_DB( 
   db, db.auth_user.id, '%
   (first_name)s' ) ) )

   There is a result list with all the first_name values...

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


[web2py] Re: crud.create next= syntax

2011-01-30 Thread Massimo Di Pierro
Valid:
next=URL(f=show, args=[id])

next=URL(f=show, args=(id,))

next=URL(f=show, args=id)

But this

next=URL(f=show, args=([id])))

is interpreted as

next=URL(f=show, args='[id]')

and therefore escaped




On Jan 30, 12:05 pm, Art Zemon a...@hens-teeth.net wrote:
 I'm tangled up in the syntax for crud.create. I have written

     form = crud.create(db.assets, message=T('Asset Created'),
     next=URL(f=show, args=([id])))

 But the URL being generated is

     .../show/%3Cbuilt-in%20function%20id%3E

 How should I write this? Or do I need to drop back to using a SQLFORM?

 Thanks,
      -- Art Z.

 --

 Art Zemon, President
 Hen's Teeth Network http://www.hens-teeth.net/
 The source of reliable, secure e-commerce web hosting
 http://www.hens-teeth.net/html/hosting/ecommerce_hosting.php
 Phone: (866)HENS-NET or (636)447-3030 ext. 200


Re: [web2py] Re: can web2py support RESTful api calls? if so any pointers on how to build one?I

2011-01-30 Thread Bruno Rocha
radbox.me has a very nice API http://radbox.me/api/index  made with web2py,

would be great if that guys could share some information and tips about it.

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


Re: [web2py] Re: Change in URL args handling

2011-01-30 Thread Jonathan Lundell
On Jan 30, 2011, at 10:29 AM, villas wrote:
 
 I don't think that they'll be any cleaner or shorter either way. The only 
 way you'll get trailing slashes (if we end up supporting them) is by asking 
 for a URL with empty trailing args. If you don't want trailing slashes, then 
 don't add empty args.
 
 Hi, I was mainly thinking of incoming urls being appended with slashes
 externally and that we could ignore them, but as it has been pointed
 out, a trailing slash already gives an empty arg, so I suppose we have
 to keep that. Anyhow,  it sounds like your thought process has covered
 all the bases!  :)

As it stands right now (in the trunk), we're not keeping the empty arg with a 
trailing slash, mainly because this appears to be a bug in the current 
implementation (which generally treats empty args as an error).

[web2py] Re: table field with reference to other in read-only mode doesn't appear right

2011-01-30 Thread szimszon
No...

from gluon.tools import *
auth = Auth( globals(), db )  # authentication/
authorization
auth.settings.hmac_key = 'sha512:144104...c136'
auth.define_tables() # creates all needed
tables
from gluon.contrib.login_methods.basic_auth import basic_auth
from gluon.contrib.login_methods.cas_auth import CasAuth

auth.settings.actions_disabled.append( 'register' )

try:
 auth.settings.login_form = CasAuth()
 auth.settings.login_form.settings( globals(), urlbase = https://
cas...hu/cas/cas )
except:
 auth.settings.login_form = CasAuth( globals(), urlbase = https://
cas...hu/cas/cas )

crud = Crud( globals(), db )  # for CRUD helpers
using auth
service = Service( globals() )   # for json, xml,
jsonrpc, xmlrpc, amfrpc

crud.settings.auth = auth  # enforces
authorization on crud
crud.settings.logger = auth
crud.messages.delete_label = T( 'Törlés' )
mail = Mail()  # mailer
mail.settings.server = 'localhost:25'# your SMTP server
mail.settings.sender = 'raktar-dontre...@in...y.hu' # your
email


On jan. 30, 19:33, Massimo Di Pierro massimo.dipie...@gmail.com
wrote:
 do you have a custom auth_user table? How does it look like?

 On Jan 30, 11:29 am, szimszon szims...@gmail.com wrote:







  Now, there is a programming error in nightly build (source version)
  [pgsql]:

  Traceback (most recent call last):
    File /home/szimszon_nfs/web2py/gluon/restricted.py, line 188, in
  restricted
      exec ccode in environment
    File /home/szimszon_nfs/web2py/applications/raktar/controllers/
  default.py, line 77, in module
    File /home/szimszon_nfs/web2py/gluon/globals.py, line 95, in
  lambda
      self._caller = lambda f: f()
    File /home/szimszon_nfs/web2py/applications/raktar/controllers/
  default.py, line 52, in user
      return dict( form = auth() )
    File /home/szimszon_nfs/web2py/gluon/tools.py, line 1034, in
  __call__
      return self.login()
    File /home/szimszon_nfs/web2py/gluon/tools.py, line 1527, in login
      self.log_event(log % self.user)
    File /home/szimszon_nfs/web2py/gluon/tools.py, line 1277, in
  log_event
      origin=origin, user_id=user_id)
    File /home/szimszon_nfs/web2py/gluon/dal.py, line 3934, in insert
      return self._db._adapter.insert(self,self._listify(fields))
    File /home/szimszon_nfs/web2py/gluon/dal.py, line 707, in insert
      raise e
  ProgrammingError: column origin specified more than once
  LINE
  1: ...t(origin,user_id,description,time_stamp,client_ip,origin,des...
                                                               ^

  Error snapshot help

  class 'psycopg2.ProgrammingError'(column origin specified more
  than once LINE
  1: ...t(origin,user_id,description,time_stamp,client_ip,origin,des...
  ^ )

  On jan. 30, 16:08, Massimo Di Pierro massimo.dipie...@gmail.com
  wrote:

   This should be fixed in trunk (and nightly build).Please give it a try
   and confirm.

   Massimo

   On Jan 30, 7:46 am, szimszon szims...@gmail.com wrote:

I wonder if somebody could help me.

Here is my Field:

    Field( 'updated_by', db.auth_user,
                                        writable = False  )

CRUD rendered it in form None but the record has a value 1 and I
have user in auth_user.id=1

If I modify the Field to:

    Field( 'updated_by', db.auth_user,
                                        writable = False ,
                                        requires = IS_EMPTY_OR( 
IS_IN_DB( db, db.auth_user.id, '%
(first_name)s' ) ) )

The result is 1 and not the first_name value.

If I modify the Field to:

    Field( 'updated_by', db.auth_user)

The result is a list with all the auth_user rows :-o

With the Field like this:

    Field( 'updated_by', db.auth_user,
                                        requires = IS_EMPTY_OR( 
IS_IN_DB( db, db.auth_user.id, '%
(first_name)s' ) ) )

There is a result list with all the first_name values...

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


Re: [web2py] Re: Deployment Confusion

2011-01-30 Thread pbreit
It's either not possible or very difficult. GoDaddy's hosting capabilities 
are extremely limited. As others have mentioned, I'd suggest considering 
another provider such as WebFaction.

[web2py] Re: Deployment Confusion

2011-01-30 Thread g...@rtplanb.com
Thank you all for your help so far.
I will try your suggestions. I can get SSH access to my host.
It runs Python 2.4.3
and Linux distro is quoted as: Linux
n1nlftpg005.shr.prod.ams1.secureserver.net 2.6.18-194.26.1.el5PAE #1
SMP Tue Nov 9 13:34:42 EST 2010 i686 i686 i386 GNU/Linux


On Jan 30, 4:46 pm, Bruno Rocha rochacbr...@gmail.com wrote:
 AS I said,I know only two host options where you can simply put the files
 there and everything runs without the need of configuration. ['Google App
 Engine', 'webfaction']

 In other shared hosts you need to follow some deployment instruction:

 I guess this slice works for 
 godaddyhttp://www.web2pyslices.com/main/slices/take_slice/76

 or if you have a VPS you can use deployment script on /scripts folder, or
 follow this slices (deppending on your VM 
 setup)http://web2pyslices.com/main/slices/take_slice/110http://web2pyslices.com/main/slices/take_slice/98

 Here in Brazil, we have a shared host (kinghost.com.br) that has 'One Click
 Install for web2py' in control panel, but I dont know any other.

 In the bookhttp://web2py.com/book/default/chapter/11you can find
 information needed to setup web2py with wsgi, mod_wsgi and mod_python.

 Python web apps (indepent of teh framework you are using) works in a
 different way of PHP or ASP applications.

 Do you know exactly what is the setup provided by GoDaddy? Python Version,
 Linux Distro?


[web2py] Re: Callable as Field.default

2011-01-30 Thread Anthony
On Friday, January 28, 2011 9:32:13 AM UTC-5, Massimo Di Pierro wrote: 

 The fact is, you can do both. If you want the values to be evaluated 
 on insert, just do 

 Field(...,default=lambda: f()) 

 
What's the difference between using default=lambda: f() and just using 
default=f (assuming f is defined as a function somewhere)?
 
Is it just that lambda: f() guarantees you get something with type = 
FunctionType (so, for example, default=lambda: datetime.datetime.now() 
would work even though type(datetime.datetime.now) is BuiltinFunctionType 
and not FunctionType), or is there some other reason to prefer the lambda 
version?
 
It would be very helpful to discuss the use of functions as field defaults 
in the book (especially the issue of calling a function once at request time 
vs. passing a function to be called per record at insert time).
 
Thanks.
 
Anthony


[web2py] Re: GAE belongs (how to map long list)

2011-01-30 Thread Arun K.Rajeevan
Oops, I made an assumption it worked for me with python sdk for appengine 
using dev_appserver.py

That was wrong.

BELONGS is broken in gae. 
db(~db.languages.id.belongs(db()._select(db.words.lang, 
distinct=True))).select()
causes dev_appserver.py to print out

  File /home/kra/Evolve/Works/Python/web2py_vl/gluon/restricted.py, line 
188, in restricted
exec ccode in environment
  File 
/home/kra/Evolve/Works/Python/web2py_vl/applications/init/controllers/manage.py:clean,
 
line 54, in module
  File /home/kra/Evolve/Works/Python/web2py_vl/gluon/globals.py, line 95, 
in lambda
self._caller = lambda f: f()
  File 
/home/kra/Evolve/Works/Python/web2py_vl/applications/init/controllers/manage.py:clean,
 
line 24, in clean
  File /home/kra/Evolve/Works/Python/web2py_vl/gluon/dal.py, line 4511, in 
select
return self.db._adapter.select(self.query,fields,attributes)
  File /home/kra/Evolve/Works/Python/web2py_vl/gluon/dal.py, line 2677, in 
select
(items, tablename, fields) = self.select_raw(query,fields,attributes)
  File /home/kra/Evolve/Works/Python/web2py_vl/gluon/dal.py, line 2637, in 
select_raw
filters = self.expand(query)
  File /home/kra/Evolve/Works/Python/web2py_vl/gluon/dal.py, line 2550, in 
expand
return expression.op(expression.first)
  File /home/kra/Evolve/Works/Python/web2py_vl/gluon/dal.py, line 2613, in 
NOT
raise SyntaxError, Not suported %s % first.op.__name__
SyntaxError: Not suported BELONGS



[web2py] widgets

2011-01-30 Thread Ovidio Marinho
How to view the contents of multiple options in widgets list.tasks

-- 
Ovidio Marinho Falcao Neto
 ovidio...@gmail.com
 Tecnologia da Informaçao
 Casa Civil do Governador
 83 3214 7885 - 88269088
  Paraiba


[web2py] Please help me on belongs

2011-01-30 Thread Arun K.Rajeevan
x = db(~db.languages.id.belongs(db()._select(db.words.lang, 
distinct=True))).select()

This works fine for sqllite on which I'm developing

But it doesn't work for appengine. 
So I tried,

lst = db().select(db.words.lang, distinct=True).as_list() 
lst = map(lambda x: x['lang'],  lst)
x = reduce((lambda x, y: x|y), map((lambda x: db(~db.languages.id == 
x).select()), lst))  

This gives me error.  *OperationalError: near DESC: syntax error*
*
*
But if I change ~db.languages.id == x to db.languages.id == x, then it works 
(notice that I removed ~), but it's not what I want.
I need to negate the result.

Please help me to correctly do this.



Full traceback

Traceback (most recent call last):
  File /home/kra/Evolve/Works/Python/web2py_vl/gluon/restricted.py, line 
188, in restricted
exec ccode in environment
  File 
/home/kra/Evolve/Works/Python/web2py_vl/applications/init/controllers/manage.py,
 
line 54, in module
  File /home/kra/Evolve/Works/Python/web2py_vl/gluon/globals.py, line 95, 
in lambda
self._caller = lambda f: f()
  File 
/home/kra/Evolve/Works/Python/web2py_vl/applications/init/controllers/manage.py,
 
line 28, in clean
x = reduce((lambda x, y: x|y), map((lambda x: db(~db.languages.id == 
x).select()), lst))
  File 
/home/kra/Evolve/Works/Python/web2py_vl/applications/init/controllers/manage.py,
 
line 28, in lambda
x = reduce((lambda x, y: x|y), map((lambda x: db(~db.languages.id == 
x).select()), lst))
  File /home/kra/Evolve/Works/Python/web2py_vl/gluon/dal.py, line 4511, in 
select
return self.db._adapter.select(self.query,fields,attributes)
  File /home/kra/Evolve/Works/Python/web2py_vl/gluon/dal.py, line 1003, in 
select
rows = response(sql)
  File /home/kra/Evolve/Works/Python/web2py_vl/gluon/dal.py, line 994, in 
response
self.execute(sql)
  File /home/kra/Evolve/Works/Python/web2py_vl/gluon/dal.py, line 1067, in 
execute
return self.log_execute(*a, **b)
  File /home/kra/Evolve/Works/Python/web2py_vl/gluon/dal.py, line 1064, in 
log_execute
return self.cursor.execute(*a,**b)
OperationalError: near DESC: syntax error

class 'sqlite3.OperationalError'(near DESC: syntax error)


[web2py] Re: problems with conditional login redirection on on_failed_authorization

2011-01-30 Thread Miguel Lopes
I'm still in need of help. Here's what I've managed to find.
My problem is that if I don't use good credentials in the command line
I get an exception because web2py is replying with the login_url. This
suggests that the failedAuthHandler I'm using in
auth.settings.on_failed_authorization is not working.

[in models/db.py]
def failedAuthHandler():
if request.function == 'private_call':
redirect(URL(f='failed_login')) # just a regular action
# or alternatively:
redirect(URL(f='public_call', args=['jsonrpc', 'failed_login']))
else:
redirect(URL(request))
auth.settings.on_failed_authorization = failedAuthHandler

Since using failed_login as a regular action or as a public_call
makes no difference. is this the correct way to use
auth.settings.on_failed_authorization = function ?

Txs for the help,
Miguel

On Sun, Jan 30, 2011 at 10:55 AM, Miguel Lopes mig.e.lo...@gmail.com wrote:
 on_failed_authorization can be a URL or a function.
 I'm think I could use this to achieve conditional login redirection.
 A use case would be service calls returning a simple string (or a JSON
 or an XML reply to non-validated requests), while still allowing for
 regular (non-service requests) to be redirected to a login page.
 This is useful for command-line clients (as a recent post argues) and
 desktops clients, but also to browser based RIA apps (e.g. Pyjamas
 based, Flex,...) where session expiration could lead to wanted
 redirections (as is mentioned in
 http://www.web2pyslices.com/main/slices/take_slice/48 ).

 I would see this as something as simple as:

 [in models/db.py]
 private_service = Service(globals())           # PRIVATE - for json,
 xml, jsonrpc, xmlrpc, amfrpc
 public_service = Service(globals())            # PUBLIC - for json,
 xml, jsonrpc, xmlrpc, amfrpc
 ...
 auth.settings.allow_basic_login = True
 def failedAuthHandler():
   if request.function == 'private_call':
       redirect(URL(f='public_call', args='failed_login'))
   else:
       redirect(URL(request))
 auth.settings.on_failed_authorization = failedAuthHandlerandler

 [in controllers/default]
 @private_service.jsonrpc
 def jsoncount():
    return dict(response=response.session_id_name, now=request.now)

 @public_service.jsonrpc
 def failed_login():
    return dict(error='Failed login')

 def public_call():
    return public_service()

 @auth.requires_login()
 def private_call():
    return private_service()

 However, I'm unable to make this code work.
 From the command line, if I issue a call with basic auth, with good
 credentials, such as:
 import jsonrpc
 sv = 
 jsonrpc.ServiceProxy(http://GOOD_USER:GOOD_PASS@127.0.0.1:8080/json_auth_test/default/private_call/jsonrpc;)
 sv.jsoncount()
 {'now': '2011-01-30 10:31:21', 'response': 'session_id_json_auth_test'}

 But bad credentials don't work as expected:
 import jsonrpc
 sv = 
 jsonrpc.ServiceProxy(http://GOOD_USER:BAD_PASS@127.0.0.1:8080/json_auth_test/default/private_call/jsonrpc;)
 sv.jsoncount()
 Traceback (most recent call last):
  File stdin, line 1, in module
  File 
 /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/jsonrpc/proxy.py,
 line 43, in __call__
    resp = loads(respdata)
  File 
 /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/jsonrpc/json.py,
 line 211, in loads
    raise JSONDecodeException('Expected []{}, or Number, Null, False or True')
 jsonrpc.json.JSONDecodeException: Expected []{}, or Number, Null, False or 
 True


 From the browser using an url with or without credentials, for both:
 .../default/private_call/jsoncount
 .../default/public_call/failed_login

 I get:
 Object does not exist with a Status 404 content header

 Am I on the right track?
 How could this be achieved?
 Txs,
 Miguel



[web2py] Re: Please help me on belongs

2011-01-30 Thread Arun K.Rajeevan
Also if you want to make sure that 

x = db(~db.languages.id.belongs(db()._select(db.words.lang, 
distinct=True))).select() 

is not working on gae, here is traceback from gae logs

Traceback (most recent call last):
  File 
/base/data/home/apps/visuallingua/2.348005112605606701/gluon/restricted.py, 
line 188, in restricted
exec ccode in environment
  File 
/base/data/home/apps/visuallingua/2.348005112605606701/applications/init/controllers/manage.py:clean,
 line 51, in module
  File 
/base/data/home/apps/visuallingua/2.348005112605606701/gluon/globals.py, line 
95, in lambda
self._caller = lambda f: f()
  File /base/data/home/apps/visuallingua/2.348005112605606701/gluon/tools.py, 
line 2297, in f
return action(*a, **b)
  File 
/base/data/home/apps/visuallingua/2.348005112605606701/applications/init/controllers/manage.py:clean,
 line 37, in clean
  File /base/data/home/apps/visuallingua/2.348005112605606701/gluon/dal.py, 
line 4511, in select
return self.db._adapter.select(self.query,fields,attributes)
  File /base/data/home/apps/visuallingua/2.348005112605606701/gluon/dal.py, 
line 2677, in select
(items, tablename, fields) = self.select_raw(query,fields,attributes)
  File /base/data/home/apps/visuallingua/2.348005112605606701/gluon/dal.py, 
line 2637, in select_raw
filters = self.expand(query)
  File /base/data/home/apps/visuallingua/2.348005112605606701/gluon/dal.py, 
line 2550, in expand
return expression.op(expression.first)
  File /base/data/home/apps/visuallingua/2.348005112605606701/gluon/dal.py, 
line 2613, in NOT
raise SyntaxError, Not suported %s % first.op.__name__
SyntaxError: Not suported BELONGS



[web2py] Re: problems with conditional login redirection on on_failed_authorization

2011-01-30 Thread Niphlod
I'm on my way out  as a first thing, try it with
auth.settings.on_failed_authorization = failedAuthHandler()


On Jan 30, 9:29 pm, Miguel Lopes mig.e.lo...@gmail.com wrote:
 I'm still in need of help. Here's what I've managed to find.
 My problem is that if I don't use good credentials in the command line
 I get an exception because web2py is replying with the login_url. This
 suggests that the failedAuthHandler I'm using in
 auth.settings.on_failed_authorization is not working.

 [in models/db.py]
 def failedAuthHandler():
     if request.function == 'private_call':
         redirect(URL(f='failed_login')) # just a regular action
         # or alternatively:
         redirect(URL(f='public_call', args=['jsonrpc', 'failed_login']))
     else:
         redirect(URL(request))
 auth.settings.on_failed_authorization = failedAuthHandler

 Since using failed_login as a regular action or as a public_call
 makes no difference. is this the correct way to use
 auth.settings.on_failed_authorization = function ?

 Txs for the help,
 Miguel

 On Sun, Jan 30, 2011 at 10:55 AM, Miguel Lopes mig.e.lo...@gmail.com wrote:
  on_failed_authorization can be a URL or a function.
  I'm think I could use this to achieve conditional login redirection.
  A use case would be service calls returning a simple string (or a JSON
  or an XML reply to non-validated requests), while still allowing for
  regular (non-service requests) to be redirected to a login page.
  This is useful for command-line clients (as a recent post argues) and
  desktops clients, but also to browser based RIA apps (e.g. Pyjamas
  based, Flex,...) where session expiration could lead to wanted
  redirections (as is mentioned in
 http://www.web2pyslices.com/main/slices/take_slice/48).

  I would see this as something as simple as:

  [in models/db.py]
  private_service = Service(globals())           # PRIVATE - for json,
  xml, jsonrpc, xmlrpc, amfrpc
  public_service = Service(globals())            # PUBLIC - for json,
  xml, jsonrpc, xmlrpc, amfrpc
  ...
  auth.settings.allow_basic_login = True
  def failedAuthHandler():
    if request.function == 'private_call':
        redirect(URL(f='public_call', args='failed_login'))
    else:
        redirect(URL(request))
  auth.settings.on_failed_authorization = failedAuthHandlerandler

  [in controllers/default]
  @private_service.jsonrpc
  def jsoncount():
     return dict(response=response.session_id_name, now=request.now)

  @public_service.jsonrpc
  def failed_login():
     return dict(error='Failed login')

  def public_call():
     return public_service()

  @auth.requires_login()
  def private_call():
     return private_service()

  However, I'm unable to make this code work.
  From the command line, if I issue a call with basic auth, with good
  credentials, such as:
  import jsonrpc
  sv = 
  jsonrpc.ServiceProxy(http://GOOD_USER:GOOD_P...@127.0.0.1:8080/json_auth_test/default/private_call/jsonrpc;)
  sv.jsoncount()
  {'now': '2011-01-30 10:31:21', 'response': 'session_id_json_auth_test'}

  But bad credentials don't work as expected:
  import jsonrpc
  sv = 
  jsonrpc.ServiceProxy(http://GOOD_USER:BAD_P...@127.0.0.1:8080/json_auth_test/default/private_call/jsonrpc;)
  sv.jsoncount()
  Traceback (most recent call last):
   File stdin, line 1, in module
   File 
  /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/jsonrpc/proxy.py,
  line 43, in __call__
     resp = loads(respdata)
   File 
  /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/jsonrpc/json.py,
  line 211, in loads
     raise JSONDecodeException('Expected []{}, or Number, Null, False or 
  True')
  jsonrpc.json.JSONDecodeException: Expected []{}, or Number, Null, False or 
  True

  From the browser using an url with or without credentials, for both:
  .../default/private_call/jsoncount
  .../default/public_call/failed_login

  I get:
  Object does not exist with a Status 404 content header

  Am I on the right track?
  How could this be achieved?
  Txs,
  Miguel




[web2py] Re: problems with conditional login redirection on on_failed_authorization

2011-01-30 Thread Niphlod
try with auth.settings.on_failed_authorization =
failedAuthHandlerandler()

 it works for me ^_^



On Jan 30, 9:29 pm, Miguel Lopes mig.e.lo...@gmail.com wrote:
 I'm still in need of help. Here's what I've managed to find.
 My problem is that if I don't use good credentials in the command line
 I get an exception because web2py is replying with the login_url. This
 suggests that the failedAuthHandler I'm using in
 auth.settings.on_failed_authorization is not working.

 [in models/db.py]
 def failedAuthHandler():
     if request.function == 'private_call':
         redirect(URL(f='failed_login')) # just a regular action
         # or alternatively:
         redirect(URL(f='public_call', args=['jsonrpc', 'failed_login']))
     else:
         redirect(URL(request))
 auth.settings.on_failed_authorization = failedAuthHandler

 Since using failed_login as a regular action or as a public_call
 makes no difference. is this the correct way to use
 auth.settings.on_failed_authorization = function ?

 Txs for the help,
 Miguel

 On Sun, Jan 30, 2011 at 10:55 AM, Miguel Lopes mig.e.lo...@gmail.com wrote:
  on_failed_authorization can be a URL or a function.
  I'm think I could use this to achieve conditional login redirection.
  A use case would be service calls returning a simple string (or a JSON
  or an XML reply to non-validated requests), while still allowing for
  regular (non-service requests) to be redirected to a login page.
  This is useful for command-line clients (as a recent post argues) and
  desktops clients, but also to browser based RIA apps (e.g. Pyjamas
  based, Flex,...) where session expiration could lead to wanted
  redirections (as is mentioned in
 http://www.web2pyslices.com/main/slices/take_slice/48).

  I would see this as something as simple as:

  [in models/db.py]
  private_service = Service(globals())           # PRIVATE - for json,
  xml, jsonrpc, xmlrpc, amfrpc
  public_service = Service(globals())            # PUBLIC - for json,
  xml, jsonrpc, xmlrpc, amfrpc
  ...
  auth.settings.allow_basic_login = True
  def failedAuthHandler():
    if request.function == 'private_call':
        redirect(URL(f='public_call', args='failed_login'))
    else:
        redirect(URL(request))
  auth.settings.on_failed_authorization = failedAuthHandlerandler

  [in controllers/default]
  @private_service.jsonrpc
  def jsoncount():
     return dict(response=response.session_id_name, now=request.now)

  @public_service.jsonrpc
  def failed_login():
     return dict(error='Failed login')

  def public_call():
     return public_service()

  @auth.requires_login()
  def private_call():
     return private_service()

  However, I'm unable to make this code work.
  From the command line, if I issue a call with basic auth, with good
  credentials, such as:
  import jsonrpc
  sv = 
  jsonrpc.ServiceProxy(http://GOOD_USER:GOOD_P...@127.0.0.1:8080/json_auth_test/default/private_call/jsonrpc;)
  sv.jsoncount()
  {'now': '2011-01-30 10:31:21', 'response': 'session_id_json_auth_test'}

  But bad credentials don't work as expected:
  import jsonrpc
  sv = 
  jsonrpc.ServiceProxy(http://GOOD_USER:BAD_P...@127.0.0.1:8080/json_auth_test/default/private_call/jsonrpc;)
  sv.jsoncount()
  Traceback (most recent call last):
   File stdin, line 1, in module
   File 
  /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/jsonrpc/proxy.py,
  line 43, in __call__
     resp = loads(respdata)
   File 
  /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/jsonrpc/json.py,
  line 211, in loads
     raise JSONDecodeException('Expected []{}, or Number, Null, False or 
  True')
  jsonrpc.json.JSONDecodeException: Expected []{}, or Number, Null, False or 
  True

  From the browser using an url with or without credentials, for both:
  .../default/private_call/jsoncount
  .../default/public_call/failed_login

  I get:
  Object does not exist with a Status 404 content header

  Am I on the right track?
  How could this be achieved?
  Txs,
  Miguel




Re: [web2py] Re: inconsistency ? == and belongs

2011-01-30 Thread Stef Mientki
of course, stupid of me,

thanks very much Massimo,
cheers,
Stef



Re: [web2py] Re: problems with conditional login redirection on on_failed_authorization

2011-01-30 Thread Miguel Lopes
On Sun, Jan 30, 2011 at 9:16 PM, Niphlod niph...@gmail.com wrote:
 try with auth.settings.on_failed_authorization =
 failedAuthHandlerandler()

  it works for me ^_^


Not for me! And I can't see how.
Miguel


Re: [web2py] query in DAL

2011-01-30 Thread Ovidio Marinho
I am doing an inventory system, you could help me with some example?

2011/1/28 beto (R3) bet...@gmail.com

 Hey guys:

 Is there a way to do this query in DAL?

 SELECT
date, count(foo.items)
 FROM
 (
SELECT
logs.date, logs.items
FROM logs
WHERE
extract(year from logs.date) = 2010)
GROUP BY date, items
 ) AS foo, stock
 WHERE
stock.items = foo.items
 GROUP by date

 Any help would be appreciated.

 thanks!




-- 
Ovidio Marinho Falcao Neto
 ovidio...@gmail.com
 Tecnologia da Informaçao
 Casa Civil do Governador
 83 3214 7885 - 88269088
  Paraiba


[web2py] Re: table field with reference to other in read-only mode doesn't appear right

2011-01-30 Thread Massimo Di Pierro
I cannot reproduce this. Can you help me?

Can you edit gluon/dal.py and the function _listify, add a print
statement before it returns. Try reproduce the error. What does it
print?

On Jan 30, 11:29 am, szimszon szims...@gmail.com wrote:
 Now, there is a programming error in nightly build (source version)
 [pgsql]:

 Traceback (most recent call last):
   File /home/szimszon_nfs/web2py/gluon/restricted.py, line 188, in
 restricted
     exec ccode in environment
   File /home/szimszon_nfs/web2py/applications/raktar/controllers/
 default.py, line 77, in module
   File /home/szimszon_nfs/web2py/gluon/globals.py, line 95, in
 lambda
     self._caller = lambda f: f()
   File /home/szimszon_nfs/web2py/applications/raktar/controllers/
 default.py, line 52, in user
     return dict( form = auth() )
   File /home/szimszon_nfs/web2py/gluon/tools.py, line 1034, in
 __call__
     return self.login()
   File /home/szimszon_nfs/web2py/gluon/tools.py, line 1527, in login
     self.log_event(log % self.user)
   File /home/szimszon_nfs/web2py/gluon/tools.py, line 1277, in
 log_event
     origin=origin, user_id=user_id)
   File /home/szimszon_nfs/web2py/gluon/dal.py, line 3934, in insert
     return self._db._adapter.insert(self,self._listify(fields))
   File /home/szimszon_nfs/web2py/gluon/dal.py, line 707, in insert
     raise e
 ProgrammingError: column origin specified more than once
 LINE
 1: ...t(origin,user_id,description,time_stamp,client_ip,origin,des...
                                                              ^

 Error snapshot help

 class 'psycopg2.ProgrammingError'(column origin specified more
 than once LINE
 1: ...t(origin,user_id,description,time_stamp,client_ip,origin,des...
 ^ )

 On jan. 30, 16:08, Massimo Di Pierro massimo.dipie...@gmail.com
 wrote:







  This should be fixed in trunk (and nightly build).Please give it a try
  and confirm.

  Massimo

  On Jan 30, 7:46 am, szimszon szims...@gmail.com wrote:

   I wonder if somebody could help me.

   Here is my Field:

       Field( 'updated_by', db.auth_user,
                                           writable = False  )

   CRUD rendered it in form None but the record has a value 1 and I
   have user in auth_user.id=1

   If I modify the Field to:

       Field( 'updated_by', db.auth_user,
                                           writable = False ,
                                           requires = IS_EMPTY_OR( IS_IN_DB( 
   db, db.auth_user.id, '%
   (first_name)s' ) ) )

   The result is 1 and not the first_name value.

   If I modify the Field to:

       Field( 'updated_by', db.auth_user)

   The result is a list with all the auth_user rows :-o

   With the Field like this:

       Field( 'updated_by', db.auth_user,
                                           requires = IS_EMPTY_OR( IS_IN_DB( 
   db, db.auth_user.id, '%
   (first_name)s' ) ) )

   There is a result list with all the first_name values...

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


[web2py] Re: Callable as Field.default

2011-01-30 Thread Massimo Di Pierro
You should be able to use

default=f

Trunk version handles this better than 1.65.6 which has problems with
MethodType.

Yet if f is an instance with a a __call__ method, it will not call it.
For instancetype it will try serialize it with __str__.



On Jan 30, 1:36 pm, Anthony abasta...@gmail.com wrote:
 On Friday, January 28, 2011 9:32:13 AM UTC-5, Massimo Di Pierro wrote:

  The fact is, you can do both. If you want the values to be evaluated
  on insert, just do

  Field(...,default=lambda: f())

 What's the difference between using default=lambda: f() and just using
 default=f (assuming f is defined as a function somewhere)?

 Is it just that lambda: f() guarantees you get something with type =
 FunctionType (so, for example, default=lambda: datetime.datetime.now()
 would work even though type(datetime.datetime.now) is BuiltinFunctionType
 and not FunctionType), or is there some other reason to prefer the lambda
 version?

 It would be very helpful to discuss the use of functions as field defaults
 in the book (especially the issue of calling a function once at request time
 vs. passing a function to be called per record at insert time).

 Thanks.

 Anthony


[web2py] Re: GAE belongs (how to map long list)

2011-01-30 Thread Massimo Di Pierro
BELONGS works. ~BELONGS does not on GAE I think.

On Jan 30, 1:51 pm, Arun K.Rajeevan the1.a...@gmail.com wrote:
 Oops, I made an assumption it worked for me with python sdk for appengine
 using dev_appserver.py

 That was wrong.

 BELONGS is broken in gae.
 db(~db.languages.id.belongs(db()._select(db.words.lang,
 distinct=True))).select()
 causes dev_appserver.py to print out

   File /home/kra/Evolve/Works/Python/web2py_vl/gluon/restricted.py, line
 188, in restricted
     exec ccode in environment
   File
 /home/kra/Evolve/Works/Python/web2py_vl/applications/init/controllers/mana 
 ge.py:clean,
 line 54, in module
   File /home/kra/Evolve/Works/Python/web2py_vl/gluon/globals.py, line 95,
 in lambda
     self._caller = lambda f: f()
   File
 /home/kra/Evolve/Works/Python/web2py_vl/applications/init/controllers/mana 
 ge.py:clean,
 line 24, in clean
   File /home/kra/Evolve/Works/Python/web2py_vl/gluon/dal.py, line 4511, in
 select
     return self.db._adapter.select(self.query,fields,attributes)
   File /home/kra/Evolve/Works/Python/web2py_vl/gluon/dal.py, line 2677, in
 select
     (items, tablename, fields) = self.select_raw(query,fields,attributes)
   File /home/kra/Evolve/Works/Python/web2py_vl/gluon/dal.py, line 2637, in
 select_raw
     filters = self.expand(query)
   File /home/kra/Evolve/Works/Python/web2py_vl/gluon/dal.py, line 2550, in
 expand
     return expression.op(expression.first)
   File /home/kra/Evolve/Works/Python/web2py_vl/gluon/dal.py, line 2613, in
 NOT
     raise SyntaxError, Not suported %s % first.op.__name__
 SyntaxError: Not suported BELONGS


[web2py] Re: Please help me on belongs

2011-01-30 Thread Massimo Di Pierro
distinct does not work on GAE either.



On Jan 30, 2:25 pm, Arun K.Rajeevan the1.a...@gmail.com wrote:
 x = db(~db.languages.id.belongs(db()._select(db.words.lang,
 distinct=True))).select()

 This works fine for sqllite on which I'm developing

 But it doesn't work for appengine.
 So I tried,

 lst = db().select(db.words.lang, distinct=True).as_list()
 lst = map(lambda x: x['lang'],  lst)
 x = reduce((lambda x, y: x|y), map((lambda x: db(~db.languages.id ==
 x).select()), lst))  

 This gives me error.  *OperationalError: near DESC: syntax error*
 *
 *
 But if I change ~db.languages.id == x to db.languages.id == x, then it works
 (notice that I removed ~), but it's not what I want.
 I need to negate the result.

 Please help me to correctly do this.

 Full traceback

 Traceback (most recent call last):
   File /home/kra/Evolve/Works/Python/web2py_vl/gluon/restricted.py, line
 188, in restricted
     exec ccode in environment
   File
 /home/kra/Evolve/Works/Python/web2py_vl/applications/init/controllers/mana 
 ge.py,
 line 54, in module
   File /home/kra/Evolve/Works/Python/web2py_vl/gluon/globals.py, line 95,
 in lambda
     self._caller = lambda f: f()
   File
 /home/kra/Evolve/Works/Python/web2py_vl/applications/init/controllers/mana 
 ge.py,
 line 28, in clean
     x = reduce((lambda x, y: x|y), map((lambda x: db(~db.languages.id ==
 x).select()), lst))
   File
 /home/kra/Evolve/Works/Python/web2py_vl/applications/init/controllers/mana 
 ge.py,
 line 28, in lambda
     x = reduce((lambda x, y: x|y), map((lambda x: db(~db.languages.id ==
 x).select()), lst))
   File /home/kra/Evolve/Works/Python/web2py_vl/gluon/dal.py, line 4511, in
 select
     return self.db._adapter.select(self.query,fields,attributes)
   File /home/kra/Evolve/Works/Python/web2py_vl/gluon/dal.py, line 1003, in
 select
     rows = response(sql)
   File /home/kra/Evolve/Works/Python/web2py_vl/gluon/dal.py, line 994, in
 response
     self.execute(sql)
   File /home/kra/Evolve/Works/Python/web2py_vl/gluon/dal.py, line 1067, in
 execute
     return self.log_execute(*a, **b)
   File /home/kra/Evolve/Works/Python/web2py_vl/gluon/dal.py, line 1064, in
 log_execute
     return self.cursor.execute(*a,**b)
 OperationalError: near DESC: syntax error

 class 'sqlite3.OperationalError'(near DESC: syntax error)


[web2py] Re: inconsistency ? == and belongs

2011-01-30 Thread Massimo Di Pierro
I think your question was excellent. In fact I hate that in, and and
or are not overloadable and I do not understand why.

On Jan 30, 3:55 pm, Stef Mientki stef.mien...@gmail.com wrote:
 of course, stupid of me,

 thanks very much Massimo,
 cheers,
 Stef


Re: [web2py] widgets

2011-01-30 Thread Alexandre Andrade
IS_IN_DB(db, db.list.id, '%(tasks)s',multiple=True)

2011/1/30 Ovidio Marinho ovidio...@gmail.com

 How to view the contents of multiple options in widgets list.tasks

 --
 Ovidio Marinho Falcao Neto
  ovidio...@gmail.com
  Tecnologia da Informaçao
  Casa Civil do Governador
  83 3214 7885 - 88269088
   Paraiba




-- 
Atenciosamente


Alexandre Andrade
Hipercenter.com Classificados Gratuitos e Inteligentes


[web2py] Re: query in DAL

2011-01-30 Thread Massimo Di Pierro
I still do not fully understand so I am making some assumptions.
Moreover you use field names either plural (and to me make more sense
singular) or not allowed (date). So...

db.define_table('item',Field('name',format='%(name)s')
db.define_table('stock',Field('item',db.item),Field('type'))
db.define_table('log',Field('item'),Field('sell_date','date'))

sold_last_year = db.log.sell_date.year()==2010
books = db.stock.type=='book'
stocked_as_books =
db.log.item.belongs(db(books)._select(db.stock.item))

rows = db(stocked_as_books)
(sold_last_year).select(db.log.sell_date,db.log.id.count(),groupy=db.log.sell_date)
for row in rows:
print row.log.sell_date, row[db.log.id.count()]


SELECT
   date, count(items)
FROM
(
   SELECT
   logs.date, logs.items
   FROM logs
   WHERE
   extract(year from logs.date) = 2010)
   GROUP BY date, items
) AS foo, stock
WHERE
   stock.items = foo.items AND
   stock.type = 'Books' AND ...
GROUP by date




On Jan 29, 10:35 am, beto (R3) bet...@gmail.com wrote:
 Hey Vasile:

 Cause I have more clauses based on the stock table that I haven't
 included in the original query. For example:

 SELECT
    date, count(items)
 FROM
 (
    SELECT
        logs.date, logs.items
    FROM logs
    WHERE
        extract(year from logs.date) = 2010)
    GROUP BY date, items
 ) AS foo, stock
 WHERE
    stock.items = foo.items AND
    stock.type = 'Books' AND ...
 GROUP by date

 cheers,







 On Sat, Jan 29, 2011 at 1:27 PM, Vasile Ermicioi elff...@gmail.com wrote:
  why do you need 'stock' table ?
  WHERE
      stock.items = foo.items


[web2py] Re: CSV import broken?

2011-01-30 Thread howesc
Forcing ID's in GAE is a bit harder, and i don't think that web2py has 
support for that yet.

also note that once the database gets to be of significant size the 
import/export features will have to be written to run as taskqueue tasks on 
GAE so that they can run for 10 minutes instead of 30 seconds for web based 
requests.

if you are only using GAE consider looking at the GAE bulk import/export 
tools.  they fix ID's, and can run on infinitely large datasets. 
http://code.google.com/appengine/docs/python/tools/uploadingdata.html


Re: [web2py] widgets

2011-01-30 Thread Ovidio Marinho
blza funcionou.

2011/1/30 Alexandre Andrade alexandrema...@gmail.com

 IS_IN_DB(db, db.list.id, '%(tasks)s',multiple=True)

 2011/1/30 Ovidio Marinho ovidio...@gmail.com

 How to view the contents of multiple options in widgets list.tasks

 --
 Ovidio Marinho Falcao Neto
  ovidio...@gmail.com
  Tecnologia da Informaçao
  Casa Civil do Governador
  83 3214 7885 - 88269088
   Paraiba




 --
 Atenciosamente


 Alexandre Andrade
 Hipercenter.com Classificados Gratuitos e Inteligentes




-- 
Ovidio Marinho Falcao Neto
 ovidio...@gmail.com
 Tecnologia da Informaçao
 Casa Civil do Governador
 83 3214 7885 - 88269088
  Paraiba


[web2py] Bugfix for CheckboxesWidget

2011-01-30 Thread Bernd Rothert
This patch fixes the CheckboxesWidget as a replacement for the
MultipleOptionsWidget in list:reference fields.

list:reference fields use the IS_IN_DB(...,multiple=True) validator. Its
options() method returns possible choices a list of string tuples (key,
label) to be used in HTML option tags and checkboxes. So the widget has to
convert the current values of the reference field to strings as well before
comparing them to the string keys returned by options() - see value=(k in
values).

Without the conversion the checkboxes won't show the current values - there
won't be any check marks.


diff -r 6e655c2a202d gluon/sqlhtml.py
--- a/gluon/sqlhtml.py  Sat Jan 29 22:49:21 2011 -0600
+++ b/gluon/sqlhtml.py  Sun Jan 30 22:53:07 2011 +0100
@@ -328,7 +328,10 @@
 

 # was values = re.compile('[\w\-:]+').findall(str(value))
-values = not isinstance(value,(list,tuple)) and [value] or value
+if isinstance(value, (list, tuple)):
+values = [str(v) for v in value]
+else:
+values = [str(value)]

 attr = OptionsWidget._attributes(field, {}, **attributes)


Cheers
Bernd


[web2py] Re: problems with conditional login redirection on on_failed_authorization

2011-01-30 Thread Niphlod
sorry  this is subtle to spot, but authentication and
authorization is a different thing and it's managed differently
whether you are allowing basic login or not I did an incorrect
assumption making my tests and replying before 

if you try with the decorator @auth.requires_membership('aaa') it
should work , but if you are protecting the page with
@auth.requires_login() the default behaviour is to redirect the user
to the login page.
I think that you may want to use
auth.settings.on_failed_authentication instead of
auth.settings.on_failed_authorization

This is because on_failed_authorization is called only when:
- you are allowing only basic login (if the user specified username
and a password and he's not allowed to see a resource, than he's not
authorized)
- if he's yet logged in and he's not allowed to see a resource
(permission, group, etc not matching)

on all the other cases the real thing happening is that the user is
not authenticated (not yet logged in or anonymous), thus the function
on_failed_authorization is not called.

To sum up briefely, on_failed_authentication gets called before
on_failed_authorization in your case.



On Jan 30, 10:57 pm, Miguel Lopes mig.e.lo...@gmail.com wrote:
 On Sun, Jan 30, 2011 at 9:16 PM, Niphlod niph...@gmail.com wrote:
  try with auth.settings.on_failed_authorization =
  failedAuthHandlerandler()

   it works for me ^_^

 Not for me! And I can't see how.
 Miguel


Re: [web2py] Re: crud.create next= syntax

2011-01-30 Thread Art Zemon

On 01/30/2011 12:35 PM, Massimo Di Pierro wrote:

Valid:
 next=URL(f=show, args=[id])
 next=URL(f=show, args=(id,))
 next=URL(f=show, args=id)


Massimo,

All of those yield .../show/built-in%20function%20id
I am running Version 1.91.6 (2011-01-03 17:55:14)

This is not urgent; I switched to using a SQLFORM which gave me access 
to form.vars.id


-- Art Z.

--

Art Zemon, President
Hen's Teeth Network http://www.hens-teeth.net/
The source of reliable, secure e-commerce web hosting 
http://www.hens-teeth.net/html/hosting/ecommerce_hosting.php

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



[web2py] JSON output errors *hard* to debug

2011-01-30 Thread Art Zemon

Folks,

I had a heckuva time this afternoon debugging this code:

   # request.extension == 'json'
   location = URL(...)
   return dict(location=location)

I get getting HTTP 405 errors. It turns out that generic.json uses a 
try/except block and thows an HTTP 405 error on any exception. The real 
error is that location is not serializable but OY VEY that was tough to 
figure out. (All I had to do was convert location to a string and all 
was well.) Is there some debugging fu that I am missing?


-- Art Z.

--

Art Zemon, President
Hen's Teeth Network http://www.hens-teeth.net/
The source of reliable, secure e-commerce web hosting 
http://www.hens-teeth.net/html/hosting/ecommerce_hosting.php

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



[web2py] Custom form bug

2011-01-30 Thread ionel
Hello,

With custom form I can do this form.table.field_name.length and I
get the field length defined in model file, ex. Field('field_name',
'text', length=200)

But for length  255, ex. Field('field_name', 'text', length=600), I
get always 255 in form.table.field_name.length

I use MySQL and I know that the max value for the data types CHAR and
VARCHAR is 255, but for TEXT is 65535 characters. I think this is a
bug.

Thanks,

i.a.



Re: [web2py] JSON output errors *hard* to debug

2011-01-30 Thread Jonathan Lundell
On Jan 30, 2011, at 4:39 PM, Art Zemon wrote:
 I had a heckuva time this afternoon debugging this code:
 # request.extension == 'json'
 location = URL(...)
 return dict(location=location)
 I get getting HTTP 405 errors. It turns out that generic.json uses a 
 try/except block and thows an HTTP 405 error on any exception. The real error 
 is that location is not serializable but OY VEY that was tough to figure out. 
 (All I had to do was convert location to a string and all was well.) Is there 
 some debugging fu that I am missing?

Did you see the no json message as well (just curious)?

Seems to me that generic.json ought to, at the very least, be more specific 
about this kind of exception. Blanket try/excepts are always asking for trouble.



[web2py] Re: Custom form bug

2011-01-30 Thread ionel
I forgot to say that I use my own function to define the fields in the
custom form.

db.py:
db.define_table('a_table', Field('field_name', 'text', length=600))

controller:
def copyField(field):
   return Field(field.name, field.type, length=field.length)

form = SQLFORM.factory(copyField(db.a_table.field_name))


i.a.


On Jan 30, 7:45 pm, ionel ionelanton...@gmail.com wrote:
 Hello,

 With custom form I can do this form.table.field_name.length and I
 get the field length defined in model file, ex. Field('field_name',
 'text', length=200)

 But for length  255, ex. Field('field_name', 'text', length=600), I
 get always 255 in form.table.field_name.length

 I use MySQL and I know that the max value for the data types CHAR and
 VARCHAR is 255, but for TEXT is 65535 characters. I think this is a
 bug.

 Thanks,

 i.a.


[web2py] Re: Callable as Field.default

2011-01-30 Thread Anthony
Got it. Thanks.

On Sunday, January 30, 2011 6:21:17 PM UTC-5, Massimo Di Pierro wrote:

 You should be able to use 

 default=f 

 Trunk version handles this better than 1.65.6 which has problems with 
 MethodType. 

 Yet if f is an instance with a a __call__ method, it will not call it. 
 For instancetype it will try serialize it with __str__. 



 On Jan 30, 1:36 pm, Anthony abas...@gmail.com wrote: 
  On Friday, January 28, 2011 9:32:13 AM UTC-5, Massimo Di Pierro wrote: 
  
   The fact is, you can do both. If you want the values to be evaluated 
   on insert, just do 
  
   Field(...,default=lambda: f()) 
  
  What's the difference between using default=lambda: f() and just using 
  default=f (assuming f is defined as a function somewhere)? 
  
  Is it just that lambda: f() guarantees you get something with type = 
  FunctionType (so, for example, default=lambda: datetime.datetime.now() 
  would work even though type(datetime.datetime.now) is BuiltinFunctionType 

  and not FunctionType), or is there some other reason to prefer the lambda 

  version? 
  
  It would be very helpful to discuss the use of functions as field 
 defaults 
  in the book (especially the issue of calling a function once at request 
 time 
  vs. passing a function to be called per record at insert time). 
  
  Thanks. 
  
  Anthony



[web2py] Querying fields with a list record

2011-01-30 Thread rāma
Can't do this anymore in the newer version. Any substitutes?

both fields has requires=IS_IN_SET with multiple=True

{{=A('('+str(db((~db.pm.deleted_by.contains(user_id))(~db.pm.read_by.contains(user_id))).count())
+')',_href='#',_class='mail')}}

Searched around and found that it can be done this way:
 db.pm.like(%|+str(user_id)+|%) to look for the pipe char '|' and
the sandwiched number.

So maybe the above is not the conventional way of doing it but if the
former is any faster, I would like to hear a solution. Please comment.


Re: [web2py] JSON output errors *hard* to debug

2011-01-30 Thread Art Zemon

On 01/30/2011 06:50 PM, Jonathan Lundell wrote:

Did you see the no json message as well (just curious)?


Oh yes... and that was what was so distracting. I spent ages trying to 
figure out how a simple dict with two elements could be failing to 
create valid JSON.


-- Art Z.

--

Art Zemon, President
Hen's Teeth Network http://www.hens-teeth.net/
The source of reliable, secure e-commerce web hosting 
http://www.hens-teeth.net/html/hosting/ecommerce_hosting.php

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



Re: [web2py] JSON output errors *hard* to debug

2011-01-30 Thread Jonathan Lundell
On Jan 30, 2011, at 6:38 PM, Art Zemon wrote:
 On 01/30/2011 06:50 PM, Jonathan Lundell wrote:
 
 Did you see the no json message as well (just curious)?
 
 Oh yes... and that was what was so distracting. I spent ages trying to figure 
 out how a simple dict with two elements could be failing to create valid 
 JSON. 

That's good, though, because it's an avenue for showing a better exception 
diagnostic.

Re: [web2py] Re: Is Web2py the right choice for me?

2011-01-30 Thread Jason (spot) Brower
Web2py can do all this with a bit of work as shown already. I am curious
about your 3d skills as I have been looking for some people to help create a
game similar to the old wizardry but using a web-based interface.  If you
interested in side project like this, drop me a personal email and we can
look into it together.
BR,
Jason Brower


On Sun, Jan 30, 2011 at 6:43 PM, Massimo Di Pierro 
massimo.dipie...@gmail.com wrote:

 Welcome Panupat
 Other users may have more to say on this issue, anyway ...

 web2py has pluggable login methods. One is gluon/contrib/login_methods/
 ldap_auth.py. It contains an example of how to use it. It will allow
 you to login using Active Directory using LDAP.

 More complex is the issue with groups. Web2py has its own mechanism
 for creating groups and checking membership.

 There is a third party  python module to get Active Directory groups
 and membership (http://timgolden.me.uk/python/
 ad_cookbook.html#find_a_user_quick).

 Somehow you need to put the two together.

 One option is to extend the class Auth in gluon/tools.py and overload
 methods add_group, del_group, add_membership, del_membership,
 has_membership to use the active directory APIs internally.

 Another option is to use Auth as it is an periodically runs a
 background script that syncs the web2py database with the ative
 directory once.

 I am sorry but if there is a simpler solution I have not seen one.

 Massimo





 On Jan 30, 4:25 am, Panupat panup...@gmail.com wrote:
  I just discovered web2py. I'm wondering if web2py is the right choice
  for me.
 
  Would greatly appreciate any input :)
 
  A little background is that I'm a PHP user and a 3D artist. So Python
  has always been on the top of the to-learn list because it can be used
  with MAX and MAYA. I recently was given an assignment to create a
  website for internal use across our LAN network. I'm given a HUGE
  amount of time so I am using this opportunity to eventually learn
  Python.
 
  Here are some of the specifications of my current assignment and I
  really would really love to know if web2py provides functionality to
  make them happen without much fuss.
 
  - username and password will be authenticated against Windows Acrive
  Directory
 
  - User group also determines by Active Directory groups.
 
  - Everything else will be in MySQL.
 
  - A lot of real time drag-and-drop using javascript on the front end.
  The back end will have to be able to respond to a lot of small
  requests and update database accordingly.
 
  Everything else are generic web stuff so my main concern is only the 4
  specs mentioned above.
 
  Thank you very much!
 
  best regards,
  Panupat.
 
  :)



[web2py] Re: table field with reference to other in read-only mode doesn't appear right

2011-01-30 Thread szimszon
The error is constant...

After the print statement:

[(gluon.dal.Field object at 0x9f9fe8c, 'auth'), (gluon.dal.Field
object at 0x9f9fc0c, 1), (gluon.dal.Field object at 0x9f9ff0c,
'User 1 Logged-in'), (gluon.dal.Field object at 0x9f9fd2c,
datetime.datetime(2011, 1, 31, 7, 43, 21, 687801)), (gluon.dal.Field
object at 0x9f9fbec, '10.1.0.100'), (gluon.dal.Field object at
0x9f9fe8c, 'auth'), (gluon.dal.Field object at 0x9f9ff0c, '')]


On jan. 31, 00:18, Massimo Di Pierro massimo.dipie...@gmail.com
wrote:
 I cannot reproduce this. Can you help me?

 Can you edit gluon/dal.py and the function _listify, add a print
 statement before it returns. Try reproduce the error. What does it
 print?

 On Jan 30, 11:29 am, szimszon szims...@gmail.com wrote:







  Now, there is a programming error in nightly build (source version)
  [pgsql]:

  Traceback (most recent call last):
    File /home/szimszon_nfs/web2py/gluon/restricted.py, line 188, in
  restricted
      exec ccode in environment
    File /home/szimszon_nfs/web2py/applications/raktar/controllers/
  default.py, line 77, in module
    File /home/szimszon_nfs/web2py/gluon/globals.py, line 95, in
  lambda
      self._caller = lambda f: f()
    File /home/szimszon_nfs/web2py/applications/raktar/controllers/
  default.py, line 52, in user
      return dict( form = auth() )
    File /home/szimszon_nfs/web2py/gluon/tools.py, line 1034, in
  __call__
      return self.login()
    File /home/szimszon_nfs/web2py/gluon/tools.py, line 1527, in login
      self.log_event(log % self.user)
    File /home/szimszon_nfs/web2py/gluon/tools.py, line 1277, in
  log_event
      origin=origin, user_id=user_id)
    File /home/szimszon_nfs/web2py/gluon/dal.py, line 3934, in insert
      return self._db._adapter.insert(self,self._listify(fields))
    File /home/szimszon_nfs/web2py/gluon/dal.py, line 707, in insert
      raise e
  ProgrammingError: column origin specified more than once
  LINE
  1: ...t(origin,user_id,description,time_stamp,client_ip,origin,des...
                                                               ^

  Error snapshot help

  class 'psycopg2.ProgrammingError'(column origin specified more
  than once LINE
  1: ...t(origin,user_id,description,time_stamp,client_ip,origin,des...
  ^ )

  On jan. 30, 16:08, Massimo Di Pierro massimo.dipie...@gmail.com
  wrote:

   This should be fixed in trunk (and nightly build).Please give it a try
   and confirm.

   Massimo

   On Jan 30, 7:46 am, szimszon szims...@gmail.com wrote:

I wonder if somebody could help me.

Here is my Field:

    Field( 'updated_by', db.auth_user,
                                        writable = False  )

CRUD rendered it in form None but the record has a value 1 and I
have user in auth_user.id=1

If I modify the Field to:

    Field( 'updated_by', db.auth_user,
                                        writable = False ,
                                        requires = IS_EMPTY_OR( 
IS_IN_DB( db, db.auth_user.id, '%
(first_name)s' ) ) )

The result is 1 and not the first_name value.

If I modify the Field to:

    Field( 'updated_by', db.auth_user)

The result is a list with all the auth_user rows :-o

With the Field like this:

    Field( 'updated_by', db.auth_user,
                                        requires = IS_EMPTY_OR( 
IS_IN_DB( db, db.auth_user.id, '%
(first_name)s' ) ) )

There is a result list with all the first_name values...

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


Re: [web2py] Re: Speeding up IS_IN_DB

2011-01-30 Thread Johann Spies
On 28 January 2011 19:54, Massimo Di Pierro massimo.dipie...@gmail.comwrote:

 Something else is wrong. If you have requires=[...] it should not
 query the db for the possible references and it should not make the
 dropdown.

 Can we see the entire model?


I have posted the model for this table in an earlier message in this
thread.  Here it is again (as it is at the moment)  with the models of all
the other tables referenced:

db.define_table(artikel,
Field(joernaal_id,
  db.joernaal,
  requires = [IS_IN_DB(db, db.joernaal.id,
  '%(titel)s')]#,
  #widget =SQLFORM.widgets.autcomplete
  ),
Field(outeur_id, 'list:reference outeur'),
Field(instansie_id, 'list:reference instansie'),
Field(titel, string, notnull=True),
Field(opsomming, text, notnull=True),
Field(sleutelwoorde, text, notnull=True),
Field(vakgebied, string, default=None),
Field(publikasiejaar, integer, default=None),
Field(begin_bladsy,  default=None),
Field(laaste_bladsy, default=None),
Field(volume, string, default=None),
Field('uitgawe', default=None),
Field('pub_tipe', default = None),
Field(taal, string,  default=None),
Field(isi_indeks, default = None),
Field(isap_indeks, default = None),
Field(scopus_verwysing,
  requires=IS_EMPTY_OR(IS_URL())),
Field(dokument_tipe),
Field('ouid', 'integer',
  requires = [IS_EMPTY_OR(IS_IN_DB(db,
'article.ouid'))]),
signature)

db.artikel.joernaal_id.represent = lambda x: db.joernaal[x].titel
db.artikel.sleutelwoorde.represent=lambda x: XML(x,sanitize=True)
db.artikel.opsomming.represent=lambda x: XML(x,sanitize=True)
db.artikel.titel.represent=lambda x: XML(x,sanitize=True)
db.artikel.id.represent = lambda value: UL(
LI(A(T('show(%d)' % value),_href=URL(r=request,c='default',
 f='data/read/artikel', args=str(value,
LI(A(T('edit'),_href=URL(r=request, c='default',
 f='data/update/artikel', args=str(value
 )

db.define_table(joernaal,
Field(titel, string, notnull=True, default=None),
Field(issn, string, default=None),
Field(frekwensie, string, default=None),
Field(id_uitgewer, db.uitgewer,
  requires = IS_EMPTY_OR(IS_IN_DB(db, db.uitgewer.id,
  '%(besonderhede)s'))),
Field(id_sa_goedgekeur_2009, db.erkende_joernale_2009,
  default = None),
Field(id_land, db.land,
  requires = IS_EMPTY_OR(IS_IN_DB(db, 'land.id',
  '%(naam)s'))),
Field(vak_kategorie, db.isi_framework,
  requires = IS_EMPTY_OR(IS_IN_DB(db, 'isi_framework.id
',

'%(level_4_categories)s'
  ))),
signature,
format = lambda r: r.titel.capitalize() or Unknown
)

db.define_table(instansie,
Field(naam, string, notnull=True, default=None),
Field('akroniem'),
Field(tersier, boolean, default=False),
Field(tipe, requires=IS_IN_SET(('University',
  'University of
Technology(Technikon)',
  'College',
  'NGO',
  'Research Institute',
  'Government',
  'Private Sector',
  'Unknown'
  ),
 zero = None),
  default='Unknown'),
Field(notas, text, default=None),
Field(adres, string, default=None),
Field(e_pos, string, requires =
IS_EMPTY_OR(IS_EMAIL())),
Field(webblad, string, requires =
IS_EMPTY_OR(IS_URL())),
Field(id_land, db.land),
signature,
format = lambda r: r.naam or Unknown,
)

db.define_table(outeur,
Field('ouid', 'integer'),
Field(van, string, notnull=True),
Field(voorletters, string, default=None),
Field(name, string, default=None),
Field(e_posadres, string,
  

Re: [web2py] Re: Speeding up IS_IN_DB

2011-01-30 Thread Johann Spies
Maybe this is related -  I have not noticed it before:

In the terminal from where I started web2py the following appeared: Uncaught
RangeError: Maximum call stack size exceeded

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