Libraries and Utilities¶
A collection of things that are used throughout the application. This includes helpful functions for sending OTPs, the form generator, and other sundry.
-
fleetingform.lib.
auth_username_field
(fform)[source]¶ Session field housing the verified username for a fform.
-
fleetingform.lib.
send_otp_email
(email, otp, fform)[source]¶ Send an email one time passcode.
- Parameters
email (str) – email to send to
otp (str) – the one time passcode to send
- Returns
True if sent, else False
- Return type
bool
-
fleetingform.lib.
send_otp_sms
(phone, otp, fform)[source]¶ Send an SMS one time passcode.
- Parameters
phone (str (E.164 formatting)) – phone number to send to
otp (str) – the one time passcode to send
- Returns
True if sent, else False
- Return type
bool
-
fleetingform.lib.form_generator.
generate_fleeting_form_class_for
(form_controls, query_params={})[source]¶ Generate a class for the given form and query parameters.
- Parameters
form_info (dict) – a dictionary that describes a Fleeting Form.
query_params (django.http.QueryDict) – URL query parameters.
Fleeting forms are all unique. To take advantage of Django’s form handling we need to generate a new class for each one.
This generator accepts a form described in a dictionary, using the Fleeting Form shorthand.
"template": { # Actions are rendered as buttons at the bottom of the # form. The name of the button clicked is stored in # the ``action`` key of the result. "actions": ["Submit", "Cancel"], # Controls are the elements on the page the user interacts # with. There can be up to 32 controls on a Fleeting Form. # Controls will be rendered in the order they are listed. "form_controls": [ # Controls have a name, type, optional help text, label, and # initial value. Any field can be required for the form to # be complete. { "name": "comments", "type": "textarea", "label": "User Comments", "required": true, "initial": "What did you think?" }, { "name": "toes", "type": "integer", "label": "How many toes?", "required": true, "initial": 10 }, { "name": "Pies", "type": "float", "label": "How many pies are left?", "required": true, "initial": 3.25 }, # Fleeting forms automatically validate user input and render # the correct form elements for you. Use the correct field # type to get the most out of your form. { "name": "pet_name", "type": "text", "label": "Pet's Name", "required": false, "initial": "fido", "help_text": "The short version." "validations": [ { "type": "max-length", "params": {"max-length": 32}, "message": "Names must be 32 characters or fewer." } ] }, # Special field types are supported to provide extra # validation for URLs and Emails. { "name": "website", "type": "url", "label": "Your Website", "required": true, "initial": "https://" }, { "name": "email", "type": "email", "label": "Your Email", "required": true, "help_text": "We will never send email without asking." }, # For restricting user input, try the choices field. This # will render a select and keep track of what the user # chooses. { "name": "breed", "type": "choice", "label": "Breed", "required": true, "choices": [ ["lab", "Labrador"], ["shepherd", "Shepherd"], ["collie", "Collier"], ["burmese", "Burmese Mountain Dog"] ] }, # Dates and times use a special form widget so the user can # select from a calendar or time picker. { "name": "incident_datetime", "type": "datetime", "label": "Incident Date and Time", "required": true }, { "name": "moms_bday", "type": "date", "label": "Mom's Birthday", "required": true }, { "name": "callback_time", "type": "time", "label": "Preferred Callback Time", "required": false }, # Boolean fields can be used to implement "I have read and..." # forms, simply set them to required. { "name": "accept_terms", "type": "boolean", "label": "I have read and accept and terms.", "required": true }, ] }
For any field that does not have an initial value in the Fleeting Form dictionary, if the field name is a key in the GET query params then the query param value will be used as the initial value.
Use this to customize a form default values, by adding a username or other custom touch, to a form that is distributed to many people.