コード例 #1
0
 def test_filter_add_condition(self):
     """
     Test that adding a condition to a filter is working.
     """
     test_filter = FilterChain(fields=[FilterChain.datatype + '.attribute_1'],
                               operations=["=="], values=['test_val'])
     filter_input = TestFiltering.DummyFilterClass(attribute_1='test_val', attribute_2=1)
     should_pass(test_filter, filter_input)
     test_filter.add_condition(FilterChain.datatype + '.attribute_2', '==', 2)
     should_fail(test_filter, filter_input)
コード例 #2
0
ファイル: input_tree.py プロジェクト: nedkab/tvb-framework
    def fill_input_tree_with_options(self, attributes_list, project_id, category_key):
        """
        For a datatype node in the input tree, load all instances from the db that fit the filters.
        """
        result = []
        for param in attributes_list:
            if param.get(KEY_UI_HIDE):
                continue
            transformed_param = copy(param)

            if KEY_TYPE in param and param[KEY_TYPE] not in STATIC_ACCEPTED_TYPES:

                if KEY_CONDITION in param:
                    filter_condition = param[KEY_CONDITION]
                else:
                    filter_condition = FilterChain('')
                filter_condition.add_condition(FilterChain.datatype + ".visible", "==", True)

                values, total_count = self.populate_option_values_for_dtype(project_id, param[KEY_TYPE], filter_condition,
                                                      category_key)
                if param.get(KEY_ATTRIBUTES): # copy complex datatype attributes to all options
                    complex_dt_attributes = self.fill_input_tree_with_options(param[KEY_ATTRIBUTES],
                                                                    project_id, category_key)
                    for value in values:
                        if value[KEY_NAME] != 'All':
                            value[KEY_ATTRIBUTES] = complex_dt_attributes

                if total_count > MAXIMUM_DATA_TYPES_DISPLAYED:
                    transformed_param[KEY_WARNING] = WARNING_OVERFLOW

                if param.get(KEY_REQUIRED) and len(values) > 0 and param.get(KEY_DEFAULT) is None:
                    transformed_param[KEY_DEFAULT] = str(values[-1][KEY_VALUE])

                transformed_param[KEY_FILTERABLE] = FilterChain.get_filters_for_type(param[KEY_TYPE])
                transformed_param[KEY_TYPE] = TYPE_SELECT
                # If Portlet dynamic parameter, don't add the options instead
                # just add the default value.
                if KEY_DYNAMIC in param:
                    dynamic_param = {KEY_NAME: param[KEY_DEFAULT],
                                     KEY_VALUE: param[KEY_DEFAULT]}
                    transformed_param[KEY_OPTIONS] = [dynamic_param]
                else:
                    transformed_param[KEY_OPTIONS] = values
                if type(param[KEY_TYPE]) == str:
                    transformed_param[KEY_DATATYPE] = param[KEY_TYPE]
                else:
                    data_type = param[KEY_TYPE]
                    transformed_param[KEY_DATATYPE] = data_type.__module__ + '.' + data_type.__name__

                ### DataType-attributes are no longer necessary, they were already copied on each OPTION
                transformed_param[KEY_ATTRIBUTES] = []

            else:
                if param.get(KEY_OPTIONS) is not None:
                    transformed_param[KEY_OPTIONS] = self.fill_input_tree_with_options(param[KEY_OPTIONS],
                                                                                        project_id, category_key)
                    if param.get(KEY_REQUIRED) and len(param[KEY_OPTIONS]) > 0 and param.get(KEY_DEFAULT) is None:
                        transformed_param[KEY_DEFAULT] = str(param[KEY_OPTIONS][-1][KEY_VALUE])

                if param.get(KEY_ATTRIBUTES) is not None:
                    transformed_param[KEY_ATTRIBUTES] = self.fill_input_tree_with_options(param[KEY_ATTRIBUTES],
                                                                                          project_id, category_key)
            result.append(transformed_param)
        return result