Module collectives.models.user_group

Contents

Module collectives.models.user_group#

Handle dynamic user groups, for restricting or payment options

class collectives.models.user_group.GroupBadgeCondition(**kwargs)#

Relationship indicating that group members must have a certain badge

activity#

Activity type associated with this condition

Type:

list(collectives.models.activity_type.ActivityType)

activity_id#

ID of the activity to which the user role should relate to. If null, any activity is allowed

Type:

int

badge_id#

Id of the role that group members must have. If null, any role is allowed

Type:

collectives.models.RoleId`

clone() GroupBadgeCondition#
Returns:

a deep copy of this object

get_condition(time: datetime)#
Returns:

the SQLAlchemy expression corresponding to this condition

group_id#

ID of the group this condition applies to

Type:

int

id#

Database primary key

Type:

int

invert#

Whether this condition should be inverted, i.e. whether the user should not match the condition to be part of the group

Type:

bool

level#

Level of the badge that group members must have. If null, any level is allowed

Type:

int

level_name() str#

Returns the name of the badge level.

query: t.ClassVar[Query]#

A SQLAlchemy query for a model. Equivalent to db.session.query(Model). Can be customized per-model by overriding query_class.

Warning

The query interface is considered legacy in SQLAlchemy. Prefer using session.execute(select()) instead.

class collectives.models.user_group.GroupConditionBase#

Base class with common fields for all group conditions.

group_id = Column(None, Integer(), ForeignKey('user_groups.id'), table=None, nullable=False)#

ID of the group this condition applies to

Type:

int

id = Column(None, Integer(), table=None, primary_key=True, nullable=False)#

Database primary key

Type:

int

invert = Column(None, Boolean(), table=None, nullable=False, default=ScalarElementColumnDefault(False))#

Whether this condition should be inverted, i.e. whether the user should not match the condition to be part of the group

Type:

bool

class collectives.models.user_group.GroupEventCondition(**kwargs)#

Relationship indicating that group members must participate (or lead) a given event.

clone() GroupEventCondition#
Returns:

a deep copy of this object

event#

Event associated with this condition

Type:

list(collectives.models.event.Event)

event_id#

ID of the activity to which the user role should relate to.

Type:

int

get_condition()#
Returns:

the SQLAlchemy expression corresponding to this condition

group_id#

ID of the group this condition applies to

Type:

int

id#

Database primary key

Type:

int

invert#

Whether this condition should be inverted, i.e. whether the user should not match the condition to be part of the group

Type:

bool

is_leader#

Whether group members should be leaders of the activity or normal users. If null, both are allowed.

Type:

int

query: t.ClassVar[Query]#

A SQLAlchemy query for a model. Equivalent to db.session.query(Model). Can be customized per-model by overriding query_class.

Warning

The query interface is considered legacy in SQLAlchemy. Prefer using session.execute(select()) instead.

class collectives.models.user_group.GroupLicenseCondition(**kwargs)#

Relationship indicating that group members must have a certain license type

clone() GroupLicenseCondition#
Returns:

a deep copy of this object

group_id#

ID of the group this condition applies to

Type:

int

id#

Database primary key

Type:

int

invert#

Whether this condition should be inverted, i.e. whether the user should not match the condition to be part of the group

Type:

bool

license_category#

User club license category.

Type:

string (2 char)

query: t.ClassVar[Query]#

A SQLAlchemy query for a model. Equivalent to db.session.query(Model). Can be customized per-model by overriding query_class.

Warning

The query interface is considered legacy in SQLAlchemy. Prefer using session.execute(select()) instead.

class collectives.models.user_group.GroupRoleCondition(**kwargs)#

Relationship indicating that group members must have a certain role

activity#

Activity type associated with this condition

Type:

list(collectives.models.activity_type.ActivityType)

activity_id#

ID of the activity to which the user role should relate to. If null, any activity is allowed

Type:

int

clone() GroupRoleCondition#
Returns:

a deep copy of this object

get_condition()#
Returns:

the SQLAlchemy expression corresponding to this condition

group_id#

ID of the group this condition applies to

Type:

int

id#

Database primary key

Type:

int

invert#

Whether this condition should be inverted, i.e. whether the user should not match the condition to be part of the group

Type:

bool

query: t.ClassVar[Query]#

A SQLAlchemy query for a model. Equivalent to db.session.query(Model). Can be customized per-model by overriding query_class.

Warning

The query interface is considered legacy in SQLAlchemy. Prefer using session.execute(select()) instead.

role_id#

Id of the role that group members must have. If null, any role is allowed

Type:

collectives.models.RoleId`

class collectives.models.user_group.UserGroup(**kwargs)#

Dynamically-defined set of users based on various conditions.

Currently three type of conditions are available:

  • Role: User must have a specific role, optionnaly for a given activity

  • Event: User must be registered or be a leader to a given event

  • Licence: Use must have a specific licence type

Those conditions are multiplicative, i.e. the user must satisfy all conditions (“and”). However, within each condition, allowed values are additive (“or”) All three types of conditions are also optional.

For instance, a user group may be defined as follow: Users which have ((the role President) or (the role Leader for activity “Ski”)) and ((lead event “Foo”) or (are registered to event “Bar”))

badge_conditions#

List of badge conditions associated with this group

Type:

list(collectives.models.user_group.GroupBadgeCondition)

clone() UserGroup#
Returns:

a deep copy of this object, cloning all conditions

contains(user: User, time: datetime) bool#

Checks if a given user is a member of the group at a specific time. The time is used to check for badge expiry.

Returns:

Whether a given user is a member of the group

event_conditions#

List of event conditions associated with this group

Type:

list(collectives.models.user_group.GroupRoleCondition)

get_members(time: datetime | None = None) List[User]#
Returns:

the list of group members

has_conditions() bool#
Returns:

whether the group defines at least one condition

id#

Database primary key

Type:

int

license_conditions#

List of license conditions associated with this group

Type:

list(collectives.models.user_group.GroupRoleCondition)

property negative_badge_conditions: List[GroupBadgeCondition]#
Returns:

the list of negative badge conditions

property negative_event_conditions: List[GroupEventCondition]#
Returns:

the list of negative event conditions

property negative_license_conditions: List[GroupLicenseCondition]#
Returns:

the list of negative license conditions

property negative_role_conditions: List[GroupRoleCondition]#
Returns:

the list of negative role conditions

property positive_badge_conditions: List[GroupBadgeCondition]#
Returns:

the list of positive badge conditions

property positive_event_conditions: List[GroupEventCondition]#
Returns:

the list of positive event conditions

property positive_license_conditions: List[GroupLicenseCondition]#
Returns:

the list of positive license conditions

property positive_role_conditions: List[GroupRoleCondition]#
Returns:

the list of positive role conditions

query: t.ClassVar[Query]#

A SQLAlchemy query for a model. Equivalent to db.session.query(Model). Can be customized per-model by overriding query_class.

Warning

The query interface is considered legacy in SQLAlchemy. Prefer using session.execute(select()) instead.

role_conditions#

List of role conditions associated with this group

Type:

list(collectives.models.user_group.GroupRoleCondition)