This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from dataclasses import dataclass | |
| from typing import Union | |
| from constants import TaskStatusE | |
| @dataclass | |
| class Project: | |
| id: Union[int, None] # this is because when creating we do not have the ID yet | |
| name: str |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import typer | |
| from database import Database | |
| from data import Project, Task | |
| from constants import TaskStatusE | |
| app = typer.Typer() | |
| project_app = typer.Typer() | |
| task_app = typer.Typer() | |
| project_app.add_typer(task_app, name="tasks") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os.path | |
| import sqlite3 | |
| from constants import TaskStatusE | |
| class Database: | |
| PROJECT_SQL = """CREATE TABLE project ( | |
| id INTEGER PRIMARY KEY AUTOINCREMENT, | |
| name text, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os.path | |
| import sqlite3 | |
| class Database: | |
| PROJECT_SQL = """CREATE TABLE project ( | |
| id INTEGER PRIMARY KEY AUTOINCREMENT, | |
| name text, | |
| description text NULL);""" | |
| TASK_SQL = """CREATE TABLE task ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import typer | |
| app = typer.Typer() | |
| project_app = typer.Typer() | |
| task_app = typer.Typer() | |
| project_app.add_typer(task_app, name="tasks") | |
| app.add_typer(project_app, name="projects") | |
| @project_app.command("list") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import weasyprint | |
| import yaml | |
| from jinja2 import Template | |
| def get_data(data_path="./data.yml"): | |
| with open(data_path, "r") as f: | |
| data = yaml.load(f, Loader=yaml.FullLoader) | |
| # we need to process the data a bit to match the HTML template; | |
| for invoice in data["invoices"]: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_data(data_path="./data.yml"): | |
| with open(data_path, "r") as f: | |
| data = yaml.load(f, Loader=yaml.FullLoader) | |
| # we need to process the data a bit to match the HTML template; | |
| for invoice in data["invoices"]: | |
| # here we simply defined customer and issuer entity in data to avoid lot of typing; | |
| invoice["customer"] = data["customer"][invoice["customer"]] | |
| invoice["issuer"] = data["issuer"][invoice["issuer"]] | |
| # we also needs to add total to items: | |
| total = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| issuer: | |
| issuer1: | |
| name: MyCorp | |
| address: 71 Cherry Court, SO53 5PD SOUTHAMPTON | |
| tax_number: UTR 12345 67890 | |
| country: United Kingdom | |
| customer: | |
| customer1: | |
| name: CoolCompany |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <link href="invoice.css" media="print" rel="stylesheet"> | |
| <title>Invoice</title> | |
| <meta name="description" content="Invoice demo sample"> | |
| </head> | |
| <body> | |
| <h1>Invoice</h1> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def render_pdf(): | |
| template = get_template() | |
| rendered = template.render(**{"name": "John"}) | |
| html = weasyprint.HTML(string=rendered, base_url="/") | |
| css = weasyprint.CSS(filename="./template.css") | |
| with open("output/test.pdf", "wb") as f: | |
| html.write_pdf(f, stylesheets=[css]) |
NewerOlder