[web2py] Re: Class-based controllers and prefixes in wizard

2011-05-18 Thread Dmitriy
Thanks Bruno, this is an interesting optimisation!

On May 15, 9:16 pm, Bruno Rocha  wrote:
> in your controllers you will just need to instantiate your classes and work 
> with inheritance,

But I need to have some basic controller class. It must expose methods
as callable URLs. Do you have any idea how to implement such class?


Re: [web2py] Re: Class-based controllers and prefixes in wizard

2011-05-15 Thread Bruno Rocha
The functional case has 15 methods. In the first case there are 3
classes and 8 methods (more compact and readable). Why do I need to
repeat some methods in the successors?

Now, with new web2py in trunk you can create this logic under /modules (as
normal Python modules)

in your controllers you will just need to instantiate your classes and work
with inheritance,
take a look the new "global" scope in trunk, now you can bind your "db" and
other application specific objects as request,session, response in to a
global object called "current" so you can access that objects in modules.

I am doing some tests and I will use DAL to create my ORM too using the new
importer and global scope.

http://martin.tecnodoc.com.ar/default/post/2011/05/13/20_optimize-your-web2py-app-using-the-new-import-method


--
Bruno Rocha
[ About me: http://zerp.ly/rochacbruno ]


[web2py] Re: Class-based controllers and prefixes in wizard

2011-05-15 Thread Dmitriy
Thanks all for the prompt answers! Massimo, I think that the flag in
Wizard can solve the prefixes issue.

Regarding the class-based controllers.

pbreit, the components and the load function can help me in the
composition, but can't help in the  inheritance.

Thanks for a good example, Bruno! I agree with you that domain
specific logic must be located in the Model and Flow specific logic
must be located in the Controller.
For such case we need ORM in the Model, but we have DAL. OK, suppose
we  have created an ORM over the DAL. It will give me a possibility to
inherit domain (model) specific logic. But I want to inherit work-flow
logic too.

Here is an example.
Suppose we have a class/table hierarchy:

Person<-Customer<-VipCustomer. Customer can Purchase something, Vip
Customer can Purchase goods with discount and get a branded gift.

1. The case of class-based controllers:

class Person(BaseController):
   def Create()
   def Read()
   def Update()
   def Delete()

class Customer(Person):
   def Purchase()

class VipCustomer(Customer):
   def Create()  #define discount
   def Purchase() #purchase a product with discount and direct a
user to a gift page
   def SelectGift()#select a gift after purchase

2. The case of function-based controllers:
Person_Create()
Person_Read()
Person_Update()
Person_Delete()

Person_Create()
Person_Read()
Person_Update()
Person_Delete()
Person_Purchase()

VipCustomer_Create()
VipCustomer_Read()
VipCustomer_Update()
VipCustomer_Delete()
VipCustomer_Purchase()
VipCustomer_SelectGift()

The functional case has 15 methods. In the first case there are 3
classes and 8 methods (more compact and readable). Why do I need to
repeat some methods in the successors?


[web2py] Re: Class-based controllers and prefixes in wizard

2011-05-14 Thread Massimo Di Pierro
On May 14, 7:53 am, Dmitriy  wrote:
> First of all, I would like to thank Massimo Di Pierro and other
> developers for the excellent framework!
>
> I have several questions:
>
> 1. Is it possible to create class-based controllers instead of
> function-based? The class will expose their public methods for calling
> like functions. I want to make a controllers hierarchy. This will give
> a possibility to inherit methods from ancestors following the DRY
> principle :)

It is not possible. It is not clear to me what problem is that trying
to solve. Could you make an example? Perhaps there is a web2py way.

> Maybe you know, that Django has already implemented such functionality
> in the 1.3 
> version:http://docs.djangoproject.com/en/dev/topics/class-based-views/
> I think that we need to get such functionality in the web2py too!
>
> 2. Is it possible to remove 'T_' and 'F_' prefixes from the 'New
> application wizard'? They are really not needed in real tables and
> fields.

We are trying to make the wizard fool proof. It should be possible to
remove them. Perhaps add an admin config flag to disable them. I will
look into it.


[web2py] Re: Class-based controllers and prefixes in wizard

2011-05-14 Thread Anthony
On Saturday, May 14, 2011 8:53:25 AM UTC-4, Dmitriy wrote: 
>
> 2. Is it possible to remove 'T_' and 'F_' prefixes from the 'New 
> application wizard'? They are really not needed in real tables and 
> fields.

 
If you really don't want them, you could probably edit the make_table() 
function in /web2py/applications/admin/controllers/wizard.py.
 


[web2py] Re: Class-based controllers and prefixes in wizard

2011-05-14 Thread pbreit
You can kind of get that type of structure with components and LOAD():
http://web2py.com/book/default/chapter/13?search=load%28#Components

Since the import wizard is primarily for newer users, I think the t_ and f_ 
are important to avoid reserved word conflicts. If you still want to use it, 
you could edit the table/field names and then delete all the database files 
(which will get regenerated on the next run).

I typically discourage anyone from using the wizard. I think it's useful, 
even for newbies, to manually create models.