API Reference
This section documents the main modules and functions in LogIt.
Routes Module
Authentication Routes (auth.py)
Handles user authentication, login/logout, and SSO integration.
- app.routes.auth.admin_page()[source]
Admin page.
Create logbooks
Add users to logbooks
Register new users
Manage SSO user logbook permissions
Accessible only to admin users.
Main Routes (main.py)
Core logbook functionality including entries, keywords, and file management.
- app.routes.main.add_entry_form()[source]
Show the add entry form.
- Returns:
HTML page – The add entry form.
- app.routes.main.add_images()[source]
Handles the addition of images to an existing entry in the database. This function performs the following steps: 1. Retrieves the entry ID from the form data. 2. Checks if the entry exists in the database. 3. Fetches the associated logbook document using the entry’s logbook ID. 4. Handles the image upload process, saving the images and collecting their filenames. 5. Updates the entry in the database with the new image filenames. 6. Redirects to the entries display page, with appropriate error messages if necessary. :returns: A redirect response to the entries display page, with error messages if the entry or logbook is not found.
- app.routes.main.add_keyword()[source]
Add a new keyword to the allowed list in MongoDB.
- Returns:
Success or failure message.
- Return type:
str
- app.routes.main.calendar_view()[source]
Renders the calendar view template with the current date.
This function retrieves the current date, formats it as ‘YYYY-MM-DD’, and passes it to the ‘show_calendar.html’ template for rendering.
- Returns:
The rendered HTML content for the calendar view.
- Return type:
str
- app.routes.main.db_activity()[source]
Renders the ‘dbactivity.html’ template.
- Returns:
A Flask response object that renders the ‘dbactivity.html’ template.
- Return type:
Response
- app.routes.main.get_calendar_events()[source]
Get the calendar events.
- Returns:
JSON – The calendar events.
- app.routes.main.get_entry_keywords(entry_id)[source]
Retrieve the keywords associated with a specific entry. :param entry_id: The ID of the entry to retrieve keywords for. :type entry_id: str
- Returns:
- A JSON response containing the keywords if the entry is found,
or an error message if the entry ID is invalid or the entry is not found. The response status code is 200 on success, 400 if the entry ID is invalid, and 404 if the entry is not found.
- Return type:
Response
- app.routes.main.get_keywords()[source]
Get the list of allowed keywords.
- Returns:
JSON – The list of allowed keywords.
- app.routes.main.handle_entry()[source]
Handle the add entry form.
- Returns:
HTML page – The add entry form.
- app.routes.main.remove_keyword()[source]
Remove a keyword from the allowed list in MongoDB.
- Returns:
Success or failure message.
- Return type:
str
- app.routes.main.require_logbook_access(f)[source]
Decorator to check if user has access to the logbook in session
- app.routes.main.save_image(image)[source]
Save an image to the filesystem.
- Parameters:
image (FileStorage) – The image to save.
- Returns:
The filename of the saved image.
- Return type:
str
- app.routes.main.show_entries()[source]
Show the logbook entries.
- Returns:
HTML page – The logbook entries page.
- app.routes.main.show_keywords()[source]
Show the list of allowed keywords.
- Returns:
HTML page – The keywords page.
- app.routes.main.test_mongo()[source]
Test the connection to MongoDB.
- Returns:
Success or failure message.
- Return type:
str
- app.routes.main.update_entry(entry_id)[source]
Update the text of an existing entry in the database. :param entry_id: The ID of the entry to be updated. :type entry_id: str
- Returns:
- A JSON response indicating the success or failure of the update operation.
If the entry ID is invalid, returns a 400 status with an error message.
If the entry is not found, returns a 404 status with an error message.
If the update is successful, returns a 200 status with a success message.
If the update fails, returns a 400 status with an error message.
- Return type:
Response
- app.routes.main.update_entry_keywords(entry_id)[source]
Update the keywords of a specific entry in the database. :param entry_id: The ID of the entry to update. :type entry_id: str
- Returns:
- A JSON response indicating success or failure.
If the entry ID is invalid, returns a JSON response with success=False and an error message, with a 400 status code.
If the update is successful, returns a JSON response with success=True and a 200 status code.
If the update fails, returns a JSON response with success=False and an error message, with a 400 status code.
- Return type:
Response
Slow Control Routes (slow_control.py)
Real-time sensor monitoring and plotting functionality.
Models Module
User Model
User authentication and authorization model.
LogBook Forms
Form definitions and validation.
- class app.models.LogBookForm.AddUsersToLogbookForm(*args, **kwargs)[source]
Bases:
FlaskForm- logbook_select = <UnboundField(SelectField, ('Select Logbook',), {'choices': [], 'validators': [<wtforms.validators.DataRequired object>]})>
- submit = <UnboundField(SubmitField, ('Add User to Logbook',), {'id': 'add_user_to_logbook'})>
- user_select = <UnboundField(SelectField, ('Select User',), {'coerce': <class 'str'>})>
- class app.models.LogBookForm.DeleteUserForm(*args, **kwargs)[source]
Bases:
FlaskForm- submit = <UnboundField(SubmitField, ('Delete User',), {'id': 'delete_user'})>
- user_select = <UnboundField(SelectField, ('Select User',), {'coerce': <class 'str'>, 'validators': [<wtforms.validators.DataRequired object>]})>
- class app.models.LogBookForm.LogbookForm(*args, **kwargs)[source]
Bases:
FlaskForm- allowed_keywords = <UnboundField(TextAreaField, ('Allowed Keywords (comma-separated)',), {})>
- logbook_name = <UnboundField(StringField, ('Logbook Name',), {'validators': [<wtforms.validators.DataRequired object>]})>
- submit = <UnboundField(SubmitField, ('Create Logbook',), {'id': 'create_logbook'})>
- class app.models.LogBookForm.ManageUserLogbooksForm(*args, **kwargs)[source]
Bases:
FlaskForm- logbook_access = <UnboundField(SelectMultipleField, ('Allowed Logbooks',), {'coerce': <class 'str'>})>
- submit = <UnboundField(SubmitField, ('Update User Permissions',), {'id': 'manage_user_logbooks'})>
- user_select = <UnboundField(SelectField, ('Select User',), {'coerce': <class 'str'>, 'validators': [<wtforms.validators.DataRequired object>]})>
- class app.models.LogBookForm.RemoveUsersFromLogbookForm(*args, **kwargs)[source]
Bases:
FlaskForm- logbook_select = <UnboundField(SelectField, ('Select Logbook',), {'choices': [], 'validators': [<wtforms.validators.DataRequired object>]})>
- submit = <UnboundField(SubmitField, ('Remove User from Logbook',), {'id': 'remove_user_from_logbook'})>
- user_select = <UnboundField(SelectField, ('Select User',), {'coerce': <class 'str'>})>
Configuration
Application configuration and settings.