Exemplo n.º 1
0
def _get_location_data_fields(domain):
    from corehq.apps.locations.views import LocationFieldsView
    fields_definition = SQLCustomDataFieldsDefinition.get(
        domain, LocationFieldsView.field_type)
    if fields_definition:
        return fields_definition.get_fields()
    else:
        return []
Exemplo n.º 2
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 = SQLCustomDataFieldsDefinition.get(domain,
                                                  field_view.field_type)
        if model:
            fields[field_view.field_type] = [{
                'slug': field.slug,
                'is_required': field.is_required,
                'label': field.label,
                'choices': field.choices,
                'regex': field.regex,
                'regex_msg': field.regex_msg,
            } for field in model.get_fields()]
    return fields
Exemplo n.º 3
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 = SQLCustomDataFieldsDefinition.get(domain, 'ProductFields')
    if custom_fields:
        for f in custom_fields.get_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},
    }