예제 #1
0
def extract_doc_adapter(request, doc_type, doc_id):
    doc = get_doc_by_id(request.registry.db, doc_type, doc_id)
    doc_type_lower = doc_type[0].lower() + doc_type[1:]
    if doc is None:
        request.errors.add("url", "%s_id" % doc_type_lower, "Not Found")
        request.errors.status = 404
        raise error_handler(request)

    method = getattr(request, "%s_from_data" % doc_type_lower)
    return method(doc)
예제 #2
0
def extract_doc_adapter(request, doc_type, doc_id):
    doc = get_doc_by_id(request.registry.db, doc_type, doc_id)
    doc_type_lower = doc_type[0].lower() + doc_type[1:]
    if doc is None:
        request.errors.add("url", "%s_id" % doc_type_lower, "Not Found")
        request.errors.status = 404
        raise error_handler(request)
    # obsolete lowercase doc_type in agreements
    if doc is not None and doc.get("doc_type") == "agreement":
        request.errors.add("url", "agreement_id", "Archived")
        request.errors.status = 410
        raise error_handler(request)

    method = getattr(request, "%s_from_data" % doc_type_lower)
    return method(doc)
예제 #3
0
def extract_doc_adapter(request, doc_type, doc_id):
    doc_type_singular = doc_type[:
                                 -1]  # lower, without last symbol  "frameworks" --> "framework"
    doc = get_doc_by_id(request.registry.databases[doc_type],
                        doc_type_singular.capitalize(), doc_id)
    if doc is None:
        request.errors.add("url", "%s_id" % doc_type_singular, "Not Found")
        request.errors.status = 404
        raise error_handler(request)
    # obsolete lowercase doc_type in agreements
    if doc is not None and doc.get("doc_type") == "agreement":
        request.errors.add("url", "agreement_id", "Archived")
        request.errors.status = 410
        raise error_handler(request)

    method = getattr(request, "%s_from_data" % doc_type_singular)
    return method(doc)
예제 #4
0
def get_framework_by_id(db, framework_id):
    return get_doc_by_id(db, "Framework", framework_id)
예제 #5
0
def get_submission_by_id(db, submission_id):
    return get_doc_by_id(db, "Submission", submission_id)
예제 #6
0
def get_agreement_by_id(db, agreement_id):
    return get_doc_by_id(db, "Agreement", agreement_id)