Helper. Updates filter dict for a queryset.

    :param dict d:
    :param User|None user:
    :param int|None status:
    :return:
977228
def update_filter_dict(d, user, status):
    
    if user is not None:
        if not user.id:
            return None
        d['user'] = user
    if status is not None:
        d['status'] = status
1232194
def update(self, *args, **kwargs):
        
        super(DictProxy, self).update(*args, **kwargs)
        return self
182095
def filter_query(filter_dict, required_keys):
    """"""
    if not isinstance(filter_dict, dict):
        raise TypeError("dict_list is not a list. Please try again")

    if not isinstance(required_keys, list):
        raise TypeError("dict_list is not a list. Please try again")

    available = []
    for k,v in filter_dict.items():
        # print(k, v)
        if k in required_keys:
            available.append(k)
    return available
522228
def _update_request_context_with_user(self, user=None):
        ''''''

        ctx = _request_ctx_stack.top
        ctx.user = self.anonymous_user() if user is None else user
1131705
def is_flagged(self, user=None, status=None):
        
        filter_kwargs = {
            'content_type': ContentType.objects.get_for_model(self),
            'object_id': self.id,
        }
        update_filter_dict(filter_kwargs, user, status)
        return self.flags.filter(**filter_kwargs).count()
860867
def get_all_users(**kwargs):
    
    users_qry = db.DBSession.query(User)

    filter_type = kwargs.get('filter_type')
    filter_value = kwargs.get('filter_value')

    if filter_type is not None:
        # Filtering the search of users
        if filter_type == "id":
            if isinstance(filter_value, str):
                # Trying to read a csv string
                log.info("[HB.users] Getting user by Filter ID : %s", filter_value)
                filter_value = eval(filter_value)
                if type(filter_value) is int:
                    users_qry = users_qry.filter(User.id==filter_value)
                else:
                    users_qry = users_qry.filter(User.id.in_(filter_value))
        elif filter_type == "username":
            if isinstance(filter_value, str):
                # Trying to read a csv string
                log.info("[HB.users] Getting user by Filter Username : %s", filter_value)
                filter_value = filter_value.split(",")
                for i, em in enumerate(filter_value):
                    log.info("[HB.users] >>> Getting user by single Username : %s", em)
                    filter_value[i] = em.strip()
                if isinstance(filter_value, str):
                    users_qry = users_qry.filter(User.username==filter_value)
                else:
                    users_qry = users_qry.filter(User.username.in_(filter_value))
        else:
            raise Exception("Filter type '{}' not allowed".format(filter_type))

    else:
        log.info('[HB.users] Getting All Users')

    rs = users_qry.all()

    return rs
707765
def get_flags(self, user=None, status=None):
        
        filter_kwargs = {}
        update_filter_dict(filter_kwargs, user, status)
        return self.flags.filter(**filter_kwargs).all()
588838
def get_filterset_kwargs(self, request, queryset, view):
        
        filter_keys = []
        # rewrite filter[field] query params to make DjangoFilterBackend work.
        data = request.query_params.copy()
        for qp, val in request.query_params.items():
            m = self.filter_regex.match(qp)
            if m and (not m.groupdict()['assoc'] or
                      m.groupdict()['ldelim'] != '[' or m.groupdict()['rdelim'] != ']'):
                raise ValidationError("invalid query parameter: {}".format(qp))
            if m and qp != self.search_param:
                if not val:
                    raise ValidationError("missing {} test value".format(qp))
                # convert jsonapi relationship path to Django ORM's __ notation
                key = m.groupdict()['assoc'].replace('.', '__')
                # undo JSON_API_FORMAT_FIELD_NAMES conversion:
                key = format_value(key, 'underscore')
                data[key] = val
                filter_keys.append(key)
                del data[qp]
        return {
            'data': data,
            'queryset': queryset,
            'request': request,
            'filter_keys': filter_keys,
        }
1365630
def filtered(self, efilter):
        '''
        
        '''
        if not self.params:
            self.params={'filter' : efilter}
            return self
        if not self.params.has_key('filter'):
            self.params['filter'] = efilter
            return self
        self.params['filter'].update(efilter)
        return self
555893
def _filter_queryset(self, perms, queryset):
        """"""
        user = self.request.user if self.request else AnonymousUser()
        return get_objects_for_user(user, perms, queryset)
905418
def update_server_filter_action(self, request, table=None):
        
        if not table:
            table = self.get_table()
        filter_info = self.get_server_filter_info(request, table)
        if filter_info is not None:
            action = filter_info['action']
            setattr(action, 'filter_string', filter_info['value'])
            if filter_info['field_param']:
                setattr(action, 'filter_field', filter_info['field'])
538125
def update_status(modeladmin, request, queryset, status):
    """"""
    # We loop over the objects here rather than use queryset.update() for
    # two reasons:
    #
    #  1. No one should ever be updating zillions of Topics or Questions, so
    #     performance is not an issue.
    #  2. To be tidy, we want to log what the user has done.
    #
    for obj in queryset:
        obj.status = status
        obj.save()
        # Now log what happened.
        # Use ugettext_noop() 'cause this is going straight into the db.
        log_message = ugettext_noop(u'Changed status to \'%s\'.' %
            obj.get_status_display())
        modeladmin.log_change(request, obj, log_message)

    # Send a message to the user telling them what has happened.
    message_dict = {
        'count': queryset.count(),
        'object': modeladmin.model._meta.verbose_name,
        'verb': dict(STATUS_CHOICES)[status],
    }
    if not message_dict['count'] == 1:
        message_dict['object'] = modeladmin.model._meta.verbose_name_plural
    user_message = ungettext(
        u'%(count)s %(object)s was successfully %(verb)s.',
        u'%(count)s  %(object)s were successfully %(verb)s.',
        message_dict['count']) % message_dict
    modeladmin.message_user(request, user_message)

    # Return None to display the change list page again and allow the user
    # to reload the page without getting that nasty "Send the form again ..."
    # warning from their browser.
    return None
366994
def active_all(self, user=None):
        
        qs = self.deleted()
        if user:
            qs = qs.filter(recipient=user)
        qs.update(deleted=False)
731572
def update_many(self, filter, update, **kwargs):
        
        self._arctic_lib.check_quota()
        return self._collection.update_many(filter, update, **kwargs)
474629
def update_dict(self,*args, **kwargs):
        
        super(Dict, self).update(*args, **kwargs)
911485
def update(self, **kwargs):
        

        item = self._client['users/*/lists/*'].update(self.username, self.id, return_type='data', **kwargs)

        if not item:
            return False

        self._update(item)
        return True
397425
def dict_filter(d, exclude=[]):
    

    if isinstance(d, list):
        ret = []
        for e in d:
            ret.append(dict_filter(e, exclude))
        return ret
    elif isinstance(d, dict):
        ret = {}
        for k, v in d.items():
            if isinstance(k, builtin_str):
                k = str(k)

            assert isinstance(k, str)
            if k in exclude:
                continue
            ret[k] = dict_filter(v, exclude)
        return ret

    return d