feat: Add basic frontend
This commit is contained in:
parent
b5bb18add6
commit
ca79aed027
14 changed files with 7620 additions and 15 deletions
44
fegen/main.py
Normal file
44
fegen/main.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import os, re, shutil
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
import pandas as pd
|
||||
|
||||
|
||||
def add_download_button(row):
|
||||
item_id = re.sub(r'<a href.*/([0-9]+)".*', "\\1", row[1])
|
||||
download_button = (
|
||||
f'<button id="btn_{item_id}"><i class="fa fa-download"></i> {item_id}</button>'
|
||||
)
|
||||
print_button = f'<a href="http://localhost:31337/print/{item_id}"><button id="prn_{item_id}"><i class="fa fa-print"></i> {item_id}</button></a>'
|
||||
return row + [download_button, print_button]
|
||||
|
||||
|
||||
def generate_dashboard():
|
||||
"""Generate dashboard from zasoby.csv file"""
|
||||
print("Generating HTML dashboard")
|
||||
website_folder = "fegen/docs"
|
||||
data = pd.read_csv("zasoby.csv")
|
||||
env = Environment(loader=FileSystemLoader("fegen/template"))
|
||||
print("Removing old website files")
|
||||
print("Creating a new website")
|
||||
shutil.copytree("fegen/template/static", f"{website_folder}/static", dirs_exist_ok=True)
|
||||
template = env.get_template("_main_layout.html")
|
||||
with open(f"{website_folder}/index.html", "w+", encoding="utf-8") as file:
|
||||
header_row = data.columns.values.tolist() + ["label", "print"]
|
||||
rows = map(
|
||||
add_download_button,
|
||||
data.values.tolist(),
|
||||
)
|
||||
html = template.render(
|
||||
title="Baza Zasobów Hackerspace Trójmiasto",
|
||||
t_header=header_row,
|
||||
t_body=rows,
|
||||
)
|
||||
file.write(html)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from discourse import DiscourseDatabase
|
||||
|
||||
DiscourseDatabase()
|
||||
generate_dashboard()
|
||||
print("Done!")
|
||||
Loading…
Add table
Add a link
Reference in a new issue