You can keep the url map in one single file but still define the classes
in separate files. You could probably even push the mapping for those urls
into the 'subapp' and append it's urls to the main url. You would still
need the full url, unlike a true subapp, and you would need to be careful
with the append because order matters.
I agree it would be nice to be able to use a regex to match on a url and
pass it to a subapp.
code.py
----------------------------------------
import web
import container
urls = (
"/containers/(\w+)/", container.FullList,
"/containers/(\w+)/attribute/" , container.Attributes,
"/containers/(\w+)/attribute/value/", container.AttributeValue,
"/containers/(\w+)/items/(\w+)/", container.Item,
"/main", "Main",
)
app = web.application(urls, globals())
class Main:
def GET(self):
return 'Main App page'
if __name__ == "__main__":
app.run()
container.py
------------------
class FullList:
def GET(self, container_id):
return "Full list. container:%s"%(container_id)
class Attributes:
def GET(self, container_id):
return "Attributes. container:%s"%(container_id)
class AttributeValue:
def GET(self, container_id):
return "AttributeValue. container:%s"%(container_id)
class Item:
def GET(self, container_id, item_id):
return "Item. container:%s item:%s"%(container_id, item_id)
On Wed, Oct 12, 2011 at 11:07 AM, Tony <[email protected]> wrote:
> Hello,
>
> I'm trying to write a REST-style backend using webpy and wondered if
> anyone had suggestions or examples. The app deals with data sets in
> the 10k to 100k range of similar items, with the need to select out
> views of the data with different groupings and orders based on the
> properties of the items and return JSON for client side parsing. So
> what I wanted to do was something like this:
>
> * /{container-uuid}/ (general listing of items)
> * /{container-uuid}/attribute (listing of items with the attribute)
> * /{container-uuid}/attribute/value (listing of items with the
> specific attribute value)
> * /{container-uuid}/{item-id} (summary listing of single item)
> * /{container-uuid}/{item-id}/detailed (detailed listing of a
> single item)
>
> I wanted to use the GET parameters for iterating through the result
> sets (using jqGrid for the HTML view) to handle skip, offset, sort
> order, etc. When I started to try doing this I ran into an
> inconsistency in the subapp regex handling, basically you can't use
> regex in subapps:
>
> https://github.com/webpy/webpy/issues/12
>
> Trying to keep everything in one giant python script makes the code
> difficult to read and it will take some careful planning to break
> things out into libraries or functions. Either that or I'll have to
> put all the parameters into GET/POST/DELETE variables which is not
> what I want to do either. Has anyone got a good template or example
> for doing this kind of thing?
>
> Tony
>
> --
> You received this message because you are subscribed to the Google Groups
> "web.py" 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/webpy?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"web.py" 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/webpy?hl=en.