Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions Budget_Project/Budget_Application/templates/core/add_expense.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends "core/base.html" %}
{% block content %}
<h2>Dodaj wydatek</h2>
<form method="post">
{% csrf_token %}
<div class="mb-3">
<label class="form-label">Kwota</label>
<input type="text" name="amount" class="form-control">
</div>
<div class="mb-3">
<label class="form-label">Kategoria</label>
<input type="text" name="category" class="form-control">
</div>
<button type="submit" class="btn btn-danger">Dodaj</button>
</form>
<a href="{% url 'main_menu' %}" class="btn btn-link mt-3">← Powrót</a>
{% endblock %}
17 changes: 17 additions & 0 deletions Budget_Project/Budget_Application/templates/core/add_income.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends "core/base.html" %}
{% block content %}
<h2>Dodaj przychód</h2>
<form method="post">
{% csrf_token %}
<div class="mb-3">
<label class="form-label">Kwota</label>
<input type="text" name="amount" class="form-control">
</div>
<div class="mb-3">
<label class="form-label">Kategoria</label>
<input type="text" name="category" class="form-control">
</div>
<button type="submit" class="btn btn-success">Dodaj</button>
</form>
<a href="{% url 'main_menu' %}" class="btn btn-link mt-3">← Powrót</a>
{% endblock %}
14 changes: 14 additions & 0 deletions Budget_Project/Budget_Application/templates/core/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<title>Budżet Domowy</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body style="background-color: #F0FFFF;">
<div class="container mt-5">
{% block content %}
{% endblock %}
</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{% extends 'core/base.html' %}

{% block content %}
<div class="container mt-5">
<h2 class="mb-4">💱 Kantor – przelicz walutę</h2>

{% if error %}
<div class="alert alert-danger">{{ error }}</div>
{% endif %}

<form method="post" class="row g-3">
{% csrf_token %}
<div class="col-md-4">
<label for="amount" class="form-label">Kwota</label>
<input type="number" step="0.01" name="amount" class="form-control" required value="{{ amount }}">
</div>

<div class="col-md-4">
<label for="from_currency" class="form-label">Z waluty</label>
<select name="from_currency" class="form-select" required>
{% for code, name in currencies.items %}
<option value="{{ code }}" {% if code == from_currency %}selected{% endif %}>
{{ code }} - {{ name }}
</option>
{% endfor %}
</select>
</div>

<div class="col-md-4">
<label for="to_currency" class="form-label">Na walutę</label>
<select name="to_currency" class="form-select" required>
{% for code, name in currencies.items %}
<option value="{{ code }}" {% if code == to_currency %}selected{% endif %}>
{{ code }} - {{ name }}
</option>
{% endfor %}
</select>
</div>

<div class="col-12">
<button type="submit" class="btn btn-primary mt-3">Przelicz</button>
</div>
</form>

{% if result %}
<div class="alert alert-success mt-4">
Wynik: <strong>{{ amount }} {{ from_currency }} = {{ result|floatformat:2 }} {{ to_currency }}</strong>
</div>
{% endif %}

<p class="mt-4">
<a href="{% url 'main_menu' %}" class="btn btn-outline-secondary">← Powrót do menu</a>
</p>
</div>
{% endblock %}
23 changes: 23 additions & 0 deletions Budget_Project/Budget_Application/templates/core/menu.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@


{% extends 'core/base.html' %}
{% load static %}

{% block content %}
<div class="container py-5" style="
background-image: url('{% static 'core/images/background.jpg' %}');
background-size: cover;
background-position: center;
border-radius: 10px;
min-height: 900px;
color: white;
">
<h2 class="mb-4 text-left fw-bold" style="color: black;">📋 Menu Główne</h2>

<div class="d-grid gap-3">
<a href="{% url 'add_income' %}" class="btn btn-success btn-lg">➕ Dodaj przychód</a>
<a href="{% url 'add_expense' %}" class="btn btn-danger btn-lg">➖ Dodaj wydatek</a>
<a href="{% url 'currency_converter' %}" class="btn btn-primary btn-lg">💱 Kantor</a>
</div>
</div>
{% endblock %}
5 changes: 5 additions & 0 deletions Budget_Project/Budget_Application/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@
path('reset/done/',
auth_views.PasswordResetCompleteView.as_view(template_name='users_test/password_reset_complete.html'),
name='password_reset_complete'),
#-----------MENU_APLIKACJI----------->
path('menu/', views.main_menu, name='main_menu'),
path('income/', views.add_income, name='add_income'),
path('expense/', views.add_expense, name='add_expense'),
path('currency/', views.currency_converter, name='currency_converter'),
]
108 changes: 108 additions & 0 deletions Budget_Project/Budget_Application/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
)

from .services import UserService
import requests


class AllUserTransactionsView(View):
Expand Down Expand Up @@ -749,3 +750,110 @@ class MyPasswordResetView(PasswordResetView):
def form_valid(self, form):
response = super().form_valid(form)
return response


def main_menu(request):
return render(request, 'core/menu.html')


def add_income(request):
if request.method == 'POST':
amount = request.POST.get('amount')
category = request.POST.get('cartegory')
print(f'Przychód: {amount} ({category})')
return render(request, 'core/thanks.html')
return render(request, 'core/add_income.html')

def add_expense(request):
if request.method == 'POST':
amount = request.POST.get('amount')
category = request.POST.get('category')
print(f'Wydatek: {amount} ({category})')
return render(request, 'core/thanks.html')
return render(request, 'core/add_expense.html')


def get_supported_currencies():
url = "https://api.frankfurter.app/currencies"
response = requests.get(url)
if response.status_code != 200:
raise Exception("Błąd pobierania walut.")
return response.json()


def convert_currency(amount, from_currency, to_currency):
if from_currency == to_currency:
return amount

url = "https://api.frankfurter.app/latest"
params = {
"amount": amount,
"from": from_currency,
"to": to_currency
}
response = requests.get(url, params=params)
if response.status_code != 200:
raise Exception("Błąd przeliczania waluty.")

data = response.json()
return data["rates"][to_currency]


def currency_converter(request):
result = None
error = None
currencies = {}
from_currency = 'PLN' # domyślna wartość
to_currency = ''
amount = ''

try:
currencies = get_supported_currencies()
except Exception as e:
error = str(e)

if request.method == 'POST':
try:
amount = request.POST.get('amount')
from_currency = request.POST.get('from_currency') or 'PLN'
to_currency = request.POST.get('to_currency')

result = convert_currency(float(amount), from_currency, to_currency)
except Exception as e:
error = str(e)

return render(request, 'core/currency_converter.html', {
'currencies': currencies,
'result': result,
'error': error,
'amount': amount,
'from_currency': from_currency,
'to_currency': to_currency,
})


# def currency_converter(request):
# result = None
# error = None
# currencies = {}
#
# try:
# currencies = get_supported_currencies()
# except Exception as e:
# error = str(e)
#
# if request.method == 'POST':
# try:
# amount = float(request.POST.get('amount'))
# from_currency = request.POST.get('from_currency') or 'PLN'
# to_currency = request.POST.get('to_currency')
#
# result = convert_currency(amount, from_currency, to_currency)
# except Exception as e:
# error = str(e)
#
# return render(request, 'core/currency_converter.html', {
# 'currencies': currencies,
# 'result': result,
# 'error': error
# })
2 changes: 1 addition & 1 deletion Budget_Project/Budget_Project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
'ENGINE': 'django.db.backends.mysql',
'NAME': 'budget_application_database',
'USER': 'root',
'PASSWORD': 'Soniapies_13',
'PASSWORD': 'root',
'HOST': 'localhost',
'PORT': '3306',
}
Expand Down
2 changes: 1 addition & 1 deletion app_zarz_bud_MENU.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def menu():
elif choice == "7":
users.menu_users()
elif choice == "0":
"***Do ZoBaCzEnIA***"
"***Do ZoBaCzEnIA***"
break
else:
print("BŁĄD.... Spróbuj ponownie....")
Expand Down