Example #1
0
def _save_or_update_json_response(cmd, _resp):
    try:
        livro = cmd()
    except CommandExecutionException:
        _resp.status_code = 500
        return JsonResponse(cmd.errors)
    short_form=facade.livro_short_form()
    return JsonResponse(short_form.fill_with_model(livro))
Example #2
0
def index():
    context = {'new_path': router.to_path(new)}
    return  TemplateResponse(context)

    cmd = facade.list_livros_cmd()
    livros = cmd()
    edit_path = router.to_path(edit)
    delete_path = router.to_path(delete)
    short_form = facade.livro_short_form()

    def short_livro_dict(livro):
        livro_dct = short_form.fill_with_model(livro)
        livro_dct['edit_path'] = router.to_path(edit_path, livro_dct['id'])
        livro_dct['delete_path'] = router.to_path(delete_path, livro_dct['id'])
        return livro_dct

    short_livros = [short_livro_dict(livro) for livro in livros]
    context = {'livros': short_livros,
               'new_path': router.to_path(new)}
    return TemplateResponse(context)
Example #3
0
def index():
    cmd = facade.list_livros_cmd()
    livro_list = cmd()
    short_form=facade.livro_short_form()
    livro_short = [short_form.fill_with_model(m) for m in livro_list]
    return JsonResponse(livro_short)