Stores a list as JSON on database, with mutability support.

    If kwargs has a param `unique_sorted` (which evaluated to True),
    list values are made unique and sorted.
175530
def JSONList(*args, **kwargs):
    
    type_ = JSON
    try:
        if kwargs.pop("unique_sorted"):
            type_ = JSONUniqueListType
    except KeyError:
        pass

    return MutationList.as_mutable(type_(*args, **kwargs))
322195
def build_sort(self, **kwargs):
        '''  '''
        sort = []
        order = kwargs.get('order_by', None)
        if order:
            if type(order) is list:
                order = order[0]
            if order[:1] == '-':
                sort.append((order[1:], -1))
            else:
                sort.append((order, 1))
        return sort
153216
def list_to_compare_dict(self, list_form):
        """"""
        compare_dict = {}
        for field in list_form:
            if field['name'] in compare_dict:
                self.pr_dbg("List has duplicate field %s:\n%s" %
                            (field['name'], compare_dict[field['name']]))
                if compare_dict[field['name']] != field:
                    self.pr_dbg("And values are different:\n%s" % field)
                return None
            compare_dict[field['name']] = field
            for ign_f in self.mappings_ignore:
                compare_dict[field['name']][ign_f] = 0
        return compare_dict
102254
def _dict_raise_on_duplicates(ordered_pairs):
    
    d = {}
    for k, v in ordered_pairs:
        if k in d:
           raise ValueError("duplicate key: %r" % (k,))
        else:
           d[k] = v
    return d
650614
def to_json(self, incl_uniqueid=False):
        
        lst = []
        for context in _contexts:
            lst += [v.to_json(incl_uniqueid=incl_uniqueid)
                    for v in self.filter(context=context,
                                         check_visible=False,
                                         check_default=False).to_list()]
        return lst
790695
def unique(iterable):
    
    """
    d = {}
    return (d.setdefault(x,x) for x in iterable if x not in d)
832783
def set_list(self, mutagen_file, values):
        
        self.store(mutagen_file, [self.serialize(value) for value in values])
22701
def __json(self):
        
        if self.exclude_list is None:
            self.exclude_list = []
        fields = {}
        for key, item in vars(self).items():
            if hasattr(self, '_sa_instance_state'):
                # load only deferred objects
                if len(orm.attributes.instance_state(self).unloaded) > 0:
                    mapper = inspect(self)
                    for column in mapper.attrs:
                        column.key
                        column.value
            if str(key).startswith('_') or key in self.exclude_list:
                continue
            fields[key] = item
        obj = Json.safe_object(fields)
        return str(obj)
1057189
def _serialize_list(cls, list_):
        

        list_serialized = []

        for item in list_:
            item_serialized = cls.serialize(item)
            list_serialized.append(item_serialized)

        return list_serialized
644917
def prettylist(list_):
    
    if not list_:
        return ''

    values = set()
    uniqueList = []

    for entry in list_:
        if not entry in values:
            values.add(entry)
            uniqueList.append(entry)

    return uniqueList[0] if len(uniqueList) == 1 \
        else '[' + '; '.join(uniqueList) + ']'
113230
def jsonify(data, pretty=False, **kwargs):
    
    isod = isinstance(data, OrderedDict)
    params = {
        'for_json': True,
        'default': _complex_encode,
    }
    if pretty:
        params['indent'] = 2
        params['sort_keys'] = False if isod else True
    params.update(kwargs)
    try:
        return json.dumps(data, ensure_ascii=False, **params)
    except UnicodeDecodeError:
        return json.dumps(data, **params)
1158174
def flatten_unique(l: Iterable) -> List:
    
    rval = OrderedDict()
    for e in l:
        if not isinstance(e, str) and isinstance(e, Iterable):
            for ev in flatten_unique(e):
                rval[ev] = None
        else:
            rval[e] = None
    return list(rval.keys())
260866
def as_json(*args)
      document = { COLLECTION => collection, ID => id }
      document.merge!(DATABASE => database) if database
      document
    end
937527
def serialize(self, value, entity, request):
        
        value = super(ListField, self).serialize(value, entity, request)
        if value is None:
            return
        ret = []
        for v in value:
            ret.append(self.itemspec.serialize(v, entity, request))
        return ret
1012675
function uniqueArray(src, key, sort) {
    var results = [];
    var values = [];
    var i = 0;

    while (i < src.length) {
        var val = key ? src[i][key] : src[i];
        if (inArray(values, val) < 0) {
            results.push(src[i]);
        }
        values[i] = val;
        i++;
    }

    if (sort) {
        if (!key) {
            results = results.sort();
        } else {
            results = results.sort(function sortUniqueArray(a, b) {
                return a[key] > b[key];
            });
        }
    }

    return results;
}
621756
def add(self, *args, **kwargs):
        

        check_uniqueness = kwargs.pop('check_uniqueness', False)
        args = self.prepare_args(args)

        for index in self._indexes:
            index.add(*args, check_uniqueness=check_uniqueness and index.handle_uniqueness, **kwargs)
            if check_uniqueness and index.handle_uniqueness:
                check_uniqueness = False
962991
def unique_(self, col):
        
        try:
            df = self.df.drop_duplicates(subset=[col], inplace=False)
            return list(df[col])
        except Exception as e:
            self.err(e, "Can not select unique data")