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.

app.routes.auth.callback()[source]

Handle SSO callback

app.routes.auth.get_available_users(logbook_id)[source]
app.routes.auth.get_logbook_users(logbook_id)[source]
app.routes.auth.get_user_logbooks(user_id)[source]

Get the logbooks a user has access to

app.routes.auth.index()[source]

Redirect to login page.

app.routes.auth.init_oauth(app)[source]

Initialize OAuth with the Flask app

app.routes.auth.load_user(user_id)[source]

Check if user is logged-in on every page load.

app.routes.auth.login()[source]

For GET requests, display the login form. For POSTS, login the current user by processing the form.

app.routes.auth.login_sso()[source]

Initiate SSO login

app.routes.auth.logout()[source]

Logout the current user.

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.allowed_file(filename)[source]
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.timeline()[source]

Get the timeline data.

Returns:

JSON – The timeline data.

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.

app.routes.slow_control.build_plot_payload()[source]
app.routes.slow_control.get_plot_data()[source]
app.routes.slow_control.make_plot(sensors, plot_title, yaxis_title, hours=672, add_rangeslider=False)[source]
app.routes.slow_control.plot_view()[source]

Models Module

User Model

User authentication and authorization model.

class app.models.User.User(_id=None, username=None, email=None, password=None, is_admin=False, auth_method='local', sso_id=None, sso_name=None, allowed_logbooks=None)[source]

Bases: UserMixin

User Class

check_password(password)[source]
classmethod find_by_sso_id(sso_id)[source]

Find user by SSO ID

classmethod find_by_username(username)[source]
get_id()[source]
has_logbook_access(logbook_name)[source]

Check if user has access to a specific logbook

save()[source]
static set_password(password)[source]
update()[source]

Update existing user in database

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.