Skip to content

Commit

Permalink
add; django view bills for monthly bills and crypto investments
Browse files Browse the repository at this point in the history
(initial version)
  • Loading branch information
toymak3r committed Jan 8, 2024
1 parent 22ab1f9 commit e5554ba
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 65 deletions.
18 changes: 18 additions & 0 deletions assets/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

.lifelogbar {
-webkit-app-region: drag;
width: 100%;
}
body {
background-color: rgb(35, 34, 39);
Expand Down Expand Up @@ -138,3 +139,20 @@ body {
.modal-content:button {
max-width: 10%;
}

.monthly-bills {
}

.bills-footer {
width: 100%;
color: white;
background-color: rgb(35, 34, 39);
left: 0;
bottom: 0;
text-align: center;
padding: 10px; /* Adjust padding as needed */
}

.crypto-investments{
mar
}
6 changes: 4 additions & 2 deletions finances/bill/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os
from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader
from django.db.models import Sum
from .models import Bill
import json
from investments.coinbase.Coinbase import Coinbase
def calculate_percentage(value, total):
if total == 0:
Expand All @@ -16,7 +16,9 @@ def index(request):
bills = Bill.objects.all()
total = Bill.objects.aggregate(total=Sum('value'))['total']

coinbase = Coinbase('QT04LeAVJu5AIr27', 'hOdqwWpEhcJos5ijE0MUlYXYIkHtujtO')
coinbase = Coinbase(os.env['COINBASE_API_KEY'],
os.env['COINBASE_API_SECRET'])

coinbase.update_balance()

print(coinbase._coins)
Expand Down
6 changes: 5 additions & 1 deletion finances/finances/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['*']


# Application definition
Expand Down Expand Up @@ -120,6 +120,10 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/

STATICFILES_DIRS = [
"/home/toy/lifelog/assets/",
]

STATIC_URL = 'static/'

# Default primary key field type
Expand Down
9 changes: 7 additions & 2 deletions finances/templates/_base.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
{% load static %}
<!DOCTYPE html>
<html>

<head>
<title> {{ title }} </title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, width=device-width, user-scalable=no">
<link rel="icon" type="image/x-icon" href="{% static 'imgs/favicon.ico' %}">
<link rel="stylesheet" type="text/css" rel="noopener" target="_blank"
href="../../../node_modules/bootstrap/dist/css/bootstrap.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" rel="noopener" target="_blank" href="{% static 'css/styles.css' %}">
</head>

<body>
<body style="overflow-x: hidden; /* Prevent horizontal scrolling */">
{% include "_navbar.html" %}

{% block content %}
{% endblock %}
</body>
<script src="https://cdn.canvasjs.com/canvasjs.min.js"> </script>

</html>
43 changes: 6 additions & 37 deletions finances/templates/_navbar.html
Original file line number Diff line number Diff line change
@@ -1,43 +1,12 @@
{% block navbar %}
{% load static %}

<nav class="navbar navbar-dark bg-dark">
<nav class="navbar-fixed-top navbar-dark bg-dark lifelogbar">
<div class="container-fluid">
<a class="navbar-brand" href="#"> .Lifelog </a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown"
aria-expanded="false">
Dropdown
</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link disabled" aria-disabled="true">Disabled</a>
</li>
</ul>
<form class="d-flex" role="search">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
<a class="navbar-brand lifelog_title" href="#">
<img src="{% static 'logo/logo.png' %}" alt="Logo" width="40" height="40" class="lifelog-logo">
lifelog
</a>
</div>
</nav>

Expand Down
109 changes: 86 additions & 23 deletions finances/templates/bills/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,94 @@
{% block title %} My Bills {% endblock %}

{% block content %}
<table class="table table-striped">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Description</th>
<th scope="col">value</th>

</tr>
</thead>
<tbody>
{% for bill in bills %}
<tr scope="row">
<th scope="row">{{ bill.id }}</th>
<td> {{ bill.description }} </td>
<td> ${{ bill.value }} </td>
<script>
window.onload = function () {
var chart = new CanvasJS.Chart("monthlybillchart", {
exportEnabled: false,
animationEnabled: true,
theme: "dark2",
title: {
text: "Monthly Bills",
dockInsidePlotArea: true,
verticalAlign: "center",
height: 350,
fontSize: 22
},
subtitles: [{
text: ""
}],
data: [{
type: "doughnut",
startAngle: -90,
indexLabel: "{name} ({y})",
yValueFormatString: "#,##0.0#\"%\"",
dataPoints: {{ bills_pie_values| safe }}
}]
});
chart.render();
}
</script>
<div class="container">
<div class="row" style="margin-top: 10px;">
<div class="col-sm-8">
<table class="table table-striped monthly-bills">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Description</th>
<th scope="col">Value</th>
<th scope="col">Due Day</th>
</tr>
</thead>
<tbody>
{% for bill in bills %}
<tr scope="row">
<th scope="row">{{ bill.id }}</th>
<td> {{ bill.description }} </td>
<td> {{ bill.currency.symbol }} {{ bill.value }} </td>
<td> {{ bill.due_day }} </td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="col-sm-4">
<div id="monthlybillchart" style="width:100%; height: 350px;"></div>
</div>
</div>

<div class="row" style="margin-top: 10px;">
<div class="col-sm-8">
<table class="table table-striped crypto-investments">
<thead>
<tr>
<th scope="col">Coin</th>
<th scope="col">Amount</th>
<th scope="col">GBP</th>
</tr>
</thead>
<tbody>
{% for key, value in coins.items %}
<tr scope="row">
<th scope="row">{{ key }}</th>
<td> {{ value.balance }} </td>
<td> {{ value.gbp }} </td>
</tr>
{% endfor %}
</tbody>
</table>
</div>

</tr>
{% endfor %}
</tbody>
</table>
<div class="shadow p-3 mb-5 bg-body-tertiary rounded bg-dark">
Total: ${{ total }}
<div class="col-sm-4">
</div>
</div>
</div>

<footer class="bills-footer">
<p><a>Total Monthly Payments: &pound; {{ total }} </a></p>
<p><a>Cryptos: &pound; {{ coin_balance_gbp }} </a></p>
</footer>


<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
crossorigin="anonymous"></script>
{% endblock %}

0 comments on commit e5554ba

Please sign in to comment.