Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

11/28 5 pm #4

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
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
24 changes: 24 additions & 0 deletions ENV SETUP/setenv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# Set Environment Variables Script

#Make it executable: Run chmod +x setenv.sh to make the script executable.
#Execute the script: Run ./setenv.sh to set the environment variables.
#Verification: After execution, verify the variables by typing echo $SECRET_KEY or any other variable name.

# Define environment variable values
SECRET_KEY='Secret123'
DATABASE_URL='mysql+pymysql://capstonepro:[email protected]/capstonepro'
MAIL_USERNAME='[email protected]'
MAIL_PASSWORD='vbla evma tqpz umof'

# Write to .bashrc or .bash_profile
echo "export SECRET_KEY='$SECRET_KEY'" >> ~/.bashrc
echo "export DATABASE_URL='$DATABASE_URL'" >> ~/.bashrc
echo "export MAIL_USERNAME='$MAIL_USERNAME'" >> ~/.bashrc
echo "export MAIL_PASSWORD='$MAIL_PASSWORD'" >> ~/.bashrc

echo "Environment variables have been set."

# Reload .bashrc or .bash_profile
source ~/.bashrc
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn -w 4 app:app
Binary file modified __pycache__/PRFSub_lib.cpython-311.pyc
Binary file not shown.
Binary file modified __pycache__/app.cpython-311.pyc
Binary file not shown.
197 changes: 131 additions & 66 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import Flask, render_template, request, redirect, url_for,flash,session
from flask import Flask, render_template, request, redirect, url_for,flash,session, current_app
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import text
from flask_mail import Mail, Message
Expand All @@ -7,7 +7,7 @@
from werkzeug.utils import secure_filename
import os
from datetime import datetime, timedelta
import pytz


#Local Imports
from PRFSub_lib import digestFileContents, store_parsed_data, restructure_data, extract_file_details
Expand Down Expand Up @@ -44,11 +44,11 @@ class User(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
email = db.Column(db.String(150), nullable=False, unique=True)
password = db.Column(db.String(150), nullable=False)
team_number = db.Column(db.Integer, nullable=False)
team_number = db.Column(db.String(150), nullable=False)

class Team(db.Model):
id = db.Column(db.Integer, primary_key=True)
team_number = db.Column(db.Integer, nullable=False)
team_number = db.Column(db.String(150), nullable=False)
team_name = db.Column(db.String(255), nullable=False)

class Item(db.Model):
Expand All @@ -63,16 +63,30 @@ class Item(db.Model):

class BOM(db.Model):
id = db.Column(db.Integer, primary_key=True)
team_number = db.Column(db.Integer, index=True, nullable=False)
team_number = db.Column(db.String(150), nullable=False)
vendor = db.Column(db.String(150), nullable=True)
part_number = db.Column(db.String(50), nullable=True)
item_status = db.Column(db.String(50), nullable=True)
date = db.Column(db.DateTime, nullable=True)
comments = db.Column(db.String(255), nullable=True)

class team_procurement_detail(db.Model):
id = db.Column(db.Integer, primary_key=True)
team_number = db.Column(db.Integer, index=True, nullable=False)
team_number = db.Column(db.String(150), nullable=False)
item_description = db.Column(db.String(255), nullable=False)
part_number = db.Column(db.String(50), nullable=True)
quantity = db.Column(db.Integer, nullable=True)
unit_price = db.Column(db.Float, nullable=True)
ext_price = db.Column(db.Float, nullable=True)
url_link = db.Column(db.String(255), nullable=True)
delivery_date = db.Column(db.DateTime, nullable=True)
file_last_modified = db.Column(db.DateTime, nullable=True) # Last modification date of the file
total_file_price = db.Column(db.Float, nullable=True) # Total price from file details
created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) # Timestamp of record creation

class approved_bom(db.Model):
id = db.Column(db.Integer, primary_key=True)
team_number = db.Column(db.String(150), nullable=False)
item_description = db.Column(db.String(255), nullable=False)
part_number = db.Column(db.String(50), nullable=True)
quantity = db.Column(db.Integer, nullable=True)
Expand All @@ -83,7 +97,6 @@ class team_procurement_detail(db.Model):
file_last_modified = db.Column(db.DateTime, nullable=True) # Last modification date of the file
total_file_price = db.Column(db.Float, nullable=True) # Total price from file details
created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) # Timestamp of record creation


#FILE UPLOAD INFORMATION
UPLOAD_FOLDER = os.getcwd() + r'/uploads'
Expand All @@ -99,11 +112,21 @@ def decorated_function(*args, **kwargs):
return f(*args, **kwargs)
return decorated_function

#Web Decoration
#Homepage
@app.route('/home')
@login_required
def home():
return render_template('HomePage.html')
# Fetch the current user's team number
user_id = session.get('user_id')
current_user = db.session.get(User, user_id)
print(current_user)
if current_user:
team_number = current_user.team_number
if current_user.team_number == "PURDUE":
ButtonDisable = False
else:
ButtonDisable = True
return render_template('HomePage.html', team_number=team_number,ButtonDisable=ButtonDisable)

@app.before_request
def before_request():
Expand Down Expand Up @@ -228,7 +251,6 @@ def login():
return render_template('LoginPage.html')



@app.route('/registration', methods=['GET', 'POST'])
def registration():
if request.method == 'POST':
Expand Down Expand Up @@ -321,7 +343,7 @@ def upload_file():
print(file_details)
restructured_list = restructure_data(DataInstance[1], file_details)
print(restructured_list)
store_parsed_data(DataInstance[1], team_number, team_procurement_detail,restructured_list,db)
store_parsed_data(DataInstance[1], team_number, team_procurement_detail, restructured_list, db)
flash('File successfully uploaded')
else:
flash('Error: User not found.')
Expand All @@ -331,57 +353,47 @@ def upload_file():
flash('Allowed file types are .xlsx')
return redirect(url_for('prfsub'))

#BOM Endpoints


#BOMlist
@app.route('/BOMlist', methods=['GET', 'POST'])
@login_required
def bomlist():
#get team # from current session
user_id = session.get('user_id')
current_user = db.session.get(User, user_id)
team_num = current_user.team_number
# Get records from TeamProcurementDetail
team_details = team_procurement_detail.query.all()
# Update BOM records based on TeamProcurementDetail
for team_detail in team_details:
bom_record = BOM(team_number=team_num)
# bom_record.vendor = team_detail.vendor
bom_record.date = team_detail.delivery_date
bom_record.part_number = team_detail.part_number
print(bom_record.part_number)

# Commit the changes
db.session.commit()
return render_template('BOMlist.html', bom_record=bom_record)

#StudentBOM
#Maintenence Endpoints
#StudentBOM
@app.route('/StudentBOM', methods=['GET'])
@login_required
def studentbom():
query = text("SELECT created_at, item_description, part_number, quantity, unit_price FROM team_procurement_detail")
result = db.session.execute(query)
stubom_data = result.fetchall()
return render_template('StudentBOM.html', stubom_data=stubom_data)

'''
#PRF Status Endpoints
@app.route('/prf_status')
curr_user = session.get('user_id')
teamquery = text("SELECT team_number FROM user WHERE id = :id LIMIT 1")
teamres = db.session.execute(teamquery, {"id": curr_user})
team_number = teamres.fetchone()

if team_number:
teamnum = str(team_number[0])

# Query to retrieve filtered data based on the team number
query = text("SELECT created_at, item_description, part_number, quantity, unit_price, team_number FROM approved_bom WHERE team_number = :teamnum")
result = db.session.execute(query, {"teamnum": teamnum})
stubom_data = result.fetchall()

return render_template('StudentBOM.html', stubom_data=stubom_data, teamnum=teamnum)

# Handle the case where team_number is not available
return render_template('error.html', message="Team number not found.")

#admin BOM
@app.route('/BOMlist', methods=['GET'])
@login_required
def prf_status():
# Query the database to retrieve the form data for the current team
form_data = db.query.filter_by(team_number=team_number).first()
# Check if the form data exists
if form_data:
# Render the template with the form data
return render_template('PrfStatus.html', form_data=form_data)
def bomlist():
user_id = session.get('user_id')
current_user = User.query.get(user_id)
# Query to retrieve filtered data based on the team number
if current_user and current_user.team_number == "PURDUE":
query = text("SELECT created_at, item_description, part_number, quantity, unit_price, team_number FROM approved_bom")
result = db.session.execute(query)
bomlist_data = result.fetchall()
return render_template('BOMlist.html', bomlist_data=bomlist_data)
else:
# Case where form data doesn't exist
return "Form data not found for this team."
'''
#Maintenence Endpoints
# Redirect to unauthorized page or handle the case where team_number is not "PURDUE"
return redirect(url_for('home'))

#show user
@app.route('/show_users')
@login_required
def show_users():
Expand All @@ -397,13 +409,18 @@ def root():


@app.route('/prf_status', methods=['GET'])
@login_required
@login_required
def prfstatus():
query = text("SELECT id, created_at, team_number FROM team_procurement_detail")
result = db.session.execute(query)
prf_data = result.fetchall()
return render_template('PrfStatus.html', prf_data=prf_data)

user_id = session.get('user_id')
current_user = User.query.get(user_id)
if current_user and current_user.team_number == "PURDUE":
query = text("SELECT id, created_at, team_number,item_description, unit_price, quantity, total_file_price FROM team_procurement_detail")
result = db.session.execute(query)
prf_data = result.fetchall()
return render_template('PrfStatus.html', prf_data=prf_data)
else:
# Redirect to unauthorized page or handle the case where team_number is not "PURDUE"
return render_template('HomePage.html')


@app.route('/<path:unknown_route>', methods=['GET'])
Expand All @@ -414,10 +431,17 @@ def catch_all(unknown_route):
@app.route('/adminview', methods=['GET'])
@login_required
def get_user_data():
query = text("SELECT email, team_number FROM user")
result = db.session.execute(query)
user_data = result.fetchall()
return render_template('adminview.html', user_data=user_data)
user_id = session.get('user_id')
current_user = User.query.get(user_id)

if current_user and current_user.team_number == "PURDUE":
query = text("SELECT email, team_number FROM user")
result = db.session.execute(query)
user_data = result.fetchall()
return render_template('adminview.html', user_data=user_data)
else:
# Redirect to unauthorized page or handle the case where team_number is not "PURDUE"
return redirect(url_for('home'))

@app.route('/file_info')
@login_required
Expand All @@ -439,5 +463,46 @@ def file_info():
'last_modified': formatted_last_modified
}

@app.route('/update_status', methods=['POST'])
@login_required
def update_status():
selected_ids = request.form.getlist('selected_ids') # Get list of selected row IDs

for id in selected_ids:
prf_row = team_procurement_detail.query.filter_by(id=id).first() # Get the row by ID
if prf_row:
status = request.form.get(f'status_{id}') # Get the selected status value for the row

if status == 'status3': # If status is 'Approved'
# Move the data to the approved_bom table
approved_data = approved_bom(
team_number=prf_row.team_number,
item_description=prf_row.item_description,
part_number=prf_row.part_number,
quantity=prf_row.quantity,
unit_price=prf_row.unit_price,
ext_price=prf_row.ext_price,
url_link=prf_row.url_link,
total_file_price=prf_row.total_file_price
)
db.session.add(approved_data)
db.session.delete(prf_row) # Delete the row from team_procurement_detail
elif status == 'status2': # If status is 'Status 2'
# Retrieve the user with the matching team_number
user = User.query.filter_by(team_number=prf_row.team_number).first()
if user:
send_notification_email(user.email, prf_row.item_description)
db.session.delete(prf_row)


db.session.commit()
return redirect(url_for('prfstatus')) # Redirect to the PRF status page after processing

def send_notification_email(email, item_description):
msg = Message("Item Not Approved Notification", sender="[email protected]", recipients=[email])
msg.body = f"Dear User,\n\nThe item '{item_description}' has not been approved. Please contact your mentor or professor for further information."
with current_app.app_context():
mail.send(msg)

if __name__ == '__main__':
app.run(debug=True)
30 changes: 0 additions & 30 deletions prfapproval.py

This file was deleted.

36 changes: 0 additions & 36 deletions prfupload.py

This file was deleted.

Binary file added requirements.txt
Binary file not shown.
Loading