def __init__(self, request=None, variables=None, variables_dict=None, endpoint_dispatch_prefix='query', **kwargs): # variables=None to make pycharm tooling not confused """ :type variables: list of Variable :type request: django.http.request.HttpRequest """ self.endpoint_dispatch_prefix = endpoint_dispatch_prefix self.request = request self._form = None def generate_variables(): if variables is not None: for variable in variables: yield variable for name, variable in variables_dict.items(): dict.__setitem__(variable, 'name', name) yield variable self.variables = sort_after(list(generate_variables())) def generate_bound_variables(): for x in self.variables: yield BoundVariable(**merged( Struct(x), query=self, attr=x.attr if x.attr is not MISSING else x.name )) bound_variables = list(generate_bound_variables()) bound_variables = [evaluate_recursive(x, query=self, variable=x) for x in bound_variables] self.bound_variables = filter_show_recursive(bound_variables) self.bound_variable_by_name = {variable.name: variable for variable in self.bound_variables} self.gui_kwargs = extract_subkeys(kwargs, 'gui')
def test_remove_and_filter_show_recursive(): class Foo(object): show = False assert { 'qwe': {}, 'foo': [{'bar'}, {}, {}], 'asd': {'bar'} } == remove_show_recursive( filter_show_recursive({ 'foo': [Foo(), { 'show': False }, {'bar'}, {}, { 'show': True }], 'bar': { 'show': False }, 'baz': Foo(), 'asd': {Foo(), 'bar'}, 'qwe': { 'show': True }, 'quux': { 'show': None }, }))
def __init__(self, request=None, variables=None, **kwargs): # variables=None to make pycharm tooling not confused """ :type variables: list of Variable :type request: django.http.request.HttpRequest """ self.request = request assert variables is not None if isinstance(variables, dict): # Declarative case self.variables = [merged(variable, name=name) for name, variable in variables.items()] else: self.variables = variables bound_variables = [BoundVariable(**merged(Struct(x), query=self)) for x in self.variables] bound_variables = [evaluate_recursive(x, query=self, variable=x) for x in bound_variables] self.bound_variables = filter_show_recursive(bound_variables) self.bound_variable_by_name = {variable.name: variable for variable in self.bound_variables} self.gui_kwargs = extract_subkeys(kwargs, 'gui')
def test_remove_and_filter_show_recursive(): class Foo(object): show = False assert {'qwe': {}, 'foo': [{'bar'}, {}, {}], 'asd': {'bar'}} == remove_show_recursive(filter_show_recursive({ 'foo': [Foo(), {'show': False}, {'bar'}, {}, {'show': True}], 'bar': {'show': False}, 'baz': Foo(), 'asd': {Foo(), 'bar'}, 'qwe': {'show': True}, 'quux': {'show': None}, }))