split templates into base and add url's

This commit is contained in:
Yisroel Baum 2024-10-07 14:31:46 +03:00
parent 6afd48aa6e
commit 2112dfd8d9
6 changed files with 152 additions and 78 deletions

View file

@ -17,6 +17,20 @@ def get_uploads_path() -> str:
break
return path
@app.route('/budget_categories')
def budget_categories():
budget_categories = db.session.execute(select(BudgetCategory)).all()
return render_template('budget_categories.html',
budget_categories=budget_categories)
@app.route('/vendors')
def vendors():
vendors = db.session.execute(select(Vendor)).all()
return render_template('vendors.html',
vendors=vendors)
@app.route('/')
def home():
# Get the current date
@ -38,13 +52,9 @@ def home():
dt_object = datetime.datetime.fromtimestamp(li[0].date)
date_string = dt_object.strftime('%Y-%m-%d')
li[0].date = date_string
vendors = db.session.execute(select(Vendor)).all()
budget_categories = db.session.execute(select(BudgetCategory)).all()
files = os.listdir(get_uploads_path())
return render_template('index.html',
files=files,
vendors=vendors,
budget_categories=budget_categories,
all_line_items=all_line_items)
@app.route('/upload_file/<filename>')

View file

@ -36,6 +36,7 @@ function startEditMode(id){
inputElem.value = placeholderText;
inputElem.id = `vendor-input-${id}`
vendor.appendChild(inputElem);
inputElem.focus()
}
document.addEventListener("DOMContentLoaded", (event) => {

50
app/templates/base.html Normal file
View file

@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}{% endblock title %}</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
{% block stylesheet %}{% endblock stylesheet %}
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="collapse navbar-collapse justify-content-center" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="{{url_for('home')}}">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{url_for('vendors')}}">Vendors</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{url_for('budget_categories')}}">Budget Categories</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
More
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
</div>
</nav>
{% block content %}{% endblock content %}
<!-- Bootstrap JS and dependencies (jQuery and Popper.js) -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.3/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
<script src="{{url_for('.static', filename='index.js')}}"></script>
</body>
</html>

View file

@ -0,0 +1,44 @@
{% extends 'base.html' %}
{% block title %}Budget Categories{% endblock title %}
{% block content %}
<main>
<div class="container mt-5">
<div class="card">
<div class="card-header bg-primary text-white">
Budget Categories
</div>
<div class="card-body">
<form action="{{ url_for('add_budget_category') }}" method="POST">
<div class="mb-3">
<label for="categoryName" class="form-label">Add Budget Category</label>
<input type="text" class="form-control" id="categoryName" name="category_name" placeholder="Enter category name" required>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Name</th>
<th scope="col">Delete</th>
</tr>
</thead>
<tbody>
{% for bc in budget_categories %}
<tr id="{{bc[0].id}}-row">
<th scope="row">{{bc[0].id}}</th>
<th scope="row">{{bc[0].name}}</th>
<th scope="row"><button class="btn btn-danger del-button" id="{{bc[0].id}}">Delete</button></th>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</main>
{% endblock content %}

View file

@ -1,12 +1,8 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Budgeting</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
{% extends 'base.html' %}
{% block title %}Homepage{% endblock title %}
{% block content %}
<main>
<div class="container mt-5">
{% if files %}
<div class="card">
@ -80,69 +76,6 @@
</div>
</div>
</div>
<div class="card">
<div class="card-header bg-primary text-white">
Budget Categories
</div>
<div class="card-body">
<form action="{{ url_for('add_budget_category') }}" method="POST">
<div class="mb-3">
<label for="categoryName" class="form-label">Add Budget Category</label>
<input type="text" class="form-control" id="categoryName" name="category_name" placeholder="Enter category name" required>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Name</th>
<th scope="col">Delete</th>
</tr>
</thead>
<tbody>
{% for bc in budget_categories %}
<tr id="{{bc[0].id}}-row">
<th scope="row">{{bc[0].id}}</th>
<th scope="row">{{bc[0].name}}</th>
<th scope="row"><button class="btn btn-danger del-button" id="{{bc[0].id}}">Delete</button></th>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
<div class="card">
<div class="card-header bg-primary text-white">
Vendors
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Name</th>
</tr>
</thead>
<tbody>
{% for vendor in vendors %}
<tr>
<th scope="row">{{vendor[0].id}}</th>
<th scope="row">{{vendor[0].name}}</th>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
<script src="{{url_for('.static', filename='index.js')}}"></script>
</body>
</html>
</main>
{% endblock content %}

View file

@ -0,0 +1,36 @@
{% extends 'base.html' %}
{% block title %}Budget Categories{% endblock title %}
{% block content %}
<main>
<div class="container mt-5">
<div class="card">
<div class="card">
<div class="card-header bg-primary text-white">
Vendors
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Name</th>
</tr>
</thead>
<tbody>
{% for vendor in vendors %}
<tr>
<th scope="row">{{vendor[0].id}}</th>
<th scope="row">{{vendor[0].name}}</th>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</main>
{% endblock content %}