Skip to content

Commit

Permalink
Added notification functionality for job posts (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
ionathomas committed Aug 6, 2023
1 parent da069d6 commit a6f1f38
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 10 deletions.
Binary file removed app/__pycache__/activities_app.cpython-311.pyc
Binary file not shown.
Binary file removed app/__pycache__/booking_history.cpython-311.pyc
Binary file not shown.
Binary file removed app/__pycache__/flights_app.cpython-311.pyc
Binary file not shown.
Binary file removed app/__pycache__/hotels_app.cpython-311.pyc
Binary file not shown.
Binary file removed app/__pycache__/login_app.cpython-311.pyc
Binary file not shown.
Binary file removed app/__pycache__/package_app.cpython-311.pyc
Binary file not shown.
Binary file removed app/__pycache__/stripePayment.cpython-311.pyc
Binary file not shown.
Binary file removed app/__pycache__/trip_app.cpython-311.pyc
Binary file not shown.
6 changes: 3 additions & 3 deletions app/applied_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#####################################################################
def get_jobs_applied():
# return "select activity_date, activity_name, cost, activity_start_time, activity_end_time, activity_id from activity natural join trip where username = '" + session['username'] + "' and is_booked = false;"
if session['username']=="admin":
return "select * from job_applied;"
return "select * from job_applied where username = '" + session['username'] + "';"


Expand All @@ -25,9 +27,7 @@ def booking_trip():
db = Database().db
cursor = db.cursor()
query = get_jobs_applied()
print(query)
cursor.execute(query)
jp = [dict(id = row[1], name=row[2], description=row[3],address= row[4],salary=row[5]) for row in cursor.fetchall()] # TODO: Correctly map activity info.
print(jp)
jp = [dict(id = row[1], name=row[2], description=row[3],address= row[4],salary=row[5],status=row[7]) for row in cursor.fetchall()] # TODO: Correctly map activity info.
# rows = cursor.fetchall()
return render_template('applied_jobs.html',items=jp, session=session)
79 changes: 73 additions & 6 deletions app/jobs_posting.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def get_jp_data():
# "select trip_id from trip natural join user where trip.is_booked=false and user.username='" + session['username'] + "';"
else:
cursor.execute("select * from job_posting;")
jp = [dict(jobid = row[0],name=row[1], description=row[2], address=row[3],salary=row[4]) for row in cursor.fetchall()]
jp = [dict(jobid = row[0],name=row[1], description=row[2], address=row[3],salary=row[4],skill=row[5]) for row in cursor.fetchall()]
return jp

#####################################################################
Expand All @@ -24,6 +24,21 @@ def get_jobs_applied():
# return "select activity_date, activity_name, cost, activity_start_time, activity_end_time, activity_id from activity natural join trip where username = '" + session['username'] + "' and is_booked = false;"
return "select * from job_applied where username = '" + session['username'] + "';"

def match_skill_sets(list1, list2):
# Convert both lists to lowercase to ignore case
list1_lower = [s.lower().strip() for s in list1]
list2_lower = [s.lower().strip() for s in list2]

# Calculate the total number of strings in both lists
total_strings = len(list1_lower) + len(list2_lower)

# Calculate the number of matching strings
matching_strings = len(set(list1_lower) & set(list2_lower))

# Calculate the match percentage
match_percentage = int((matching_strings / total_strings) * 100)

return match_percentage


# Shows all available attractions.
Expand All @@ -37,12 +52,23 @@ def attractions():
def add_to_trip(jp_index):
cursor = db.cursor()
cursor.execute("select * from job_posting;")
jp = [dict(id = row[0], name=row[1], description=row[2],address= row[3],salary=row[4]) for row in cursor.fetchall()] # TODO: Correctly map activity info.
jp = [dict(id = row[0], name=row[1], description=row[2],address= row[3],salary=row[4],skills=row[5]) for row in cursor.fetchall()] # TODO: Correctly map activity info.
jobid = jp[int(jp_index) - 1]['id']
description = jp[int(jp_index) - 1]['description']
name = jp[int(jp_index) - 1]['name']
price = jp[int(jp_index) - 1]['salary']
address = jp[int(jp_index) - 1]['address']
required_skill = jp[int(jp_index) - 1]['skills'].split(",")

query = """SELECT * from skills
WHERE username = '{}'""".format(session["username"])
cursor.execute(query)
data = cursor.fetchone()
applicant_skill = data[1].split(",")
match_percentage = match_skill_sets(required_skill,applicant_skill)
if int(match_percentage)<50:
return render_template('error_apply.html', session=session,data=match_percentage)

values = (jobid,name,description,price,address, session['username'])
query_trip_common = "INSERT IGNORE INTO job_applied ( job_id, company_name ,description,salary,address, username) VALUES (%s, %s, %s, %s, %s,%s)"
print(query_trip_common,values)
Expand Down Expand Up @@ -76,16 +102,56 @@ def review_jobs(jp_index):
cursor = db.cursor()
cursor.execute("select * from job_applied where job_id= " + jp_index + ";")
db.commit()
jp = [dict(id = row[1], name=row[2], description=row[3],address= row[4],salary=row[5],username= row[6]) for row in cursor.fetchall()] # TODO: Correctly map activity info.
jp = [dict(keyid=row[0],id = row[1], name=row[2], description=row[3],address= row[4],salary=row[5],username= row[6],status=row[7]) for row in cursor.fetchall()] # TODO: Correctly map activity info.

return render_template('review_candidate.html',items=jp,jobid=jp_index, session=session)


@job_blueprint.route('/review-candidate/<jp_username>', methods=['POST'])
def review_candidate(jp_username):
@job_blueprint.route('/review-candidate/<jp_id>/<jp_username>', methods=['POST'])
def review_candidate(jp_id,jp_username):
db = Database().db
cursor = db.cursor()
print("update job_applied set status='Review' where applied_job_id="+jp_id+ " ;")
cursor.execute("update job_applied set status='Review' where applied_job_id="+jp_id+ " ;")
db.commit()
alert = "There has been an update in your job application with JobID " +str(jp_id) +" Current Status -> Review"
query = "insert into notifications (username,alert,seen) values (%s,%s,%s) ;"
values = (jp_username, alert, 0)
cursor.execute(query,values)
db.commit()
return render_template('resume.html',username=jp_username, session=session)


@job_blueprint.route('/approve-candidate/<jp_id>/<jp_username>/<jobid>', methods=['POST'])
def approve_candidate(jp_id,jp_username,jobid):
db = Database().db
cursor = db.cursor()
cursor.execute("update job_applied set status='Approved' where applied_job_id="+jp_id+ " ;")
db.commit()
alert = "There has been an update in your job application with JobID " +str(jp_id) +" Current Status -> Approved"
query = "insert into notifications (username,alert,seen) values (%s,%s,%s) ;"
values = (jp_username, alert, 0)
cursor.execute(query,values)
db.commit()
return redirect('/review-jobs/'+jobid, code=307)



@job_blueprint.route('/decline-candidate/<jp_id>/<jp_username>/<jobid>', methods=['POST'])
def decline_candidate(jp_id,jp_username,jobid):
db = Database().db
cursor = db.cursor()
cursor.execute("update job_applied set status='Declined' where applied_job_id="+jp_id+ " ;")
db.commit()
alert = "There has been an update in your job application with JobID " +str(jp_id) +" Current Status -> Declined"
query = "insert into notifications (username,alert,seen) values (%s,%s,%s) ;"
values = (jp_username, alert, 0)
cursor.execute(query,values)
db.commit()
return redirect('/review-jobs/'+jobid, code=307)




@job_blueprint.route('/add-activity', methods=['GET'])
def add_activityt():
Expand All @@ -99,7 +165,8 @@ def create_activitys():
activity_desc = request.form['activity_desc']
activity_address = request.form['activity_address']
price = request.form['price']
activity_object = Activity(activity_name, activity_desc, activity_address,price)
skill = request.form['skill']
activity_object = Activity(activity_name, activity_desc, activity_address,price,skill)
activity_object.save()
return redirect('/jobs')
return redirect('/jobs')
39 changes: 38 additions & 1 deletion app/resume.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ def get_all_activities_in_a_trip():
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
@resume_blueprint.route('/edit-user/<username>')
def edit_user(username):
db = Database().db
cursor = db.cursor()
query = """SELECT u.username, u.email, u.is_admin, u.first_name, u.last_name, u.suspended,
a.street_no, a.street_name, a.city, a.state, a.country, a.zip
FROM user u
JOIN address a ON u.address_id = a.address_id
WHERE u.username = '{}'""".format(username)
cursor.execute(query)
data = cursor.fetchone()
return render_template('edit-user.html', param=username, data=data)


@resume_blueprint.route('/upload', methods=['GET', 'POST'])
def upload_file():
Expand Down Expand Up @@ -51,5 +64,29 @@ def show_pdf(id=None):
# Shows all available attractions.
@resume_blueprint.route('/resume')
def view_resume():
return render_template('resume.html', session=session)
db = Database().db
cursor = db.cursor()
query = """SELECT * from skills
WHERE username = '{}'""".format(session["username"])
cursor.execute(query)
data = cursor.fetchone()
return render_template('resume.html', session=session,data=data)


@resume_blueprint.route('/update-skill', methods=['POST'])
def update_skills():
db = Database().db
cursor = db.cursor()
username = session["username"]
skill=request.form['skill']
firstname=request.form['register_firstname']
lastname=request.form['register_lastname']
email=request.form['register_email']

query1= "INSERT INTO skills (username, skills,first_name,last_name,email_address) VALUES (%s,%s,%s,%s,%s) ON DUPLICATE KEY UPDATE skills = %s"
query = """insert
WHERE username = '{}'""".format(session["username"])
values = (username,skill,firstname,lastname,email,skill)
cursor.execute(query1,values)
db.commit()
return redirect("/resume")

0 comments on commit a6f1f38

Please sign in to comment.