예제 #1
0
def model_field_paths(model,
                      exclude_field_types=(),
                      field_names=None,
                      excludes=[],
                      for_value_queryset=False):
    """
        Returns the field names of the main model.
        If for_value_queryset=True, we use attname rather than name for the field so that ForeignKeys return their [related]_id name
        instead of just [related] name.
        Since model_field_paths is used (right now) for value_query_sets, it's not
        useful to get the name of the foreign key field, because the corresponding value will always
        be the id of the related model, not the related model instance. Thus it's more accurate
        to return the _id version, since either way it points at an id. This allows us to construct
        unmodeled join classes.
    """

    # Sort by the field's position in fields if fields is defined
    return compact(
        map(
            lambda field: (field.attname if for_value_queryset else field.name)
            if field_predicate(field, exclude_field_types, field_names,
                               excludes) else None,
            sorted(model._meta.fields,
                   key=index_of_field_for_sort(field_names,
                                               for_value_queryset))))
예제 #2
0
            def dehydrate(self, bundle):
                bundle = super(JoinFeatureResource, self).dehydrate(bundle)
                def map_related_to_field_and_label(field_name, related_model):
                    """
                        Creates a mapping from the _id attribute of ForeignKeys to
                        to the related attribute (e.g. built_form_id to built_form).
                        It puts the related attribute in the main dict with its resource_uri
                        and puts a label representation in the __labels dict so that
                        the related attribute can map from its id to a label. This
                        is similar to what the regular FeatureResource does but it is
                        more manual since we only have the _id attribute and must
                        resolve the related instance ourselves
                    """
                    client_field_name = self.client_field_name(field_name)
                    related_id = getattr(bundle.obj, client_field_name) if hasattr(bundle.obj, client_field_name) else None
                    if related_id:
                        related_model_instance = related_model.objects.get(id=related_id)
                        related_field_name = field_name.replace('_id', '')
                        return {
                            # Get the resource class of the related model so we can make a uri
                            related_field_name: FootprintResource.resolve_resource_class(related_model)().get_resource_uri(related_model_instance),
                            # The label representation
                            '__labels': {related_field_name: LayerSelection.resolve_instance_label(related_model_instance)}
                        }
                    return None

                related_field_lookup = self.related_field_lookup
                if related_field_lookup:
                    # For join queries, we need to manually add related models--not the joins,
                    # rather related models on the main feature, such as a BuiltForm reference
                    bundle.data = deep_merge(bundle.data, *compact(map_dict(
                        map_related_to_field_and_label,
                        related_field_lookup
                    )))
                return bundle
예제 #3
0
def related_field_paths(manager,
                        related_model,
                        exclude_field_types=(),
                        field_names=None,
                        excludes=[],
                        separator=None,
                        for_value_queryset=False):
    """
        Iterates through the fields of the related model, appending each to the related model field name
        from the main model. Returns the list of related field paths.

        if for_values_query_set=True, we use attname instead of the name of the field. This gives us the _id version of Foreign keys,
        which is what we want assuming we're created a values_query_set, since the the value will always
        be the related instance id and not the instance itself
    """
    related_field = resolve_related_model_path_via_geographies(
        manager, related_model)
    return compact(map(
        lambda field: string.replace(
            '{0}__{1}'.format(related_field, field.attname if for_value_queryset else field.name),
            '__',
            separator or '__') if \
                field_predicate(field, exclude_field_types, field_names, excludes) else \
                None,
        # Sort by the field's position in fields if fields is defined
        sorted(
            related_model._meta.fields,
            key=index_of_field_for_sort(field_names, for_value_queryset)
    )))
예제 #4
0
            def dehydrate(self, bundle):
                bundle = super(JoinFeatureResource, self).dehydrate(bundle)
                def map_related_to_field_and_label(field_name, related_model):
                    """
                        Creates a mapping from the _id attribute of ForeignKeys to
                        to the related attribute (e.g. built_form_id to built_form).
                        It puts the related attribute in the main dict with its resource_uri
                        and puts a label representation in the __labels dict so that
                        the related attribute can map from its id to a label. This
                        is similar to what the regular FeatureResource does but it is
                        more manual since we only have the _id attribute and must
                        resolve the related instance ourselves
                    """
                    client_field_name = self.client_field_name(field_name)
                    related_id = getattr(bundle.obj, client_field_name) if hasattr(bundle.obj, client_field_name) else None
                    if related_id:
                        related_model_instance = related_model.objects.get(id=related_id)
                        related_field_name = field_name.replace('_id', '')
                        return {
                            # Get the resource class of the related model so we can make a uri
                            related_field_name: FootprintResource.resolve_resource_class(related_model)().get_resource_uri(related_model_instance),
                            # The label representation
                            '__labels': {related_field_name: LayerSelection.resolve_instance_label(related_model_instance)}
                        }
                    return None

                related_field_lookup = self.related_field_lookup
                if related_field_lookup:
                    # For join queries, we need to manually add related models--not the joins,
                    # rather related models on the main feature, such as a BuiltForm reference
                    bundle.data = deep_merge(bundle.data, *compact(map_dict(
                        map_related_to_field_and_label,
                        related_field_lookup
                    )))
                return bundle
예제 #5
0
def related_field_paths(
    manager,
    related_model,
    exclude_field_types=(),
    field_names=None,
    excludes=[],
    separator=None,
    for_value_queryset=False,
):
    """
        Iterates through the fields of the related model, appending each to the related model field name
        from the main model. Returns the list of related field paths.

        if for_values_query_set=True, we use attname instead of the name of the field. This gives us the _id version of Foreign keys,
        which is what we want assuming we're created a values_query_set, since the the value will always
        be the related instance id and not the instance itself
    """
    related_field = resolve_related_model_path_via_geographies(manager, related_model)
    return compact(
        map(
            lambda field: string.replace(
                "{0}__{1}".format(related_field, field.attname if for_value_queryset else field.name),
                "__",
                separator or "__",
            )
            if field_predicate(field, exclude_field_types, field_names, excludes)
            else None,
            # Sort by the field's position in fields if fields is defined
            sorted(related_model._meta.fields, key=index_of_field_for_sort(field_names, for_value_queryset)),
        )
    )
예제 #6
0
def create_layer_style_for_parent_model(parent_model,
                                        style_value_context_resolver,
                                        related_field=None):
    """
        Creates the LayerStyle for the given model by iterating through all of its child instances and styling
        its parent foreign_key (e.g. BuiltForm subclasses' parent foreign key is built_form_id)
        The object created is a LayerStyle instance in the following format
        LayerStyle(
            style_attributes=[
                StyleAttribute(
                    attribute='land_use_definition__id' (or anything else representing a BuiltForm id),
                    style_value_contexts=[
                        StyleValueContext(
                            value=1,
                            symbol='=',
                            default_style: Style(
                                polygon-fill='#FFFFCC'
                            )
                        ),
                        StyleValueContext(
                            value=2,
                            symbol='=',
                            default_style: Style(
                                polygon-fill='#99FF99'
                            )
                        ),
                        ...
                    ]
                )
            ]
        )
    :param parent_model: The model that has a parent foreign key
    :param style_value_context_resolver: A function that accepts the instance as an argument and returns the correct color.
    :param related_field: Optional string to specify the related field name to reach the model whose parent
    is specified here. For instance if FooFeatures has ManyToMany built_forms, which is a collection of BuiltForm subclass instance,
    then related_field should be 'built_forms'. If built_form is simply a ForeignKey on the source model, then
    this field isn't needed
    :return: A complete default context_dict for all instances of the give model
    """
    # Using the parent foreign key (e.g. builtform_id instead of id, seems unneeded)
    parent_foreign_key = '%s' % parent_model._meta.pk.attname
    attribute = '{0}__{1}'.format(
        related_field,
        parent_foreign_key) if related_field else parent_foreign_key
    instances = list(parent_model.objects.all())

    return dict(
        geometry_type=GeometryTypeKey.POLYGON,
        style_attributes=[
            dict(
                attribute=attribute,
                opacity=1,
                style_type=StyleTypeKey.CATEGORICAL,
                style_value_contexts=compact(
                    map(
                        # Find the StyleValueContext associated with the instance
                        style_value_context_resolver,
                        sorted(instances, key=lambda instance: instance.id))))
        ])
def create_layer_style_for_parent_model(parent_model, style_value_context_resolver, related_field=None):
    """
        Creates the LayerStyle for the given model by iterating through all of its child instances and styling
        its parent foreign_key (e.g. BuiltForm subclasses' parent foreign key is built_form_id)
        The object created is a LayerStyle instance in the following format
        LayerStyle(
            style_attributes=[
                StyleAttribute(
                    attribute='land_use_definition__id' (or anything else representing a BuiltForm id),
                    style_value_contexts=[
                        StyleValueContext(
                            value=1,
                            symbol='=',
                            default_style: Style(
                                polygon-fill='#FFFFCC'
                            )
                        ),
                        StyleValueContext(
                            value=2,
                            symbol='=',
                            default_style: Style(
                                polygon-fill='#99FF99'
                            )
                        ),
                        ...
                    ]
                )
            ]
        )
    :param parent_model: The model that has a parent foreign key
    :param style_value_context_resolver: A function that accepts the instance as an argument and returns the correct color.
    :param related_field: Optional string to specify the related field name to reach the model whose parent
    is specified here. For instance if FooFeatures has ManyToMany built_forms, which is a collection of BuiltForm subclass instance,
    then related_field should be 'built_forms'. If built_form is simply a ForeignKey on the source model, then
    this field isn't needed
    :return: A complete default context_dict for all instances of the give model
    """
    # Using the parent foreign key (e.g. builtform_id instead of id, seems unneeded)
    parent_foreign_key = '%s' % parent_model._meta.pk.attname
    attribute = '{0}__{1}'.format(related_field, parent_foreign_key) if related_field else parent_foreign_key
    instances = list(parent_model.objects.all())

    return dict(
        geometry_type=GeometryTypeKey.POLYGON,
        style_attributes=[
            dict(
                attribute=attribute,
                opacity=1,
                style_type=StyleTypeKey.CATEGORICAL,
                style_value_contexts=compact(map(
                    # Find the StyleValueContext associated with the instance
                    style_value_context_resolver,
                    sorted(instances, key=lambda instance: instance.id)))
            )
        ]
    )
예제 #8
0
 def user_group_name(self, global_group_name):
     """
         All ConfigEntity's define a default User Group name based on their schema.
         The one special case is GlobalConfig, whose ConfigEntity Group is
         UserGroupKey.ADMIN. It returns None here.
         The name returned is '__'.join([self.schema_prefix, global_group_name]) where global_group_name
         is a global group name, such as UserGroupKey.ADMIN. Normally there
         will just be one group per ConfigEntity with full permissions, but you must
         pass the expected global group name to form the name
     :return:
     """
     return '__'.join(compact([self.schema_prefix, global_group_name])) if \
         self.parent_config_entity else None
예제 #9
0
 def user_group_name(self, global_group_name):
     """
         All ConfigEntity's define a default User Group name based on their schema.
         The one special case is GlobalConfig, whose ConfigEntity Group is
         UserGroupKey.ADMIN. It returns None here.
         The name returned is '__'.join([self.schema_prefix, global_group_name]) where global_group_name
         is a global group name, such as UserGroupKey.ADMIN. Normally there
         will just be one group per ConfigEntity with full permissions, but you must
         pass the expected global group name to form the name
     :return:
     """
     return '__'.join(compact([self.schema_prefix, global_group_name])) if \
         self.parent_config_entity else None
    def create_result_map(self, related_models=[], map_path_segments={}):
        """
            Given the field_paths of the queryset, returns a ResultMap instance.
            ResultMap.result_fields is a list of field_paths minus specifically omitted ones--
            the parent id and geometry column.
            ResultMap.title_lookup is a lookup from the field_path to a title appropriate for the user.
            The generated title uses '.' in place of '__'
            ResultMap.value_map is a lookup from the field_path to a property path that describes
            how to convert the value to a more human readable form. This is used to convert
            instances to a readable label and dates, etc, to a more readable format.
            :param: related_models: pass the related_models represented in the query results so that unneeded
            paraent reference fields can be removed from the result fields
            :param: map_path_segments: An optional dict that matches segments of the field_paths. The value
            corresponding the key is the name to convert it to for the title. If the value is None it will
            be eliminated from the path when it is rejoined with '.'
        """

        result_paths = self.model_result_paths(related_models)
        # Get a mapping of the each result field_path to its field class path along
        # with the related model of that field, if the field is a ForeignKey or AutoField
        result_field_path_lookup = self.model_result_field_path_field_lookup(
            related_models, True)
        join_models = map(lambda model: full_module_path(model.__base__),
                          related_models)
        return ResultMap(
            # Replace '__' with '_x_'. We can't use __ because it confuses tastypie
            result_fields=map(lambda path: string.replace(path, '__', '_x_'),
                              result_paths),
            # Create a lookup from field name to title
            # The only processing we do to the title is to remove the middle path
            title_lookup=map_to_dict(
                lambda path: [
                    # Replace '__' with '_x_'. We can't use __ because it confuses tastypie
                    string.replace(path, '__', '_x_'),
                    # match each segment to map_path_segments or failing that return the segment
                    # remove segments that map to None
                    '__'.join(
                        compact(
                            map(
                                lambda segment: map_path_segments.get(
                                    segment, segment), path.split('__'))))
                ],
                result_paths),
            field_lookup=map_dict_to_dict(
                lambda field_path, tup: [field_path, tup[0]],
                result_field_path_lookup),
            related_model_lookup=compact_dict(
                map_dict_to_dict(lambda field_path, tup: [field_path, tup[1]],
                                 result_field_path_lookup)),
            join_models=join_models,
        )
예제 #11
0
def _update_or_create_config_entity_group(config_entity, global_group_name):
    # ConfigEntity group name is created by combining it's schema with the global
    # group's name. The exception is GlobalConfig, whose ConfigEntity Group is simply the global admin group
    if not config_entity.schema_prefix:
        # GlobalConfig case, nothing to do here
        return Group.objects.get(name=global_group_name)

    config_entity_group_name = '__'.join(
        compact([config_entity.schema_prefix, global_group_name]))

    # The superiors of this group are our global Group and
    # the parent ConfigEntity's groups whose global Group is equal or greater than ours
    # (e.g. foo__user's superior is user and and bar_user and bar_manager if bar is the parent ConfigEntity of foo)

    # Get the name of all groups of the parent ConfigEntity
    all_parent_config_entity_group_hierarchies = config_entity.parent_config_entity.group_hierarchies.all(
    )

    # Only accept Groups that are at least at our global Group level
    eligible_global_groups_names = UserGroupKey.GLOBAL[
        0:UserGroupKey.GLOBAL.index(global_group_name) + 1]

    # Given a minimum eligible permission level (e.g. above Manager),
    # find all of the parent ConfigEntity's Groups that have at least that permission level (e.g. Manager and Admin).
    # These logically deserve all the permissions of the child ConfigEntity Group.
    # It's unlikely that a parent ConfigEntity Group would be a lower permission level (e.g. User), so this will normally accept all parent ConfigEntity Groups
    config_entity_groups_matching_eligible_global_groups = []
    for group_hierarchy in all_parent_config_entity_group_hierarchies:
        if group_hierarchy.globalized_group(
        ).name in eligible_global_groups_names:
            config_entity_groups_matching_eligible_global_groups.append(
                group_hierarchy)

    # Sort by ascending permission. This probably doesn't matter--
    # it just means we process the lower permission first for consistent logging. (There is typically only one Group anyway)
    group_hierarchies = sorted(
        config_entity_groups_matching_eligible_global_groups,
        key=lambda group_hierarchy: eligible_global_groups_names.index(
            group_hierarchy.globalized_group().name))

    # Combine our global Group name with the parent ConfigEntity Groups
    superior_group_names = unique([global_group_name] + map(
        lambda group_hierarchy: group_hierarchy.group.name, group_hierarchies))

    # Update or create the Group
    return update_or_create_group(name=config_entity_group_name,
                                  config_entity=config_entity,
                                  superiors=superior_group_names)
예제 #12
0
    def create_result_map(self, related_models=[], map_path_segments={}):
        """
            Given the field_paths of the queryset, returns a ResultMap instance.
            ResultMap.result_fields is a list of field_paths minus specifically omitted ones--
            the parent id and geometry column.
            ResultMap.title_lookup is a lookup from the field_path to a title appropriate for the user.
            The generated title uses '.' in place of '__'
            ResultMap.value_map is a lookup from the field_path to a property path that describes
            how to convert the value to a more human readable form. This is used to convert
            instances to a readable label and dates, etc, to a more readable format.
            :param: related_models: pass the related_models represented in the query results so that unneeded
            paraent reference fields can be removed from the result fields
            :param: map_path_segments: An optional dict that matches segments of the field_paths. The value
            corresponding the key is the name to convert it to for the title. If the value is None it will
            be eliminated from the path when it is rejoined with '.'
        """

        result_paths = self.model_result_paths(related_models)
        # Get a mapping of the each result field_path to its field class path along
        # with the related model of that field, if the field is a ForeignKey or AutoField
        result_field_path_lookup = self.model_result_field_path_field_lookup(related_models, True)
        join_models = map(lambda model: full_module_path(model.__base__), related_models)
        return ResultMap(
            # Replace '__' with '_x_'. We can't use __ because it confuses tastypie
            result_fields=map(lambda path: string.replace(path, '__', '_x_'), result_paths),
            # Create a lookup from field name to title
            # The only processing we do to the title is to remove the middle path
            title_lookup=map_to_dict(
                lambda path: [
                    # Replace '__' with '_x_'. We can't use __ because it confuses tastypie
                    string.replace(path, '__', '_x_'),
                    # match each segment to map_path_segments or failing that return the segment
                    # remove segments that map to None
                    '__'.join(compact(
                        map(
                            lambda segment: map_path_segments.get(segment, segment),
                            path.split('__')
                        )
                    ))
                ],
                result_paths
            ),
            field_lookup=map_dict_to_dict(lambda field_path, tup: [field_path, tup[0]], result_field_path_lookup),
            related_model_lookup=compact_dict(map_dict_to_dict(lambda field_path, tup: [field_path, tup[1]], result_field_path_lookup)),
            join_models=join_models,

        )
    def dump_values(self, attribute):
        """
            Dumps this instance's values for the given adopted attribute, along with that of the donor hierarchy
        :return:
        """
        resolved_attribute = self.through_attribute(self.many_field(attribute)) if \
            has_explicit_through_class(self, attribute) else \
            attribute

        keys = sorted(map(lambda x: x.key, self._computed(attribute)))
        owned_keys = sorted(map(lambda x: x.key, getattr(self, resolved_attribute).all()))

        return '\n'.join(compact([
            ': '.join([self.name, str(len(keys)), ', '.join(keys)]),
            '\tof which %s are owned: %s' % (str(len(owned_keys)), ', '.join(owned_keys)),
            self.donor().dump_values(attribute) if self.donor() else None
        ]))
예제 #14
0
def model_field_paths(model, exclude_field_types=(), field_names=None, excludes=[], for_value_queryset=False):
    """
        Returns the field names of the main model.
        If for_value_queryset=True, we use attname rather than name for the field so that ForeignKeys return their [related]_id name
        instead of just [related] name.
        Since model_field_paths is used (right now) for value_query_sets, it's not
        useful to get the name of the foreign key field, because the corresponding value will always
        be the id of the related model, not the related model instance. Thus it's more accurate
        to return the _id version, since either way it points at an id. This allows us to construct
        unmodeled join classes.
    """

    # Sort by the field's position in fields if fields is defined
    return compact(map(
        lambda field: (field.attname if for_value_queryset else field.name) if field_predicate(field, exclude_field_types, field_names, excludes) else None,
        sorted(model._meta.fields, key=index_of_field_for_sort(field_names, for_value_queryset))
    ))
def create_layer_style_for_related_field(related_field_path, related_model, color_lookup, color_lookup_field, visible):
    """
        Creates the CSS context_dict to use in a LayerStyle instance for the given ForeignKey model field
    :param related_field_path: If the field is a many-to-many, specify this, e.g. 'built_form__id'.
    :param related_model - Model object having items with a color_lookup_field
    :param color_lookup: A dict that maps a field of the ForeignKey model class to a color
    :param color_lookup_field: The field of the ForeignKey model that matches the keys of the color_lookup
    :return: A complete default context_dict for the give model field
    """

    def create_style_value_context(lookup_field_value, color):
        if color:
            try:
                foreign_key = related_model.objects.get(**{color_lookup_field: lookup_field_value}).id
                return StyleValueContext(
                    value=foreign_key,
                    symbol='=',
                    style=Style(
                        polygon_fill=color,
                        polygon_opacity=0.8,
                        line_color='#d2d2d5',
                        line_opacity=0.7,
                        line_width=.5
                    )
                )
            except:
                return None
        return None

    return dict(
        geometry_type=GeometryTypeKey.POLYGON,
        style_attributes=[
            dict(
                attribute=related_field_path,
                opacity=1,
                visible=visible,

                style_type=StyleTypeKey.CATEGORICAL,
                style_value_contexts=[null_style_value_context()] +
                    sorted(compact(map_dict(
                        create_style_value_context,
                        color_lookup
                    )), key=lambda style_value_context: style_value_context.value)
            )
        ]
    )
def create_layer_style_for_related_field(related_field_path, related_model, color_lookup, color_lookup_field, visible):
    """
        Creates the CSS context_dict to use in a LayerStyle instance for the given ForeignKey model field
    :param related_field_path: If the field is a many-to-many, specify this, e.g. 'built_form__id'.
    :param related_model - Model object having items with a color_lookup_field
    :param color_lookup: A dict that maps a field of the ForeignKey model class to a color
    :param color_lookup_field: The field of the ForeignKey model that matches the keys of the color_lookup
    :return: A complete default context_dict for the give model field
    """

    def create_style_value_context(lookup_field_value, color):
        if color:
            try:
                foreign_key = related_model.objects.get(**{color_lookup_field: lookup_field_value}).id
                return StyleValueContext(
                    value=foreign_key,
                    symbol='=',
                    style=Style(
                        polygon_fill=color,
                        polygon_opacity=0.8,
                        line_color='#d2d2d5',
                        line_opacity=0.7,
                        line_width=.5
                    )
                )
            except:
                return None
        return None

    return dict(
        geometry_type=GeometryTypeKey.POLYGON,
        style_attributes=[
            dict(
                attribute=related_field_path,
                opacity=1,
                visible=visible,

                style_type=StyleTypeKey.CATEGORICAL,
                style_value_contexts=[null_style_value_context()] +
                    sorted(compact(map_dict(
                        create_style_value_context,
                        color_lookup
                    )), key=lambda style_value_context: style_value_context.value)
            )
        ]
    )
예제 #17
0
def _update_or_create_config_entity_group(config_entity, global_group_name):
    # ConfigEntity group name is created by combining it's schema with the global
    # group's name. The exception is GlobalConfig, whose ConfigEntity Group is simply the global admin group
    if not config_entity.schema_prefix:
        # GlobalConfig case, nothing to do here
        return Group.objects.get(name=global_group_name)

    config_entity_group_name = '__'.join(compact([config_entity.schema_prefix, global_group_name]))

    # The superiors of this group are our global Group and
    # the parent ConfigEntity's groups whose global Group is equal or greater than ours
    # (e.g. foo__user's superior is user and and bar_user and bar_manager if bar is the parent ConfigEntity of foo)

    # Get the name of all groups of the parent ConfigEntity
    all_parent_config_entity_group_hierarchies = config_entity.parent_config_entity.group_hierarchies.all()

    # Only accept Groups that are at least at our global Group level
    eligible_global_groups_names = UserGroupKey.GLOBAL[0:UserGroupKey.GLOBAL.index(global_group_name)+1]

    # Given a minimum eligible permission level (e.g. above Manager),
    # find all of the parent ConfigEntity's Groups that have at least that permission level (e.g. Manager and Admin).
    # These logically deserve all the permissions of the child ConfigEntity Group.
    # It's unlikely that a parent ConfigEntity Group would be a lower permission level (e.g. User), so this will normally accept all parent ConfigEntity Groups
    config_entity_groups_matching_eligible_global_groups = []
    for group_hierarchy in all_parent_config_entity_group_hierarchies:
        if group_hierarchy.globalized_group().name in eligible_global_groups_names:
            config_entity_groups_matching_eligible_global_groups.append(group_hierarchy)

    # Sort by ascending permission. This probably doesn't matter--
    # it just means we process the lower permission first for consistent logging. (There is typically only one Group anyway)
    group_hierarchies = sorted(
        config_entity_groups_matching_eligible_global_groups,
        key=lambda group_hierarchy: eligible_global_groups_names.index(group_hierarchy.globalized_group().name))

    # Combine our global Group name with the parent ConfigEntity Groups
    superior_group_names = unique(
        [global_group_name] +
        map(lambda group_hierarchy: group_hierarchy.group.name, group_hierarchies)
    )

    # Update or create the Group
    return update_or_create_group(
        name=config_entity_group_name,
        config_entity=config_entity,
        superiors=superior_group_names)
예제 #18
0
    def config_entity_groups(self):
        """
            Get ConfigEntity-specific groups of the given ConfigEntity.
        :return: Group objects of the ConfigEntity
        """
        from footprint.client.configuration.fixture import ConfigEntityFixture

        # Each ConfigEntity class has its own groups according to the configuration
        # global groups listed in its configuration
        # Iterate through the configured global groups and create ConfigEntity-specific versions
        client_fixture = ConfigEntityFixture.resolve_config_entity_fixture(self)

        # Map the fixture to its ConfigEntity Group
        # GlobalConfig returns nothing here since the SuperAdmin Group is both its Global Group
        # and ConfigEntity Group
        return compact(map(
            lambda global_group_name: self.config_entity_group(global_group_name),
            client_fixture.default_config_entity_groups()
        ))
예제 #19
0
    def config_entity_groups(self):
        """
            Get ConfigEntity-specific groups of the given ConfigEntity.
        :return: Group objects of the ConfigEntity
        """
        from footprint.client.configuration.fixture import ConfigEntityFixture

        # Each ConfigEntity class has its own groups according to the configuration
        # global groups listed in its configuration
        # Iterate through the configured global groups and create ConfigEntity-specific versions
        client_fixture = ConfigEntityFixture.resolve_config_entity_fixture(self)

        # Map the fixture to its ConfigEntity Group
        # GlobalConfig returns nothing here since the SuperAdmin Group is both its Global Group
        # and ConfigEntity Group
        return compact(map(
            lambda global_group_name: self.config_entity_group(global_group_name),
            client_fixture.default_config_entity_groups()
        ))
예제 #20
0
 def __init__(self, result_fields, title_lookup, field_lookup, related_model_lookup, join_models):
     self['result_fields'] = result_fields
     self['title_lookup'] = title_lookup
     self['field_lookup'] = field_lookup
     self['related_model_lookup'] = related_model_lookup
     self['join_models'] = join_models
     # Create a list of the attributes that correspond to the join_models so we can resolve foreign keys
     # on each JoinFeature (These will look like geographies_3__countyboundary10rel__countyboundary10_ptr_id)
     # Note that if a join_model is the primary geography, it won't match anything in related_model_lookup,
     # hence we use compact to remove None from the results. It isn't needed in the join_model_attributes.
     self['django_join_model_attributes'] = compact(map(
             lambda model_path: map_dict_first(
                 lambda key, value: key if value == model_path else None,
                 related_model_lookup),
             join_models))
     # Map each join model attribute to the _x_ format like result_fields
     # We use these in the distinct clause of the query to get just primary key fields or their join model
     # foreign key equivalents
     self['join_model_attributes'] = map(
         lambda path: string.replace(path, '__', '_x_'),
         self.django_join_model_attributes)