Skip to content

Commit

Permalink
Piglet Version 1.1.1
Browse files Browse the repository at this point in the history
    - Fixed some errors in future spend
    - Changed design of alert messages
    - Currency of budget is now shown in notifications
    - Bugfixes
  • Loading branch information
k3nd0x committed Jul 19, 2023
1 parent f90ac2b commit 926bb57
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 98 deletions.
7 changes: 2 additions & 5 deletions webapp/api/routes/futurespends.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ async def spends(budget_id: int, max_entries: Optional[int]=30, current_user = D
check(mysql,current_user["bid_mapping"], budget_id)

query = '''select (select name from registered_user where id=user_id) as user, (select name from pig_category where id=category_id) as category, CONCAT(value,' ',currency) AS value, id, DATE_FORMAT(timestamp, '%Y-%m-%d') as timestamp,description FROM pig_futurespends where budget_id={} order by timestamp DESC'''.format(budget_id)
print(query,flush=True)
response = mysql.get(query)

max_count = 1
Expand Down Expand Up @@ -57,7 +56,6 @@ async def spends(budget_id: int, max_entries: Optional[int]=30, current_user = D
updated_data.append({'monthnumber': month_number, 'month': month_name,
'value': 0.0, 'currency': response[0]["currency"]})

print(updated_data,flush=True)

for i in updated_data:
if i["monthnumber"] >= currentMonth:
Expand All @@ -73,7 +71,7 @@ async def spends(budget_id: int, max_entries: Optional[int]=30, current_user = D

class newSpend(BaseModel):
value: str
userid: str
userid: int
category: str
description: Optional[str] = None
budget_id: str
Expand All @@ -100,7 +98,7 @@ async def spends(newSpend: newSpend,current_user = Depends(get_current_user)):
description = newSpend.description
timestamp = newSpend.timestamp
except:
return "Variables not valid"
raise HTTPException(status_code=422, detail="Variables not valid")
mysql = sql()

if userid != current_user["id"]:
Expand All @@ -112,7 +110,6 @@ async def spends(newSpend: newSpend,current_user = Depends(get_current_user)):
curr = mysql.get(currency_query)[0]["currency"]

query = '''insert into pig_futurespends(value,currency,user_id,category_id,budget_id,description,timestamp) VALUES ({},"{}",{},{},{},"{}","{}")'''.format(value,curr,userid,category,budget_id,description,timestamp)
print(query)
insert = mysql.post(query)
if insert == True:
output = "Order added".format(userid,value, curr, category,description)
Expand Down
8 changes: 5 additions & 3 deletions webapp/api/routes/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,16 @@ async def orders(newOrder: newOrder,current_user = Depends(get_current_user)):

if notisettings[0]["mail"] == 1:
username = '''select name from registered_user where id={}'''.format(userid)
budget_name = '''select name from pig_budgets where id={}'''.format(budget_id)
budget_name = '''select name,currency from pig_budgets where id={}'''.format(budget_id)
email = '''select email from registered_user where id={}'''.format(dstuid)

username = mysql.get(username)[0]["name"]
budget_name = mysql.get(budget_name)[0]["name"]
budget = mysql.get(budget_name)[0]
budget_name = budget["name"]
budget_currency = budget["currency"]
email = mysql.get(email)[0]["email"]

mailvalue = '''{} added {} $ to the budget {}'''.format(username, value, budget_name)
mailvalue = '''{} added {} {} to the budget {}'''.format(username, value,currency, budget_name)

header = '''{} went shopping!'''.format(username)

Expand Down
1 change: 0 additions & 1 deletion webapp/source/app/api_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ def put(url,auth=None):

elif mode == "register":
url = baseurl + "user/register_user"
print(url,flush=True)
response = post(url)


Expand Down
12 changes: 12 additions & 0 deletions webapp/source/app/budget_sharing.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,21 @@ def connect():

flash(flash_message)
return redirect(url_for('connect'))
@app.route('/newbudget',methods=["GET", "POST"])
def newbudget():
if session:
noticount, notilist, notifications = get_notis()
if request.method == "POST":
form_data = request.form.to_dict()

userid = session["userid"]
name = form_data["budgetname"]

data = { "user_id": userid, "name": name, "currency": currency }

response = post_data_api("newbudget", data,auth=auth())


return redirect(url_for('budget'))


9 changes: 4 additions & 5 deletions webapp/source/app/future_spends.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from flask import Flask, render_template, url_for, flash, redirect, request, session, send_from_directory
from source.app import app
from werkzeug.utils import secure_filename
from hashlib import sha256
import os
import json
from datetime import date

from .api_func import get_data_api, post_data_api, del_data_api
from .funcs import get_notis, auth
Expand All @@ -19,14 +17,15 @@ def futurespends():
session["title"] = "futurespends"
apidata = get_data_api("futurespends", data=data,auth=auth())
orderlist = apidata["orders"]
today = date.today()

monthlist = apidata["monthlist"]
valuelist = apidata["valuelist"]
colorlist = apidata["colorlist"]

categorylist = get_data_api("categorylist",data=budget_id,auth=auth())

return render_template("futurespends.html",orderlist=orderlist,notifications=notifications, notilist=notilist, noticount=noticount, monthlist=monthlist, valuelist=valuelist, colorlist=colorlist, categorylist=categorylist )
return render_template("futurespends.html",orderlist=orderlist,notifications=notifications, notilist=notilist, noticount=noticount, monthlist=monthlist, valuelist=valuelist, colorlist=colorlist, categorylist=categorylist,today=today )
else:
return redirect(url_for('login'))
else:
Expand All @@ -40,7 +39,7 @@ def fdelete():
data = { "id": id, "budget_id": session["budget_id"] }
return_value = del_data_api("futurespends",data,auth=auth())
if return_value =="Entity deleted":
flash_message = {"Entity deleted": "success"}
flash_message = {"Entity deleted": "danger"}
else:
flash_message = {"Error at delete": "danger"}

Expand Down
13 changes: 12 additions & 1 deletion webapp/source/app/templates/budget_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
name="budgetname"
placeholder="Budget Name"
style="margin-top: 10px; text-align: center" />
<select
class="form-control form-control_piglet"
name="currency"
style="margin-top: 10px"
required>
<option
value="USD">USD</option>
<option
value="EUR">EUR</option>
</select>
<button
class="btn btn-piglet"
type="submit"
Expand Down Expand Up @@ -92,6 +102,7 @@
class="form-control form-control_piglet"
name="newname"
placeholder="{{ i.name }}"
value="{{ i.name }}"
style="margin-top: 10px;text-align: center;" />
<select
class="form-control form-control_piglet"
Expand Down Expand Up @@ -201,7 +212,7 @@
class="col-xl-6 offset-xl-3">
<div
class="alert alert-{{ value }} d-lg-flex justify-content-lg-center"
style="border-radius: 40px; text-align: center">
style="border-radius: 4px; text-align: center">
{{key}}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion webapp/source/app/templates/category.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
for msgs in messages %} {% for key,value in msgs.items() %}
<div
class="alert alert-{{ value }}"
style="border-radius: 40px; text-align: center"
style="border-radius: 4px; text-align: center"
>
{{key}}
</div>
Expand Down
93 changes: 52 additions & 41 deletions webapp/source/app/templates/futurespends.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,54 @@ <h5 style="font-weight: bold; margin-bottom: auto;" class="text-piglet">Future S
</div>
<div class="col-lg-12 col-xxl-6 offset-lg-0" style="margin-top: 10px">
<div class="card text-center">
<div class="card-header text-center">
<h5 style="font-weight: bold; margin-bottom: auto;" class="text-piglet">Future Spends Overview</h5>
</div>
<div class="card-body">
{% with messages = get_flashed_messages() %} {% if messages %} {% for msgs in messages %} {%
for key,value in msgs.items() %}
{% if key == "Entity deleted" %}
<div class="alert alert-{{ value }}"
style="border-radius: 4px;margin-top: 30px;text-align: center;">
{{key}}
</div>
{% endif %}
{% endfor %} {% endfor %} {% endif %} {% endwith %}
<div class="table-responsive table mt-2" id="dataTable" role="grid" aria-describedby="dataTable_info">
<table id="orders" class="table cell-border compact hover">
<thead>
<tr>
<th>User</th>
<th>Category</th>
<th>Value</th>
<th>Timestamp</th>
<th>Description</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr>
{% for item in orderlist %}
<td> {{ item.user }} </td>
<td> {{ item.category }} </td>
<td> {{ item.value }} </td>
<td> {{ item.timestamp }} </td>
<td> {{ item.description }} </td>
<td><a style=text-decoration:none href="/fdelete?name=futurespends&id={{ item.id }}" class="btn-sm btn-danger"><i class="far fa-trash-alt"></a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="container" style="margin-top: 10px">
<div class="row">
<div class="col-lg-12 offset-lg-0">
<div class="card">
<div class="card-header">
<h5 style="font-weight: bold; margin-bottom: auto;" class="text-piglet">Add Future spend</h5>
</div>
Expand All @@ -40,17 +88,19 @@ <h5 style="font-weight: bold; margin-bottom: auto;" class="text-piglet">Add Futu
</select>
<label class="form-label d-lg-flex justify-content-lg-center"
style="margin-top: 30px;">Select date</label>
<input class="form-control form-control_piglet" name="timestamp" type="date" value="2023-06-26" />
<input class="form-control form-control_piglet" name="timestamp" type="date" value="{{ today }}" />
<button class="btn btn-piglet" type="submit"
style="width: 100%;margin-top: 30px;">Add future spend</button>
</form>

{% with messages = get_flashed_messages() %} {% if messages %} {% for msgs in messages %} {%
for key,value in msgs.items() %}
{% if key != "Entity deleted" %}
<div class="alert alert-{{ value }}"
style="border-radius: 40px;margin-top: 30px;text-align: center;">
style="border-radius: 4px;margin-top: 10px;text-align: center;">
{{key}}
</div>
{% endif %}
{% endfor %} {% endfor %} {% endif %} {% endwith %}
</div>
</div>
Expand All @@ -59,45 +109,6 @@ <h5 style="font-weight: bold; margin-bottom: auto;" class="text-piglet">Add Futu
</div>
</div>
</div>
<div class="container" style="margin-top: 10px">
<div class="row">
<div class="col-lg-12 offset-lg-0">
<div class="card">
<div class="card-header text-center">
<h5 style="font-weight: bold; margin-bottom: auto;" class="text-piglet">Future Spends Overview</h5>
</div>
<div class="card-body">{% with messages = get_flashed_messages() %} {% if messages %} {% for msgs in messages %} {{msgs}} {% endfor %} {% endif %} {% endwith %}
<div class="table-responsive table mt-2" id="dataTable" role="grid" aria-describedby="dataTable_info">
<table id="orders" class="table cell-border compact hover">
<thead>
<tr>
<th>User</th>
<th>Category</th>
<th>Value</th>
<th>Timestamp</th>
<th>Description</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr>
{% for item in orderlist %}
<td> {{ item.user }} </td>
<td> {{ item.category }} </td>
<td> {{ item.value }} </td>
<td> {{ item.timestamp }} </td>
<td> {{ item.description }} </td>
<td><a style=text-decoration:none href="/fdelete?name=futurespends&id={{ item.id }}" class="btn-sm btn-danger"><i class="far fa-trash-alt"></a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" class="init">
$(document).ready(function() {
$('#orders').DataTable({
Expand Down
2 changes: 1 addition & 1 deletion webapp/source/app/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
{% with messages = get_flashed_messages() %} {% if messages %} {% for msgs in messages %} {% for key,value in msgs.items() %}
<div class="row" style="margin-top: 30px;">
<div class="col-lg-10 offset-lg-1">
<div style="border-radius: 40px;" class="alert alert-{{ value }}">
<div style="border-radius: 4px;" class="alert alert-{{ value }}">
{{key}}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion webapp/source/app/templates/new-order.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h5 style="font-weight: bold; margin-bottom: auto;" class="text-piglet">Add Orde
{% with messages = get_flashed_messages() %} {% if messages %} {% for msgs in messages %} {%
for key,value in msgs.items() %}
<div class="alert alert-{{ value }}"
style="border-radius: 40px;margin-top: 30px;text-align: center;">
style="border-radius: 4px;margin-top: 30px;text-align: center;">
{{key}}
</div>
{% endfor %} {% endfor %} {% endif %} {% endwith %}
Expand Down
33 changes: 0 additions & 33 deletions webapp/source/app/templates/new_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,39 +101,6 @@ <h5 style="font-weight: bold; margin-bottom: auto;" class="text-piglet">Notifica
</div>
</div>
</div>
<!--
<div class="container" style="margin-top: 60px;">
<div class="accordion" role="tablist" id="accordion-1">
<div class="accordion-item" style="box-shadow: 2px 1px 12px rgba(33,37,41,0.35);border-radius: 10px;border-width: 1px;border-color: brown">
<header class="header-piglet" style="border-radius: 10px;border-width: 1px;">
<button class="accordion-button collapsed text-danger" data-bs-toggle="collapse" data-bs-target="#accordion-1 .item-1" aria-expanded="true" aria-controls="accordion-1 .item-1" style="border-top-left-radius: 10px; border-top-right-radius: 10px;border-width: 1px; font-weight: bold; color: var(--bs-danger);">Danger Zone</button>
</header>
<div class="accordion-collapse collapse item-1" role="tabpanel" data-bs-parent="#accordion-1">
<div class="accordion-body">
<div class="row">
<div class="col-lg-5 col-xl-8 offset-xl-0">
<label class="form-label"><strong>Useraccount löschen:</strong>
<br>Löscht den aktuellen Useraccount, wenn keine Buchungen gepeichert sind<br>
</label>
<hr>
<label class="form-label"><strong>Useraccount löschen (force):</strong>
<br>Löscht den aktuellen Useraccount &amp; sämtliche Buchungen/Kategorien/Budgets<br>
</label>
</div>
<div class="col-lg-5 col-xl-4 offset-xl-0" style="margin-top: 18px">
<form method="post" action="/settings">
<button name="mode" value="regular" class="btn btn-danger d-lg-flex justify-content-lg-center" type="submit" style="width: 100%;">User löschen</button>
<hr>
<button name="mode" value="force" class="btn btn-danger d-lg-flex justify-content-lg-center" type="submit" style="width: 100%;">User löschen (force)</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
-->

</body>
{% extends "footer.html" %}
Expand Down
2 changes: 1 addition & 1 deletion webapp/source/app/templates/passwordlost.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{% with messages = get_flashed_messages() %} {% if messages %} {% for msgs in messages %} {% for key,value in msgs.items() %}
<div class="row" style="margin-top: 30px;">
<div class="col-lg-10 offset-lg-1">
<div style="border-radius: 40px;" class="alert alert-{{ value }}">
<div style="border-radius: 4px;" class="alert alert-{{ value }}">
{{key}}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion webapp/source/app/templates/register.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
{% with messages = get_flashed_messages() %} {% if messages %} {% for msgs in messages %} {% for key,value in msgs.items() %}
<div class="row" style="margin-top: 30px;">
<div class="col-lg-10 offset-lg-1">
<div style="border-radius: 40px;" class="alert alert-{{ value }}">
<div style="border-radius: 4px;" class="alert alert-{{ value }}">
{{key}}
</div>

Expand Down
Loading

0 comments on commit 926bb57

Please sign in to comment.