Exemplo n.º 1
0
def delete_object_level_properties(object_key, level):
    """
    Delete properties of a level of the given object.

    Args:
        object_key: (string) object' key.
        level: (number) object's level.
    """
    OBJECT_PROPERTIES.delete_properties(object_key, level)
Exemplo n.º 2
0
def save_object_level_properties(object_key, level, values):
    """
    Save properties of an object.

    Args:
        object_key: (string) object' key.
        level: (number) object's level.
        values: (dict) values to save.
    """
    OBJECT_PROPERTIES.add_properties(object_key, level, values)
Exemplo n.º 3
0
    def load_custom_properties(self, level):
        """
        Load body properties from db. Body properties do no include mutable properties.
        """
        # Get object level.
        if level is None:
            level = self.db.level

        # Load values from db.
        values = {}
        for record in OBJECT_PROPERTIES.get_properties(self.get_data_key(),
                                                       level):
            key = record.property
            serializable_value = record.value
            if serializable_value == "":
                value = None
            else:
                try:
                    value = ast.literal_eval(serializable_value)
                except (SyntaxError, ValueError) as e:
                    # treat as a raw string
                    value = serializable_value
            values[key] = value

        # Set body values.
        for key, info in self.get_properties_info().items():
            if not info["mutable"]:
                self.custom_properties_handler.add(key, values.get(key, None))
                self.body_properties_handler.add(key, values.get(key, None))

        # Set default mutable custom properties.
        self.set_default_custom_properties()
Exemplo n.º 4
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
Exemplo n.º 5
0
    def load_custom_properties(self, level):
        """
        Load body properties from db. Body properties do no include mutable properties.
        """
        # Get object level.
        if level is None:
            level = self.db.level

        # Load values from db.
        data_key = self.get_data_key()
        clone = getattr(self.system, "clone", None)
        if clone:
            data_key = self.system.clone

        values = {}
        for record in OBJECT_PROPERTIES.get_properties(data_key, level):
            key = record.property
            serializable_value = record.value
            if serializable_value == "":
                value = None
            else:
                try:
                    value = ast.literal_eval(serializable_value)
                except (SyntaxError, ValueError) as e:
                    # treat as a raw string
                    value = serializable_value
            values[key] = value

        # Set body values.
        for key, info in self.get_properties_info().items():
            if not info["mutable"]:
                value = None
                if key in values:
                    value = values[key]
                else:
                    # Get default value.
                    default = info["default"]
                    try:
                        value = ast.literal_eval(default)
                    except (SyntaxError, ValueError) as e:
                        # treat as a raw string
                        value = default

                self.custom_properties_handler.add(key, value)
                self.body_properties_handler.add(key, value)

        # Set default mutable custom properties.
        self.set_mutable_custom_properties()
Exemplo n.º 6
0
 def load_custom_properties(self):
     """
     Load body properties from db. Body properties do no include mutable properties.
     """
     # Load values from db.
     values = {}
     for record in OBJECT_PROPERTIES.get_properties(self.get_data_key(), self.db.level):
         key = record.property
         serializable_value = record.value
         if serializable_value == "":
             value = None
         else:
             try:
                 value = ast.literal_eval(serializable_value)
             except (SyntaxError, ValueError), e:
                 # treat as a raw string
                 value = serializable_value
         values[key] = value
Exemplo n.º 7
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