Skip to content

Commit 16c15d1

Browse files
chore: 🎨 improved web page design
1 parent 73aa4a3 commit 16c15d1

19 files changed

+345
-178
lines changed

app.py

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class GoldTransaction(db.Model):
5757
service_charge = db.Column(db.Float, nullable=False)
5858
tax = db.Column(db.Float, nullable=False)
5959
total = db.Column(db.Float, nullable=False)
60+
currency = db.Column(db.String(3), nullable=False)
6061
timestamp = db.Column(db.DateTime, default=datetime.utcnow)
6162

6263

@@ -68,6 +69,7 @@ class SilverTransaction(db.Model):
6869
service_charge = db.Column(db.Float, nullable=False)
6970
tax = db.Column(db.Float, nullable=False)
7071
total = db.Column(db.Float, nullable=False)
72+
currency = db.Column(db.String(3), nullable=False)
7173
timestamp = db.Column(db.DateTime, default=datetime.utcnow)
7274

7375

@@ -89,7 +91,6 @@ class Settings(db.Model):
8991
currency = db.Column(db.String(10), nullable=False)
9092
theme = db.Column(db.String(10), nullable=False)
9193

92-
9394
class AuditLog(db.Model):
9495
id = db.Column(db.Integer, primary_key=True)
9596
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
@@ -106,6 +107,15 @@ def __repr__(self):
106107
with app.app_context():
107108
db.create_all()
108109

110+
111+
# first commit in database for settings
112+
with app.app_context():
113+
db.create_all()
114+
settings = Settings(currency='INR', theme='light')
115+
db.session.add(settings)
116+
db.session.commit()
117+
118+
109119
@app.route('/health')
110120
def health():
111121
health_info = {
@@ -133,9 +143,22 @@ def home() -> str:
133143
def inject_theme():
134144
return dict(current_theme=app.config.get('THEME', 'light'))
135145

146+
136147
# Gold calculator route
137148
@app.route('/gold-calculator', methods=['GET', 'POST'])
138149
def gold_calculator():
150+
151+
currency_to_symbol_dict = {
152+
"INR" : "₹ ",
153+
"USD" : "$ ",
154+
"EUR" : "€ ",
155+
"GBP" : "£ ",
156+
"JPY" : "¥ ",
157+
"AUD" : "A$ ",
158+
}
159+
160+
current_currency = Settings.query.first().currency
161+
currency_symbol = currency_to_symbol_dict.get(current_currency, '$')
139162
if request.method == 'POST':
140163
try:
141164
weight = float(request.form['weight'])
@@ -160,17 +183,25 @@ def gold_calculator():
160183
purity=purity,
161184
service_charge=gold_service_charge,
162185
tax=gold_tax,
163-
total=bill_details['Final Price']
186+
total=bill_details['Final Price'],
187+
currency=current_currency,
164188
)
165189
db.session.add(transaction)
166190
db.session.commit()
167191

192+
# if user is logged in, log the transaction
193+
if current_user.is_authenticated:
194+
log_action(user_id=current_user.id, username=current_user.username,
195+
action='Gold Calculator', details=f"Calculated gold price for weight {weight} grams")
196+
168197
return render_template('gold_bill.html',
169198
bill=bill_details,
170199
weight=weight,
171200
price_per_gram=gold_price_per_gram,
172201
purity=purity,
173-
config=app.config)
202+
config=app.config,
203+
current_currency=current_currency,
204+
currency_symbol=currency_symbol)
174205
except ValueError as e:
175206
logging.error(f"ValueError in gold calculator: {str(e)}")
176207
flash(f"Input error: {str(e)}", 'error')
@@ -185,7 +216,10 @@ def gold_calculator():
185216
price_per_gram=gold_price_per_gram,
186217
service_charge=gold_service_charge,
187218
tax=gold_tax,
188-
config=app.config)
219+
config=app.config,
220+
current_currency=current_currency,
221+
currency_symbol=currency_symbol)
222+
189223

190224
# Silver calculator route
191225
@app.route('/silver-calculator', methods=['GET', 'POST'])
@@ -224,7 +258,7 @@ def silver_calculator():
224258
)
225259
db.session.add(transaction)
226260
db.session.commit()
227-
261+
228262
return render_template('silver_bill.html',
229263
bill=bill_details,
230264
weight=weight,
@@ -257,20 +291,24 @@ def history():
257291
if selected_type == 'gold':
258292
transactions = GoldTransaction.query.all()
259293
transactions = [{'id': t.id, 'type': 'Gold', 'weight': t.weight, 'price_per_gram': t.price_per_gram,
260-
"purity": t.purity, 'service_charge': t.service_charge, 'tax': t.tax, 'total': t.total, 'timestamp': t.timestamp} for t in transactions]
294+
"purity": t.purity, 'service_charge': t.service_charge, 'tax': t.tax, 'total': t.total, 'currency': t.currency,
295+
'timestamp': t.timestamp} for t in transactions]
261296
elif selected_type == 'silver':
262297
transactions = SilverTransaction.query.all()
263298
transactions = [{'id': t.id, 'type': 'Silver', 'weight': t.weight, 'price_per_gram': t.price_per_gram,
264-
'purity': t.purity, 'service_charge': t.service_charge, 'tax': t.tax, 'total': t.total, 'timestamp': t.timestamp} for t in transactions]
299+
'purity': t.purity, 'service_charge': t.service_charge, 'tax': t.tax, 'total': t.total, 'currency': t.currency,
300+
'timestamp': t.timestamp} for t in transactions]
265301
else:
266302
gold_transactions = GoldTransaction.query.all()
267303
silver_transactions = SilverTransaction.query.all()
268304

269305
transactions = [{'id': t.id, 'type': 'Gold', 'weight': t.weight, 'price_per_gram': t.price_per_gram,
270-
'purity': t.purity, 'service_charge': t.service_charge, 'tax': t.tax, 'total': t.total, 'timestamp': t.timestamp} for t in gold_transactions]
306+
'purity': t.purity, 'service_charge': t.service_charge, 'tax': t.tax, 'total': t.total, 'currency': t.currency,
307+
'timestamp': t.timestamp} for t in gold_transactions]
271308

272309
transactions += [{'id': t.id, 'type': 'Silver', 'weight': t.weight, 'price_per_gram': t.price_per_gram,
273-
'purity': t.purity, 'service_charge': t.service_charge, 'tax': t.tax, 'total': t.total, 'timestamp': t.timestamp} for t in silver_transactions]
310+
'purity': t.purity, 'service_charge': t.service_charge, 'tax': t.tax, 'total': t.total, 'currency': t.currency,
311+
'timestamp': t.timestamp} for t in silver_transactions]
274312

275313
return render_template('history.html', transactions=transactions, selected_type=selected_type)
276314

@@ -290,18 +328,22 @@ def download_csv():
290328
if selected_type == 'gold':
291329
transactions = GoldTransaction.query.all()
292330
for t in transactions:
293-
writer.writerow([t.id, 'Gold', t.weight, t.price_per_gram, t.purity, t.service_charge, t.tax, t.total, t.timestamp])
331+
writer.writerow([t.id, 'Gold', t.weight, t.price_per_gram, t.purity, t.service_charge, t.tax, t.total, t.currency,
332+
t.timestamp])
294333
elif selected_type == 'silver':
295334
transactions = SilverTransaction.query.all()
296335
for t in transactions:
297-
writer.writerow([t.id, 'Silver', t.weight, t.price_per_gram, t.purity, t.service_charge, t.tax, t.total, t.timestamp])
336+
writer.writerow([t.id, 'Silver', t.weight, t.price_per_gram, t.purity, t.service_charge, t.tax, t.total, t.currency,
337+
t.timestamp])
298338
else:
299339
gold_transactions = GoldTransaction.query.all()
300340
for t in gold_transactions:
301-
writer.writerow([t.id, 'Gold', t.weight, t.price_per_gram, t.purity, t.service_charge, t.tax, t.total, t.timestamp])
341+
writer.writerow([t.id, 'Gold', t.weight, t.price_per_gram, t.purity, t.service_charge, t.tax, t.total, t.currency,
342+
t.timestamp])
302343
silver_transactions = SilverTransaction.query.all()
303344
for t in silver_transactions:
304-
writer.writerow([t.id, 'Silver', t.weight, t.price_per_gram, t.purity, t.service_charge, t.tax, t.total, t.timestamp])
345+
writer.writerow([t.id, 'Silver', t.weight, t.price_per_gram, t.purity, t.service_charge, t.tax, t.total, t.currency,
346+
t.timestamp])
305347

306348
output = si.getvalue().encode('utf-8')
307349
return send_file(
@@ -381,16 +423,18 @@ def dashboard():
381423
else:
382424
system_health = "Good"
383425

426+
audit_logs = AuditLog.query.filter_by(user_id=current_user.id).all()
384427
return render_template('admin_dashboard.html',
385428
total_users=total_users,
386429
active_sessions=active_sessions,
387430
system_health=system_health,
388431
cpu_core=cpu_core,
389-
cpu_util=cpu_utilization)
390-
elif current_user.user_level == 'manager':
391-
return render_template('manager_dashboard.html')
392-
else:
393-
return render_template('customer_dashboard.html')
432+
cpu_util=cpu_utilization,
433+
audit_logs=audit_logs)
434+
elif current_user.user_level == 'customer':
435+
audit_logs = AuditLog.query.filter_by(user_id=current_user.id).all()
436+
return render_template('customer_dashboard.html', audit_logs=audit_logs)
437+
394438

395439
@app.route("/logout")
396440
def logout():

static/css/admin_dashboard.css

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@
6565
margin-bottom: 15px;
6666
}
6767

68+
.admin-tools {
69+
margin-top: 30px;
70+
}
71+
6872
.admin-tools h3 {
6973
font-size: 1.8em;
7074
margin-bottom: 15px;
@@ -77,30 +81,38 @@
7781
margin-right: 10px;
7882
}
7983

80-
.admin-tools ul {
81-
list-style: none;
82-
padding: 0;
83-
}
84-
85-
.admin-tools ul li {
86-
margin-bottom: 10px;
84+
.button-grid {
85+
display: grid;
86+
grid-template-columns: repeat(2, 1fr);
87+
gap: 20px;
8788
}
8889

89-
.admin-tools ul li a {
90-
text-decoration: none;
91-
color: #007bff;
92-
font-size: 1.2em;
93-
transition: color 0.3s ease-in-out;
90+
.btn {
9491
display: flex;
9592
align-items: center;
93+
justify-content: center;
94+
padding: 20px;
95+
font-size: 1.25em;
96+
color: #fff;
97+
background: #007bff;
98+
border: none;
99+
border-radius: 8px;
100+
text-decoration: none;
101+
transition: background 0.3s ease, transform 0.3s ease;
102+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
103+
}
104+
105+
.btn i {
106+
margin-right: 10px;
96107
}
97108

98-
.admin-tools ul li a i {
99-
margin-right: 8px;
109+
.btn:hover {
110+
background: #0056b3;
111+
transform: scale(1.05);
100112
}
101113

102-
.admin-tools ul li a:hover {
103-
color: #0056b3;
114+
.btn:active {
115+
background: #004085;
104116
}
105117

106118
.disabled-link {

static/css/base.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
body {
2+
background-color: #f0f2f5;
3+
display: flex;
4+
flex-direction: column;
5+
min-height: 100vh;
6+
margin-top: 0;
7+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
8+
}
9+
10+
footer {
11+
background-color: #343a40;
12+
color: #adb5bd;
13+
padding: 1rem 0;
14+
position: relative;
15+
width: 100%;
16+
bottom: 0;
17+
text-align: center;
18+
}
19+
20+
footer a {
21+
color: #ffffff;
22+
text-decoration: none;
23+
}
24+
25+
footer a:hover {
26+
color: #ced4da;
27+
text-decoration: underline;
28+
}

static/css/base_dark.css

Lines changed: 0 additions & 15 deletions
This file was deleted.

static/css/base_light.css

Lines changed: 0 additions & 15 deletions
This file was deleted.

static/css/calculator.css

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ body {
1818
flex: 2;
1919
background-color: #ffffff;
2020
border-radius: 15px;
21-
padding: 30px;
21+
padding: 20px;
2222
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
2323
animation: fadeIn 1s ease-in-out;
2424
}
@@ -140,3 +140,10 @@ p.text-center {
140140
color: #333;
141141
font-size: 1rem;
142142
}
143+
144+
.form-row {
145+
display: flex;
146+
justify-content: space-between;
147+
gap: 15px;
148+
margin-bottom: 20px;
149+
}

0 commit comments

Comments
 (0)