[web2py] Re: custom validation, was: Re: IS_IN_DB referencing linked tables

2010-09-08 Thread annet
Something like this in the controller:

eventtyperows=db(db.event.eventtype==db.eventtype.id).\
select(db.event.eventtype,db.eventtype.eventtype,\
distinct=True,orderby=db.eventtype.eventtype)

a=[e.event.eventtype for e in eventtyperows]
b=[e.eventtype.eventtype for e in eventtyperows]

form=SQLFORM.factory(SQLField('eventtype',requires=IS_IN_SET(a,b))


Annet.


[web2py] How to insert only new items in db as fast as possible?

2010-09-08 Thread Miguel
Hi

I have the following table:
db.define_table("products",
Field("categoryID", db.productCategory, writable=False,
readable=False, requires=IS_IN_DB(db, "productCategory.id",
"productCategory.name") ), # reference field
Field("productName", 'string',length=512,  default=None),
Field("description", 'text',default=None)
)

- I have a list of (2) rows that might contain products and I
would like to update my table. However some products might already be
in the db while others are completely new.
- I want to insert a row if it does not exist in the db (productName
could play the role of the identifier here) is already there AND
update a row in the case the product already exists in the DB>


I can do it pretty easily if I go item by item and check if it already
exits in the db and then take the appropriate action (insert or
update). What I am looking for is the most efficient way to do this
(especially on GAE).

thanks
Miguel


Re: [web2py] Reverse table look up in GAE

2010-09-08 Thread b vivek
Ok so if i have a table in my db named homepage as below:-
--
id  | data |
---
1   | vivek|
--
2  | andrew|
---

Now if I want to retrieve only the last row .. i can do this
homepage=db().select(db.homepage.ALL,orderby=~db.homepage.id,limitby=(0,1))

Now let me point out that this works prefectly on localhost using the normal
rdbms like mysql or sqlite. However when I use the local development GAE
environ or even when I upload it to GAE,it just returns the first row. Seems
like it totally ignores the tilde.

The same command when used on GAE gives me the first row,rather than the
last one.

Thanks
Vivek

On Thu, Sep 9, 2010 at 11:27 AM, Andrew Thompson wrote:

>  On 9/9/2010 12:24 AM, b vivek wrote:
>
> Hi I wanted to retrieve the latest data entered in a table and thus used
> the below syntax for data look up
>
> homepage=db().select(db.homepage.ALL,orderby=~db.homepage.id
> ,limitby=(0,1))
>
>  This is expected to retrieve the last row entered in the table homepage .
> While this works perfectly, it does not work on GAE. It would be really
> helpful, if someone could please help me with this..
>
>
> While I'm not familiar with GAE, I can say for sure that you've not
> provided enough information.
>
> How does it "not work"?
>
> For example, can you make any .select() work? If you remove the orderby or
> the limitby does it change how it doesn't work?
>
> --
> Andrew Thompsonhttp://aktzero.com/
>
>


Re: [web2py] Reverse table look up in GAE

2010-09-08 Thread Andrew Thompson

 On 9/9/2010 12:24 AM, b vivek wrote:
Hi I wanted to retrieve the latest data entered in a table and thus 
used the below syntax for data look up


homepage=db().select(db.homepage.ALL,orderby=~db.homepage.id 
,limitby=(0,1))


This is expected to retrieve the last row entered in the table 
homepage . While this works perfectly, it does not work on GAE. It 
would be really helpful, if someone could please help me with this..




While I'm not familiar with GAE, I can say for sure that you've not 
provided enough information.


How does it "not work"?

For example, can you make any .select() work? If you remove the orderby 
or the limitby does it change how it doesn't work?


--
Andrew Thompson
http://aktzero.com/



[web2py] Re: plugin legacy mysql: generates web2py code to access your mysql legacy db

2010-09-08 Thread ron_m


On Sep 8, 1:30 pm, mdipierro  wrote:
> > So maybe tonight do you want me to go through the manual and find all
> > the missing datatypes and try to add them to the map?
>
> I would not stop you. ;-)
>

Here is a replacement data_type_map, it was shuffled a bit to put like
types together for easier maintenance. I didn't know what to do with
the YEAR type so it is commented out. I am not sure the decimal type
should be mapped to integer since the DAL accepts decimal(n,M) as a
field type.

data_type_map = dict(
varchar = 'string',
int = 'integer',
integer = 'integer',
tinyint = 'integer',
smallint = 'integer',
mediumint = 'integer',
bigint = 'integer',
float = 'double',
double = 'double',
char = 'string',
decimal = 'integer',
date = 'date',
#year = 'date',
time = 'time',
timestamp = 'datetime',
datetime = 'datetime',
binary = 'blob',
blob = 'blob',
tinyblob = 'blob',
mediumblob = 'blob',
longblob = 'blob',
text = 'text',
tinytext = 'text',
mediumtext = 'text',
longtext = 'text',
)

I also fixed the remaining problem in the line match re.search so line
75 or line 87 after above dict is changed

75c87
< hit = re.search('(\S+)\s+(\S+)( .*)?', line)
---
> hit = re.search('(\S+)\s+(\S+)(,| )( .*)?', line)

this fixes the matching on lines like

`description` longtext,

The comma immediately after the type got included as part of the type
string match in error.

Here is the output for the auth_event table

legacy_db.define_table('auth_event',
Field('id','integer'),
Field('time_stamp','datetime'),
Field('client_ip','string'),
Field('user_id','integer'),
Field('origin','string'),
Field('description','text'),
migrate=False)

The id field should not be printed since it will be added
automatically.

The varchar fields have a length in () e.g. varchar(64) which could be
used to add on a length=N value for the Field constructor. The same
holds true for int fields but I don't think there is a real use for
that.

There is no recognition of foreign keys, fixing this would probably be
a significant effort. Some human intervention required as it
stands. ;-)

It certainly is a great start to getting a model file for an existing
MySQL database.

Ron


[web2py] Reverse table look up in GAE

2010-09-08 Thread b vivek
Hi I wanted to retrieve the latest data entered in a table and thus used the
below syntax for data look up

homepage=db().select(db.homepage.ALL,orderby=~db.homepage.id,limitby=(0,1))

This is expected to retrieve the last row entered in the table homepage .
While this works perfectly, it does not work on GAE. It would be really
helpful, if someone could please help me with this..
Thanks
Vivek


Re: [web2py] Re: Routes.py on GAE

2010-09-08 Thread Miguel Goncalves
Hi Massimo

Did you, by any chance, make any progress on this issue?

Thanks
Miguel



On Tue, Sep 7, 2010 at 4:43 AM, mdipierro  wrote:

> Thanks for the reminder. I will look into this today.
>
> On Sep 7, 1:28 am, Miguel Goncalves  wrote:
> > Hi
> >
> > I guess this bug has not been fixed yet?
> >
> > I am getting the following error:
> >
> > unable to import Rocket
> > Your routes.py has a syntax error Please fix it before you restart web2py
> > Traceback (most recent call last):
> >   File
> "/base/data/home/apps/reviewround/1.344628390884008259/gluon/rewrite.py",
> > line 106, in load
> > exec routesfp.read() in symbols
> >   File "", line 3
> >
> >^
> > SyntaxError: invalid syntax
> >
> > : invalid syntax (, line 3)
> > Traceback (most recent call last):
> >   File
> "/base/data/home/apps/reviewround/1.344628390884008259/gaehandler.py",
> > line 52, in 
> > import gluon.main
> >   File
> "/base/data/home/apps/reviewround/1.344628390884008259/gluon/main.py",
> > line 66, in 
> > rewrite.load()
> >   File
> "/base/data/home/apps/reviewround/1.344628390884008259/gluon/rewrite.py",
> > line 114, in load
> > raise e
> > : invalid syntax (, line 3)
> >
> > The routes.py looks like :
> > #!/usr/bin/python
> > # -*- coding: utf-8 -*-
> >
> > default_application = 'reviewround' # ordinarily set in base
> routes.py
> > default_controller = 'default'  # ordinarily set in app-specific
> > routes.py
> > default_function = 'index'
> >
> > routes_in = ( ('/', '/reviewround/default/index'),)
> > routes_out = ( ('/reviewround/default/index', '/'),)
> >
> > thanks
> > Miguel
>


[web2py] custom validation, was: Re: IS_IN_DB referencing linked tables

2010-09-08 Thread Andrew Thompson

 On 9/7/2010 10:42 AM, mdipierro wrote:

You cannot do a join in a IS_IN_DB

IS_IN_DB(db((db.flockdata.flock==db.flocks.id)&(db.flockdata.house==db.houses.id)),
db.flockdata.id, '%(houses.name)s')),

and the format cannot contain a "."


If I can build the validator a different way, is there a way to attach 
it to the SQLFORM object? (It will be customer specific, so it'd be best 
to apply it at controller time, I think.)


I see a _validate attribute on SQLFORM, but I don't see how to use it.

--
Andrew Thompson
http://aktzero.com/



Re: [web2py] Re: CRUD RBAC problem

2010-09-08 Thread Alexey Nezhdanov
Sure

On Thu, Sep 9, 2010 at 6:11 AM, mdipierro  wrote:

> No, it does not. It must be done in two queries. Can you send me the
> patch by email? thanks.
>
> On Sep 8, 8:44 pm, Alexey Nezhdanov  wrote:
> > Updated version of the patch then. Includes case where there is no such
> row
> > ('create' action).
> > However, I'm not sure if these changes are GAE-compartible. Not sure if
> > bigtable likes .belongs on multiple columns.
> > Can anybody test?
> >
> > Regards
> > Alexey.
> >
> > --- tools.py_   2010-09-08 08:40:22.266751051 +0400
> > +++ tools.py2010-09-08 09:44:30.050746520 +0400
> > @@ -2415,17 +2415,10 @@
> >  == user_id).select(membership.group_id)
> >  groups = set([row.group_id for row in rows])
> >  permission = self.settings.table_permission
> > -rows = self.db(permission.name == name)(permission.table_name
> > - == str(table_name))(permission.record_id
> > - == record_id).select(permission.group_id)
> > +rows = self.db(permission.name.belongs((name,'any'))&
> > +
> permission.table_name.belongs((str(table_name),''))&
> > +
> > permission.record_id.belongs((record_id,0))).select(permission.group_id)
> >  groups_required = set([row.group_id for row in rows])
> > -if record_id:
> > -rows = self.db(permission.name
> > -== name)(permission.table_name
> > - == str(table_name))(permission.record_id
> > - == 0).select(permission.group_id)
> > -groups_required = groups_required.union(set([row.group_id
> > -for row in rows]))
> >  if groups.intersection(groups_required):
> >  r = True
> >  else:
> >
> > On Wed, Sep 8, 2010 at 5:14 PM, mdipierro 
> wrote:
> > > I think this should be considered a bug and I agree with the change.
> > > Anybody opposed?
> >
> > > Massimo
> >
> > > On Sep 7, 11:46 pm, Alexey Nezhdanov  wrote:
> > > > Hi. I think that I found some inconsistency in the topic.
> > > > When you do, say,
> > > > auth.add_permission(group_id) - it assumes the permission name 'any',
> > > table
> > > > name empty and record_id 0.
> > > > Which in turn feels like "full admin rights" - any action on any
> table on
> > > > any record.
> > > > In fact, that gives no permissions whatsoever.
> >
> > > > I've came out with the following patch to make it work for me, but
> since
> > > > that is the very core of RBAC, I'm not sure if that is the right
> solution
> > > or
> > > > if I am looking in the correct direction at all.
> >
> > > > --- tools.old.py2010-09-08 08:40:22.266751051 +0400
> > > > +++ tools.py2010-09-08 08:41:25.894746181 +0400
> > > > @@ -2420,10 +2420,9 @@
> > > >   == record_id).select(permission.group_id)
> > > >  groups_required = set([row.group_id for row in rows])
> > > >  if record_id:
> > > > -rows = self.db(permission.name
> > > > -== name)(permission.table_name
> > > > - == str(table_name))(permission.record_id
> > > > - == 0).select(permission.group_id)
> > > > +rows = self.db(permission.name.belongs((name,'any'))&
> > > > +
> > > > permission.table_name.belongs((str(table_name),''))&
> > > > +
> > > >
> permission.record_id.belongs((record_id,0))).select(permission.group_id)
> > > >  groups_required =
> groups_required.union(set([row.group_id
> > > >  for row in rows]))
> > > >  if groups.intersection(groups_required):
> >
> > > > Regards
> > > > Alexey
> >
> >
>
--- tools.py_	2010-09-08 08:40:22.266751051 +0400
+++ tools.py	2010-09-08 09:44:30.050746520 +0400
@@ -2415,17 +2415,10 @@
 == user_id).select(membership.group_id)
 groups = set([row.group_id for row in rows])
 permission = self.settings.table_permission
-rows = self.db(permission.name == name)(permission.table_name
- == str(table_name))(permission.record_id
- == record_id).select(permission.group_id)
+rows = self.db(permission.name.belongs((name,'any'))&
+   permission.table_name.belongs((str(table_name),''))&
+   permission.record_id.belongs((record_id,0))).select(permission.group_id)
 groups_required = set([row.group_id for row in rows])
-if record_id:
-rows = self.db(permission.name
-== name)(permission.table_name
- == str(table_name))(permission.record_id
- == 0).select(permission.group_id)
-groups_required = groups_required.union(set([row.group_id
-for row in rows]))
 if groups.intersection(groups_required):
 r = True
 else:


[web2py] Re: web2py_vs_others missing T() section!

2010-09-08 Thread mdipierro
thanks. can you take charge and post it on a google doc? I can help
editing.

On Sep 8, 9:08 pm, weheh  wrote:
> Here's the text of the pdf document, courtesy one of my websites,
> YAKiToMe!http://www.yakitome.com.
>
> ---
>
> web frameworks design comparison
> draft - please help me improve it focus on Model-View-Controller
> frameworks
>
> Controllers
> In Rails class MyTestController < ApplicationController def index
> render_text "Hello World" end end
>
> The name of the class has to match the name of the controller file.
>
> Controllers
> In Django from django.http import HttpResponse def index(request):
> return HttpResponse("Hello World")
>
> Django is explicit, you need to import all functions you use.
>
> Controllers
> In Cherrypy and TurboGears 1.0 import cherrypy class MyRoot:
> @cherrypy.expose() def index(self): return "Hello World"
>
> Cherrypy, Turbogears, and Pylons are also explicit. You need to import
> all functions you want to use.
>
> Controllers
> In web2py def index(): return "Hello World"
>
> web2py is similar to Rails. It imports for you all the web2py keyword.
> Often, like in this case, you do not need any.
>
> Get/Post requests
> In Rails class MyTestController < ApplicationController def index
> render_text "Hello "+params[:who] end end
>
> GET and POST variables are passed via params but other request
> parameters (client ip for example) are passed via a different
> mechanism.
>
> Get/Post requests
> In Django from django.http import HttpResponse def index(request):
> return HttpResponse("Hello World %s" % request.REQUEST[`who’])
>
> Nice, simple. The request contains all the info. You can use .GET
> or .POST instead of .REQUEST to be more specific.
>
> Get/Post requests
> In Cherrypy and TurboGears 1.0 import cherrypy class MyRoot:
> @cherrypy.expose() def index(self,who): return "Hello %s" % who
>
> GET and POST variables are passed via arguments of the action, but
> other request parameters (client ip for example) are passed via a
> different mechanism.
>
> Get/Post requests
> In web2py def index(): return "Hello %s" % request.vars.who
>
> Similar to Django. All request data is in one place. You can
> use .get_vars and .post_vars instead of .vars to be more specific.
>
> Dispatching
> In Rails URLhttp://hostname/MyTest/indexgets mapped into class
> MyTestController < ApplicationController def index render_text "Hello
> World" end end
>
> By default Rails does not allow running multiple apps without running
> multiple copies of Rails, since the name of the app is not in the URL,
> only the controller name (MyTest) and the action name (index) appear.
> This can be changed by configuring routes.
>
> Dispatching
> In Django you need to edit url.py to map URLs into actions from
> django.conf.urls.defaults import * urlpatterns = patterns(’’, (r’^index
> $’, myapp.mycontroller.index), )
>
> This is the equivalent of Rails’ routes and it requires using regular
> expressions. There is no default. You need one entry in url.py for
> every action.
>
> Dispatching
> In Cherrypy and TurboGears 1.0 import cherrypy class MyRoot:
> @cherrypy.expose() def index(self,who): return "Hello %s" % who
>
> Works very much like Rails and default mapping between URL and action
> can be overwritten.
>
> Dispatching
> In web2py a URL likehttp://hostname/myapp/mycontroller/indexcalls
> def index(): return "Hello %s" % request.vars.who
>
> Similar to Rails and Charrypy but, by default the URL requires that
> you specify the name of the app. This allows web2py to run multiple
> apps without using routes. Web2py has its own version of routes that
> supports two different syntaxes (with and without regular expression)
> to overwrite the mapping and reverse mapping as well.
>
> Calling Views
> In Rails class MyTestController < ApplicationController def index
> @message="Hello World" end end
>
> It calls the default view (MyTest/index) which renders the page. The
> variables marked by @ are global vars and are passed to the view.
> Notice that if the view is not defined, this results in an error
> message.
>
> Calling Views
> In Django from django.shortcuts import render_to_response def
> index(request): return render_to_response("index.html",
> {`message’:’Hello World’})
>
> This is the short way of doing it in Django. You have to specify the
> view name "index.html" since there is no default. Parameters are
> passed via a dictionary. You get an error message if the view is not
> defined. Notice that in Django a view is called a template and a
> controller is called a view.
>
> Calling Views
> In TurboGears 1.0 with Cherrypy import turbogears from turbogears
> import controllers, expose class MyRoot(controllers.RootController):
> @expose(template="MyApp.MyRoot.index") def index(self): return
> dict(message="Hello World")
>
> The view is specified in the expose decorator.
>
> Calling Views
> In web2py def index(): return dict(message="Hello World")
>
> The last line wor

[web2py] Re: CRUD RBAC problem

2010-09-08 Thread mdipierro
No, it does not. It must be done in two queries. Can you send me the
patch by email? thanks.

On Sep 8, 8:44 pm, Alexey Nezhdanov  wrote:
> Updated version of the patch then. Includes case where there is no such row
> ('create' action).
> However, I'm not sure if these changes are GAE-compartible. Not sure if
> bigtable likes .belongs on multiple columns.
> Can anybody test?
>
> Regards
> Alexey.
>
> --- tools.py_   2010-09-08 08:40:22.266751051 +0400
> +++ tools.py    2010-09-08 09:44:30.050746520 +0400
> @@ -2415,17 +2415,10 @@
>                          == user_id).select(membership.group_id)
>          groups = set([row.group_id for row in rows])
>          permission = self.settings.table_permission
> -        rows = self.db(permission.name == name)(permission.table_name
> -                 == str(table_name))(permission.record_id
> -                 == record_id).select(permission.group_id)
> +        rows = self.db(permission.name.belongs((name,'any'))&
> +                       permission.table_name.belongs((str(table_name),''))&
> +
> permission.record_id.belongs((record_id,0))).select(permission.group_id)
>          groups_required = set([row.group_id for row in rows])
> -        if record_id:
> -            rows = self.db(permission.name
> -                            == name)(permission.table_name
> -                     == str(table_name))(permission.record_id
> -                     == 0).select(permission.group_id)
> -            groups_required = groups_required.union(set([row.group_id
> -                    for row in rows]))
>          if groups.intersection(groups_required):
>              r = True
>          else:
>
> On Wed, Sep 8, 2010 at 5:14 PM, mdipierro  wrote:
> > I think this should be considered a bug and I agree with the change.
> > Anybody opposed?
>
> > Massimo
>
> > On Sep 7, 11:46 pm, Alexey Nezhdanov  wrote:
> > > Hi. I think that I found some inconsistency in the topic.
> > > When you do, say,
> > > auth.add_permission(group_id) - it assumes the permission name 'any',
> > table
> > > name empty and record_id 0.
> > > Which in turn feels like "full admin rights" - any action on any table on
> > > any record.
> > > In fact, that gives no permissions whatsoever.
>
> > > I've came out with the following patch to make it work for me, but since
> > > that is the very core of RBAC, I'm not sure if that is the right solution
> > or
> > > if I am looking in the correct direction at all.
>
> > > --- tools.old.py        2010-09-08 08:40:22.266751051 +0400
> > > +++ tools.py    2010-09-08 08:41:25.894746181 +0400
> > > @@ -2420,10 +2420,9 @@
> > >                   == record_id).select(permission.group_id)
> > >          groups_required = set([row.group_id for row in rows])
> > >          if record_id:
> > > -            rows = self.db(permission.name
> > > -                            == name)(permission.table_name
> > > -                     == str(table_name))(permission.record_id
> > > -                     == 0).select(permission.group_id)
> > > +            rows = self.db(permission.name.belongs((name,'any'))&
> > > +
> > > permission.table_name.belongs((str(table_name),''))&
> > > +
> > > permission.record_id.belongs((record_id,0))).select(permission.group_id)
> > >              groups_required = groups_required.union(set([row.group_id
> > >                      for row in rows]))
> > >          if groups.intersection(groups_required):
>
> > > Regards
> > > Alexey
>
>


[web2py] Re: web2py_vs_others missing T() section!

2010-09-08 Thread weheh
Here's the text of the pdf document, courtesy one of my websites,
YAKiToMe! http://www.yakitome.com.

---

web frameworks design comparison
draft - please help me improve it focus on Model-View-Controller
frameworks

Controllers
In Rails class MyTestController < ApplicationController def index
render_text "Hello World" end end

The name of the class has to match the name of the controller file.

Controllers
In Django from django.http import HttpResponse def index(request):
return HttpResponse("Hello World")

Django is explicit, you need to import all functions you use.

Controllers
In Cherrypy and TurboGears 1.0 import cherrypy class MyRoot:
@cherrypy.expose() def index(self): return "Hello World"

Cherrypy, Turbogears, and Pylons are also explicit. You need to import
all functions you want to use.

Controllers
In web2py def index(): return "Hello World"

web2py is similar to Rails. It imports for you all the web2py keyword.
Often, like in this case, you do not need any.

Get/Post requests
In Rails class MyTestController < ApplicationController def index
render_text "Hello "+params[:who] end end

GET and POST variables are passed via params but other request
parameters (client ip for example) are passed via a different
mechanism.

Get/Post requests
In Django from django.http import HttpResponse def index(request):
return HttpResponse("Hello World %s" % request.REQUEST[`who’])

Nice, simple. The request contains all the info. You can use .GET
or .POST instead of .REQUEST to be more specific.

Get/Post requests
In Cherrypy and TurboGears 1.0 import cherrypy class MyRoot:
@cherrypy.expose() def index(self,who): return "Hello %s" % who

GET and POST variables are passed via arguments of the action, but
other request parameters (client ip for example) are passed via a
different mechanism.

Get/Post requests
In web2py def index(): return "Hello %s" % request.vars.who

Similar to Django. All request data is in one place. You can
use .get_vars and .post_vars instead of .vars to be more specific.

Dispatching
In Rails URL http://hostname/MyTest/index gets mapped into class
MyTestController < ApplicationController def index render_text "Hello
World" end end

By default Rails does not allow running multiple apps without running
multiple copies of Rails, since the name of the app is not in the URL,
only the controller name (MyTest) and the action name (index) appear.
This can be changed by configuring routes.

Dispatching
In Django you need to edit url.py to map URLs into actions from
django.conf.urls.defaults import * urlpatterns = patterns(’’, (r’^index
$’, myapp.mycontroller.index), )

This is the equivalent of Rails’ routes and it requires using regular
expressions. There is no default. You need one entry in url.py for
every action.

Dispatching
In Cherrypy and TurboGears 1.0 import cherrypy class MyRoot:
@cherrypy.expose() def index(self,who): return "Hello %s" % who

Works very much like Rails and default mapping between URL and action
can be overwritten.

Dispatching
In web2py a URL like http://hostname/myapp/mycontroller/index calls
def index(): return "Hello %s" % request.vars.who

Similar to Rails and Charrypy but, by default the URL requires that
you specify the name of the app. This allows web2py to run multiple
apps without using routes. Web2py has its own version of routes that
supports two different syntaxes (with and without regular expression)
to overwrite the mapping and reverse mapping as well.

Calling Views
In Rails class MyTestController < ApplicationController def index
@message="Hello World" end end

It calls the default view (MyTest/index) which renders the page. The
variables marked by @ are global vars and are passed to the view.
Notice that if the view is not defined, this results in an error
message.

Calling Views
In Django from django.shortcuts import render_to_response def
index(request): return render_to_response("index.html",
{`message’:’Hello World’})

This is the short way of doing it in Django. You have to specify the
view name "index.html" since there is no default. Parameters are
passed via a dictionary. You get an error message if the view is not
defined. Notice that in Django a view is called a template and a
controller is called a view.

Calling Views
In TurboGears 1.0 with Cherrypy import turbogears from turbogears
import controllers, expose class MyRoot(controllers.RootController):
@expose(template="MyApp.MyRoot.index") def index(self): return
dict(message="Hello World")

The view is specified in the expose decorator.

Calling Views
In web2py def index(): return dict(message="Hello World")

The last line works like Cherrypy but by default it looks for a view
called "mycontroller/index.html" in "myapp". If this view does not
exist it uses a generic view to show all variables returned in the
dictionary. The default can be overwritten with
response.view=’filename.html’

Views
In Rails <% @recipes.each do |recipe| %> <%= recipe.name %> <%

Re: [web2py] Re: CRUD RBAC problem

2010-09-08 Thread Alexey Nezhdanov
Updated version of the patch then. Includes case where there is no such row
('create' action).
However, I'm not sure if these changes are GAE-compartible. Not sure if
bigtable likes .belongs on multiple columns.
Can anybody test?

Regards
Alexey.

--- tools.py_   2010-09-08 08:40:22.266751051 +0400
+++ tools.py2010-09-08 09:44:30.050746520 +0400
@@ -2415,17 +2415,10 @@
 == user_id).select(membership.group_id)
 groups = set([row.group_id for row in rows])
 permission = self.settings.table_permission
-rows = self.db(permission.name == name)(permission.table_name
- == str(table_name))(permission.record_id
- == record_id).select(permission.group_id)
+rows = self.db(permission.name.belongs((name,'any'))&
+   permission.table_name.belongs((str(table_name),''))&
+
permission.record_id.belongs((record_id,0))).select(permission.group_id)
 groups_required = set([row.group_id for row in rows])
-if record_id:
-rows = self.db(permission.name
-== name)(permission.table_name
- == str(table_name))(permission.record_id
- == 0).select(permission.group_id)
-groups_required = groups_required.union(set([row.group_id
-for row in rows]))
 if groups.intersection(groups_required):
 r = True
 else:

On Wed, Sep 8, 2010 at 5:14 PM, mdipierro  wrote:

> I think this should be considered a bug and I agree with the change.
> Anybody opposed?
>
> Massimo
>
> On Sep 7, 11:46 pm, Alexey Nezhdanov  wrote:
> > Hi. I think that I found some inconsistency in the topic.
> > When you do, say,
> > auth.add_permission(group_id) - it assumes the permission name 'any',
> table
> > name empty and record_id 0.
> > Which in turn feels like "full admin rights" - any action on any table on
> > any record.
> > In fact, that gives no permissions whatsoever.
> >
> > I've came out with the following patch to make it work for me, but since
> > that is the very core of RBAC, I'm not sure if that is the right solution
> or
> > if I am looking in the correct direction at all.
> >
> > --- tools.old.py2010-09-08 08:40:22.266751051 +0400
> > +++ tools.py2010-09-08 08:41:25.894746181 +0400
> > @@ -2420,10 +2420,9 @@
> >   == record_id).select(permission.group_id)
> >  groups_required = set([row.group_id for row in rows])
> >  if record_id:
> > -rows = self.db(permission.name
> > -== name)(permission.table_name
> > - == str(table_name))(permission.record_id
> > - == 0).select(permission.group_id)
> > +rows = self.db(permission.name.belongs((name,'any'))&
> > +
> > permission.table_name.belongs((str(table_name),''))&
> > +
> > permission.record_id.belongs((record_id,0))).select(permission.group_id)
> >  groups_required = groups_required.union(set([row.group_id
> >  for row in rows]))
> >  if groups.intersection(groups_required):
> >
> > Regards
> > Alexey
>


[web2py] Re: web2py_vs_others missing T() section!

2010-09-08 Thread mdipierro
Unfortunately I lost the source of that document and I have been
unable to update it in more than 1 year.

It would be great if somebody were to extract the text from pdf and
post it on google code so that more of us can contribute and keep it
updated. Actually I seem to remember somebody did that already but
cannot find that either. :-(

Massimo

On Sep 8, 5:53 pm, Tom  Campbell  wrote:
> I just learned about  
> http://www.web2py.com/examples/static/web2py_vs_others.pdf
> on StackOverflow a few minutes ago so maybe this is old news, but the
> Internationalization section doesn't talk about web2py's elegant T()
> object. That section doesn't mention web2py at all!
>
> Just discovered web2py Friday & am totally blown away.


[web2py] web2py_vs_others missing T() section!

2010-09-08 Thread Tom Campbell
I just learned about  http://www.web2py.com/examples/static/web2py_vs_others.pdf
on StackOverflow a few minutes ago so maybe this is old news, but the
Internationalization section doesn't talk about web2py's elegant T()
object. That section doesn't mention web2py at all!

Just discovered web2py Friday & am totally blown away.


[web2py] Re: Parent -> Child Models in a single form

2010-09-08 Thread mdipierro
No but this idea can be extended and used to create a more complex
widget using reference fields.

On Sep 8, 3:52 pm, geoff  wrote:
> This works for me now.  Indeed it was the formatting.  Probably on my
> end.
>
> Of course this does not really solve an 'address' issue if an address is
> more than one field, which is the case for both myself and the original
> poster.
>
> In any case, that is a wonderful widget!
>
> Best,
> Geoff
>
> On Wed, 2010-09-08 at 13:47 -0700, mdipierro wrote:
> > To try it. just drop in new empty app under models/ and access the
> > person table using appadmin.
>
> > On Sep 8, 3:45 pm, Massimo Di Pierro  wrote:
> > > perhaps this works
>
> > >  db_list_string.py
> > > 1KViewDownload
>
>


[web2py] hacking sf menu: how to make it ignore as menu items if they are in some

2010-09-08 Thread Jurgis Pralgauskis


If smb could take a look at
https://web2py-gae-test.appspot.com/CodeByExample/default/topic_examples/115002/view

I try to trick sf menu to pop up some info for me where user could set
his preferences, or see the tree like stuff which involves LI's.

but it hijacks my LI's and they become like menu :/

could I  instruct it to ignore LIs inside DIVs,
or should I better look at one of tose..
http://pop.seaofclouds.com/

http://www.sitepoint.com/blogs/2009/03/31/make-a-mega-drop-down-menu-with-jquery/


[web2py] Re: Parent -> Child Models in a single form

2010-09-08 Thread mdipierro
PPS.

perhaps the JS code should go in web2py_ajax.html and we should make
this a default widget for list:integer and list:string types. Do we
need a list:double also?

Massimo

On Sep 8, 3:47 pm, mdipierro  wrote:
> To try it. just drop in new empty app under models/ and access the
> person table using appadmin.
>
> On Sep 8, 3:45 pm, Massimo Di Pierro  wrote:
>
> > perhaps this works
>
> >  db_list_string.py
> > 1KViewDownload
>
>


Re: [web2py] Re: Parent -> Child Models in a single form

2010-09-08 Thread geoff
This works for me now.  Indeed it was the formatting.  Probably on my
end.

Of course this does not really solve an 'address' issue if an address is
more than one field, which is the case for both myself and the original
poster.

In any case, that is a wonderful widget!

Best,
Geoff



On Wed, 2010-09-08 at 13:47 -0700, mdipierro wrote:
> To try it. just drop in new empty app under models/ and access the
> person table using appadmin.
> 
> On Sep 8, 3:45 pm, Massimo Di Pierro  wrote:
> > perhaps this works
> >
> >  db_list_string.py
> > 1KViewDownload
> >
> >
> 




[web2py] Re: Parent -> Child Models in a single form

2010-09-08 Thread mdipierro
ps. requires latest trunk code or you may get corrupted data in db.


On Sep 8, 3:47 pm, mdipierro  wrote:
> To try it. just drop in new empty app under models/ and access the
> person table using appadmin.
>
> On Sep 8, 3:45 pm, Massimo Di Pierro  wrote:
>
> > perhaps this works
>
> >  db_list_string.py
> > 1KViewDownload
>
>


[web2py] Re: Parent -> Child Models in a single form

2010-09-08 Thread mdipierro
To try it. just drop in new empty app under models/ and access the
person table using appadmin.

On Sep 8, 3:45 pm, Massimo Di Pierro  wrote:
> perhaps this works
>
>  db_list_string.py
> 1KViewDownload
>
>


[web2py] Re: Parent -> Child Models in a single form

2010-09-08 Thread Massimo Di Pierro

perhaps this works



def ListStringWidget(field,value,**attributes):
_id = '%s_%s' % (field._tablename, field.name)
_name = field.name
if field.type=='list:integer': _class = 'integer'
else: _class = 'string'
requires = field.requires
items=[LI(INPUT(_id=_id,_class=_class,_name=_name,value=v,hideerror=True)) for v in value or ['']]
#if items:
#items[-1][0]['hideerror'] = False
script=SCRIPT("""
// from http://refactormycode.com/codes/694-expanding-input-list-using-jquery
(function(){
jQuery.fn.grow_input = function() {
  return this.each(function() {
var ul = this;
jQuery(ul).find(":text").keypress(function (e) { return (e.which == 13) ? pe(ul) : true; });
  });
};
function pe(ul) {
  var new_line = ml(ul);
  rel(ul);
  new_line.appendTo(ul);
  new_line.find(":text").focus();
  return false;
}
function ml(ul) {
  var line = jQuery(ul).find("li:first").clone(true);
  line.find(':text').val('');
  return line;
}
function rel(ul) {
  jQuery(ul).find("li").each(function() {
var trimmed = jQuery.trim(jQuery(this.firstChild).val());
if (trimmed=='') jQuery(this).remove(); else jQuery(this.firstChild).val(trimmed);
  });
}
})();
jQuery(document).ready(function(){jQuery('#%s_grow_input').grow_input();});
""" % _id)
attributes['_id']=_id+'_grow_input'
return TAG[''](UL(*items,**attributes),script)

db.define_table('person',Field('name'),Field('addresses','list:string',widget=ListStringWidget))


Re: [web2py] Re: Parent -> Child Models in a single form

2010-09-08 Thread geoff
This breaks, I believe formatting is the culprit.  I was not able to fix
it right away.

On Wed, 2010-09-08 at 13:27 -0700, mdipierro wrote:
> A little better:
> 
> 
> def ListStringWidget(field,value,**attributes):
> _id = '%s_%s' % (field._tablename, field.name)
> _name = field.name
> if field.type=='list:integer': _class = 'integer'
> else: _class = 'string'
> requires = field.requires
>  
> items=[LI(INPUT(_id=_id,_class=_class,_name=_name,value=v,hideerror=True))
> for v in value or ['']]
> #if
> items:
> #items[-1][0]['hideerror'] =
> False
>  
> script=SCRIPT("""
> // from http://refactormycode.com/codes/694-expanding-input-list-using-jquery
> (function()
> {
> jQuery.fn.grow_input = function()
> {
>   return this.each(function()
> {
> var ul =
> this;
> jQuery(ul).find(":text").keypress(function (e) { return (e.which
> == 13) ? pe(ul) :
> true; });
>   });
> };
> function pe(ul)
> {
>   var new_line =
> ml(ul);
>  
> rel(ul);
>  
> new_line.appendTo(ul);
>  
> new_line.find(":text").focus();
>   return
> false;
> }
> function ml(ul)
> {
>   var line =
> jQuery(ul).find("li:first").clone(true);
>  
> line.find(':text').val('');
>   return
> line;
> }
> function rel(ul)
> {
>   jQuery(ul).find("li").each(function()
> {
> var trimmed =
> jQuery.trim(jQuery(this.firstChild).val());
> if (trimmed=='') jQuery(this).remove(); else
> jQuery(this.firstChild).val(trimmed);
>   });
> }
> })
> ();
> jQuery(document).ready(function(){jQuery('#
> %s_grow_input').grow_input();});
> """ % _id)
> attributes['_id']=_id+'_grow_input'
> return TAG[''](UL(*items,**attributes),script)
> 
> db.define_table('person',Field('name'),Field('addresses','list:string',widget=ListStringWidget))
> 




[web2py] Re: plugin legacy mysql: generates web2py code to access your mysql legacy db

2010-09-08 Thread mdipierro

> So maybe tonight do you want me to go through the manual and find all
> the missing datatypes and try to add them to the map?

I would not stop you. ;-)

> There are
> possibly some types that are not supported by web2py so not sure what
> to do there. The other possible problem I see is fields like boolean
> that are mapped to char but in the legacy database they are still
> boolean so the DB would have to be migrated to work I think if the
> user plans to put the web2py server over the legacy database as is.

I think boolean can be mapped to CHAR and/or INTEGER. One of them may
just work.
Worth a try.

>
> Ron
>
> Ron


Re: [web2py] Re: Parent -> Child Models in a single form

2010-09-08 Thread geoff
Simply dropping this in does not appear to work, I am getting nothing
where the widget ought to be.

In any case, I don't think this is going to work for my case, as a
simply storing mutltiple strings in a single field isn't what I need.

I have another table with ~20 columns.. nutrition information
specifically.

Two types of things have nutrition information, recipes and basic foods.
Basic foods are simple

Name |  Type  |  Nutrition Table Ref

Recipes are quite a bit more complex, but also need to reference the
Nutrtion Table.

Maybe I am just structuring this wrong entirely and should keep the
Nutrition information in the two tables?  Since I will have to be
querying the Nutrition table to get both basic Foods and Recipes back, I
think it makes sense to keep the Nutrition information separate.

There is only a one to one correspondence between nutrition information
and another row.. the same row in the nutrition table won't be
referenced by two different rows in either the recipe table or the
basic_foods table.

I hope that this explanation makes clear why I believe your list:string
solution (which is great and I will use else where in this app) does not
solve this particular problem.

Thanks
Geoff

On Wed, 2010-09-08 at 12:46 -0700, mdipierro wrote:
> How about this?
> 
> def ListStringWidget(field,value,**attributes):
> _id = '%s_%s' % (field._tablename, field.name)
> _class = isinstance(field.type,str) and field.type or None
> _name = field.name
> requires = field.requires
> items=[LI(INPUT(_id=_id,_class=_class,_name=_name,value=v)) for v
> in value or [''] if v.strip()]
> script=SCRIPT("""
> // from http://refactormycode.com/codes/694-expanding-input-list-using-jquery
> (function(){$.fn.grow_input = function() { return this.each(function()
> { var ul = this;$(ul).find(":text").keypress(function (e) { return
> (e.which == ENTER_KEY) ? enter_press(ul) : true;}); }); };
> var ENTER_KEY = 13;
> function enter_press(ul) { var new_line = make_line(ul);
> remove_empty_lines(ul); new_line.appendTo(ul);
> new_line.find(":text").focus();
>   return false;
> } function make_line(ul) {  var line = $
> (ul).find("li:first").clone(true);   line.find(':text').val('');
>   return line;
> }
> function remove_empty_lines(ul) {  $(ul).find("li").each(function()
> {var trimmed = jQuery.trim($(this.firstChild).val()); if (trimmed=='')
> { $(this).remove();  }  else {$
> (this.firstChild).val(trimmed); } }); }
> })
> ();
> jQuery(document).ready(function(){jQuery('#
> %s_grow_input').grow_input();});
> """ % _id)
> attributes['_id']=_id+'_grow_input'
> return TAG[''](UL(*items,**attributes),script)
> 
> db.define_table('person',Field('name'),Field('addresses','list:string',widget=ListStringWidget))
> 




[web2py] Re: Parent -> Child Models in a single form

2010-09-08 Thread mdipierro

A little better:


def ListStringWidget(field,value,**attributes):
_id = '%s_%s' % (field._tablename, field.name)
_name = field.name
if field.type=='list:integer': _class = 'integer'
else: _class = 'string'
requires = field.requires
 
items=[LI(INPUT(_id=_id,_class=_class,_name=_name,value=v,hideerror=True))
for v in value or ['']]
#if
items:
#items[-1][0]['hideerror'] =
False
 
script=SCRIPT("""
// from http://refactormycode.com/codes/694-expanding-input-list-using-jquery
(function()
{
jQuery.fn.grow_input = function()
{
  return this.each(function()
{
var ul =
this;
jQuery(ul).find(":text").keypress(function (e) { return (e.which
== 13) ? pe(ul) :
true; });
  });
};
function pe(ul)
{
  var new_line =
ml(ul);
 
rel(ul);
 
new_line.appendTo(ul);
 
new_line.find(":text").focus();
  return
false;
}
function ml(ul)
{
  var line =
jQuery(ul).find("li:first").clone(true);
 
line.find(':text').val('');
  return
line;
}
function rel(ul)
{
  jQuery(ul).find("li").each(function()
{
var trimmed =
jQuery.trim(jQuery(this.firstChild).val());
if (trimmed=='') jQuery(this).remove(); else
jQuery(this.firstChild).val(trimmed);
  });
}
})
();
jQuery(document).ready(function(){jQuery('#
%s_grow_input').grow_input();});
""" % _id)
attributes['_id']=_id+'_grow_input'
return TAG[''](UL(*items,**attributes),script)

db.define_table('person',Field('name'),Field('addresses','list:string',widget=ListStringWidget))


[web2py] Re: plugin legacy mysql: generates web2py code to access your mysql legacy db

2010-09-08 Thread ron_m


On Sep 8, 11:56 am, mdipierro  wrote:
> I think I fixed these. One more try?
>

I did a temporary add of the key "longtext," to get it to run further
and found a key error mediumtext which also is at end of line with a
comma so the regular expression parsing the line pulls out
"mediumtext," as the key. I did the same to add a key "mediumtext,"
and it ran to completion.

The MySQL data types chapter is here

http://dev.mysql.com/doc/refman/5.1/en/data-type-overview.html

So maybe tonight do you want me to go through the manual and find all
the missing datatypes and try to add them to the map? There are
possibly some types that are not supported by web2py so not sure what
to do there. The other possible problem I see is fields like boolean
that are mapped to char but in the legacy database they are still
boolean so the DB would have to be migrated to work I think if the
user plans to put the web2py server over the legacy database as is.

Ron

Ron


[web2py] Re: Parent -> Child Models in a single form

2010-09-08 Thread mdipierro
How about this?

def ListStringWidget(field,value,**attributes):
_id = '%s_%s' % (field._tablename, field.name)
_class = isinstance(field.type,str) and field.type or None
_name = field.name
requires = field.requires
items=[LI(INPUT(_id=_id,_class=_class,_name=_name,value=v)) for v
in value or [''] if v.strip()]
script=SCRIPT("""
// from http://refactormycode.com/codes/694-expanding-input-list-using-jquery
(function(){$.fn.grow_input = function() { return this.each(function()
{ var ul = this;$(ul).find(":text").keypress(function (e) { return
(e.which == ENTER_KEY) ? enter_press(ul) : true;}); }); };
var ENTER_KEY = 13;
function enter_press(ul) { var new_line = make_line(ul);
remove_empty_lines(ul); new_line.appendTo(ul);
new_line.find(":text").focus();
  return false;
} function make_line(ul) {  var line = $
(ul).find("li:first").clone(true);   line.find(':text').val('');
  return line;
}
function remove_empty_lines(ul) {  $(ul).find("li").each(function()
{var trimmed = jQuery.trim($(this.firstChild).val()); if (trimmed=='')
{ $(this).remove();  }  else {$
(this.firstChild).val(trimmed); } }); }
})
();
jQuery(document).ready(function(){jQuery('#
%s_grow_input').grow_input();});
""" % _id)
attributes['_id']=_id+'_grow_input'
return TAG[''](UL(*items,**attributes),script)

db.define_table('person',Field('name'),Field('addresses','list:string',widget=ListStringWidget))


[web2py] Re: plugin legacy mysql: generates web2py code to access your mysql legacy db

2010-09-08 Thread ron_m


On Sep 8, 11:56 am, mdipierro  wrote:
> I think I fixed these. One more try?
>
> On Sep 8, 10:30 am, ron_m  wrote:

I think the re match still has a problem but it is closer.

The fault is on a key error for "longtext," which should not be trying
to match on the field type including the comma. This the same
description field of type longtext that appears in table auth_event.

  `description` longtext,

$ python scripts/extract_mysql_models.py user:p...@db_name
Traceback (most recent call last):
  File "scripts/extract_mysql_models.py", line 94, in 
print mysql(m.group(3),m.group(1),m.group(2))
  File "scripts/extract_mysql_models.py", line 80, in mysql
web2py_table_code += "\nField('%s','%s'),"%
(name,data_type_map[d_type])
KeyError: 'longtext,'

Looks like the second (\S+) also pulled in the comma after longtext

hit = re.search('(\S+)\s+(\S+)( .*)?', line)

I added a print name, d_type just before the failure line and got this
output
`id` int(11)
`time_stamp` datetime
`client_ip` varchar(512)
`user_id` int(11)
`origin` varchar(512)
`description` longtext,


Re: [web2py] Re: Parent -> Child Models in a single form

2010-09-08 Thread geoff
Dominic,

Could you give a high level overview of what is going on here and how
you were able to implement the Parent -> Child model in a single form?

Following your links, I wasn't able to discern where/if the input form
was actually accepting values for multiple tables.

I need similar functionality to Portly, and don't really want to go the
iframe route.

Specifically I need to show the 'children' of a table in the same input
form as the parent.

Thanks
Geoff

On Fri, 2010-09-03 at 05:28 -0700, Dominic wrote:
> We (Sahana-Eden) use to do such things with web2py, in connection with
> a RESTful API.
> 
> See for example:
> http://vita.sahanafoundation.org/eden/pr/person/1
> http://vita.sahanafoundation.org/eden/pr/person/1/address
> 
> It can also speak several XML formats, of course, and JSON;
> http://vita.sahanafoundation.org/eden/pr/person/1.xml
> http://vita.sahanafoundation.org/eden/pr/person.json
> 
> The code behind that looks like:
> 
> Person Model:
> http://bazaar.launchpad.net/~flavour/sahana-eden/trunk/annotate/head%3A/models/02_pr.py#L2
> http://bazaar.launchpad.net/~flavour/sahana-eden/trunk/annotate/head%3A/models/04_pr.py#L2
> 
> The actual Person controller:
> http://bazaar.launchpad.net/~flavour/sahana-eden/trunk/annotate/head%3A/controllers/pr.py#L101
> 
> HTML frontend controller:
> http://bazaar.launchpad.net/~flavour/sahana-eden/trunk/annotate/head%3A/models/01_crud.py#L763
> 
> Backend extensions:
> http://bazaar.launchpad.net/~flavour/sahana-eden/trunk/annotate/head%3A/modules/s3xrc.py#L2
> 
> Regards,
> Dominic




[web2py] Re: plugin legacy mysql: generates web2py code to access your mysql legacy db

2010-09-08 Thread mdipierro
I think I fixed these. One more try?

On Sep 8, 10:30 am, ron_m  wrote:
> On Sep 8, 5:40 am, mdipierro  wrote:
>
> > I think I fixed some of this in trunk. Could you print form me the
> > line offending hit? If i see it I can fix the regular expression too.
> > Thanks.
>
> I ran the new version from trunk. The if hit!=None: line added at line
> 74 covers up the problem so now I get a key error on double. Added a
> new key to data_type_map at line 38
>
>         datetime = 'datetime',
>         double = 'double',
>         )
>
> Now it runs to completion and prints out a model.
>
> The line that is causing the problem with hit is line 75 before I
> added above key
>
>                     name, d_type = hit.group(1), hit.group(2)
>
> because hit is None
>
> The listing of the auth_event table is missing the field for
>
>   `description` longtext,
>
> because of the if hit!-None: test from this mysqldump output for the
> auth_event table
>
> CREATE TABLE `auth_event` (
>   `id` int(11) NOT NULL AUTO_INCREMENT,
>   `time_stamp` datetime DEFAULT NULL,
>   `client_ip` varchar(512) DEFAULT NULL,
>   `user_id` int(11) DEFAULT NULL,
>   `origin` varchar(512) DEFAULT NULL,
>   `description` longtext,
>   PRIMARY KEY (`id`),
>   KEY `user_id__idx` (`user_id`),
>   CONSTRAINT `auth_event_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES
> `auth_user` (`id`) ON DELETE CASCADE
> ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
>
> It appears the hit = re.search('(\S+) (\S+) .*', line)
> fails the test because there is nothing after the field type on the
> description line but I am guessing. There is also no longtext type in
> the data_type_map.
>
> It is very close. Of course there could be other key errors because my
> database might not have every data type but I could check the MySQL
> manual for that.


[web2py] Re: plugin legacy mysql: generates web2py code to access your mysql legacy db

2010-09-08 Thread ron_m

On Sep 8, 5:40 am, mdipierro  wrote:
> I think I fixed some of this in trunk. Could you print form me the
> line offending hit? If i see it I can fix the regular expression too.
> Thanks.
>

I ran the new version from trunk. The if hit!=None: line added at line
74 covers up the problem so now I get a key error on double. Added a
new key to data_type_map at line 38

datetime = 'datetime',
double = 'double',
)

Now it runs to completion and prints out a model.

The line that is causing the problem with hit is line 75 before I
added above key

name, d_type = hit.group(1), hit.group(2)

because hit is None

The listing of the auth_event table is missing the field for

  `description` longtext,

because of the if hit!-None: test from this mysqldump output for the
auth_event table

CREATE TABLE `auth_event` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `time_stamp` datetime DEFAULT NULL,
  `client_ip` varchar(512) DEFAULT NULL,
  `user_id` int(11) DEFAULT NULL,
  `origin` varchar(512) DEFAULT NULL,
  `description` longtext,
  PRIMARY KEY (`id`),
  KEY `user_id__idx` (`user_id`),
  CONSTRAINT `auth_event_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES
`auth_user` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;

It appears the hit = re.search('(\S+) (\S+) .*', line)
fails the test because there is nothing after the field type on the
description line but I am guessing. There is also no longtext type in
the data_type_map.

It is very close. Of course there could be other key errors because my
database might not have every data type but I could check the MySQL
manual for that.


Re: [web2py] arbitrary delimiters in templates

2010-09-08 Thread Michele Comitini
great!

2010/9/8 mdipierro :
> I just implemented arbitrary delimiters in web2py trunk. Now you can
> do in a controller:
>
>    def render(filename,**variables):
>        context = globals()
>        context.update(variables)
>        from gluon.template import render
>        return
> render(filename=os.path.join(request.folder,'views',filename),
>                      path=os.path.join(request.folder,'views'),
>                      context=context,delimiters=('{%','%}'))
>
>    def index():
>        return render('default/index.html',message='hello world')
>
> and in default/index.html:
>
>    {%=message%}
>
> This is very new (5 mins ago) so give it a try and let me know if it
> works for you.
> Not sure it is a good idea. Not sure it should stay. Not sure it works
> 100%.
> Anyway, share your thoughts.
>
> Massimo


[web2py] Re: Debian Packaging

2010-09-08 Thread José L .
We're on September 8th, and no news from the packaging. Debian testing
is frozen, which means that we won't see web2py in Debian stable
before a year or two.

I'd like to know if you keep on trying to do the packaging. Also, if
you need help I can create a collaboration group for the packaging in
alioth.debian.org.
And, if you think you can not do it, please let me hijack to ITP, I'd
try to do the packaging, so in the medium term, we can have a working
package to be tested by the Debian community (and its derivatives, as
Ubuntu, Linux Mint, LinEx, etc.)

Regards.
José L.

On 2 jul, 14:41, Mark Breedveld  wrote:
> Thanks, i'm currently busy on a class diagram and a technical report
> to make the application clear. Because it's quite complex, but
> possible.
>
> But in the mean while, I would like to get a list of currently used
> configurations.
> Like this.
> web2py + apache wsgi + postgreSQL (textual configuration)
> web2py (textual configuration) + apache proxy (textual configuration)
> + postgreSQL (textual configuration)
> web2py (textual configuration) + tomcat  (XML configuration)  +
> postgreSQL  (textual configuration) //This will probably not exist,
> just an example
>
> On 18 jun, 15:46, Christopher Steel  wrote:
>
>
>
>
>
>
>
> > Mark,
>
> > That sounds like a great idea.
>
> > Chris
>
> > On Jun 18, 5:33 am, mdipierro  wrote:
>
> > > This is an excellent idea.
>
> > > On Jun 17, 12:35 pm, Mark Breedveld  wrote:
>
> > > > Hello everone,
>
> > > > I've two announcements to make.
> > > > First one is that the Hogeschool Rotterdam (HRO) about to launch a
> > > > test educational environment with web2py.
> > > > Tested on GAE and SUN. So support is on his way.
>
> > > > Secondly I just got an idea with a hole different approach to
> > > > packaging.
> > > > We make a program that manages (create, delete, update, configures)
> > > > multiple instances of web2py with different users and frontend servers
> > > > like apache.
> > > > With configures, I mean the wsgi, fastgci, proxy, but also passwords,
> > > > clustering. etc.
> > > > We upload that single program into the repo.
>
> > > > - This is ideal for universities how want to give every student a
> > > > web2py server.
> > > > - Hosting compagnies (same idea as above)
> > > > - Single users
> > > > And of course our packagers who have not to take up against the
> > > > release frequency of web2py (which is to high for industrial
> > > > packaging).
> > > > Also it easier the get compliant to the guidelines ofdebian/novell
> > > > opensuse.
>
> > > > And last but not least. The current publishing way has not the be
> > > > changed.
>
> > > > I hope the idea is clear and I hope to hear of you al soon.
>
> > > > regards Mark Breedveld,
>
> > > > On May 27, 1:38 pm, Mark Breedveld  wrote:
>
> > > > > My excuse for my late reaction, but you all landed up my spambox of my
> > > > > provider.
> > > > > Which I've solved now.
>
> > > > > Thank you both for your reaction.
> > > > > You're (Jose) right on the best practices.
>
> > > > > In order to set up adebianpackaging proces we should have or do the
> > > > > following
> > > > > - The web2py community should have a maintainer (group)
> > > > >        - Which has manage the releases repo's
> > > > >        - Ajust web2py for use through the repo
> > > > >               - example : disables the buildin update function /
> > > > > splits data into the right locations etc
>
> > > > > - We should release a debain version on short notice after the sources
> > > > > release of Massimo.
>
> > > > > - We could usehttp://build.opensuse.orgwhichis/looksverygood
>
> > > > > Because the maintainer has to invest a lot of time on regular bases.
> > > > > My idea is to launch a vacature for it on the community.
> > > > > And have Massimo make a decide how will become the lead packager,
> > > > > because he will have to work with him
>
> > > > > I will testhttp://build.opensuse.orgtolookifit'susefull for
> > > > > web2py.
> > > > > My guesses is that it will be.
> > > > > I hope to do the testing this weekend.
>
> > > > > Dimo has been started to package gluon map.
> > > > > For futher info on the plans. there is another post on this.
> > > > > Search fordebianon the web2py group and you will found a hole thread
> > > > > on this.
>
> > > > > I hope i have informed you well.
>
> > > > > regards Mark Breedveld,www.markbreedveld.nl
>
> > > > > On 21 mei, 07:37, Trollkarlen  wrote:
>
> > > > > > For packaging i sugest using thehttp://build.opensuse.org.
> > > > > > Its a service where you can package for all mager distros, and have
> > > > > > them all in se same repo.
>
> > > > > > /T
>
> > > > > > On 18 Maj, 08:42, José L.  wrote:
>
> > > > > > > On 17 mayo, 17:32, Mark Breedveld  wrote:
>
> > > > > > > > I've been through the material and it's quite straight forward.
> > > > > > > > So we could keep the current packaging system like it's now.
>
> > > > > > > > But we both now that it ain't suitable fordebianpackaging 

[web2py] book editors

2010-09-08 Thread Massimo Di Pierro
If you have registered with the book app, you should now be able to  
edit it.


Massimo


[web2py] arbitrary delimiters in templates

2010-09-08 Thread mdipierro
I just implemented arbitrary delimiters in web2py trunk. Now you can
do in a controller:

def render(filename,**variables):
context = globals()
context.update(variables)
from gluon.template import render
return
render(filename=os.path.join(request.folder,'views',filename),
  path=os.path.join(request.folder,'views'),
  context=context,delimiters=('{%','%}'))

def index():
return render('default/index.html',message='hello world')

and in default/index.html:

{%=message%}

This is very new (5 mins ago) so give it a try and let me know if it
works for you.
Not sure it is a good idea. Not sure it should stay. Not sure it works
100%.
Anyway, share your thoughts.

Massimo


[web2py] Re: web2py on gae

2010-09-08 Thread Peterle
Yes, the django-nonrel leader made a clear separation between micro-
frameworks and the bigger ones (apps speed versus development speed
and reusability)


-
On 8 Set, 14:45, Richard  wrote:
> seems you are referring to this 
> thread:http://groups.google.com/group/google-appengine-python/browse_thread/...
>
> On Sep 8, 10:25 pm, Peterle  wrote:
>
>
>
> > considerations of..
>
> > 
> > On 8 Set, 13:57, Peterle  wrote:
>
> > > google-appengine-python group, Google Appengine Python Best Framework:
> > > what's about web2py? Interesting the valutations of Waldemar.


[web2py] Re: Expando and Polymodel on GAE?

2010-09-08 Thread mdipierro
Can you please try again using latest trunk?

Massimo



On Sep 4, 7:13 pm, Dave  wrote:
> I tested this, and it does give all contacts when using
>
> > contacts = db(db.contact.id>0).select()
>
> Unfortunately, using
>
> > person = db(db.person.id>0).select()
>
> also returns all the contacts.  I think the intended behavior is to
> just return the contacts that are also a person (as well as those that
> are a sub-class of person.)  Additionally, trying to get at the person-
> specific fields fails in that case, e.g.:> for contact in person
> >    response.flash= contact.first_name
>
> doesn't work.
>
> Also, the syntax is great for supportingpolymodel, but if you want to
> later add support for expando classes, it might be a bit awkward.
>
> ~Dave
>
> On Sep 4, 10:34 am, mdipierro  wrote:
>
> > Can you help testingpolymodel? In trunk:
>
> > db=DAL('gae')
> > db.define_table('contact',Field('address'),polymodel=True)
> > db.define_table('person',Field('first_name'),polymodel=db.contact)
> > db.define_table('company',Field('business_name'),
> >polymodel=db.contact)
>
> > db.person.insert(first_name="John", address="here')
> > db.company.insert(business_name="John Inc", address="there')
> > contacts = db(db.contact.id>0).select() # should lists both persons
> > and conpanies
>
> > Massimo
>
> > On Sep 2, 11:07 am, mdipierro  wrote:
>
> > > I agree thatpolymodelwould be trivial. We would only need to decide
> > > how to pass parameters to db.define_table to determine if a table is a
> > >polymodelor extends an existing one. This would not have an
> > > equivalent in SQL.
>
> > > On Sep 2, 10:40 am, Dave  wrote:
>
> > > > I'm new to Web2py and trying to get a sense for its GAE support,
> > > > beyond the basic "RDBMS-like" functions (which Web2py seems to support
> > > > very well!)
>
> > > > Expando models andPolyModel:  Is there any way to use either of these
> > > > with the DAL currently?  Are there plans to, if not?  PolyModel
> > > > especially seems like it wouldn't be too difficult to add, as it can
> > > > be used identically to the default Model class (all of its magic is
> > > > handled under the hood I think.)
>
> > > > Thanks for the information, and the great work so far.  I'm really
> > > > impressed with how easy web2py is to develop with.
>
>


[web2py] Re: Logging unsuccessful logins

2010-09-08 Thread mdipierro
In trunk now:

auth.settings.login_failed_log = "attempted failed login for email=%
(email)s"


On Sep 8, 5:04 am, Kenneth  wrote:
> Is there a way to log unseccessful logins, with username, tried
> password and things like that?
>
> I´m having some problems with a couple of users not been able to
> login. Or do you have some other ways/ideas to  troubleshoot this?
>
> Kenneth


[web2py] Re: CRUD RBAC problem

2010-09-08 Thread mdipierro
I think this should be considered a bug and I agree with the change.
Anybody opposed?

Massimo

On Sep 7, 11:46 pm, Alexey Nezhdanov  wrote:
> Hi. I think that I found some inconsistency in the topic.
> When you do, say,
> auth.add_permission(group_id) - it assumes the permission name 'any', table
> name empty and record_id 0.
> Which in turn feels like "full admin rights" - any action on any table on
> any record.
> In fact, that gives no permissions whatsoever.
>
> I've came out with the following patch to make it work for me, but since
> that is the very core of RBAC, I'm not sure if that is the right solution or
> if I am looking in the correct direction at all.
>
> --- tools.old.py        2010-09-08 08:40:22.266751051 +0400
> +++ tools.py    2010-09-08 08:41:25.894746181 +0400
> @@ -2420,10 +2420,9 @@
>                   == record_id).select(permission.group_id)
>          groups_required = set([row.group_id for row in rows])
>          if record_id:
> -            rows = self.db(permission.name
> -                            == name)(permission.table_name
> -                     == str(table_name))(permission.record_id
> -                     == 0).select(permission.group_id)
> +            rows = self.db(permission.name.belongs((name,'any'))&
> +
> permission.table_name.belongs((str(table_name),''))&
> +
> permission.record_id.belongs((record_id,0))).select(permission.group_id)
>              groups_required = groups_required.union(set([row.group_id
>                      for row in rows]))
>          if groups.intersection(groups_required):
>
> Regards
> Alexey


[web2py] Re: web2py on gae

2010-09-08 Thread Richard
seems you are referring to this thread:
http://groups.google.com/group/google-appengine-python/browse_thread/thread/fad46eb3745c39c2


On Sep 8, 10:25 pm, Peterle  wrote:
> considerations of..
>
> 
> On 8 Set, 13:57, Peterle  wrote:
>
> > google-appengine-python group, Google Appengine Python Best Framework:
> > what's about web2py? Interesting the valutations of Waldemar.
>
>


[web2py] Re: plugin legacy mysql: generates web2py code to access your mysql legacy db

2010-09-08 Thread mdipierro
I think I fixed some of this in trunk. Could you print form me the
line offending hit? If i see it I can fix the regular expression too.
Thanks.

On Sep 8, 3:03 am, ron_m  wrote:
> On Sep 7, 5:10 pm, mdipierro  wrote:
>
> > If you have a mysql database running locally, please help me test it.
>
> First problem I ran into
> Last line parameters are out of order on mysql() call
> so it outputs incorrect database URL string
> $ python scripts/extract_mysql_models.py user:p...@db_name
> user
> pass
> db_name
> legacy_db = DAL('mysql://pass:db_n...@localhost/user')
>
> Changed last line
>     print mysql(m.group(1),m.group(2),m.group(3))
> to be
>     print mysql(m.group(3),m.group(1),m.group(2))
>
> Next run I get a key error on the data_type_map
> $ python scripts/extract_mysql_models.py user:p...@db_name
> user
> pass
> db_name
> Traceback (most recent call last):
>   File "scripts/extract_mysql_models.py", line 100, in 
>     print mysql(m.group(3),m.group(1),m.group(2))
>   File "scripts/extract_mysql_models.py", line 82, in mysql
>     web2py_table_code += "\n    Field('%s','%s'),"%
> (name,data_type_map[d_type])
> KeyError: 'datetime'
>
> Thinking I could fix this I added a line to the data_type_map last 2
> lines so you get a reference point are
>         timestamp = 'datetime',
>         datetime = 'datetime',
>         )
>
> Next run produces
> $ python scripts/extract_mysql_models.py user:p...@db_name
> user
> pass
> db_name
> Traceback (most recent call last):
>   File "scripts/extract_mysql_models.py", line 101, in 
>     print mysql(m.group(3),m.group(1),m.group(2))
>   File "scripts/extract_mysql_models.py", line 80, in mysql
>     name, d_type = hit.group(1), hit.group(2)
> AttributeError: 'NoneType' object has no attribute 'group'
>
> Added a print line statement just above line 80 and it stops on the
> mysqldump of the auth_event table at line
>   `description` longtext,
>
> So it looks like hit is empty because there is no match on this line
> (print line and flush commented out
>                 hit = re.search('(\S+) (\S+) .*', line)
>                 # print line
>                 # if hit != None:
>                 #   print hit.group(1), hit.group(2)
>                 # sys.stdout.flush()
>                 name, d_type = hit.group(1), hit.group(2)
> Added a test for hit != None and see what hit.group(1) and
> hit.group(2) are they are the name and type except for this line.
> Looks like longtext needs to be added to the type dictionary but not
> getting there because of this failure.
>
> Added a test for hit == None with continue to skip around this code
>
> Next failure is in the CODE() call, global name CODE is not defined.
> Looks like a missing import - I am just running from the bash shell.
>
> I don't really understand why the regular expression filling hit fails
> but then I am weak in that area with Python.
>
> Here is the complete mysqldump CREATE TABLE stanza for auth_event
> I am using mysql 5.1.41 on Ubuntu 10.04 with all patches.
>
> CREATE TABLE `auth_event` (
>   `id` int(11) NOT NULL AUTO_INCREMENT,
>   `time_stamp` datetime DEFAULT NULL,
>   `client_ip` varchar(512) DEFAULT NULL,
>   `user_id` int(11) DEFAULT NULL,
>   `origin` varchar(512) DEFAULT NULL,
>   `description` longtext,
>   PRIMARY KEY (`id`),
>   KEY `user_id__idx` (`user_id`),
>   CONSTRAINT `auth_event_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES
> `auth_user` (`id`) ON DELETE CASCADE
> ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
>
> Time to catch some ZZZs it is 1 am
>
> Ron


[web2py] Re: Django Sentry

2010-09-08 Thread mdipierro
It would not be difficult to do something like this in web2py. All
events are already in the auth_event table and tickets can be moved to
db using scripts/tickets2db.py

Any volunteers?


On Sep 8, 3:24 am, Adi  wrote:
> http://github.com/dcramer/django-sentry
>
> Interesting way to track tickets and logs real-time.


[web2py] Re: Translate texts Email and Password in login page

2010-09-08 Thread mdipierro
You can still do

db.auth_user.email.label=T('email')
db.auth_user.password.label=T('password')

Did you try this?



On Sep 8, 4:53 am, Kenneth  wrote:
> I´m pretty sure this worked before but now i can´t get the texts Email
> and Password translated on the login page.
>
> Kenneth


[web2py] Re: web2py on gae

2010-09-08 Thread Peterle
considerations of..


On 8 Set, 13:57, Peterle  wrote:
> google-appengine-python group, Google Appengine Python Best Framework:
> what's about web2py? Interesting the valutations of Waldemar.


[web2py] web2py on gae

2010-09-08 Thread Peterle
google-appengine-python group, Google Appengine Python Best Framework:
what's about web2py? Interesting the valutations of Waldemar.


Re: [web2py] Re: Permissions on records

2010-09-08 Thread Johann Spies
Thanks.  That brings some light.  I was trying to fit it into a controller.

Regards
Johann

-- 
    "Be not deceived; God is not mocked: for whatsoever a
     man soweth, that shall he also reap."
                                  Galatians 6:7


[web2py] Logging unsuccessful logins

2010-09-08 Thread Kenneth
Is there a way to log unseccessful logins, with username, tried
password and things like that?

I´m having some problems with a couple of users not been able to
login. Or do you have some other ways/ideas to  troubleshoot this?


Kenneth


[web2py] Translate texts Email and Password in login page

2010-09-08 Thread Kenneth
I´m pretty sure this worked before but now i can´t get the texts Email
and Password translated on the login page.


Kenneth


[web2py] Django Sentry

2010-09-08 Thread Adi
http://github.com/dcramer/django-sentry

Interesting way to track tickets and logs real-time.


[web2py] Re: plugin legacy mysql: generates web2py code to access your mysql legacy db

2010-09-08 Thread ron_m


On Sep 7, 5:10 pm, mdipierro  wrote:
> If you have a mysql database running locally, please help me test it.
>

First problem I ran into
Last line parameters are out of order on mysql() call
so it outputs incorrect database URL string
$ python scripts/extract_mysql_models.py user:p...@db_name
user
pass
db_name
legacy_db = DAL('mysql://pass:db_n...@localhost/user')

Changed last line
print mysql(m.group(1),m.group(2),m.group(3))
to be
print mysql(m.group(3),m.group(1),m.group(2))

Next run I get a key error on the data_type_map
$ python scripts/extract_mysql_models.py user:p...@db_name
user
pass
db_name
Traceback (most recent call last):
  File "scripts/extract_mysql_models.py", line 100, in 
print mysql(m.group(3),m.group(1),m.group(2))
  File "scripts/extract_mysql_models.py", line 82, in mysql
web2py_table_code += "\nField('%s','%s'),"%
(name,data_type_map[d_type])
KeyError: 'datetime'

Thinking I could fix this I added a line to the data_type_map last 2
lines so you get a reference point are
timestamp = 'datetime',
datetime = 'datetime',
)


Next run produces
$ python scripts/extract_mysql_models.py user:p...@db_name
user
pass
db_name
Traceback (most recent call last):
  File "scripts/extract_mysql_models.py", line 101, in 
print mysql(m.group(3),m.group(1),m.group(2))
  File "scripts/extract_mysql_models.py", line 80, in mysql
name, d_type = hit.group(1), hit.group(2)
AttributeError: 'NoneType' object has no attribute 'group'

Added a print line statement just above line 80 and it stops on the
mysqldump of the auth_event table at line
  `description` longtext,

So it looks like hit is empty because there is no match on this line
(print line and flush commented out
hit = re.search('(\S+) (\S+) .*', line)
# print line
# if hit != None:
#   print hit.group(1), hit.group(2)
# sys.stdout.flush()
name, d_type = hit.group(1), hit.group(2)
Added a test for hit != None and see what hit.group(1) and
hit.group(2) are they are the name and type except for this line.
Looks like longtext needs to be added to the type dictionary but not
getting there because of this failure.

Added a test for hit == None with continue to skip around this code

Next failure is in the CODE() call, global name CODE is not defined.
Looks like a missing import - I am just running from the bash shell.

I don't really understand why the regular expression filling hit fails
but then I am weak in that area with Python.

Here is the complete mysqldump CREATE TABLE stanza for auth_event
I am using mysql 5.1.41 on Ubuntu 10.04 with all patches.

CREATE TABLE `auth_event` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `time_stamp` datetime DEFAULT NULL,
  `client_ip` varchar(512) DEFAULT NULL,
  `user_id` int(11) DEFAULT NULL,
  `origin` varchar(512) DEFAULT NULL,
  `description` longtext,
  PRIMARY KEY (`id`),
  KEY `user_id__idx` (`user_id`),
  CONSTRAINT `auth_event_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES
`auth_user` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;

Time to catch some ZZZs it is 1 am

Ron