Module collectives.models#

Model module for collectives

This module contains other submodules for collectives model. Persistence is made by SQLAlchemy. This module exposes most important submodules classes by importing them. It also create the db object

Module collectives.models.activity_type#

Module to describe the type of activity.

class collectives.models.activity_type.ActivityType(**kwargs)#

Class of the type of activity.

An activity type is a sport (climbing, hiking). Previouslu it could also be another occupation (training), but this distinction should now be made using event types. Persistence is done with SQLAlchemy and in the table activity_types

badges#

Person with a badge with this activity

Type

collectives.models.user.User

deprecated#

Indicates a deprecated activity type, now replaced by an event type

Kept in the table for backward compatibility, but excluded from activity lists

Type

bool

email#

Activity dedicated email.

Mail to be used to send notifications to activity leader.

Type

string

classmethod get(required_id)#

Get the name of the specified activity id

Parameters

required_id (integer) – the id of the Activity type

Returns

name of the activity type

Return type

ActivityType

classmethod get_all_types(include_deprecated=False)#

List all activity_types in database

Parameters

include_deprecated (bool) – Whether to include deprecated activity types

Returns

list of types

Return type

list(ActivityType)

classmethod js_values()#

Class method to get all actitivity type as js dict

Returns

types as js Dictionnary

Return type

String

name#

Activity name.

Type

string

order#

Order to display this activity

Type

int

persons#

Person with a role with this activity

Type

collectives.models.user.User

short#

Activity short name.

It is especially used for icon CSS classes.

Type

string

trigram#

Three-letter code.

Mainly used to identify activity type in payment order references

Type

string

truncate_string(key, value)#

Truncates a string to the max SQL field length

In contrast to one may naively think, trigrams may be longer than three letters. Make sure the value is truncated before trying to insert it in base

Parameters
  • key (string) – name of field to validate

  • value (string) – tentative value

Returns

Truncated string.

Return type

string

Module collectives.models.auth#

Module to manage authentification model

Example: Account creation tokens. However, User is in module collectives.model.user.

class collectives.models.auth.ConfirmationToken(user_license, existing_user, duration=None)#

Class of a Token

A confirmation token is a way to check the mail address of a user. An UUID is sent to an email address and user has to be able to access the email address to validate the token. Tokens have a limited life duration.

existing_user#

The user to which this token is linked.

existing_user_id#

Associated Id if the token affects an existing account

Type

int

expiry_date#

Token expiration date

Expiration date is automatically set during token creation, in constructor.

Type

datetime.datetime

status#

Sending status of this token.

Type

collectives.models.auth.TokenEmailStatus

token_type#

Type of token (account creation, reset, …)

Type

collectives.models.auth.ConfirmationTokenType

user_license#

License number of relevant user

It is mainly used for account activation where user account does not exists yet. Thus, activation token must remember which user is associated.

Type

string

uuid#

UUID to indentify the token

Type

string

class collectives.models.auth.ConfirmationTokenType(value)#

Enum listing types of token

ActivateAccount = 0#

Token for account activation

RecoverAccount = 1#

Token to recover the lost password of an account

class collectives.models.auth.TokenEmailStatus(value)#

Enum Status for this token

Failed = 2#

Token has failed during its expedition

Pending = 0#

Token will be sent

Success = 1#

Token has been succesfully sent

Module collectives.models.badge#

Module for user badges related classes

class collectives.models.badge.Badge(**kwargs)#

Badge for a specific user.

These objects are linked to collectives.models.user.User and to a collectives.models.activity_type.ActivityType. A same user can have several badges, including on the same activity type.

Roles are stored in SQL table badges.

activity_id#

ID of the activity to which the badge is applied.

Type

int

property activity_name#

Returns the name of the corresponding activity

Returns

name of the corresponding activity

Return type

string

badge_id#

Type of the badge.

Type

BadgeIds

expiration_date#

Date at which this badge will expire

Type

datetime.date

id#

Database primary key

Type

int

is_expired() bool#

Returns True if badge is no longer valid now.

level#

Level of the badge. Depending of the type of badge, might be: level of expertise, nb of absences,…

Type

int

property name#

Returns the name of the badge.

Returns

name of the badge.

Return type

string

user_id#

ID of the user to which the badge is applied.

Type

int

class collectives.models.badge.BadgeIds(value)#

Enum listing the type of a badge

classmethod display_names()#

Display name for all badges

Returns

badge name

Return type

string

relates_to_activity() bool#

Check if this badge needs an activity.

Returns

True if the badge requires an activity.

Return type

boolean

Module collectives.models.event#

Module collectives.models.event_tag#

Module for event tag classes.

class collectives.models.event_tag.EventTag(tag_id)#

Class of an event tag.

An event tag is related to a single event and is defined by a type.

classmethod all(include_deprecated=False) Dict[int, Dict[str, Any]]#

Returns tag dictionnary as defined by EVENT_TAGS in config.

Parameters

include_deprecated (bool) – Whether to include deprecated activity types

Type

dict

classmethod choices()#

Returns all tag types formatted for a wtform multiple selection field.

Type

array

property csv_code: str#

Alternative name of the tag type, to be used in CSV imports

Type

string

event_id#

Primary key of the event which holds this tag (see collectives.models.event.Event)

Type

int

property full: Dict[str, Any]#

All information about the tag type.

Type

dict

classmethod get_type_from_csv_code(csv_code: str) int#
Parameters

short (string) – CSV code of the searched tag

Returns

Tag id

classmethod get_type_from_short(short) int#
Parameters

short (string) – Shortname of the searched tag

Returns

Tag id

Return type

int

id#

Event tag unique id.

ID is used as DB primary key

Type

int

property name: str#

Name of the tag type

Type

string

property short: str#

Short name of the tag type, used as css class

Type

string

type#

Type of the tag.

Possible values are keys of config EVENT_TAGS.

Type

collectives.models.event_tag.EventTagTypes

Module collectives.models.globals#

System wide model tools

collectives.models.globals.db = <SQLAlchemy>#

SQL Alchemy object to manipulate DB.

Module collectives.models.payment#

Module collectives.models.question#

Module defining question-related models

class collectives.models.question.Question(**kwargs)#

Database model describing a set of questions

choices#

Possible answers for this question, one per line

type: string

choices_array() List[str]#
Returns

the list of possible choices for the question

description#

Longer description for this question

Type

string

enabled#

Whether this question is enabled

Type

string

event_id#

Key of the event the questionnaire is associated to

Type

int

id#

Database primary key

Type

int

static make_choices_array(choices_text: str) List[str]#

Converts choices stored as a single string to an array of individual choices :param choices_text: the string containing one choice per non-empty line :returns: the list of possible choices

order#

Number for ordering questions within a questionnaire

Type

int

question_type#

Type of question

Type

collectives.models.question.QuestionType

required#

Whether answering this question is required

Type

string

title#

Subtitle for this question

Type

string

class collectives.models.question.QuestionAnswer(**kwargs)#

Database model describing a set of questions

id#

Database primary key

Type

int

question_id#

Primary key of the question which is being answered

Type

int

static user_answers(event_id: int, user_id: int) List[collectives.models.question.QuestionAnswer]#
Returns

the list of answers to an event’s questions by a given user

user_id#

Primary key of the user who answered the question

Type

int

value#

Answer value for non choice-based answers

class collectives.models.question.QuestionType(value)#

Enumeration listing possible question types

MultipleChoices = 1#

Question with a multiple possible answers among a predefined list

Numeric = 2#

Question with an integer answer

SingleChoice = 0#

Question with a single possible answer among a predefined list

Text = 3#

Question with arbitrary textual answer

YesNo = 5#

Boolean question

classmethod display_names()#
Returns

a dict defining display names for all enum values

Return type

dict

Module collectives.models.registration#

Module for registration related classes

class collectives.models.registration.Registration(**kwargs)#

Object linking a user (participant) and an event.

Co-leader are also registering. Leader are not registered to their events.

event_id#
Primary key of the event to which the user is registered (see

collectives.models.event.Event)

Type

int

holding_index() int#

Returns the chronlogical place this registration has in all holding place registrations. None if not active. Starts at 1.

id#

Database primary key

Type

int

is_active()#

Check if this registation is active.

Returns

True if status is Active or Present and the user’s license has not expired

Return type

boolean

is_holding_slot()#

Check if this registation is holding a slot.

Returns

Is status active or pending?

Return type

boolean

is_overbooked() bool#

Check if the registration is not overbooking.

An overbooked registration is:

  • an online registration with more previous Waiting registration
    than online slots
  • or an holding place registration with more previous holding place registration
    than total slots
  • a Waiting registration with more previous Waiting registration
    than Waiting slots
is_pending_payment()#

Check if this registation is pending payment.

Returns

Is status pending payment ?

Return type

boolean

is_pending_renewal()#

Check if this registation is pending license renewal.

Returns

True if the user’s license expires before the end of the event

Return type

boolean

is_rejected()#

Check if this registation is rejected.

Returns

Is status rejected ?

Return type

boolean

is_self#

Whether this is a self-registration (by the user themselves)

Type

bool

is_unregistered()#

Check if this registation is unregistered.

Returns

Is status unregistered ?

Return type

boolean

level#

Level of the participant for this event (normal, co-leader…)

Type

collectives.models.registration.RegistrationLevels

online_index() int#

Returns the chronlogical place this registration has in all online and holding slot registrations. None if not holding slot and online. Starts at 1.

payments#

List of payments associated to this registration.

Type

list(collectives.models.payment.Payment)

status#

Status of the registration (active, rejected…)

Type

collectives.models.registration.RegistrationStatus

unsettled_payments()#

Returns the list of unsettled payments associated to this registration

Returns

The list of payments with ‘Initiated’ status

Return type

list[collectives.modes.payment.Payment]

user_id#

Primary key of the registered user (see collectives.models.user.User)

Type

int

valid_transitions()#
Returns

The list of all achievable transitions from the current status

Return type

list[collectives.models.registration.RegistrationStatus]

waiting_index() int#

Returns the chronlogical place this registration has in waiting registrations. None if not waiting. Starts at 1.

class collectives.models.registration.RegistrationLevels(value)#

Enum listing acceptable registration levels.

A registration level is type of event participant, such as a co-leader or a regular participant.

CoLeader = 1#

Participant that will help the event leader.

Normal = 0#

Normal participant, no specific power.

classmethod display_names()#
Returns

a dict defining display names for all enum values

Return type

dict

class collectives.models.registration.RegistrationStatus(value)#

Enum listing acceptable registration status.

Active = 0#

Registered user is planned to be present.

JustifiedAbsentee = 4#

User has been absent to the event, but excused by the leader.

PaymentPending = 2#

User has initiated but not yet completed payment

This registration is temporarily holding up a spot, but may be removed after timeout

Present = 7#

User has been present to the event.

Rejected = 1#

Registered user has been rejected by a leader.

A rejected user shall not be counted in occupied slots, nor be able to register again

SelfUnregistered = 3#

User has self unregister to the event.

User should not be able to register again without leader help.

ToBeDeleted = 99999#

Registration should be deleted. This is not a valid SQL enum entry and should only be used as a temporary marker

UnJustifiedAbsentee = 5#

User has been absent to the event, but not excused by the leader.

Waiting = 6#

User is in waiting list.

classmethod display_names()#
Returns

a dict defining display names for all enum values

Return type

dict

is_valid()#

Checks if registration is valid, ie active or present

Returns

True or False

Return type

bool

classmethod transition_table(requires_payment)#
Returns

a dict defining possible transitions for all enum values

Parameters

requires_payment (bool) – whether this is a paid event.

Return type

dict

classmethod valid_status() list#

Returns the list of registration status considered as valid.

See collectives.models.registration.RegistrationStatus.is_valid()

valid_transitions(requires_payment)#
Returns

The list of all achievable transitions for a given status (excluding itself)

Parameters

requires_payment (bool) – whether this is a paid event.

Return type

list[collectives.models.registration.RegistrationStatus]

Module collectives.models.role#

Module for user roles related classes

class collectives.models.role.Role(**kwargs)#

Role for a specific user.

These objects are linked to collectives.models.user.User and sometimes to a collectives.models.activity_type.ActivityType. A same user can have several roles.

Roles are stored in SQL table roles.

activity_id#

ID of the activity to which the role is applied.

Is null if the role is global.

Type

int

id#

Database primary key

Type

int

property name: str#

Returns the name of the role.

Returns

name of the role.

role_id#

Type of the role.

Type

RoleIds

user_id#

ID of the user to which the role is applied.

Type

int

class collectives.models.role.RoleIds(value)#

Enum listing the type of a role

Global roles are not related to an activity and are website wide:

  • Moderator

  • Administrator

  • President

  • Technician

  • Hotline

  • Accountant

  • Staff

Activity related roles: - EventLeader: can lead an event of this activity type - ActivitySupervisor: supervises a whole activity - Trainee: Currently training to become a leader for an activity - ActivityStaff: can create event types that do not require leader

classmethod all_activity_leader_roles() List[collectives.models.role.RoleIds]#
Returns

List of all roles that allow users to lead event activities

classmethod all_activity_organizer_roles() List[collectives.models.role.RoleIds]#
Returns

List of all roles that allow users to organize events with an activity

classmethod all_equipment_management_roles() List[collectives.models.role.RoleIds]#
Returns

List of all roles that allow users manage equipment

classmethod all_event_creator_roles() List[collectives.models.role.RoleIds]#
Returns

List of all roles that allow users to create events

Return type

list[RoleIds]

classmethod all_moderator_roles() List[collectives.models.role.RoleIds]#
Returns

List of all roles that grant moderator capabilities

classmethod all_relates_to_activity() List[collectives.models.role.RoleIds]#
Returns

List of all roles that are related to an activity.

classmethod all_reservation_creator_roles() List[collectives.models.role.RoleIds]#
Returns

List of all roles that allow users to create reservation

Return type

list[RoleIds]

classmethod all_reservation_management_roles() List[collectives.models.role.RoleIds]#
Returns

List of all roles that allow users manage reservation

Return type

list[RoleIds]

classmethod all_supervisor_manageable() List[collectives.models.role.RoleIds]#
Returns

List of all roles that can be managed by an activity supervisor.

classmethod display_names() Dict[collectives.models.role.RoleIds, str]#

Display names for all rolesrole

Returns

dictionnary role -> role name

relates_to_activity() bool#

Check if this role needs an activity.

See RoleIds Global roles vs Event related roles.

Returns

True if the role requires an activity.

Module collectives.models.upload#

Module for file upload related classes

collectives.models.upload.THUMBNAIL_HEIGHT = 480#

Default height in pixels for image thumbnails

collectives.models.upload.THUMBNAIL_WIDTH = 640#

Default width in pixels for image thumbnails

class collectives.models.upload.UploadedFile(**kwargs)#

User-uploaded file.

For now, each uploaded file is linked to an event. This may change in the future

activity#

Activity to which this file belong. May be null

Type

collectives.models.event.Event

activity_id#

Primary key of the activity to which this file belong

Type

int

date#

Upload date

Type

datetime.datetime

delete_file()#

Deletes the on-disk file

event#

Event to which this file belongs. May be null

Type

collectives.models.event.Event

event_id#

Primary key of the event to which this file belong

Type

int

full_path()#
Returns

the full on-disk file path

Return type

string

has_edit_rights(user: collectives.models.user.User)#

Checks whether an user has edit rights on this file

  • if the file is associated to an activity, user needs to be a supervisor

  • if the file is associated to an event, user needs edit rights on event

  • if the file is unassociated, user needs to have uploaded it

Parameters

user (collectives.models.User) – user to check

Returns

whether the user has edit rights

Return type

bool

id#

Upload unique id.

Type

int

is_image()#

Checks if this file is an image

Returns

True if extension is in flask_uploads.IMAGES

name#

Original file name

Type

string

path#

On-disk path

Type

string

static purge_old_uploads(current_session_id: int, days: int = 1)#

Removes uploaded files from temporary sessions that where never attached to an event

Parameters
  • current_session_id (int) – Id of current editing session, or None. Files from the current editing session will not be purged.

  • days (int) – Number of days since upload to consider purging the file

save_file(file)#

Save from a raw file

Parameters

file (werkzeug.datastructures.FileStorage) – The direct output of a FileInput

session_id#

If the upload is not associated to an event yet, id of the edit session

Type

string

size#

Size, in bytes

Type

Integer

thumbnail_url(width: int = 640, height: int = 480)#

If this file is an image, returns its thumbnail URL

Parameters
  • width (int, optional) – max width of the thumbnail in pixels, defaults to THUMBNAIL_WIDTH

  • height (int, optional) – max height of the thumnail in pixels, defaults to THUMBNAIL_HEIGHT

Returns

The thumbnail URL or None if not an image

Return type

int

url()#
Returns

the static URL for an uploaded file

Return type

str

user#

User who uploaded this file

Type

collectives.models.user.User

user_id#

Primary key of the user who uploaded this file

Type

int

validate_filename(key, value)#

Makes a file name secure and truncates it to the max SQL field length :param string key: name of field to validate :param string value: tentative value :return: Truncated file name. :rtype: string

collectives.models.upload.documents = <flask_uploads.UploadSet object>#

Upload instance for documents

Type

flask_uploads.UploadSet

Module collectives.models.user#

Module collectives.models.user_group#

Module collectives.models.utils#

Set utils classes for models

class collectives.models.utils.ChoiceEnum(value)#

Enum with additionnal methods which is easy to get lists from.

classmethod choices()#

Class method to get all choices

Returns

list of Tuple with all choices as (id, name)

Return type

Array

classmethod coerce(item)#

Check if an item if part the Enum

Parameters

item – Item to check if it is in the Enum

Returns

if item is part of the Enum

Return type

boolean

display_name()#

Display name of the current value

Returns

name of the instance

Return type

string

classmethod js_keys() List[str]#

Class method to cast Enum keys as js dict

Returns

JSON representation of enum keys dict

classmethod js_values()#

Class method to cast Enum as js dict

Returns

enum as js Dictionnary

Return type

String