Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions core/utils_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
# Default master database
MASTER_DATABASE = "datasets/data.db"

ALLOWED_TABLES = {
"resourcetype",
"resource_inventory",
"cost_inventory",
"risk_inventory",
"scoring_data",
"alternative",
"alternativetechnology",
"risk",
}


def connect(db_path=MASTER_DATABASE):
try:
Expand All @@ -20,6 +31,8 @@ def connect(db_path=MASTER_DATABASE):


def load_data(table_name, db_path=MASTER_DATABASE):
if table_name not in ALLOWED_TABLES:
raise ValueError(f"Disallowed table name: {table_name}")
try:
conn = connect(db_path)
cursor = conn.cursor()
Expand Down
5 changes: 3 additions & 2 deletions core/utils_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
import logging
from typing import Any
from jinja2 import Template
from jinja2 import Environment

# ReportLab
from reportlab.lib.pagesizes import A4
Expand Down Expand Up @@ -134,7 +134,8 @@ def generate_html_report(
with open(template_path, "r") as file:
template_content = file.read()

template = Template(template_content)
env = Environment(autoescape=True)
template = env.from_string(template_content)
html_content = template.render(
**metadata,
**scoring_context,
Expand Down
4 changes: 3 additions & 1 deletion core/utils_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

def _assess_url(host: str) -> str:
host = host.strip().rstrip("/")
if not host.startswith("http"):
if host.startswith("http://"):
host = "https://" + host[len("http://") :]
elif not host.startswith("https://"):
host = f"https://{host}"
return f"{host}{_ASSESS_PATH}"

Expand Down
4 changes: 3 additions & 1 deletion utils/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

def _build_url(host: str) -> str:
host = host.strip().rstrip("/")
if not host.startswith("http"):
if host.startswith("http://"):
host = "https://" + host[len("http://") :]
elif not host.startswith("https://"):
host = f"https://{host}"
return f"{host}{_AUTH_PATH}"

Expand Down
4 changes: 3 additions & 1 deletion utils/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

def _build_url(host: str) -> str:
host = host.strip().rstrip("/")
if not host.startswith("http"):
if host.startswith("http://"):
host = "https://" + host[len("http://") :]
elif not host.startswith("https://"):
host = f"https://{host}"
return f"{host}{_ASSESS_PATH}"

Expand Down