예제 #1
0
def _setup_case_property_builder(app):
    defaults = ('name', 'date-opened', 'status', 'last_modified')
    if app.case_sharing:
        defaults += ('#owner_name',)
    per_type_defaults = None
    if is_usercase_in_use(app.domain):
        per_type_defaults = get_per_type_defaults(app.domain, [USERCASE_TYPE])
    builder = ParentCasePropertyBuilder(app, defaults=defaults,
                                        per_type_defaults=per_type_defaults)
    return builder
예제 #2
0
def _get_case_schema_subsets(app, base_case_type, hashtag='#case/', source=None):
    builder = ParentCasePropertyBuilder.for_app(app, ['case_name'], include_parent_properties=False)
    related = builder.get_parent_type_map(None)
    map = builder.get_properties_by_case_type()
    descriptions_dict = get_case_property_description_dict(app.domain)

    # Generate hierarchy of case types, represented as a list of lists of strings:
    # [[base_case_type], [parent_type1, parent_type2...], [grandparent_type1, grandparent_type2...]]
    # Vellum case management only supports three levels
    generation_names = ['case', 'parent', 'grandparent']
    generations = [[] for g in generation_names]

    def _add_ancestors(ctype, generation):
        if generation < len(generation_names):
            generations[generation].append(ctype)
            for parent in related.get(ctype, {}).get('parent', []):
                _add_ancestors(parent, generation + 1)

    _add_ancestors(base_case_type, 0)

    # Remove any duplicate types or empty generations
    generations = [set(g) for g in generations if len(g)]

    name_source = f" - {source}" if source else ""
    id_source = f":{slugify(source)}" if source else ""
    hashtag = f"{hashtag}{id_source}"

    def _name(i, ctypes):
        if i > 0:
            return "{} ({}){}".format(generation_names[i], " or ".join(ctypes), name_source)
        return f"{base_case_type}{name_source}"

    return [{
        "id": f"{generation_names[i]}{id_source}",
        "name": _name(i, ctypes),
        "structure": {
            p: {"description": descriptions_dict.get(t, {}).get(p, '')}
            for t in ctypes for p in map[t]},
        "related": {"parent": {
            "hashtag": hashtag + generation_names[i + 1],
            "subset": f"{generation_names[i + 1]}{id_source}",
            "key": "@case_id",
        }} if i < len(generations) - 1 else None,
    } for i, ctypes in enumerate(generations)]
예제 #3
0
def _setup_case_property_builder(app):
    defaults = ('name', 'date-opened', 'status', 'last_modified')
    if app.case_sharing:
        defaults += ('#owner_name', )
    return ParentCasePropertyBuilder.for_app(app, defaults=defaults)
예제 #4
0
def _setup_case_property_builder(app):
    defaults = ('name', 'date-opened', 'status', 'last_modified')
    if app.case_sharing:
        defaults += ('#owner_name',)
    return ParentCasePropertyBuilder.for_app(app, defaults=defaults)
예제 #5
0
def get_casedb_schema(form):
    """Get case database schema definition for vellum to display as an external data source.

    This lists all case types and their properties for the given app.
    """
    app = form.get_app()
    base_case_type = form.get_module().case_type if form.requires_case(
    ) else None
    case_types = app.get_case_types() | get_shared_case_types(app)
    per_type_defaults = get_per_type_defaults(app.domain, case_types)
    builder = ParentCasePropertyBuilder(app, ['case_name'],
                                        per_type_defaults,
                                        include_parent_properties=False)
    related = builder.get_parent_type_map(case_types)
    map = builder.get_case_property_map(case_types)
    descriptions_dict = get_case_property_description_dict(app.domain)

    if base_case_type:
        # Generate hierarchy of case types, represented as a list of lists of strings:
        # [[base_case_type], [parent_type1, parent_type2...], [grandparent_type1, grandparent_type2...]]
        # Vellum case management only supports three levels
        generation_names = ['case', 'parent', 'grandparent']
        generations = [[] for g in generation_names]

        def _add_ancestors(ctype, generation):
            if generation < len(generation_names):
                generations[generation].append(ctype)
                for parent in related.get(ctype, {}).get('parent', []):
                    _add_ancestors(parent, generation + 1)

        _add_ancestors(base_case_type, 0)

        # Remove any duplicate types or empty generations
        generations = [set(g) for g in generations if len(g)]
    else:
        generations = []

    subsets = [{
        "id":
        generation_names[i],
        "name":
        "{} ({})".format(generation_names[i], " or ".join(ctypes))
        if i > 0 else base_case_type,
        "structure": {
            p: {
                "description": descriptions_dict.get(t, {}).get(p, '')
            }
            for t in ctypes for p in map[t]
        },
        "related": {
            "parent": {
                "hashtag": "#case/" + generation_names[i + 1],
                "subset": generation_names[i + 1],
                "key": "@case_id",
            }
        } if i < len(generations) - 1 else None,
    } for i, ctypes in enumerate(generations)]

    if is_usercase_in_use(app.domain):
        subsets.append({
            "id": USERCASE_TYPE,
            "name": "user",
            "key": "@case_type",
            "structure":
            {p: {}
             for p in get_usercase_properties(app)[USERCASE_TYPE]},
        })

    return {
        "id": "casedb",
        "uri": "jr://instance/casedb",
        "name": "case",
        "path": "/casedb/case",
        "structure": {},
        "subsets": subsets,
    }
예제 #6
0
def get_casedb_schema(form):
    """Get case database schema definition for vellum to display as an external data source.

    This lists all case types and their properties for the given app.
    """
    app = form.get_app()
    base_case_type = form.get_module().case_type if form.requires_case() else None
    builder = ParentCasePropertyBuilder.for_app(app, ['case_name'], include_parent_properties=False)
    related = builder.get_parent_type_map(None)
    map = builder.get_properties_by_case_type()
    descriptions_dict = get_case_property_description_dict(app.domain)

    if base_case_type:
        # Generate hierarchy of case types, represented as a list of lists of strings:
        # [[base_case_type], [parent_type1, parent_type2...], [grandparent_type1, grandparent_type2...]]
        # Vellum case management only supports three levels
        generation_names = ['case', 'parent', 'grandparent']
        generations = [[] for g in generation_names]

        def _add_ancestors(ctype, generation):
            if generation < len(generation_names):
                generations[generation].append(ctype)
                for parent in related.get(ctype, {}).get('parent', []):
                    _add_ancestors(parent, generation + 1)

        _add_ancestors(base_case_type, 0)

        # Remove any duplicate types or empty generations
        generations = [set(g) for g in generations if len(g)]
    else:
        generations = []

    subsets = [{
        "id": generation_names[i],
        "name": "{} ({})".format(generation_names[i], " or ".join(ctypes)) if i > 0 else base_case_type,
        "structure": {
            p: {"description": descriptions_dict.get(t, {}).get(p, '')}
            for t in ctypes for p in map[t]},
        "related": {"parent": {
            "hashtag": "#case/" + generation_names[i + 1],
            "subset": generation_names[i + 1],
            "key": "@case_id",
        }} if i < len(generations) - 1 else None,
    } for i, ctypes in enumerate(generations)]

    if is_usercase_in_use(app.domain):
        subsets.append({
            "id": USERCASE_TYPE,
            "name": "user",
            "key": "@case_type",
            "structure": {p: {} for p in get_usercase_properties(app)[USERCASE_TYPE]},
        })

    return {
        "id": "casedb",
        "uri": "jr://instance/casedb",
        "name": "case",
        "path": "/casedb/case",
        "structure": {},
        "subsets": subsets,
    }