def handle(self, *args, **options):
        for domain in Domain.get_all_names():
            fields_definition = cdm.CustomDataFieldsDefinition.get_or_create(
                domain,
                'UserFields'
            )
            had_fields = bool(fields_definition.fields)

            user_ids = (CommCareUser.ids_by_domain(domain) +
                        CommCareUser.ids_by_domain(domain, is_active=False))

            existing_field_slugs = set([field.slug for field in fields_definition.fields])
            for user in iter_docs(CommCareUser.get_db(), user_ids):
                user_data = user.get('user_data', {})
                for key in user_data.keys():
                    if (key and key not in existing_field_slugs
                        and not cdm.is_system_key(key)):
                        existing_field_slugs.add(key)
                        fields_definition.fields.append(cdm.CustomDataField(
                            slug=key,
                            label=key,
                            is_required=False,
                        ))

            for field in fields_definition.fields:
                if cdm.is_system_key(field.slug):
                    fields_definition.fields.remove(field)
            # Only save a definition for domains which use custom user data
            if fields_definition.fields or had_fields:
                fields_definition.save()
            print 'finished domain "{}"'.format(domain.name)
    def handle(self, *args, **options):
        for domain in Domain.get_all_names():
            fields_definition = cdm.CustomDataFieldsDefinition.get_or_create(
                domain,
                'LocationFields'
            )
            had_fields = bool(fields_definition.fields)

            existing_field_slugs = set([field.slug for field in fields_definition.fields])
            for location in Location.by_domain(domain):
                location_data = location.metadata
                for key in location_data.keys():
                    if (key and key not in existing_field_slugs
                        and not cdm.is_system_key(key)):
                        existing_field_slugs.add(key)
                        fields_definition.fields.append(cdm.CustomDataField(
                            slug=key,
                            label=key,
                            is_required=False,
                        ))

            for field in fields_definition.fields:
                if cdm.is_system_key(field.slug):
                    fields_definition.fields.remove(field)
            # Only save a definition for domains which use custom location data
            if fields_definition.fields or had_fields:
                fields_definition.save()
            print 'finished domain "{}"'.format(domain)
Example #3
0
    def handle(self, *args, **options):
        for domain in Domain.get_all_names():
            fields_definition = cdm.CustomDataFieldsDefinition.get_or_create(
                domain, 'LocationFields')
            had_fields = bool(fields_definition.fields)

            existing_field_slugs = set(
                [field.slug for field in fields_definition.fields])
            for location in Location.by_domain(domain):
                location_data = location.metadata
                for key in location_data.keys():
                    if (key and key not in existing_field_slugs
                            and not cdm.is_system_key(key)):
                        existing_field_slugs.add(key)
                        fields_definition.fields.append(
                            cdm.CustomDataField(
                                slug=key,
                                label=key,
                                is_required=False,
                            ))

            for field in fields_definition.fields:
                if cdm.is_system_key(field.slug):
                    fields_definition.fields.remove(field)
            # Only save a definition for domains which use custom location data
            if fields_definition.fields or had_fields:
                fields_definition.save()
            print 'finished domain "{}"'.format(domain)
    def handle(self, *args, **options):
        for domain in Domain.get_all_names():
            fields_definition = cdm.CustomDataFieldsDefinition.get_or_create(
                domain, 'UserFields')
            had_fields = bool(fields_definition.fields)

            user_ids = (CommCareUser.ids_by_domain(domain) +
                        CommCareUser.ids_by_domain(domain, is_active=False))

            existing_field_slugs = set(
                [field.slug for field in fields_definition.fields])
            for user in iter_docs(CommCareUser.get_db(), user_ids):
                user_data = user.get('user_data', {})
                for key in user_data.keys():
                    if (key and key not in existing_field_slugs
                            and not cdm.is_system_key(key)):
                        existing_field_slugs.add(key)
                        fields_definition.fields.append(
                            cdm.CustomDataField(
                                slug=key,
                                label=key,
                                is_required=False,
                            ))

            for field in fields_definition.fields:
                if cdm.is_system_key(field.slug):
                    fields_definition.fields.remove(field)
            # Only save a definition for domains which use custom user data
            if fields_definition.fields or had_fields:
                fields_definition.save()
            print 'finished domain "{}"'.format(domain)
    def handle(self, *args, **options):
        for domain in Domain.get_all():
            if domain['commtrack_enabled']:
                fields_definition = cdm.CustomDataFieldsDefinition.get_or_create(
                    domain['name'], 'ProductFields')
                had_fields = bool(fields_definition.fields)

                product_ids = Product.ids_by_domain(domain['name'])

                existing_field_slugs = set(
                    [field.slug for field in fields_definition.fields])
                for product in iter_docs(Product.get_db(), product_ids):
                    product_data = product.get('product_data', {})
                    for key in product_data.keys():
                        if key and key not in existing_field_slugs:
                            existing_field_slugs.add(key)
                            fields_definition.fields.append(
                                cdm.CustomDataField(
                                    slug=key,
                                    label=key,
                                    is_required=False,
                                ))

                for field in fields_definition.fields:
                    if cdm.is_system_key(field.slug):
                        fields_definition.fields.remove(field)
                # Only save a definition for domains which use custom product data
                if fields_definition.fields or had_fields:
                    fields_definition.save()
            print 'finished domain "{}"'.format(domain['name'])
    def handle(self, *args, **options):
        for domain in Domain.get_all():
            if domain["commtrack_enabled"]:
                fields_definition = cdm.CustomDataFieldsDefinition.get_or_create(domain["name"], "ProductFields")
                had_fields = bool(fields_definition.fields)

                product_ids = Product.ids_by_domain(domain["name"])

                existing_field_slugs = set([field.slug for field in fields_definition.fields])
                for product in iter_docs(Product.get_db(), product_ids):
                    product_data = product.get("product_data", {})
                    for key in product_data.keys():
                        if key and key not in existing_field_slugs:
                            existing_field_slugs.add(key)
                            fields_definition.fields.append(cdm.CustomDataField(slug=key, label=key, is_required=False))

                for field in fields_definition.fields:
                    if cdm.is_system_key(field.slug):
                        fields_definition.fields.remove(field)
                # Only save a definition for domains which use custom product data
                if fields_definition.fields or had_fields:
                    fields_definition.save()
            print 'finished domain "{}"'.format(domain["name"])
Example #7
0
def _get_invalid_user_data_fields(user, configured_field_keys):
    return [
        key for key in user.user_data
        if not is_system_key(key) and not key in configured_field_keys
    ]