Created
January 7, 2012 05:54
-
-
Save j2labs/1573929 to your computer and use it in GitHub Desktop.
Backbone API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from brubeck.request_handling import Brubeck, AutoAPIBase, WebMessageHandler | |
from brubeck.queryset import DictQueryset | |
from brubeck.templating import Jinja2Rendering, load_jinja2_env | |
from dictshield.document import Document | |
from dictshield.fields import StringField, IntField, BooleanField | |
### Todo Model | |
class Todo(Document): | |
done = BooleanField(default=False) | |
order = IntField() | |
text = StringField() | |
### API Implementation | |
class TodosAPI(AutoAPIBase): | |
queries = DictQueryset() | |
model = Todo | |
def render(self, **kwargs): | |
return super(TodosAPI, self).render(hide_status=True, **kwargs) | |
### Landing Page | |
class TodosHandler(Jinja2Rendering): | |
def get(self): | |
return self.render_template('index.html') | |
### Instantiate app instance | |
app = Brubeck( | |
mongrel2_pair=('ipc://brubeck_incoming', 'ipc://brubeck_outgoing'), | |
handler_tuples=((r'^/$', TodosHandler),), | |
template_loader=load_jinja2_env('./templates') | |
) | |
### Register API with instance | |
app.register_api(TodosAPI) | |
### Rev the engine. | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment