Generic proxies

These proxies are generic. They can be used regardless of the type of source and destination.

Rename

pydantic model crudcreator.proxy.proxy.Rename.Rename[source]

Proxy that changes entity field names. Also changes the entity name.

Example of descriptor, which changes the name of the interface on the destination side to “my_entity”, and the field name “column_1” to “field_1” on the destination side:

{
    "name": "Rename",
    "params": {
        "interface_name": "my_entity",
        "translation_list": [
            {
                "source": "column_1",
                "destination": "field_1"
            }
        ]
    }
}
field params: RenameParams [Required][source]

Rename proxy settings.

async create(
params: CreateParams,
)[source]

Change column names from destination to source, then call the next proxy.

Parameters:

params (CreateParams) –

async delete(
params: DeleteParams,
)[source]

Change ids from destination to source, then call the next proxy.

Parameters:

params (DeleteParams) –

async read(
params: ReadParams,
) list[dict[str, Any]][source]

Changes filter names from destination to source. Changes the name of columns to be read from destination to source. Calls the next proxy. Then changes the name of the result columns from source to destination.

Parameters:

params (ReadParams) –

Return type:

list[dict[str, Any]]

async update(
params: UpdateParams,
)[source]

Changes column names and ids from destination to source, then calls the next proxy.

Parameters:

params (UpdateParams) –



pydantic model crudcreator.proxy.proxy.Rename.RenameParams[source]

Rename proxy settings.

Validators:
field interface_name: str [Required][source]

Destination-side entity name.

field translation_list: list[Translation] [Required][source]

List of changes to be made.

Validated by:
  • unique_value

RenameParams.unique_value[source]

Checks that each field has a unique name, both on the source and destination sides.

Parameters:

translation_list (list[Translation]) –

Return type:

list[Translation]

property destination_to_source_index: dict[str, str][source]

A destination->source index built automatically from translation_list.

property source_to_destination_index: dict[str, str][source]

A source->destination index built automatically from translation_list.



pydantic model crudcreator.proxy.proxy.Rename.Translation[source]
field destination: str [Required][source]

Destination-side field name.

field source: str [Required][source]

Source-side field name.

RecastType

pydantic model crudcreator.proxy.proxy.type.RecastType.RecastType[source]

Changes the type of a field and reprocesses it to match the new type.

Example of descriptor, which changes the type of the “field_bool_converted” field, which is a str at source, and becomes a boolean at destination.

{
    "name": "RecastType",
    "params": {
        "list_recast_field": [
            {
                "field_name": "field_bool_converted",
                "special_type": "$oui_non_type$"
            }
        ]
    }
}

With “yes_no_type” defined as follows:

def oui_non_to_bool(v: str):
    if v == "oui":
        return True
    elif v == "non":
        return False
    elif v == None:
        return None
    else:
        raise NotImplementedError()

def bool_to_oui_non(v: bool):
    if v == True:
        return "oui"
    elif v == False:
        return "non"
    elif v == None:
        return None
    else:
        raise NotImplementedError() 

oui_non_type = SpecialType(
    destination_type=bool,
    destination_to_source=bool_to_oui_non,
    source_to_destination=oui_non_to_bool
)

Let’s assume that the source contains the following entities:

[
    {
        "field_foo": "1",
        "field_bar": "1",
        "field_bool_converted": "oui"
    },
    {
        "field_foo": "1",
        "field_bar": "1",
        "field_bool_converted": "non"
    },
    {
        "field_foo": "1",
        "field_bar": "2",
        "field_bool_converted": null
    }
]

A read will therefore return a result of this form :

[
    {
        "field_foo": "1",
        "field_bar": "1",
        "field_bool_converted": true
    },
    {
        "field_foo": "1",
        "field_bar": "1",
        "field_bool_converted": false
    },
    {
        "field_foo": "1",
        "field_bar": "2",
        "field_bool_converted": null
    }
]

And the entity type interface will be changed accordingly (field_bool_converted will be of type bool).

The recast is also applied on the filters, the creation body, the update body and ids, and the delete ids.

field params: RecastTypeParams [Required][source]

RecastType proxy settings.

async create(
params: CreateParams,
)[source]

Recast fields from destination type to source type. Then sends the query to the next proxy.

Parameters:

params (CreateParams) –

async delete(
params: DeleteParams,
)[source]

Recast id fields from destination type to source type. Then sends the query to the next proxy.

Parameters:

params (DeleteParams) –

async read(
params: ReadParams,
) list[Any][source]

Recast filters from destination type to source type. Sends the query to the next proxy. Then recasts the result fields from the source type to the destination type, before returning the result.

Parameters:

params (ReadParams) –

Return type:

list[Any]

async update(
params: UpdateParams,
)[source]

Recast update fields and id fields from destination type to source type. Then sends the query to the next proxy.

Parameters:

params (UpdateParams) –



pydantic model crudcreator.proxy.proxy.type.RecastType.RecastTypeParams[source]

RecastType proxy settings.

field list_recast_field: list[FieldRecast] [Required][source]

List of recasts to do.

property recast_index: dict[str, SpecialType][source]

A field_name->special_type index built automatically from list_recast_field.



pydantic model crudcreator.proxy.proxy.type.RecastType.FieldRecast[source]
field field_name: str [Required][source]

The name of the field to be recast.

field special_type: SpecialType [Required][source]

The new type.



pydantic model crudcreator.proxy.proxy.type.SpecialType.SpecialType[source]
Validators:
field destination_to_source: Any [Required][source]

The function that reprocesses the destination-side field to set it to the correct source-side type.

Validated by:
field destination_type: Any [Required][source]

Destination-side field type.

field source_to_destination: Any [Required][source]

The function that reprocesses fields on the source side to set them to the correct type on the destination side.

Validated by:
field source_type: Any = None[source]

Source-side field type.

validator callable_type  »  source_to_destination, destination_to_source[source]

AddFilter

pydantic model crudcreator.proxy.proxy.AddFilter.AddFilter[source]

Adds hard-coded filter instances to the read CRUD request.

Example of descriptor, which will return, to the user executing a read, only those entities whose “can_be_seen” field is set to True:

{
    "name": "AddFilter",
    "params": {
        "list_filter_instance_to_add": [
            {
            "field_name": "can_be_seen",
            "filter_value": true,
            "filtration_type": "equal"
            }
        ]
    }
}
field params: AddFilterParams [Required][source]

AddFilter proxy parameters.

async read(
params: ReadParams,
) list[dict[str, Any]][source]

Adds the list of filter instances to the CRUD request, then forwards the request to the next proxy.

Parameters:

params (ReadParams) –

Return type:

list[dict[str, Any]]



pydantic model crudcreator.proxy.proxy.AddFilter.AddFilterParams[source]

AddFilter proxy parameters.

field list_filter_instance_to_add: list[FilterInstance] [Required][source]

The list of filter instances to be added.

SoftDelete

pydantic model crudcreator.proxy.proxy.SoftDelete.SoftDelete[source]

Transforms the delete into a “soft delete”. The delete thus becomes an update on fields that will indicate whether or not the entity should be considered as deleted.

Example of descriptor, which, when read, only returns entities where is_active!=false and is_deleted!=true. The “is_active” value of each entity will remain visible on reading (but not that of the “is_deleted” field, which therefore does not exist in the eyes of the CRUD user).

{
    "name": "SoftDelete",
    "params": {
        "list_field_value_if_deleted": [
            {
                "field_name": "is_active",
                "value_if_deleted": false,
                "keep_visible": true
            },
            {
                "field_name": "is_deleted",
                "value_if_deleted": true,
                "keep_visible": false
            }
        ]
    }
}
field params: SoftDeleteParams [Required][source]

SoftDelete proxy settings.

async delete(
params: DeleteParams,
)[source]

The delete becomes an update of the fields indicating deletion.

Parameters:

params (DeleteParams) –

async read(
params: ReadParams,
) list[dict[str, Any]][source]

We only read entities that have not been soft deleted.

Parameters:

params (ReadParams) –

Return type:

list[dict[str, Any]]



pydantic model crudcreator.proxy.proxy.SoftDelete.SoftDeleteParams[source]

SoftDelete proxy settings.

field list_field_value_if_deleted: list[FieldValueIfDeleted] [Required][source]

List of fields/values that indicate that the entity is deleted. This is an “OR” for reading: if only one of the fields has the value “value_if_deleted”, then the field is considered deleted. On the other hand, “delete” will set all the fields in the list to the correct value.

property value_if_deleted_index: dict[str, FieldValueIfDeleted][source]

Index field_name->FieldValueIfDeleted automatically created from list_field_value_if_deleted.



pydantic model crudcreator.proxy.proxy.SoftDelete.FieldValueIfDeleted[source]
field field_name: str [Required][source]

The field whose value determines whether an entity is deleted or not.

field keep_visible: bool [Required][source]

Indicates whether the field can still be read, or whether it is completely invisible to the CRUD user.

field value_if_deleted: Any [Required][source]

The value of the field indicating whether the entity is deleted. TODO: allow to enter a function (datetime.now for example).

AddOptions

pydantic model crudcreator.proxy.proxy.AddOptions.AddOptions[source]

Adds options to the interface.

Example of descriptor, which adds two read options, “limit” and “offset”, as well as an update option:

{
    "name": "AddOptions",
    "params": {
        "list_read_options": [
            {
                "name": "limit",
                "type": "int",
                "default": null,
                "is_mandatory": false
            },
            {
                "name": "offset",
                "type": "int",
                "default": null,
                "is_mandatory": false
            }
        ],
        "list_updator_options": [
            {
                "name": "add_update_date",
                "type": "bool",
                "default": true,
                "is_mandatory": false
            }
        ]
    }
}
field params: AddOptionsParams [Required][source]

AddOptions proxy settings.



pydantic model crudcreator.proxy.proxy.AddOptions.AddOptionsParams[source]

AddOptions proxy settings.

field list_creator_options: list[OptionModel] = [][source]

The list of options that will be requested from the CRUD user for create.

field list_deletor_options: list[OptionModel] = [][source]

The list of options the CRUD user will be asked to delete.

field list_read_options: list[OptionModel] = [][source]

The list of options that will be requested from the CRUD user for the read.

field list_updator_options: list[OptionModel] = [][source]

The list of options that will be requested from the CRUD user for the update.

AddDefault

pydantic model crudcreator.proxy.proxy.AddDefault.AddDefault[source]

Adds default values to certain fields.

Example of descriptor, which will add the default value of 10 to the “field_foo” field:

{
    "name": "AddDefault",
    "params": {
        "default_on_fields": [
            {
                "field_name": "field_foo",
                "default": 10
            }
        ]
    }
}
field params: AddDefaultParams [Required][source]

AddDefault proxy settings.



pydantic model crudcreator.proxy.proxy.AddDefault.AddDefaultParams[source]

AddDefault proxy settings.

field default_on_fields: list[DefaultOnField] [Required][source]

List of default fields/values to be given.

property default_index: dict[str, list[FilterType]][source]

Index field_name->default automatically created from default_on_fields.

AddWriteValue

pydantic model crudcreator.proxy.proxy.AddWriteValue.AddWriteValue[source]

Adds hard-coded values to creation or update.

Example of descriptor, which adds a new value at creation (creation date), and a new value at update (the update date):

{
    "name": "AddWriteValue",
    "params": {
        "list_create_value": [
            {
                "name": "creation_date",
                "value": "$now$"
            }
        ],

        "list_update_value": [
            {
                "name": "last_update_date",
                "value": "$now$"
            }
        ]
    }
}

With “now” a substitution defined as follows:

"now": datetime.now
field params: AddWriteValueParams [Required][source]

AddWriteValue proxy parameters.

async create(
params: CreateParams,
)[source]

Adds the new values to the CRUD request, then forwards the request to the next proxy.

Parameters:

params (CreateParams) –

async update(
params: UpdateParams,
)[source]

Adds the new values to the CRUD request, then forwards the request to the next proxy.

Parameters:

params (UpdateParams) –



pydantic model crudcreator.proxy.proxy.AddWriteValue.AddWriteValueParams[source]

AddWriteValue proxy parameters.

field list_create_value: list[WriteValue] [Required][source]

The list of values to be added to the creation.

field list_update_value: list[WriteValue] [Required][source]

The list of values at update.

AddIdValue

pydantic model crudcreator.proxy.proxy.AddIdValue.AddIdValue[source]

Adds hard-coded ids to CRUD update and delete requests. The ids are used to select the entity to be updated or deleted.

Example of descriptor :

{
    "name": "AddIdValue",
    "params": {
        "list_ids_value": [
            {
                "name": "field_1",
                "value": 1
            }
        ]
    }
}
field params: AddIdValueParams [Required][source]

AddIdValue proxy settings.

async delete(
params: DeleteParams,
)[source]

Adds the ids to the CRUD request, then forwards the request to the next proxy.

Parameters:

params (DeleteParams) –

async update(
params: UpdateParams,
)[source]

Adds the ids to the CRUD request, then forwards the request to the next proxy.

Parameters:

params (UpdateParams) –



pydantic model crudcreator.proxy.proxy.AddIdValue.AddIdValueParams[source]

AddIdValue proxy settings.

field list_ids_value: list[IdValue] [Required][source]

List of ids to be added to CRUD requests.

GroupBy

pydantic model crudcreator.proxy.proxy.GroupBy.GroupBy[source]

Has more or less the same effect as a SQL “group by” accompanied by a “GROUP_CONCAT”. Groups entities by distinct values of fields appearing in grouped_by_fields, and groups all entities with these values in a list.

Not to be confused with the “GatherField” proxy.

Example of descriptor. Group by field_foo and field_bar, and collects the list of entities in the “my_group” field:

{
    "name": "GroupBy",
    "params": {
        "group_name": "my_group",
        "grouped_by_fields": ["field_foo", "field_bar"],
        "one_elem_with_all_none_means_empty": true,
        "see_group_only_on_option": "extend_group"
    }
}

Let’s assume that the source contains the following entities:

[
    {
        "field_foo": "1",
        "field_bar": "1",
        "other_field": "a",
        "other_field_2": "b"
    },
    {
        "field_foo": "1",
        "field_bar": "1",
        "other_field": "c",
        "other_field_2": "d"
    },
    {
        "field_foo": "1",
        "field_bar": "2",
        "other_field": "a",
        "other_field_2": "b"
    }
]

A read will therefore return a result of this form :

[
    {
        "field_foo": "1",
        "field_bar": "1",
        "my_group": [
            {
                "other_field": "a",
                "other_field_2": "b"
            },
            {
                "other_field": "c",
                "other_field_2": "d"
            }
        ]
    },
    {
        "field_foo": "1",
        "field_bar": "2",
        "my_group": [
            {
                "other_field": "a",
                "other_field_2": "b"
            }
        ]
    }
]
field params: GroupByParams [Required][source]

GroupBy proxy settings.

async read(
params: ReadParams,
) list[dict[str, Any]][source]

Builds the list of fields to be read, depending on whether the option is enabled. Sends the request to the next proxy. Then groups the entities as required, before returning the result.

Parameters:

params (ReadParams) –

Return type:

list[dict[str, Any]]



pydantic model crudcreator.proxy.proxy.GroupBy.GroupByParams[source]

GroupBy proxy settings.

field group_name: str [Required][source]

The name of the list that will contain all the other fields.

field grouped_by_fields: list[str] [Required][source]

Names of fields to be grouped by.

field one_elem_with_all_none_means_empty: bool [Required][source]

If there is only one element in the list, and all the attributes of this element are set to None, then the list is considered empty. (to manage outer joins)

field see_group_only_on_option: str | None = None[source]

The name of the option which, if set to “True”, displays the group in the entities read.

property index_grouped_by_fields: dict[str, bool][source]

Index on grouped by field names. Automatically created from grouped_by_fields.

GatherFields

pydantic model crudcreator.proxy.proxy.GatherFields.GatherFields[source]

Groups several fields from the same entity into a single object field. Not a “group by” as understood in SQL. The group will therefore be an object and not a list. Not to be confused with the “GroupBy” proxy.

Example of descriptor. Gathers field_foo and field_bar into a single field named “my_group”

{
    "name": "GatherFields",
    "params": {
        "group_name": "my_group",
        "gathered_fields": ["field_foo", "field_bar"],
        "see_group_only_on_option": "extend_group"
    }
}

Let’s assume that the source contains the following entities:

[
    {
        "field_foo": "1",
        "field_bar": "1",
        "other_field": "a",
        "other_field_2": "b"
    },
    {
        "field_foo": "1",
        "field_bar": "1",
        "other_field": "c",
        "other_field_2": "d"
    },
    {
        "field_foo": "1",
        "field_bar": "2",
        "other_field": "a",
        "other_field_2": "b"
    }
]

A read will therefore return a result of this form :

[
    {
        "other_field": "a",
        "other_field_2": "b",
        "my_group": [
            {
                "field_foo": "1",
                "field_bar": "1"
            }
        ]
    },
    {
        "other_field": "c",
        "other_field_2": "d",
        "my_group": [
            {
                "field_foo": "1",
                "field_bar": "1"
            }
        ]
    },
    {
        "other_field": "a",
        "other_field_2": "b"
        "my_group": [
            {
                "field_foo": "1",
                "field_bar": "2"
            }
        ]
    }
]
field params: GatherFieldsParams [Required][source]

GatherFields proxy settings.

async read(
params: ReadParams,
) list[dict[str, Any]][source]

Builds the list of fields to be read, depending on whether the option is enabled. Sends the request to the next proxy. Then groups the entities as required, before returning the result.

Parameters:

params (ReadParams) –

Return type:

list[dict[str, Any]]



pydantic model crudcreator.proxy.proxy.GatherFields.GatherFieldsParams[source]

GatherFields proxy settings.

field gathered_fields: list[str] [Required][source]

The list of field names to be collected in the group.

field group_name: str [Required][source]

The name to give to the new group.

field see_group_only_on_option: str | None = None[source]

The name of the option which, if set to “True”, displays the group in the entities read.

property index_gathered_fields: dict[str, bool][source]

Index on grouped field names. Automatically created from gathered_fields.

Firewalls

ReadFirewall

pydantic model crudcreator.proxy.proxy.ReadFirewall.ReadFirewall[source]

Whitelists the fields that can be read by the CRUD user. Set can_be_read to False for other interface fields.

Example of descriptor, which makes only the “field_foo” and “field_bar” fields visible for reading:

{
    "name": "ReadFirewall",
    "params": {
        "list_readable_field_name": [
            "field_foo",
            "field_bar"
        ]
    }
}
field params: ReadFirewallParams [Required][source]

ReadFirewall proxy settings.

async read(
params: ReadParams,
) list[dict[str, Any]][source]

Checks that the fields to be read, given in the CRUD request, are indeed part of the whitelist.

Parameters:

params (ReadParams) –

Return type:

list[dict[str, Any]]



pydantic model crudcreator.proxy.proxy.ReadFirewall.ReadFirewallParams[source]

ReadFirewall proxy settings.

field list_readable_field_name: list[str] [Required][source]

List of field names that the CRUD user can read.

property index_readable_field_name: dict[str, bool][source]

Index on field names. Automatically created from list_readable_field_name.

CreateFirewall

pydantic model crudcreator.proxy.proxy.CreateFirewall.CreateFirewall[source]

Whitelists the fields that can be filled in when an entity is created by the CRUD user. Set can_be_created to False for other interface fields.

Example of descriptor, which allows only the “field_foo” and “field_bar” fields to be filled at creation:

{
    "name": "CreateFirewall",
    "params": {
        "list_creatable_field_name": [
            "field_foo",
            "field_bar"
        ]
    }
}
field params: CreateFirewallParams [Required][source]

CreateFirewall proxy settings.

async create(
params: CreateParams,
) list[dict[str, Any]][source]

Checks that the fields entered in the CRUD request are part of the whitelist.

Parameters:

params (CreateParams) –

Return type:

list[dict[str, Any]]



pydantic model crudcreator.proxy.proxy.CreateFirewall.CreateFirewallParams[source]

CreateFirewall proxy settings.

field list_creatable_field_name: list[str] [Required][source]

The list of field names that the CRUD user can fill in when creating an entity.

property index_creatable_field_name: dict[str, bool][source]

Index on field names. Automatically created from list_creatable_field_name.

UpdateFirewall

pydantic model crudcreator.proxy.proxy.UpdateFirewall.UpdateFirewall[source]

Whitelists the fields that can be filled in when an entity is updated by the CRUD user. Set can_be_updated to False for other interface fields.

Example of descriptor, which allows only the “field_foo” and “field_bar” fields to be filled at update:

{
    "name": "UpdateFirewall",
    "params": {
        "list_updatable_field_name": [
            "field_foo",
            "field_bar"
        ]
    }
}
field params: UpdateFirewallParams [Required][source]

UpdateFirewall proxy settings.

async update(
params: UpdateParams,
) list[dict[str, Any]][source]

Checks that the fields entered in the CRUD request are part of the whitelist.

Parameters:

params (UpdateParams) –

Return type:

list[dict[str, Any]]



pydantic model crudcreator.proxy.proxy.UpdateFirewall.UpdateFirewallParams[source]

UpdateFirewall proxy settings.

field list_updatable_field_name: list[str] [Required][source]

The list of field names that the CRUD user can fill in when updating an entity.

property index_updatable_field_name: dict[str, bool][source]

Index on field names. Automatically created from list_updatable_field_name.

FilterFirewall

pydantic model crudcreator.proxy.proxy.FilterFirewall.FilterFirewall[source]

Whitelists filters that can be set by the CRUD user during the read. Modifies list_allowed_filter_type of fields in the interface.

Example of descriptor, which allows a “contain” filter on “field_foo” and an “equal” filter on “field_bar”:

{
    "name": "FilterFirewall",
    "params": {
        "allowed_filter_on_fields": [
            {
                "field_name": "field_foo",
                "allowed_filter_type": {
                    "filtration_type": "contain", 
                    "is_mandatory": false,
                    "default": null
                }
            },
            {
                "field_name": "field_bar",
                "allowed_filter_type": {
                    "filtration_type": "equal", 
                    "is_mandatory": true,
                    "default": null
                }
            }
        ]
    }
}
field params: FilterFirewallParams [Required][source]

FilterFirewall proxy settings.

async read(
params: ReadParams,
) list[dict[str, Any]][source]

Does nothing for now. TODO: add validation.

Parameters:

params (ReadParams) –

Return type:

list[dict[str, Any]]



pydantic model crudcreator.proxy.proxy.FilterFirewall.FilterFirewallParams[source]

FilterFirewall proxy settings.

field allowed_filter_on_fields: list[AllowedFilterOnField] [Required][source]

The list of filters that the CRUD user can fill in when reading.

property allowed_filter_type_index: dict[str, list[FilterType]][source]

Index field_name->allowed_filter_type automatically created from allowed_filter_on_fields.