Hey,
2010/10/31 cd34 <[email protected]>:
> On Oct 31, 2:14 am, Alexandre Conrad <[email protected]>
> wrote:
>> I would make sure a site and a subsite is a "resource" in Routes.
>> RESTful really means that you are using the verbs available in HTTP,
>> that is, GET, POST, UPDATE, DELETE without wasting name spaces like
>> addsite, delsite, etc., in your URL. RESTful doesn't necessarily mean
>> that you must *not* use a query in the URL (like ?site_id=1).
>>
>> So, for your sites, I would have the following CRUD:
>> Create: /admin/site/ (POST)
>> Read: /admin/site/id (GET)
>> Update: /admin/site/id (PUT)
>> Delete: /admin/site/id (DELETE)
>>
>> Meaning that for your subsites, you could have the following CRUD:
>>
>> Create: /admin/subsite (POST) (where parent ID and any other info
>> would be in the POST body)
>> Read: /admin/subsite/id (GET)
>> Update: /admin/subsite/id (PUT)
>> Delete: /admin/subsite/id (DELETE)
>
> I looked at this and the same real issue persists with CRUD/Restful.
> My terminology was wrong - this is for a client facing application
> where I wanted clean URLs.
>
> How does one signify a subsite is being added to a site? The only way
> I can see it being done is adding another route.
The file config/routing.py is meant to be edited and adapted to your
needs. I have seen too many people boxing them self with the default
Pylons routes, myself included some time ago. Right now I'm working on
an application with config/routing.py having pages full of route maps.
And it's not as "messy" as one could imagine.
> With the default routes,
> /admin/subsite/1
> would indicate that you are editing subsite 1, not adding subsite to
> site 1
When you create something, like a subsite, you really should want the
client (browser, script, ...) to send a POST request. If you intend to
create a new subsite with a GET with "/admin/subsite?site_id=1" as the
path, how would you handle a user hitting multiple times the "reload"
button? You'd create as many subsites as the number of times the
reload button was hit and that's probably not what you want.
So as I said in my previous mail, I would create a new subsite with a
POST request to /admin/subsite where the request's body would have
"site_id=1". So from your controller the action "create" would get the
paren'ts site ID from the request's body: request.POST["site_id"].
> It seems no matter what I come up with, I'm having to alter routes to
> handle things and it just seemed like I was overlooking something.
> I've got workarounds, but, I was just curious how other people have
> handled similar situations.
>
> Having clean urls just seems nicer, but, I think in this case I am
> relegated to using ?site_id=1. If I find a better way, I can always
> rewrite that portion.
By the way, I realize that you said in your original mail that the
controller is "admin" (AdminController). I think that's what might be
your problem. You should have a controller per entity, such as "site"
(SiteController) and "subsite" (SubsiteController). Each having all
the necessary CRUD methods (Pylons actions) like "paster
restcontroller subsite subsites" would create for you. You would then
just need to add map.resource("site", "sites", path_prefix="/admin/")
and map.resource("subsite", "subsites", path_prefix="/admin/") in
routing.py. (I have never played with path_prefix kwarg, so you might
want to double check how it behaves). This way you wouldn't need an
AdminController at all if all you want to have is the prepending
/admin/ path in your URL to make it pretty.
HTH,
--
Alex | twitter.com/alexconrad
--
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.