def root(self, request, **kwargs): try: name = kwargs.get('name', None) items = Item.lookup_list(name=name) return Ok([{'id': i.id, 'name': i.name} for i in items]) except Exception as e: return BadRequest('Internal error: {}'.format(unicode(e)))
def root(self, request): return Ok('<!DOCTYPE html>' ' <html>' ' <head><title>Dummy Root</title></head>' ' <body>' ' <h1>This is the Dummy Root. F**k yeah!</h1>' ' </body>' ' </html>')
def test_send_back(self): request = DummyRequest(['/test'], '') result = Ok('Testing', {'content-type': 'application/json'}) request = request result = yield self.c.sendback(result, request) self.assertEqual(result, None) self.assertEqual(request.written[0], 'Testing')
def create(self, request, **kwargs): name = kwargs.get('name', None) if not name: return BadRequest('Name not filled') try: return Ok('{}'.format(Item.upsert(name=unicode(name)))) except Exception as e: return BadRequest('Internal error: {}'.format(unicode(e)))
def root_deferred(self, request, **kwargs): name = kwargs.get('name', None) d = ItemsManager.lookup_items(name=name) d.addCallback(lambda items: Ok([{ 'id': i.id, 'name': i.name } for i in items])) d.addErrback( lambda e: BadRequest('Internal error: {}'.format(unicode(e)))) return d
def create_deferred(self, request, **kwargs): name = kwargs.get('name', None) if not name: return BadRequest('Name not filled') d = ItemsManager.upsert_item_with_name(name=unicode(name)) d.addCallback(lambda res: Ok('{}'.format(res))) d.addErrback( lambda e: BadRequest('Internal error: {}'.format(unicode(e)))) return d
def hello(self, request, name, **kwargs): return Ok('Hello {}!'.format(name))
def root(self, request, **kwargs): return Ok('I am the Hello, hello world!')
def dummy_test(self, request): return Ok('<h1>Dummy Test</h1>', {'content-type': 'text/html'})