Exemplo n.º 1
0
def _get_location_data_fields(domain):
    from corehq.apps.locations.views import LocationFieldsView
    fields_definition = get_by_domain_and_type(domain, LocationFieldsView.field_type)
    if fields_definition:
        return fields_definition.fields
    else:
        return []
Exemplo n.º 2
0
def _get_location_data_fields(domain):
    from corehq.apps.locations.views import LocationFieldsView
    fields_definition = get_by_domain_and_type(domain, LocationFieldsView.field_type)
    if fields_definition:
        return fields_definition.fields
    else:
        return []
Exemplo n.º 3
0
def product_fixture_generator_json(domain):
    if not SQLProduct.objects.filter(domain=domain).exists():
        return None

    fields = filter(lambda x: x != CUSTOM_DATA_SLUG, PRODUCT_FIELDS)
    fields.append('@id')

    custom_fields = get_by_domain_and_type(domain, 'ProductFields')
    if custom_fields:
        for f in custom_fields.fields:
            fields.append(CUSTOM_DATA_SLUG + '/' + f.slug)

    uri = 'jr://fixture/{}'.format(ProductFixturesProvider.id)
    return {
        'id': 'products',
        'uri': uri,
        'path': '/products/product',
        'name': 'Products',
        'structure': {f: {
            'name': f,
            'no_option': True
        }
                      for f in fields},

        # DEPRECATED PROPERTIES
        'sourceUri': uri,
        'defaultId': 'products',
        'initialQuery': "instance('products')/products/product",
    }
Exemplo n.º 4
0
def product_fixture_generator_json(domain):
    if not SQLProduct.objects.filter(domain=domain).exists():
        return None

    fields = filter(lambda x: x != CUSTOM_DATA_SLUG, PRODUCT_FIELDS)
    fields.append('@id')

    custom_fields = get_by_domain_and_type(domain, 'ProductFields')
    if custom_fields:
        for f in custom_fields.fields:
            fields.append(CUSTOM_DATA_SLUG + '/' + f.slug)

    uri = 'jr://fixture/{}'.format(ProductFixturesProvider.id)
    return {
        'id': 'products',
        'uri': uri,
        'path': '/products/product',
        'name': 'Products',
        'structure': {
            f: {
                'name': f,
                'no_option': True
            } for f in fields},

        # DEPRECATED PROPERTIES
        'sourceUri': uri,
        'defaultId': 'products',
        'initialQuery': "instance('products')/products/product",
    }
Exemplo n.º 5
0
def get_custom_data_models(domain, limit_types=None):
    fields = {}
    for field_view in [LocationFieldsView, ProductFieldsView, UserFieldsView]:
        if limit_types and field_view.field_type not in limit_types:
            continue
        model = get_by_domain_and_type(domain, field_view.field_type)
        if model:
            fields[field_view.field_type] = model.to_json()['fields']
    return fields
Exemplo n.º 6
0
def remove_unused_custom_fields_from_users(domain):
    """
    Removes all unused custom data fields from all users in the domain
    """
    from corehq.apps.users.views.mobile.custom_data_fields import CUSTOM_USER_DATA_FIELD_TYPE
    fields_definition = get_by_domain_and_type(domain, CUSTOM_USER_DATA_FIELD_TYPE)
    assert fields_definition, 'remove_unused_custom_fields_from_users called without a valid CustomDataFieldsDefinition'
    configured_field_keys = set([f.slug for f in fields_definition.get_fields()])
    for user in get_all_commcare_users_by_domain(domain):
        keys_to_delete = _get_invalid_user_data_fields(user, configured_field_keys)
        if keys_to_delete:
            for key in keys_to_delete:
                del user.user_data[key]
            user.save()
Exemplo n.º 7
0
def product_fixture_generator_json(domain):
    if not SQLProduct.objects.filter(domain=domain).exists():
        return None

    fields = [x for x in PRODUCT_FIELDS if x != CUSTOM_DATA_SLUG]
    fields.append('@id')

    custom_fields = get_by_domain_and_type(domain, 'ProductFields')
    if custom_fields:
        for f in custom_fields.fields:
            fields.append(CUSTOM_DATA_SLUG + '/' + f.slug)

    uri = 'jr://fixture/{}'.format(ProductFixturesProvider.id)
    return {
        'id': 'products',
        'uri': uri,
        'path': '/products/product',
        'name': 'Products',
        'structure': {f: {'name': f, 'no_option': True} for f in fields},
    }
Exemplo n.º 8
0
def product_fixture_generator_json(domain):
    if not SQLProduct.objects.filter(domain=domain).exists():
        return None

    fields = filter(lambda x: x != CUSTOM_DATA_SLUG, PRODUCT_FIELDS)
    fields.append('@id')

    custom_fields = get_by_domain_and_type(domain, 'ProductFields')
    if custom_fields:
        for f in custom_fields.fields:
            fields.append(CUSTOM_DATA_SLUG + '/' + f.slug)

    return {
        'sourceUri': 'jr://fixture/commtrack:products',
        'defaultId': 'products',
        'initialQuery': "instance('products')/products/product",
        'name': 'Products',
        'structure': {
            f: {
                'name': f,
                'no_option': True
            } for f in fields},
    }
Exemplo n.º 9
0
def product_fixture_generator_json(domain):
    if not SQLProduct.objects.filter(domain=domain).exists():
        return None

    fields = [x for x in PRODUCT_FIELDS if x != CUSTOM_DATA_SLUG]
    fields.append('@id')

    custom_fields = get_by_domain_and_type(domain, 'ProductFields')
    if custom_fields:
        for f in custom_fields.fields:
            fields.append(CUSTOM_DATA_SLUG + '/' + f.slug)

    uri = 'jr://fixture/{}'.format(ProductFixturesProvider.id)
    return {
        'id': 'products',
        'uri': uri,
        'path': '/products/product',
        'name': 'Products',
        'structure': {f: {
            'name': f,
            'no_option': True
        }
                      for f in fields},
    }
Exemplo n.º 10
0
    def _copy_custom_data(self, type_):
        from corehq.apps.custom_data_fields.dbaccessors import get_by_domain_and_type

        doc = get_by_domain_and_type(self.existing_domain, type_)
        if doc:
            self.save_couch_copy(doc, self.new_domain)
Exemplo n.º 11
0
 def _copy_custom_data(self, type_):
     from corehq.apps.custom_data_fields.dbaccessors import get_by_domain_and_type
     doc = get_by_domain_and_type(self.existing_domain, type_)
     if doc:
         self.save_couch_copy(doc, self.new_domain)