Exemple #1
0
def query_object_properties(typeclass_key, object_key):
    """
    Query all properties of the given object.

    Args:
        typeclass_key: (string) typeclass' key.
        object_key: (string) object' key.
    """
    # Get fields.
    fields = []
    fields.append({
        "name": "level",
        "label": _("Level"),
        "help_text": _("Properties's level.")
    })

    properties_info = TYPECLASS(typeclass_key).get_properties_info()
    for key, info in properties_info.items():
        if info["mutable"]:
            continue

        fields.append({
            "name": key,
            "label": info["name"],
            "help_text": info["desc"]
        })

    if len(fields) == 1:
        # No custom properties.
        table = {
            "fields": [],
            "records": [],
        }
        return table

    # Get rows.
    levels = []
    data = {}
    records = OBJECT_PROPERTIES.get_properties_all_levels(object_key)
    for record in records:
        if record.level not in levels:
            levels.append(record.level)
            data[record.level] = {"level": record.level}
        data[record.level][record.property] = record.value

    rows = []
    for level in levels:
        line = [data[level].get(field["name"], "") for field in fields]
        rows.append(line)

    table = {
        "fields": fields,
        "records": rows,
    }

    return table
Exemple #2
0
def query_object_level_properties(object_key, level):
    """
    Query properties of a level of the given object.

    Args:
        object_key: (string) object' key.
        level: (number) object's level.
    """
    # Get fields.
    fields = []

    # Object's key.
    fields.append({
        "name": "key",
        "label": _("Key"),
        "disabled": True,
        "help_text": "",
        "type": "TextInput",
        "value": object_key
    })

    # Object's level.
    fields.append({
        "name": "level",
        "label": _("Level"),
        "disabled": False,
        "help_text": "",
        "type": "NumberInput",
        "value": level
    })

    # Get typeclass from the object's record
    table_name = TYPECLASS("OBJECT").model_name
    record = general_query_mapper.get_record_by_key(table_name, object_key)
    obj_typeclass = record.typeclass

    properties_info = TYPECLASS(obj_typeclass).get_properties_info()

    # Get properties.
    data = {}
    records = OBJECT_PROPERTIES.get_properties(object_key, level)
    for record in records:
        data[record.property] = record.value

    # Set fields.
    for key, info in properties_info.items():
        if info["mutable"]:
            continue

        field = {
            "name": key,
            "label": info["name"],
            "disabled": False,
            "help_text": info["desc"],
            "type": "TextInput",
            "value": data.get(key, "")
        }

        fields.append(field)

    return fields