Example #1
0
def _save_or_update_json_response(cmd):
    try:
        book = cmd()
    except CommandExecutionException:
        return JsonResponse({'errors': cmd.errors})
    short_form=facade.book_short_form()
    return JsonResponse(short_form.fill_with_model(book))
Example #2
0
def _save_or_update_json_response(_resp, cmd):
    try:
        book = cmd()
    except CommandExecutionException:
        _resp.status_code = 500
        _resp.get('nome')
        return JsonResponse(cmd.errors)
    short_form = facade.book_short_form()
    model = short_form.fill_with_model(book)
    return JsonResponse(model)
Example #3
0
def index():
    cmd = facade.list_books_cmd()
    books = cmd()
    edit_path = router.to_path(edit)
    delete_path = router.to_path(delete)
    short_form = facade.book_short_form()

    def short_book_dict(book):
        book_dct = short_form.fill_with_model(book)
        book_dct['edit_path'] = router.to_path(edit_path, book_dct['id'])
        book_dct['delete_path'] = router.to_path(delete_path, book_dct['id'])
        return book_dct

    short_books = [short_book_dict(book) for book in books]
    context = {'books': short_books,
               'new_path': router.to_path(new)}
    return TemplateResponse(context)
Example #4
0
def index():
    cmd = facade.list_books_cmd()
    book_list = cmd()
    short_form=facade.book_short_form()
    book_short = [short_form.fill_with_model(m) for m in book_list]
    return JsonResponse(book_short)