Esempio n. 1
0
def register_expressions():
    from corehq.apps.userreports.extension_points import custom_ucr_expressions
    from corehq.apps.userreports.expressions.factory import ExpressionFactory

    expressions = copy.copy(settings.CUSTOM_UCR_EXPRESSIONS)
    expressions.extend(custom_ucr_expressions())

    for type_name, factory_function_path in expressions:
        ExpressionFactory.register(type_name,
                                   import_string(factory_function_path))
Esempio n. 2
0
 def test_bad_spec_error(self, _):
     ExpressionFactory.register("missing_expression", lambda x, y: x)
     data_source_1 = get_sample_data_source()
     data_source_1.configured_indicators[0] = {
         "column_id": "date",
         "type": "expression",
         "expression": {
             "type": "missing_expression",
         },
         "datatype": "datetime"
     }
     data_source_1.save()
     del ExpressionFactory.spec_map["missing_expression"]
     ds_1_domain = data_source_1.domain
     table_manager = ConfigurableReportTableManagerMixin(
         [DynamicDataSourceProvider()])
     table_manager.bootstrap()
     self.assertEqual(0, len(table_manager.table_adapters_by_domain))
     self.assertEqual(
         0, len(table_manager.table_adapters_by_domain[ds_1_domain]))
    def test_double_registration(self):

        ExpressionFactory.register("foo", lambda x: x)
        with self.assertRaises(ValueError):
            ExpressionFactory.register("foo", lambda x: x * 2)
    def test_double_registration(self):

        ExpressionFactory.register("foo", lambda x: x)
        with self.assertRaises(ValueError):
            ExpressionFactory.register("foo", lambda x: x * 2)
Esempio n. 5
0
from django.conf import settings
from django.utils.module_loading import import_by_path
from corehq.apps.userreports.expressions.factory import ExpressionFactory

# Bootstrap plugin expressions
for type_name, factory_function_path in settings.CUSTOM_UCR_EXPRESSIONS:
    ExpressionFactory.register(type_name, import_by_path(factory_function_path))
Esempio n. 6
0
import copy

from django.conf import settings
from django.utils.module_loading import import_string
from corehq.apps.userreports.expressions.factory import ExpressionFactory


def get_custom_ucr_expressions():
    custom_ucr_expressions = copy.copy(settings.CUSTOM_UCR_EXPRESSIONS)

    for path_to_expression_lists in settings.CUSTOM_UCR_EXPRESSION_LISTS:
        custom_ucr_expressions += import_string(path_to_expression_lists)

    return custom_ucr_expressions

# Bootstrap plugin expressions
for type_name, factory_function_path in get_custom_ucr_expressions():
    ExpressionFactory.register(type_name, import_string(factory_function_path))