Exemplo n.º 1
0
    def _update_diffed_value(self, name, value):
        if is_iterable(value):
            self._init_list_diff(name)
            self[name] = value

            if name in self['diffs']:
                new_removed = []
                for element in self['diffs'][name]['removed']:
                    if element in self[name]:
                        self[name].remove(element)
                        new_removed.append(element)

                self['diffs'][name]['removed'] = new_removed

                new_added = []
                for element in self['diffs'][name]['added']:
                    if element not in self[name]:
                        self[name].append(element)
                        new_added.append(element)

                self['diffs'][name]['added'] = new_added
        else:
            self[name] = value
            if name in self['diffs']:
                if self['diffs'][name] == value:
                    del self['diffs'][name]
                else:
                    self[name] = self['diffs'][name]
Exemplo n.º 2
0
def remove_fields(instances, fields):
    if isinstance(instances, dict):
        for field in fields:
            remove_field(instances, field)
    elif is_iterable(instances):
        for instance in instances:
            for field in fields:
                remove_field(instance, field)

    return instances
Exemplo n.º 3
0
    def update_setting_value(self, name, value):
        if is_iterable(self[name]):
            value = list_value(value)

            for element in value:
                if element not in self[name]:
                    self._add_value(name, element)

            for element in self[name]:
                if element not in value:
                    self._remove_value(name, element)

            self[name] = value
        else:
            if self[name] != value:
                self['diffs'][name] = value
                self[name] = value