Patterns can be farily complex. Assuming

db.define_table('person',Field('name'))
db.define_table('pet',Field('owner',db.person),Field('name'),Field('info'))

you can do

patterns = [
  '/person-by-id/{person.id}',
  '/person-by-id/{person.id}/:field',
  '/person-by-id/{person.id}/pets[owner.person],
  '/person-by-id/{person.id}/pet[owner.person]/{pet.name.startswith},
  '/person-by-id/{person.id}/pet[owner.person]/
{pet.name.startswith}/:field,
]

you get the idea. I will add a pattern to get list of readable fields.

What I am not convinced yet is this part

def api():
    def GET(*args,**vars): ...

should or should we not parse request.args and request.vars and pass
them to the GET and POST functions?
If there is no match it is difficult to catch the errors. It adds some
overhead. Yet it is handy to be able to do

def api():
    def GET(table-name,record_id): return db[table_name]
(record_id).as_dict()

and have web2py deal with errors.



On Mar 13, 3:28 pm, mart <[email protected]> wrote:
> this is interesting...
>
> I added the function in a app's default controller, the did this:
>
> for x in [item.strip().split('/')  for item in urllib2.urlopen('http://
> 127.0.0.1:8000/appRM/default/api/list.json')]:
>         for item in [string.strip(y,'", "') for y in x[1:-1]]:
>              blablabalbla...
>
> Just from the output of that, lots can be done in script... :)
>
> I have something in mind, but I'm missing something... How would I get
> additional field information? I.e the field type?
>
> And in a more general sense, how and where do I set a pattern?
>
> I figure with just a couple more lines, I would have enough info to
> create a VIEW of those table or even the model itself (hopefully
> without having to know/remember anything too specific about the
> tables)
>
> I.e. something that looks a little like this but with more stuff to
> make better/more specific statement...
>
> CREATE VIEW "test" AS select * from data
>
> Thanks,
> Mart
>
> On Mar 13, 10:04 am, "[email protected]"
>
>
>
>
>
>
>
> <[email protected]> wrote:
> > Would not it be better to do this?
>
> > @request.get()
> > <@request.post()>
> > <@request.put()>
> > <@request.delete()>
> > def api():
> >     (...)
> >     return dict(...)
>
> > _____________________________________________
> > *Gilson Filho*
> > *Web Developerhttp://gilsondev.com*

Reply via email to