On Tue, Feb 7, 2012 at 4:50 PM, amiroff <amir...@gmail.com> wrote:
>
> Thanks Mariano for answers,
>
> On Feb 7, 2:11 pm, Mariano Reingart <reing...@gmail.com> wrote:
> >
> > You can have your shared settings in a common python module, and then
> > import it in your model:
> >
> > from shared_settings import DB_URI
> > db=DAL(DBURI)
>
> This is obvious, what I was looking for was a web2py way of doing
> this, ie without imports, using autoload or exec. Isn't a constant
> defined in one of my apps' models available to other apps' models
> thanks to auto execution of models?
No, it isn't. Again, this may be a confusion on terminology.
Having available other app constants/models may be a bad idea
(consider DBURI, it should be unique per app or your tables will
overlap).
Remember, apps are "projects" in web2py. "django apps" are more
similar to "web2py plugins".
web2py let you have several apps in the same site, but they are
separate entities.

You can see the official book for a more deep explanation:

http://www.web2py.com/books/default/chapter/29/12#Component-plugins

Sorry if I'm not clear enough, English is not one of my best skills,
fell free to provide and example and we can analyse it.

>
> > There is not direct support for shared views now, mainly because I think
> > you may be confused about terminology.
> > web2py "applications" are the similar to django "projects", so it would be
> > not required to share views across applications in web2py.
> >
> > Anyway, a more flexible view rendering system should be possible
> > (response.render already receives the template filename, extending this to
> > include a path should not be a major issue, see compileapp.run_view_in)
>
> I'm sure Massimo will take on this one because I've counted many other
> users requesting or asking for project-wide layouts/views. So for now,
> I guess it's not ready yet.
>

Again, maybe you mean site-wide layouts/views.
Project wide layouts are currently available (they are the views in an app).
For example, using the layout plugin you can change the layout of the
entire app:

http://web2py.com/layouts

And yes, site-wide layouts would be helpful but they are not available
yet, I'll write down this in my TODO list ;-)

>
> >
> > > 3. What is the best way to create something like front controller? It
> > > should include common functions for all other controllers in all apps.
> >
> > According the "wikipedia" definition of  front controllers, web2py
> > models/controllers implement that pattern, as they "provides a centralized
> > entry point for handling requests"
> > You can put common application-wide functions in the models, and specific
> > function in the controllers, including caching, redirecting, security, etc.
>
> Umm, no. I am not talking about common app-wide setting, what I meant
> was project wide common controller functions, like requiring login on
> all (but some) controllers. It would consolidate all request handling
> by channeling requests through a single handler which in turn would
> carry out common behavior, which can be modified at runtime.
>

Again, project == app in web2py, so you can implement project wide
functions just putting it in a controller or model, see the following
example to change CRUD settings based on the function called:

http://code.google.com/p/web2conf/source/browse/controllers/activity.py#6

For example, if you want that all the functions in a controller to
require a valid login, just write at the beginning of your controller:

if not auth.is_logged_in():
    raise HTTP(403,"Not authorized")

You also can use routes.py to have a single entry point and then
dispatch each request as you like.

Maybe if you have an example, we could translate it to web2py.

>
> >
> > > 4. What are the alternatives to scopes (Rails) or custom model
> > > managers (Django) and model callbacks/observers (Rails) or signals
> > > (Django)?
> >
> > I do not remember any, but there are some discussions on the developer list
> > to implement some features like signals for data updates.
> > Also, there are some workaround depending in your needs.
>
> These are very essential, I am sure there must be some undocumented
> features for this.

There are some hooks like oncreate/onupdate/ondelete for forms,
update/compute properties for fields, etc.

There may be other methods too, but I'm not aware of them.

> >
> > > 5. What is the best place to define view helpers and how to pass them
> > > to views?
> >
> > View helpers aren't mandatory in web2py (as a python template language is
> > used).
> > But, if you want to have functions to use in the views, you can put then in
> > the models or in modules.
>
> Well, putting view logic in models is a no-no but helper modules would
> be of use. Thanks for the tip!

In the model, you can use represent & widget field properties to do
some basic formatting, like the one done in other frameworks class
model methods.
web2py also comes with handy functions like prettydate in gluon.tools,
but you can define your helpers as your wish.

>
>
> >
> > > And last, is Py3k compatible version under works or planned?
> >
> > Yes, there are two py3k "unnoficial" versions under development:
> >
> > a proof of concept running under python 
> > 3.2:http://code.google.com/r/reingart-web2py/source/browse/?name=py3k
> >
> > a manual attempt to make a python 3 alternative 
> > codebase:https://github.com/cannatag/web2py-python3
>
> Great to hear that, keep it up please.
>
> Cheers,
> Metin.
>
>

Best regards,

Mariano Reingart
http://www.sistemasagiles.com.ar
http://reingart.blogspot.com

Reply via email to