On Mon, May 25, 2009 at 2:10 AM, Cezary Biele<[email protected]> wrote:
> On Mon, May 25, 2009 at 4:04 AM, Mike Orr <[email protected]> wrote:
>
>>
>> I assume the middle component is what you want to save or add, and
>> that the action will know what to do with it.
>>
>> map.connect("panel", "/panel/{what}/{action}",
>>    controller="panel_gallery")
>>
>> def  save(self, what):
>>
>> def add(self, what):
>>
>> You'll have to see how Pylons capitalizes controller names with "_" in
>> them.  I'd assume "Panel_galleryController'.
>>
>> Note that this route will match any 3-component URL starting with
>> "/panel", including any that you may have intended for other routes.
>> As always, put the most specific routes first.
>
> Thanks for your answers,
>
> I think I explained my idea wrong ;-)
>
> I want to have administration panel with different sections for managing
> aspects of the user account (like gallery section, overall settings,
> guestbook entries and so on) and I thought that the best idea is to have
> different controllers for handling each section (similarly as I have
> different controller for managing i.e guestbook and gallery).
>
> the solution given by Tomasz Narloch was to use:
>
> map.connect('/panel/overall/{action}/{id}', controller='panel/overall',
> action='index', id=None, _minimize=True)
>
> seems to do the trick (thoughI haven't tried that yet, will do that
> tonight), I assume I should manually add entries for all my panel secions
> like::
>
> # for gallery management
> map.connect('/panel/gallery/{action}/{id}', controller='panel/gallery',
> id=None, _minimize=True)
>
> # for guestbook management
> map.connect('/panel/guestbook/{action}/{id}', controller='panel/gallery',
> id=None, _minimize=True)
>
> I was thinking if it is possible to accomplish the same automatically.

You can add them in a 'for' loop.  (I assume you want the
'panel/guestbook' controller when the section is guestbook.)

for section in ['gallery', 'guestbook']:
    map.connect('/panel/%s/{action}/{id}' % section,
        controller = 'panel/%s' % section,
        id=None, _minimize=True)

PS. Minimize is evil!  It's too easy for a minimizing route to match
an unintended URL, which can lead to hard-to-diagnose bugs.  It's
better to add extra routes for the minimized URLs.

You could pack it all into one route this way:

def panel_function(environ, match_dict):
    section = match_dict["section"]
    if section not in ["gallery", "guestbook"]:
        return False    # The route refuses this URL.
    match_dict["controller"] = "panel/%s" % section
    return True
conditions = {"function": panel_function}
map.connect("/panel/{section}/{action}/{id}", conditions=conditions)

I have no idea what effect _minimize=True might have on that.

-- 
Mike Orr <[email protected]>

--~--~---------~--~----~------------~-------~--~----~
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