Exemplo n.º 1
0
Arquivo: base.py Projeto: toirl/ringo
    def get_values(self, include_relations=False, serialized=False):
        """Will return a dictionary with the values of the item. On
        default the function will return the pythonic values and
        excludes all related items. This behaviour can be changed by
        setting the `include_relations` and `serialized` option.

        In case the relations are included and the values are serialized
        then the serialized value of a related item is its id.

        :include_relations: Flag if relations should be included in the
                            returned dictionary.
        :serialized: Flag if the values should be serialized.
        :returns: Dictionary with key value pairs.
        """
        values = {}
        for field in get_columns_from_instance(self, include_relations):
            # Ignore private form fields
            if field.startswith("_"):
                continue
            if serialized:
                value = serialize(getattr(self, field))
            else:
                value = getattr(self, field)
            values[field] = value
        return values
Exemplo n.º 2
0
    def get_values(self, include_relations=False, serialized=False):
        """Will return a dictionary with the values of the item. On
        default the function will return the pythonic values and
        excludes all related items. This behaviour can be changed by
        setting the `include_relations` and `serialized` option.

        In case the relations are included and the values are serialized
        then the serialized value of a related item is its id.

        :include_relations: Flag if relations should be included in the
                            returned dictionary.
        :serialized: Flag if the values should be serialized.
        :returns: Dictionary with key value pairs.
        """
        values = {}
        for field in get_columns_from_instance(self, include_relations):
            # Ignore private form fields
            if field.startswith("_"):
                continue
            if serialized:
                value = serialize(getattr(self, field))
            else:
                value = getattr(self, field)
            values[field] = value
        return values
Exemplo n.º 3
0
 def set_values(self, values, use_strict=False, request=None):
     """Will set the given values into Blobform items. This function
     overwrites the default behavior of the BaseItem and takes care
     that the data will be saved in the data attribute as JSON
     string."""
     json_data = json.loads(self.get_values().get('data') or "{}")
     columns = get_columns_from_instance(self, True)
     for key, value in values.iteritems():
         # Ignore private form fields
         if key.startswith('_'):
             continue
         if key in columns or key.find(".") > -1:
             log.debug("Setting value '%s' for '%s' in DB" % (value, key))
             setattr(self, key, value)
         else:
             if isinstance(value, datetime.date):
                 value = str(value)
             log.debug("Setting value '%s' for '%s' in JSON" % (value, key))
             json_data[key] = value
     setattr(self, 'data', json.dumps(json_data))
Exemplo n.º 4
0
 def set_values(self, values):
     """Will set the given values into Blobform items. This function
     overwrites the default behavior of the BaseItem and takes care
     that the data will be saved in the data attribute as JSON
     string."""
     json_data = json.loads(self.get_values().get('data') or "{}")
     columns = get_columns_from_instance(self, True)
     for key, value in values.iteritems():
         # Ignore private form fields
         if key.startswith('_'):
             continue
         if key in columns:
             log.debug("Setting value '%s' for '%s' in DB" % (value, key))
             setattr(self, key, value)
         else:
             if isinstance(value, datetime.date):
                 value = str(value)
             log.debug("Setting value '%s' for '%s' in JSON" % (value, key))
             json_data[key] = value
     setattr(self, 'data', json.dumps(json_data))