geonature.core.imports.routes

Submodules

Attributes

Classes

Destination

The base class of the SQLAlchemy.Model declarative model class.

DestinationSchema

This mixin automatically exclude from serialization:

Functions

list_all_destinations(action_code)

Return the list of all destinations. If an action code is provided, only the destinations

get_destination(destinationCode)

Package Contents

class geonature.core.imports.routes.Destination[source]

Bases: geonature.utils.env.db.Model

The base class of the SQLAlchemy.Model declarative model class.

To define models, subclass db.Model, not this. To customize db.Model, subclass this and pass it as model_class to SQLAlchemy. To customize db.Model at the metaclass level, pass an already created declarative model class as model_class.

__tablename__ = 'bib_destinations'
__table_args__
id_destination
id_module
code
label
table_name
active
module
entities
get_transient_table()[source]
property validity_columns
property statistics_labels
property actions
static allowed_destinations(user: pypnusershub.db.models.User | None = None, action_code: str = 'C') List[Destination][source]

Return a list of allowed destinations for a given user and an action.

Parameters

userUser, optional

The user to filter destinations for. If not provided, the current_user is used.

actionstr

The action to filter destinations for. Possible values are “C”, “R”, “U”, “V”, “E”, “D”.

Returns

allowed_destinationList of Destination

List of allowed destinations for the given user.

classmethod filter_by_role(user: pypnusershub.db.models.User | None = None, action_code: str = 'C', **kwargs)[source]

Filter Destination by role.

Parameters

userUser, optional

The user to filter destinations for. If not provided, the current_user is used.

Returns

sqlalchemy.sql.elements.BinaryExpression

A filter criterion for the id_destination column of the Destination table.

has_instance_permission(user: pypnusershub.db.models.User | None = None, action_code: str = 'C')[source]

Check if a user has the permissions to do an action on this destination.

Parameters

userUser, optional

The user to check the permission for. If not provided, the current_user is used.

action_codestr

The action to check the permission for. Possible values are “C”, “R”, “U”, “V”, “E”, “D”.

Returns

bool

True if the user has the right to do the action on this destination, False otherwise.

__repr__()[source]
class geonature.core.imports.routes.DestinationSchema(*args, **kwargs)[source]

Bases: utils_flask_sqla.schema.SmartRelationshipsMixin, geonature.utils.env.ma.SQLAlchemyAutoSchema

This mixin automatically exclude from serialization:

  • Nested, RelatedList and Related fields

  • all fields with exclude=True in their metadata (e.g. fields.String(metadata={'exclude': True}))

  • For SQLAlchemyAutoSchema, all deffered columns

Default marshmallow behaviour is to serialize only fields specified in only. This mixin add these:

  • If they are only Nested fields in only, they are added to serialized fields along with default serialized fields.

  • To serialize Nested fields only and not default serialized fields, add "-" special value to only.

  • To add excluded fields (through metadata or deffered fields) to the serialization in addition to default serialized fields, use “+field_name” syntax.

Examples :

class FooSchema(SmartRelationshipsMixin):
    id = fields.Int()
    name = field.Str()
    default_excluded_field = fields.Str(metadata={"exclude": True})
    relationship = fields.Nested(OtherSchema) # or field.RelatedList() / field.Related()

FooSchema().dump() -> {"id": 1, "name": "toto" }
FooSchema(only=["id"]).dump() -> {"id": 1}
FooSchema(only=["default_excluded_field"]).dump() -> {"default_excluded_field": "test"}
FooSchema(only=["+default_excluded_field"]).dump() -> {"id": 1, "name": "toto", "default_excluded_field": "test"}
FooSchema(only=["relationship"]).dump() -> {"id": 1, "name": "toto",  "relationship": {OtherSchema...} }
FooSchema(only=["id", "relationship"]).dump() -> {"id": 1, "relationship": {OtherSchema...}}
FooSchema(only=["-", "relationship"]).dump() -> {"relationship": {OtherSchema...}}
class Meta

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Meta):
        additional = True  # Incompatible types in assignment

Supprimé dans la version 3.0.0b7: Remove strict.

Ajouté dans la version 3.0.0b12: Add unknown.

Modifié dans la version 3.0.0b17: Rename dateformat to datetimeformat.

Ajouté dans la version 3.9.0: Add timeformat.

Modifié dans la version 3.26.0: Deprecate ordered. Field order is preserved by default.

Supprimé dans la version 4.0.0: Remove ordered.

model
include_fk = True
load_instance = True
sqla_session
module
geonature.core.imports.routes.blueprint[source]
geonature.core.imports.routes.list_all_destinations(action_code)[source]

Return the list of all destinations. If an action code is provided, only the destinations that the user has permission (based on the action_code) to access are returned.

Parameters:

action_codestr

The action code to filter destinations. Possible values are “C”, “R”, “U”, “V”, “E”, “D”.

Returns:

destinationsList of Destination

List of all destinations.

geonature.core.imports.routes.get_destination(destinationCode)[source]