heroweb/poc/webcomponents0/tasks/web.py

53 lines
1.6 KiB
Python

from jinja2 import Environment, FileSystemLoader
from webcomponents.models.tasks import TaskList,TaskCategory,TaskStatus,new
from webcomponents.tasks.model import convert_task_list_to_html,TaskListHtml
import os
from tools.deduper import Deduper
current_dir = os.path.dirname(os.path.abspath(__file__))
templates_dir = os.path.join(current_dir, 'templates')
def render(jsondata :str = "", deduper: Deduper | None = None) -> str:
# Create a Jinja2 environment
env = Environment(loader=FileSystemLoader(templates_dir))
task_list_html = _new_tasklist(jsondata=jsondata)
# Load the template
template = env.get_template('task_overview.html')
env.globals['deduper'] = deduper
# Render the template with the task list
rendered_html = template.render(task_list_html=task_list_html)
return rendered_html
def _new_tasklist(jsondata :str = "") -> TaskListHtml:
task_list = new(jsondata=jsondata)
# Example usage:
task_list_html = convert_task_list_to_html(task_list)
return task_list_html
if __name__ == "__main__":
task_list_html = _new_tasklist()
# Print some information about the HTML tasks
for task in task_list_html.tasks:
print(f"Name: {task.name}")
print(f"Category: {task.category}")
print(f"Icon Color: {task.icon_color}")
print(f"Background Color: {task.background_color}")
print(f"Is Highlighted: {task.is_highlighted}")
print(f"Icon SVG: {task.icon_svg}")
print(f"Action SVG: {task.action_svg}")
print("---")
rr=render()
print(rr)