If someone absolutely, positively, did not want to redirect, then I
agree with you.  It probably should be refactored.  But no one should
be afraid to post code.  We all wanna help :-).

The easiest thing to do in this case, is to have your action be a
proxy to some other method that does it's magic.  If your method isn't
too coupled to your controller, this is easy.

# Before ...
class MyController(BaseController):

    def double(self, x):
        return '%d' % int(x) * 2

# After ...

def double(x):
    return '%d' % int(x) * 2

class MyController(BaseController):
    def double(self, x):
        return double(x)

But, if you're going to do something this crafty, you could also just
write a mixin class.

class MyMixin:
    def double(self, x):
        return '%d' % int(x) * 2

class MyController(BaseController, MyMixin):
    ...

Alternatively, you could just write a class that is a controller and
derive from it.

class MyController(BaseController):
    def double(self, x):
        return '%d' % int(x) * 2

class MyDerivedController(MyController):
    '''Yay.  This class and other derived classes have a double method
now.'''
    pass


So, in a nutshell you can:

* decouple your method from your controller, making your original
action a proxy to the new decoupled function.
* mixin
* inheritance

Good luck.

jw

On Jan 16, 3:29 am, wolf <[EMAIL PROTECTED]> wrote:
> not wanting to discourage other authors, but don't you think that the
> solution posted above is quite heavy and almost a bit black-magical?
> don't you think it is quite hard to read & relies a bit too heavily on
> implementation details? when all that this code achieves (assuming it
> does) is something you are IMHO much better off *avoiding* to do in
> the first place? see my original response to the OP for considerations
> about how to avoid the issue of 'cross-calling controller code'
> altogether.
>
> in short: you shouldn't be doing that, it's not the way to go. calling
> controller A from controller B is * too hard to do in pylons, * not
> especially useful, * of doubtful (architectural) merit.
>
> you can do what you want without allowing another brittle code beast
> into your application by doing a simple refatoring of code. maybe you
> can argue it should be posssible, maybe other frameworks make it
> painless. but should you resort to throwing a hog like the one posted
> at this problem? i doubt it.
>
> _wolf
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to