Modules collectives.forms
Contents
Modules collectives.forms
#
Module for Form
objects
This module contains all form object used in collectives
. It heavily uses
the WTForm pip. By default, all form are CSRF protected. This module imports
other form submodules and create some configuration for all forms.
- collectives.forms.configure_forms(app)#
Configure forms at app startup (eg uploads)
Module collectives.forms.auth
#
Authentification related modules.
This module contains form related to authentification such as login and account creation.
- class collectives.forms.auth.AccountActivationForm(*args, **kwargs)
Account activation form merging password definition and legal acceptance.
- class collectives.forms.auth.AccountRecoverForm(*args, **kwargs)
Form for a user to (optionally) reset their password.
- class collectives.forms.auth.AdminTokenCreationForm(*args, **kwargs)
Form for administrators to generate conformation tokens
- class collectives.forms.auth.ExtranetAccountCreationForm(*args, **kwargs)
Form to create an account from extranet
- class Meta
- class collectives.forms.auth.LegalAcceptation
Form to accept or reject the legal terms of the site
- class collectives.forms.auth.LocalAccountCreationForm(*args, **kwargs)
Form to create an account from extranet
- class Meta
- class collectives.forms.auth.LoginForm(*args, **kwargs)
Form to log a user .
- class collectives.forms.auth.RequiredPasswordForm
Form with required field to define a password
Module collectives.forms.event
#
Module containing forms related to event management
- class collectives.forms.event.EventForm(*args, **kwargs)
Form to create or modify an event.
- class Meta
- can_remove_leader(event: collectives.models.event.Event, leader: collectives.models.user.User) int
Checks whether the current user has the right to remove a leader from the form. This is prevented if:
There is only one leader
The leader is the main leader
The user is not allowed to remove the leader from the event
seealso:: :py:
collectives.models.event.Event.can_remove_leader()
- Parameters
event (
collectives.models.event.Event
:) – Event the form is operating onleader (
collectives.models.user.User
:) – leader to be removed from the form
- Returns
whether authorization to remove the leader is granted.
- Return type
bool
- can_switch_multi_activity_mode() bool
- Returns
Whether the current user can switch between single-activty/multi-activity modes. If False, this means that editing is restricted to multi-activty mode.
- current_activities() List[collectives.models.activity_type.ActivityType]
- Returns
the list of currently selected activities.
- current_activity_ids() List[int]
- Returns
the list of currently selected activity ids.
- current_event_type() collectives.models.event.event_type.EventType
- Returns
The currently selected event type, of the first available if none has been elected yet
- current_leader_ids() List[int]
- Returns
the list of current leader ids.
- leader_activity_ids() List[int]
Returns the list of activities with which to filter potential new leaders.
In multi-activty mode, returns an empty list, meaning that leaders with not be filtered by activity.
- Returns
List of activity ids
- set_current_leaders(leaders: List[collectives.models.user.User])
Stores the list of current leaders, used to populate form fields
- Parameters
leaders – list of current leaders
- set_default_values()
Populates optional online registration fields with default value and description field with event description template
- setup_leader_actions()
Setups action form for all current leaders
- update_choices()
Updates possible choices for activity and new leader select fields
- class collectives.forms.event.LeaderAction
Class describing the action to be performed for a given leader
- delete = False
Whether the leader should be delete
- Type
bool
- leader_id = -1
Id of leader that will be affected by the action
- Type
int
- class collectives.forms.event.LeaderActionForm(*args, **kwargs)
Form to remove a leader from the event.
- class collectives.forms.event.PaymentItemChoiceForm(*args, **kwargs)
Form allowing users to choose a payment item and price
- class collectives.forms.event.RegistrationForm(*args, **kwargs)
Form for a leader to register an user to an event
- class Meta
- collectives.forms.event.available_activities(activities: List[collectives.models.activity_type.ActivityType], leaders: List[collectives.models.user.User], event_type: collectives.models.event.event_type.EventType, multi_activity_mode: bool) List[collectives.models.activity_type.ActivityType]
Creates a list of activities theses leaders can lead.
This list can be used in a select form input. It will contain activities leaders of this event can lead, plus activities given in parameters (usually, in case of event modification, it is the event activity). In any case, if the current user has a moderator role (admin or moderator), it will return all activities.
- Parameters
activities – list of activities that will always appears in the list
leaders – list of leader used to build activity list. Must not be empty
event_type – the type of the event
multi_activity_mode – whether this is a multi-actiivty event
- Returns
List of authorized activities
- collectives.forms.event.available_event_types(source_event_type: collectives.models.event.event_type.EventType, leaders: List[collectives.models.user.User]) List[collectives.models.event.event_type.EventType]
Returns all available event types given the current leaders. This means:
All existing event types if the current user is a moderator
All existing event types if all of the current leaders can lead at least one activity
All event types that do not require an activity in other cases, plus the source event type if provided
- Parameters
source_event_type – Event type to unconditionally include
leaders – List of leaders currently added to the event
- Returns
Available event types
- collectives.forms.event.payment_item_choice_text(price: collectives.models.payment.ItemPrice, intervals: List[collectives.utils.payment.PriceDateInterval]) str
Generates the text to be used for the payment item choice radio fields. Informs the user about the evolution of the item price across time
- Parameters
price – Cheapest currently available price
intervals – Price intervals as generated by
generate_price_intervals()
- Returns
Price selection radio field text
module collectives.forms.payment
#
Module for payment forms
- class collectives.forms.payment.AmountForm(*args, **kwargs)
Form component for inputting an amount in euros
- update_max_amount()
Update range of price validator from the config variable PAYMENT_MAX_PRICE
Cannot be done in field initializer as current_app is not available
- class collectives.forms.payment.CopyItemForm(*args, **kwargs)
Form to copy payment item from an event to another.
- class Meta
- class collectives.forms.payment.ItemPriceForm(*args, **kwargs)
Form associated to the
collectives.models.payment.ItemPrice
model- class Meta
- get_price(item)
- Parameters
event (
collectives.models.event.Event
) – Event to which the payment item belongs- Returns
Returns both the price and its parent item from which this form was created If the ids are inconsistent or do not correspond to valid elements, raise a ValueError
- Return type
tuple (
collectives.models.payment.PaymentItem
,collectives.models.payment.ItemPrice
)
- validate_max_uses(field)
Sets max_uses to None if it was set to a falsy value, for clarity
- class collectives.forms.payment.NewItemPriceForm(*args, **kwargs)
Form component for inputting a new item and price
- class Meta
- validate_item_title(field)
Validates that if a new item is created, then the new item title field is not empty, and is unique for this event See https://wtforms.readthedocs.io/en/2.3.x/validators/#custom-validators
- validate_max_uses(field)
Sets max_uses to None if it was set to a falsy value, for clarity
- class collectives.forms.payment.OfflinePaymentForm(*args, **kwargs)
Form for notifying an offline payment
- class Meta
- class collectives.forms.payment.PaymentItemForm(*args, **kwargs)
Form for editing a single payment item and associated prices
- class Meta
- get_item(event)
- Parameters
event (
collectives.models.event.Event
) – Event to which the payment item belongs- Returns
Returns both the price and its parent item from which this form was created If the ids are inconsistent or do not correspond to valid elements, raise a ValueError
- Return type
tuple (
collectives.models.payment.PaymentItem
,collectives.models.payment.ItemPrice
)
- populate_prices(item)
Setups form for all current prices
- Parameters
item (
collectives.models.payment.PaymentItem
) – payment item for which to create a form entry
- validate_title(field)
Validates that the item title is unique for this event See https://wtforms.readthedocs.io/en/2.3.x/validators/#custom-validators
- class collectives.forms.payment.PaymentItemsForm(*args, **kwargs)
Form for editing payment items and prices
- other_item_titles(item_id)
Returns the titles of all items other than the one with id item_id :param item_id: Id of item to exclude :type item_id: int :return: List of other item titles :rtype: list[str]
- populate_items(items)
Setups form for all current prices
- Parameters
items (list[
collectives.models.payment.PaymentItem
]) – list of payment items for which to create a form entry
Module collectives.forms.user
#
Module containing forms for updating user information
- class collectives.forms.user.AddBadgeForm(*args, **kwargs)
Form for supervisors to add badges to Users
- class collectives.forms.user.AddLeaderForm(*args, **kwargs)
Form for supervisors to add “Trainee” or “EventLeader” role to users
- class collectives.forms.user.AdminTestUserForm(*args, **kwargs)
Form for admins to edit test users info
- class Meta
- class collectives.forms.user.AdminUserForm(*args, **kwargs)
Form for admins to edit real users info
- class Meta
- class collectives.forms.user.AvatarForm(user)
Form component adding an avatar field
- class collectives.forms.user.BadgeForm(*args, **kwargs)
Form for administrators to add badges to users
- class Meta
- class collectives.forms.user.DeleteUserForm(*args, **kwargs)
Form for confirming user suppression
- validate_license(field: wtforms.fields.simple.StringField)
Validates that the user confirmed the license number of the account to delete
- class collectives.forms.user.ExtranetUserForm(*args, **kwargs)
Form for extranet users to edit their own info
- class Meta
- class collectives.forms.user.LocalUserForm(*args, **kwargs)
Form for extranet users to edit their own info
- class Meta
- class collectives.forms.user.OptionalPasswordForm
Form component adding password and password confirmation fields
- class collectives.forms.user.RenewBadgeForm(*args, **kwargs)
Form for administrators to add badges to users
- class Meta
- class collectives.forms.user.RoleForm(*args, **kwargs)
Form for administrators to add roles to users
- class Meta
- collectives.forms.user.compute_default_expiration_date()
Compute the default expiration date for a badge
module collectives.forms.order
#
Helper module for explicitly ordering fields in WTForms
- class collectives.forms.order.OrderedForm(*args, **kwargs)#
Extends FlaskForm with an optional ‘field_order’ property
- class collectives.forms.order.OrderedModelForm(*args, **kwargs)#
Extends FlaskForm with an optional ‘field_order’ property
- class Meta#
- collectives.forms.order.sort_fields(form)#
Sort fields according to their index the field_order attribute. If field_order constaints the “*”, then it will be replace by all fields that are not explicitly mentioned
module collectives.forms.validators
#
Module containing custom WTForms validators.
- class collectives.forms.validators.LicenseValidator#
WTForm Validator for license fields
- help_string()#
Generate an help sentence.
- Returns
an help sentence.
- Return type
string
- length = 12#
Length of the license number.
Type: int
- pattern()#
Construct the pattern attribute to validate license.
- Returns
A regex pattern to validate a license.
- Return type
String
- sample_value()#
Generate a sample value (place holder).
- Returns
a place holder
- Return type
string
- class collectives.forms.validators.PasswordValidator#
Custom validator to check that password are strong enough when set.
- help_string()#
- Returns
A string explaining what is accepted as a suitable password
- class collectives.forms.validators.PhoneValidator#
Custom validator to check that phone numbers are real phones.
- help_string()#
- Returns
A string explaining what is accepted as a phone number
- class collectives.forms.validators.UniqueValidator(column=None, get_session=None, message='déjà associé(e) à un compte Collectives. Vous souhaitez peut-être récupérer un compte existant ?')#
Validator to check if a license number already exists in database
- collectives.forms.validators.remove_unique_validators(validators)#
Remove all elements that are instance of :py:class::UniqueValidator
- Parameters
validators (list) – Validator list
- Returns
List without unique validators
- Return type
list
module collectives.forms.csv
#
Module containing forms related to CSV import
- class collectives.forms.csv.CSVForm(*args, **kwargs)#
Form to load events from a csv file.