Esempio n. 1
0
File: app.py Progetto: Maillol/woof
from woof.resource import *


# models.py
class Book(Resource):
    title = StringField()
    abstract = StringField()
    chapters = ComposedBy('Chapter')

class Chapter(Resource):
    number = IntegerField(weak_id=True)
    title = StringField()


# controllers.py
root_url = EntryPoint('/api')
root_url.crud('/books/[id]', Book)
root_url.crud('/books/{book_id}/chapters/[number]', Chapter)

"""
@root_url.post('/books/{book_id}/chapters')
def create_chapter(body, book_id):
    body["book_id"] = book_id
    Chapter(**body).save()


@root_url.get('/books/{book_id}/chapters')
def get_chapters(book_id):
    return Chapter.select().where(Chapter.book_id == book_id)

Esempio n. 2
0
#!/usr/bin/env python3

from woof.url import EntryPoint
from .models import Hotel, Person, Room

root_url = EntryPoint('/api')

root_url.crud('/hotels/[id]', Hotel)
root_url.crud('/hotels/{hotel_id}/rooms/[number]', Room)
root_url.crud('/persons/[id]', Person)