show user donations on his own page
This commit is contained in:
parent
cf4b642461
commit
62e307f6a2
3 changed files with 33 additions and 8 deletions
|
|
@ -1,7 +1,7 @@
|
|||
from app import db
|
||||
from flask import current_app
|
||||
from flask_login import UserMixin, current_user
|
||||
from sqlalchemy import TEXT, Column, Boolean, ForeignKey, TEXT, INTEGER, VARCHAR
|
||||
from sqlalchemy import TEXT, Column, Boolean, ForeignKey, TEXT, INTEGER, VARCHAR, select
|
||||
import jwt
|
||||
from datetime import datetime, timezone, timedelta
|
||||
|
||||
|
|
@ -15,7 +15,9 @@ class User(db.Model, UserMixin):
|
|||
password = Column('password', TEXT(), nullable=False)
|
||||
user_type = Column('user_type', TEXT(), nullable=False)
|
||||
|
||||
|
||||
def get_donations(self):
|
||||
from app.main.models import Donation
|
||||
return db.session.execute(select(Donation.currency_type,Donation.amount).where(Donation.user_id == self.id)).all()
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"{self.first_name} {self.last_name}"
|
||||
|
|
|
|||
|
|
@ -19,8 +19,10 @@ def user_page(user_id):
|
|||
if not int(current_user.id) == int(user_id):
|
||||
return redirect(url_for('main.homepage'))
|
||||
user = User.query.filter_by(id=user_id).first()
|
||||
donations = user.get_donations()
|
||||
return render_template('user_page.html',
|
||||
user=user)
|
||||
user=user,
|
||||
donations=donations)
|
||||
|
||||
|
||||
@users.route('/')
|
||||
|
|
|
|||
|
|
@ -1,19 +1,40 @@
|
|||
{% extends 'base.html' %}
|
||||
{% block title %}User Page{% endblock title %}
|
||||
{% block content %}
|
||||
<main class="container">
|
||||
<main class="container-lg mt-5">
|
||||
<div class="row mt-4">
|
||||
<div class="col-md-6 offset-md-3">
|
||||
<h1>Welcome, {{ user.first_name }} {{ user.last_name }}</h1>
|
||||
<hr>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6">
|
||||
<div class="card mb-5">
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-center align-items-center">
|
||||
<h2 class="text-center">Donations</h2>
|
||||
</div>
|
||||
<table class="table table-bordered table-striped">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th>Currency</th>
|
||||
<th>Amount</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for donation in donations %}
|
||||
<tr>
|
||||
<td>{{donation[0]}}</td>
|
||||
<td>{{donation[1]}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-10 offset-md-1">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
{% endblock %}
|
||||
Loading…
Add table
Add a link
Reference in a new issue