Skip to content

Commit

Permalink
working istitution page
Browse files Browse the repository at this point in the history
  • Loading branch information
caseybecking committed Nov 17, 2024
1 parent af57852 commit 728034d
Show file tree
Hide file tree
Showing 13 changed files with 285 additions and 44 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ flask-restx = "*"
flask-login = "*"
python-dotenv = "*"
pylint = "*"
requests = "*"

[dev-packages]

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ flask run
### Plugins

## Roadmap and releases
### Models
### Required Models
- Users
- Email
- Password
Expand Down Expand Up @@ -58,6 +58,7 @@ flask run
- Amount
- Transaction Type

### Nice to haves
- Items (thought here is to be able to track the items that make up the transaction)
- Merchant
- Tags
Expand Down
2 changes: 1 addition & 1 deletion api/categories_group/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self, user_id, name):

def __repr__(self):
return '<CategoriesGroup %r>' % self.name

def to_dict(self):
return {
'id': self.id,
Expand Down
3 changes: 1 addition & 2 deletions api/institution/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ def post(self):

def get(self):
institutions = InstitutionModel.query.all()
_isntitutions = []
_isntitutions.append([institution.to_dict() for institution in institutions])
_isntitutions = [institution.to_dict() for institution in institutions]
return make_response(jsonify({'institutions': _isntitutions}), 200)
3 changes: 1 addition & 2 deletions api/institution_account/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,5 @@ def post(self):

def get(self):
accounts = InstitutionAccountModel.query.all()
_accounts = []
_accounts.append([account.to_dict() for account in accounts])
_accounts = [account.to_dict() for account in accounts]
return make_response(jsonify({'accounts': _accounts}), 200)
1 change: 1 addition & 0 deletions api/user/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ def post(self):

def get(self):
users = _user_model.query.all()
users = [user.to_dict() for user in users]
return make_response(jsonify({'users': users}), 200)

14 changes: 14 additions & 0 deletions api/user/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ def __init__(self, email, username, password, first_name, last_name):
self.last_name = last_name
self.api_key = None # Initialize without an API key

def __repr__(self):
return '<User %r>' % self.username

def to_dict(self):
return {
'id': self.id,
'email': self.email,
'username': self.username,
'first_name': self.first_name,
'last_name': self.last_name,
'created_at': self.created_at,
'updated_at': self.updated_at
}

def generate_api_key(self):
"""Generate a new unique API key and save it to the database."""
self.api_key = secrets.token_hex(32) # Generate a 64-character API key
Expand Down
10 changes: 8 additions & 2 deletions app/institution/controllers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from flask import Blueprint, render_template
from flask import Blueprint, render_template, url_for, session
from flask_login import login_required
import requests

institution_blueprint = Blueprint('institution', __name__)

@institution_blueprint.route('/institution')
@login_required
def institution():
return render_template('institution/index.html')
api_url = url_for('institution', _external=True)
response = requests.get(api_url)
institutions = response.json().get('institutions', [])
user_id = session.get('_user_id')

return render_template('institution/index.html', institutions=institutions, user_id=user_id)
10 changes: 8 additions & 2 deletions app/institution_account/controllers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from flask import Blueprint, render_template
from flask import Blueprint, render_template, url_for
from flask_login import login_required
import requests


institution_account_blueprint = Blueprint('institution_account', __name__)

@institution_account_blueprint.route('/account')
@login_required
def institution_account():
return render_template('institution_account/index.html')
api_url = url_for('institution_account', _external=True)
response = requests.get(api_url)
accounts = response.json().get('accounts', [])

return render_template('institution_account/index.html', accounts=accounts)
32 changes: 32 additions & 0 deletions app/static/js/institution/institution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function instituionFormSubmit(event) {
event.preventDefault();

const institutionName = document.getElementById('institutionName').value;
const institutionLocation = document.getElementById('institutionLocation').value;
const institutionDescription = document.getElementById('institutionDescription').value;
const user_id = document.getElementById('user_id').value;

const data = {
name: institutionName,
location: institutionLocation,
description: institutionDescription,
user_id: user_id
};

fetch('/api/institution', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})
.then(response => response.json())
.then(data => {
console.log('Success:', data);
// redirect to the institutions page
window.location.href = '/institution';
})
.catch((error) => {
console.error('Error:', error);
});
}
Empty file.
183 changes: 152 additions & 31 deletions app/templates/institution/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,161 @@
{% block extra_css %}
{% endblock extra_css %}
{% block content %}
<!-- ============================================================== -->
<!-- Start right Content here -->
<!-- ============================================================== -->
<div class="main-content">

<div class="page-content">
<div class="container-fluid">

<!-- start page title -->
<div class="row">
<div class="col-12">
<div class="page-title-box d-sm-flex align-items-center justify-content-between bg-galaxy-transparent">
<h4 class="mb-sm-0">Institution</h4>

<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="breadcrumb-item"><a href="javascript: void(0);">Pages</a></li>
<li class="breadcrumb-item active">Institution</li>
</ol>
</div>
<div class="main-content">

</div>
<div class="page-content">
<div class="container-fluid">

<!-- start page title -->
<div class="row">
<div class="col-12">
<div
class="page-title-box d-sm-flex align-items-center justify-content-between bg-galaxy-transparent">
<h4 class="mb-sm-0">Institution</h4>

<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="breadcrumb-item"><a href="javascript: void(0);">Pages</a></li>
<li class="breadcrumb-item active">Institution</li>
</ol>
</div>
</div>
<!-- end page title -->

</div>
</div>
<!-- container-fluid -->
</div>
<!-- End Page-content -->
<!-- end page title -->
<div class="row">
<div class="col-xl-12">
<div class="card">
<div class="card-header align-items-center d-flex">
<h4 class="card-title mb-0 flex-grow-1">Institutions</h4>

{% block footer %}
{% include "partials/footer.html" %}
{% endblock footer %}
</div>
<!-- end main content-->
{% endblock content %}
<div class="flex-shrink-0">
<div class="hstack gap-2 ">
<button type="button" class="btn btn-success btn-icon waves-effect waves-light"
data-bs-toggle="modal" data-bs-target="#InstitutionModalgrid"><i
class="ri-add-box-line"></i></button>
<div class="live-preview">
<div class="modal fade" id="InstitutionModalgrid" tabindex="-1"
aria-labelledby="InstitutionModalgridLabel">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="InstitutionModalgridLabel">Add
Institution</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="Close"></button>
</div>
<div class="modal-body">
<!-- <form action="javascript:void(0);"> -->
<form action="" onsubmit="instituionFormSubmit(event)">
<input type="hidden" id="user_id" value="{{ user_id }}">
<div class="row g-3">
<div class="col-xxl-12">
<div>
<label for="institutionName" class="form-label">Institution Name</label>
<input type="text" class="form-control"
id="institutionName"
placeholder="Enter Institution Name">
</div>
</div>
<div class="col-xxl-12">
<label for="institutionLocation"
class="form-label">Institution Location</label>
<input type="text" class="form-control"
id="institutionLocation" placeholder="Enter Institution Location">
</div>
<!--end col-->
<div class="col-xxl-12">
<label for="institutionDescription"
class="form-label">Institution Description</label>
<textarea class="form-control" id="institutionDescription" rows="3" placeholder="Enter Institution Description"></textarea>
</div>
<!--end col-->
<div class="col-lg-12">
<div class="hstack gap-2 justify-content-end">
<button type="button" class="btn btn-light"
data-bs-dismiss="modal">Close</button>
<button type="submit"
class="btn btn-primary">Submit</button>
</div>
</div>
<!--end col-->
</div>
<!--end row-->
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

</div><!-- end card header -->



<div class="card-body">
<p class="text-muted mb-4">Add Instiutions with the + button</p>

<div class="live-preview">
<div class="table-responsive table-card">
<table class="table align-middle table-nowrap table-striped-columns mb-0">
<thead class="table-light">
<tr>
<th scope="col" style="width: 46px;">
<div class="form-check">
<input class="form-check-input" type="checkbox" value=""
id="cardtableCheck">
<label class="form-check-label" for="cardtableCheck"></label>
</div>
</th>
<th scope="col">Name</th>
<th scope="col">Description</th>
<th scope="col">Last Updated</th>

<th scope="col" style="width: 150px;">Action</th>
</tr>
</thead>
<tbody>
{% for institution in institutions %}
<tr>
<td>
<div class="form-check">
<input class="form-check-input" type="checkbox" value=""
id="cardtableCheck01">
<label class="form-check-label" for="cardtableCheck01"></label>
</div>
</td>

<td>{{ institution.name }}</td>
<td>{{ institution.description }}</td>
<td>{{ institution.updated_at }}</td>
<td>
<button type="button" class="btn btn-sm btn-light">Details</button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div><!-- end card-body -->
</div><!-- end card -->
</div><!-- end col -->
</div><!-- end row -->

</div>
<!-- container-fluid -->
</div>

{% block footer %}
{% include "partials/footer.html" %}
{% endblock footer %}
</div>
<!-- end main content-->
{% endblock content %}
{% block extra_js %}
<script src="{{ url_for('static', filename='js/institution/institution.js') }}"></script>
{% endblock extra_js %}
Loading

0 comments on commit 728034d

Please sign in to comment.