This is the primary endpoint of the application which serves the login page.
Request parameters: None.
Response: Login page.
Errors: None.
This endpoint handles the login requests. Upon successful login, the user is redirected to the admin dashboard.
Request parameters:
u: Username of the user.p: Password of the user.
Response: Redirects to /admin upon successful login, serves the login page with error message upon unsuccessful login.
Errors:
- 400: Bad Request - In case of invalid username or password.
After a successful login, the user will need to save the cookies.gary file to maintain their session. This cookie is used for authentication for the subsequent requests.
EXAMPLE
curl -c cookies.gary -d "u=username&p=password" http://localhost:5000/
This endpoint provides the admin dashboard.
This endpoint is authenticated; you need to be logged in as an admin to access it.
- 200 OK: Successfully renders the admin dashboard.
- 401 Unauthorized: User is not authenticated or is not an admin.
This function takes in various parameters required by the admin template and renders the template.
- services (
List[Dict[str, Any]]): A list of dictionaries containing service-related information. - username (
str): The username of the admin. - email (
str): The email address of the admin. - notifications (
List[Dict[str, Any]]): A list of dictionaries containing notification details. - notification_count (
int): The total number of notifications. - scoreboard_users (
List[Dict[str, Any]]): A list of dictionaries containing user scores. - the_7_day_score (
List[Dict[str, Any]]): A list of dictionaries containing the 7-day scoreboard. - job (
Dict[str, Any]): A dictionary containing the latest job details.
- str: The rendered HTML template for the admin dashboard.
Admin route handler function. This function builds the service list, retrieves user information, notifications, and scoreboard data, then returns a rendered template with these data.
- None.
- str: The rendered HTML template for the admin dashboard.
- May show a flash message for errors related to notifications or the latest job.
This endpoint logs out the current user.
This endpoint is authenticated; you need to be logged in to access it.
- 302 Redirect: Redirects to the home route after successful logout.
- 401 Unauthorized: User is not authenticated.
Logout route handler function. Logs out the current user and redirects to the home route.
- None.
- Response: A Flask Response object, redirecting the user to the home route.
- Logs out the current user.
This endpoint adds a new customer.
This endpoint is authenticated; you need to be logged in as an admin to access it.
- Form Data: Requires a form body with details about the customer.
- 302 Redirect: Redirects to the admin dashboard with a flash message about the operation's success or failure.
- 400 Bad Request: Invalid or incomplete form data.
- 401 Unauthorized: User is not authenticated.
Add customer route handler function. This function adds a new customer based on form data and redirects to the admin route.
- Form Data: Uses a Flask
request.formobject to capture the customer's details. Includes optional flags for sending a welcome email (sendEmail) and adding to a mailing list (mailList).
- Response: A Flask Response object, redirecting the user to the admin dashboard.
- May show a flash message for errors related to adding the customer or for successful addition.
- If the
sendEmailflag is set, sends a welcome email to the new customer. - If the
mailListflag is set, adds the new customer to a mailing list.
This endpoint deletes a customer specified by the id.
This endpoint is authenticated; you need to be logged in as an admin to access it.
- id (
int): The ID of the customer to be deleted.
- 200 OK: JSON response with details about the operation's success.
- 400 Bad Request: JSON response with details about the operation's failure.
- 401 Unauthorized: User is not authenticated.
Delete customer route handler function. This function deletes a customer based on the given id.
- id (
int): The ID of the customer to be deleted.
- Tuple[Any, int]: A tuple containing a JSON-serializable response and the HTTP status code.
- May show a flash message for the successful deletion of the customer.
This endpoint creates a new table in the database.
This endpoint is authenticated; you need to be logged in as an admin to access it.
- 200 OK: Renders a template that will redirect to the admin dashboard, and includes details about the operation's success.
- 400 Bad Request: JSON response with details about the operation's failure.
- 401 Unauthorized: User is not authenticated.
Create table route handler function. This function creates a new table and returns a response.
- None.
- Any: Either renders a template with a redirect to the admin dashboard, or returns a JSON-serializable response and the HTTP status code.
- Creates a new table in the database if the operation is successful.
This endpoint retrieves all customers from the database.
This endpoint is authenticated; you need to be logged in as an admin to access it.
- 200 OK: Renders a template that displays the list of all customers.
- 400 Bad Request: JSON response with an error message.
- 401 Unauthorized: User is not authenticated.
All customers route handler function. This function retrieves all customers and returns a response.
- None.
- Any: Either renders a template that displays the list of all customers, or returns a JSON-serializable response and the HTTP status code.
- Retrieves all customers from the database.
This endpoint retrieves a custom table of customers based on passed query parameters.
This endpoint is authenticated; you need to be logged in as an admin to access it.
- Query parameters to filter customers (optional).
- 200 OK: Renders a template that displays the custom list of customers based on the query parameters.
- 400 Bad Request: JSON response with an error message.
- 401 Unauthorized: User is not authenticated.
Custom table route handler function. This function retrieves customers based on query parameters and returns a response.
- Query Parameters: Optional query parameters to filter customers.
- Any: Either renders a template that displays the custom list of customers or returns a JSON-serializable response and the HTTP status code.
- Retrieves a custom list of customers based on query parameters from the database.
This endpoint deletes a table in the database.
This endpoint is authenticated; you need to be logged in as an admin to access it.
Authorization = headers.get('Authorization')
if Authorization == "Basic superlfadmin:removemydata": # Consider using an environment variable here
- Headers may include information needed to authenticate or specify parameters for table deletion (optional).
- Redirects to the admin dashboard with a response indicating the success or failure of the operation.
Delete table route handler function. This function deletes a table in the database.
- Headers: Optional HTTP headers to specify parameters for table deletion or authentication.
- str: Renders a template that redirects to the admin dashboard, and includes a response indicating the success or failure of the operation.
- Deletes a table in the database.
This endpoint allows for a single spreadsheet upload and processes the uploaded file asynchronously.
This endpoint is authenticated; you need to be logged in as an admin to access it.
spreadsheetFile: The spreadsheet file to be uploaded.
- Redirects to the admin dashboard with a message indicating that the spreadsheet is being processed.
Upload single spreadsheet route handler function. This function processes the uploaded spreadsheet file asynchronously.
- Form Data: Contains the
spreadsheetFilethat needs to be uploaded and processed.
- str: Renders a template that redirects to the admin dashboard, and includes a message indicating that the spreadsheet is being processed.
- Initiates asynchronous processing of the uploaded spreadsheet.
This endpoint adds a new job to the job board.
This endpoint is authenticated; you need to be logged in as an admin to access it.
JobForm: The form containing details about the job to be added.
- Redirects to the admin job board with a message indicating the success or failure of the operation.
Add job route handler function. This function adds a new job based on the submitted form data.
- Form Data: Contains the
JobFormwith details about the job that needs to be added.
- str: Renders a template that redirects to the admin job board, and includes a message indicating the success or failure of the operation.
- Adds a new job to the job board based on the submitted form data.
This endpoint edits an existing job on the job board.
This endpoint is authenticated; you need to be logged in as an admin to access it.
JobForm: The form containing updated details about the job.id: The ID of the job to be edited.
- Redirects to the admin job board with a message indicating the success or failure of the operation.
Edit job route handler function. This function edits an existing job based on the submitted form data and job ID.
- Form Data: Contains the
JobFormwith updated details about the job that needs to be edited. - id: The ID of the job to be edited.
- str: Renders a template that redirects to the admin job board, and includes a message indicating the success or failure of the operation.
- Edits an existing job on the job board based on the submitted form data and job ID.
This endpoint deletes a job specified by its ID.
This endpoint is authenticated; you need to be logged in as an admin to access it.
id: The ID of the job to be deleted.email: The email to which an exit email will be sent if specified.exitEmail: A boolean flag indicating whether or not to send an exit email.
- Redirects to the admin job board with a message indicating the success or failure of the operation.
Delete job route handler function. This function deletes a job specified by its ID and optionally sends an exit email.
- id: The ID of the job to be deleted.
- email: The email to which an exit email will be sent if specified.
- exitEmail: A boolean flag indicating whether or not to send an exit email.
- str: Renders a template that redirects to the admin job board, and includes a message indicating the success or failure of the operation.
- Deletes the specified job and optionally sends an exit email.
This endpoint allows for the downloading of job data in CSV format.
This endpoint is authenticated; you need to be logged in as an admin or a salesman to access it.
- Returns a CSV file containing the list of jobs for the current user if the request is successful.
- Returns an error with a status code of
500 Internal Server Errorif there was an issue retrieving the jobs.
Download jobs route handler function. This function allows for the downloading of job data in CSV format.
- salesman: The current user's ID, converted to a readable string format.
- admin: A boolean flag to indicate whether the current user is an admin.
- Tuple[Any, int]: Returns a CSV file in the HTTP response if the request is successful or an error message with a status code of
500 Internal Server Errorotherwise.
- Reads job data and generates a CSV file for download.
This endpoint sends a quote email based on the details provided in the form body.
This endpoint is authenticated and requires the user to be logged in to access it.
jobTitle: The title of the job.jobDescription: Description of the job.quoteAmount: Amount to be quoted.customerName: Name of the customer.customerAddress: Address of the customer.customerEmail: Email of the customer.customerPhone: Phone number of the customer.yourEmail: Your email address.yourPhone: Your phone number.note: Notes regarding the quote. Multiple notes can be provided.
- Returns a message indicating the success or failure of the email sending operation.
Handles the quote form submission and sends the quote via email.
form_data: Dictionary containing the form fields for the quote.
- str: A string containing a message indicating the success or failure of the email sending operation.
- Sends an email containing the quote details.
- The method breaks down the form data to fill in the
QuoteFormclass attributes. - Combines multiple note fields into one for the final quote.
This endpoint retrieves all quotes stored in the system.
This endpoint is authenticated and requires the user to be logged in to access it.
None
- Returns a list of quotes if successful.
- Returns an error message if the operation fails.
Retrieves a list of all quotes stored in the system.
None
- str: A string containing the rendered HTML template displaying the list of quotes or a redirect in case of an error.
- Formats the
notesfield of each quote for better readability.
- The method formats the notes for each quote, splitting them based on the
<>separator and then joining them into an HTML paragraph format. - Renders the list of quotes in a template and passes the
is_adminflag to indicate admin access.
This endpoint deletes a specific quote identified by the given id.
This endpoint is authenticated and requires the user to be logged in to access it.
- id: Integer specifying the ID of the quote to be deleted.
- Returns a JSON response detailing the outcome of the operation if successful.
- Returns an error message and redirects to the admin dashboard if the operation fails.
Deletes a specific quote identified by the given id.
- id: Integer specifying the ID of the quote to be deleted.
- str: A string containing either a JSON response detailing the outcome of the deletion operation or a rendered HTML template for redirection in case of failure.
None.
- The function calls the
delete_quotefunction and checks theHTTPStatusto determine the outcome of the operation.
This endpoint resends an email for a specific quote identified by the given id.
This endpoint is authenticated and requires the user to be logged in to access it.
- id: Integer specifying the ID of the quote for which the email will be resent.
- Returns a message indicating the outcome of the operation and redirects to the admin dashboard.
Resends an email for a specific quote identified by the given id.
- id: Integer specifying the ID of the quote for which the email will be resent.
- str: A string containing a rendered HTML template for redirection, along with a response message indicating the outcome of the operation.
None.
- The function calls the
resend_quote_emailfunction and uses its response andHTTPStatusto determine the outcome of the operation.
This endpoint provides a health check for the application.
This endpoint is authenticated and requires the user to be logged in to access it.
None.
- Returns a message indicating the health status of the application and redirects to the admin dashboard.
Checks the health status of the server and application.
None.
- str: A string containing a rendered HTML template for redirection, along with a message indicating the health status of the application.
None.
- The function calls the
check_healthfunction to determine the health status of the application.