def crosswalk():
    session["definition"] = request.form.get("definition")
    session["list_definition"] = request.form.get("list_definition")
    session["subject_namespace"] = request.form.get("subject_namespace")
    session["subject_identifier"] = request.form.get("subject_identifier")
    session["list_subject_namespace"] = request.form.get("list_subject_namespace")
    session["list_subject_identifier"] = request.form.get("list_subject_identifier")
    session["list_limit"] = request.form.get("list_limit")
    session["is_limited"] = True if "is_limited" in request.form else False
    session["list_offset"] = request.form.get("list_offset")
    session["is_offset"] = True if "is_offset" in request.form else False
    session["endpoint"] = request.form.get("endpoint")
    session["username"] = request.form.get("username")
    session["password"] = request.form.get("password")
    session["format"] = request.form.get("format")
    session["output_html"] = True if "output_html" in request.form else False
    session["definition_type"] = request.form.get("definition_type")

    select_q = None
    count_q = None

    definition_type = request.form.get("definition_type")
    if not definition_type:
        if "definition" in request.form and "list_definition" not in request.form:
            definition_type = "individual"
        elif "definition" not in request.form and "list_definition" in request.form:
            definition_type = "list"
        else:
            definition_type = default_definition_type

    if definition_type == "individual":
        o, s, g, q = execute(
            definitions[request.form.get("definition", default_definition)],
            request.form.get("subject_namespace", default_subject_namespace),
            request.form.get("subject_identifier", default_subject_identifier),
            request.form.get("endpoint", default_endpoint),
            request.form.get("username", default_username),
            request.form.get("password", default_password),
            serialization_format=request.form.get("format", default_format),
        )
    else:
        o, s, g, q, select_q, count_q = execute_list(
            list_definitions[request.form.get("list_definition", default_list_definition)],
            request.form.get("list_subject_namespace", default_subject_namespace),
            request.form.get("list_subject_identifier", default_subject_identifier),
            request.form.get("endpoint", default_endpoint),
            request.form.get("username", default_username),
            request.form.get("password", default_password),
            serialization_format=request.form.get("format", default_format),
            offset=request.form.get("list_offset", default_list_offset) if "is_offset" in request.form else None,
            limit=request.form.get("list_limit", default_list_limit) if "is_limited" in request.form else None,
        )

    if "output_html" in request.form:
        return crosswalk_form(output=o, obj=s, graph=g, query=q, select_query=select_q, count_query=count_q)
    else:
        return Response(o, content_type=formats[request.form.get("format", default_format)])
Beispiel #2
0
    parser.add_argument("--format", choices=["json", "yaml", "xml", "nt", "pretty-xml", "trix"],
                        help="The format for serializing. Default is json.", default="json")
    parser.add_argument("--indent", default="4", type=int, help="Number of spaces to use for indents.")
    parser.add_argument("--file", help="Filepath to which to serialize.")
    parser.add_argument("--debug", action="store_true", help="Also output the query, result graph, and python object.")
    parser.add_argument("--offset", type=int, help="Offset for lists.")
    parser.add_argument("--limit", type=int, help="Limit for lists.")

    #Parse
    args = parser.parse_args()

    main_select_q = None
    main_count_q = None
    if args.definition in definitions:
        main_o, main_s, main_g, main_q = execute(definitions[args.definition], args.subject_namespace,
                                                 args.subject_identifier, args.endpoint, args.username, args.password,
                                                 serialization_format=args.format, indent_size=args.indent)
    else:
        (main_o, main_s, main_g,
         main_q, main_select_q, main_count_q) = execute_list(list_definitions[args.definition], args.subject_namespace,
                                                             args.subject_identifier, args.endpoint, args.username,
                                                             args.password, serialization_format=args.format,
                                                             indent_size=args.indent, offset=args.offset, limit=args.limit)

    if args.file:
        with codecs.open(args.file, "w") as out:
            out.write(main_o)
    else:
        print(main_o)

    if args.debug: