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

Profile UI for CCE Minor Experiences. #1293

Open
wants to merge 17 commits into
base: development
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
3 changes: 2 additions & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from flask import Flask, render_template
from playhouse.shortcuts import model_to_dict, dict_to_model
from app.logic.config import load_config_files

app = Flask(__name__)
app.debug = True # Enable debug mode
# Initialize our application
app = Flask(__name__, template_folder="templates")

Expand Down
167 changes: 161 additions & 6 deletions app/controllers/minor/routes.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from flask import g, render_template, request, abort, flash, redirect, url_for
from flask import g, render_template, request, abort, flash, redirect, url_for, jsonify
from peewee import DoesNotExist

from app.controllers.minor import minor_bp
from app.models.user import User
from app.models.term import Term
from app.models.attachmentUpload import AttachmentUpload
from app.models.summerExperience import SummerExperience
from app.models.otherExperience import OtherExperience

from app.logic.fileHandler import FileHandler
from app.logic.utils import selectSurroundingTerms, getFilesFromRequest
from app.logic.minor import getProgramEngagementHistory, getCourseInformation, getCommunityEngagementByTerm, removeSummerExperience
from app.logic.minor import saveOtherEngagementRequest, setCommunityEngagementForUser, saveSummerExperience, getSummerTerms, getSummerExperience, getEngagementTotal
from app.logic.minor import saveOtherEngagementRequest, setCommunityEngagementForUser, saveSummerExperience, getSummerTerms, getSummerExperience, getEngagementTotal, createSummerExperience, createOtherEngagement
import logging

@minor_bp.route('/profile/<username>/cceMinor', methods=['GET'])
def viewCceMinor(username):
Expand All @@ -28,7 +30,160 @@ def viewCceMinor(username):
summerExperience = summerExperience if summerExperience else "",
selectedSummerTerm = selectedSummerTerm,
totalSustainedEngagements = getEngagementTotal(sustainedEngagementByTerm),
summerTerms = getSummerTerms())
summerTerms = getSummerTerms(),
allTerms = getSummerExperience(username))


# ################################################## SUMMER EXPERIENCE START ###########################################################

@minor_bp.route('/cceMinor/<username>/addSummerExperience', methods=['POST'])
def addASummerExperience(username):
try:
createSummerExperience(username, request.form)
flash(f'Summer Experience added successfully by {username}', 'success')
return redirect(url_for('minor.viewProposal', username=username, activeTab='trainingEvents'))
except Exception as e:
flash(f'An error occurred while adding the summer experience: {e}', 'danger')
logging.error(f'An error occurred while adding the summer experience: {e}')
return redirect(url_for('minor.viewCceMinor', username=username))




@minor_bp.route('/profile/<username>/withdrawSummerExperience', methods=['POST'])
def withdrawSummerExperience(username):
try:
user = User.get(User.username == username)
experience_id = request.form.get('experience_id')

summer_experience = SummerExperience.get(SummerExperience.id == experience_id, SummerExperience.user == user)
summer_experience.delete_instance()

flash('Summer experience proposal withdrawn successfully.', 'success')
return jsonify({'status': 'success', 'message': 'Summer experience proposal withdrawn successfully.'})
except Exception as e:
logging.error(f"Error withdrawing summer experience: {e}")
flash('An error occurred while withdrawing the proposal.', 'danger')
return jsonify({'status': 'error', 'message': 'An error occurred while withdrawing the proposal.'}), 500




@minor_bp.route('/cceMinor/<username>/updateSummerExperience', methods=['GET', 'POST'])
def updateSummerExperience(username):
try:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update and create need to be combined or otherwise share functionality

form_data = request.form
user = User.get(User.username == username)
experience_id = form_data['experience_id']
summer_experience = SummerExperience.get(SummerExperience.id == experience_id)

content_area = ', '.join(form_data.getlist('contentArea'))
experience_type = form_data['experienceType']
if experience_type == 'Other':
other_experience_description = form_data.get('otherExperienceDescription', '')
if not other_experience_description:
raise ValueError("Other experience description is required.")
experience_type = other_experience_description

summer_experience.studentName = form_data['studentName']
summer_experience.summerYear = form_data['summerYear']
summer_experience.roleDescription = form_data['roleDescription']
summer_experience.experienceType = experience_type
summer_experience.CceMinorContentArea = content_area
summer_experience.experienceHoursOver300 = form_data['experienceHoursOver300'] == 'Yes'
summer_experience.experienceHoursBelow300 = form_data.get('experienceHoursBelow300')
summer_experience.company = form_data['company']
summer_experience.companyAddress = form_data['companyAddress']
summer_experience.companyPhone = form_data['companyPhone']
summer_experience.companyWebsite = form_data['companyWebsite']
summer_experience.supervisorName = form_data['directSupervisor']
summer_experience.supervisorPhone = form_data['supervisorPhone']
summer_experience.supervisorEmail = form_data['supervisorEmail']
summer_experience.save()

flash("Proposal updated successfully.", 'success')
return redirect(url_for('minor.viewProposal', username=username))
except Exception as e:
flash(f"Error updating proposal: {e}", 'danger')
return redirect(url_for('minor.viewProposal', username=username))


# ################################################## SUMMER EXPERIENCE END ###########################################################
@minor_bp.route('/cceMinor/<username>/addOtherEngagement', methods=['POST'])
def addOtherEngagement(username):
try:
form_data = request.form
# Process form data and create a new OtherExperience
new_experience = OtherExperience.create(
user=User.get(User.username == username),
activity=form_data['experienceName'],
term=Term.get(Term.id == form_data['term']),
hours=form_data['totalHours'],
weeks=form_data['weeks'],
service=form_data['description'],
company=form_data['companyOrOrg']
# Add other fields as needed
)
flash('Other Community Engaged Experience added successfully!', 'success')
return redirect(url_for('minor.view_other_engagement', username=username))
except Exception as e:
flash(f'An error occurred while adding the engagement: {e}', 'danger')
logging.error(f'An error occurred while adding the engagement: {e}', exc_info=True)
return redirect(url_for('minor.view_other_engagement', username=username))

@minor_bp.route('/cceMinor/<username>/otherEngagement', methods=['GET'])
def view_other_engagement(username):
user = User.get(User.username == username)
try:
other_experience = OtherExperience.get(OtherExperience.user == user)
except OtherExperience.DoesNotExist:
other_experience = None
return render_template('minor/profile.html', user=user, other_experience=other_experience)




@minor_bp.route('/api/terms', methods=['GET'])
def get_terms():
terms = Term.select()
term_list = [{'id': term.id, 'name': term.description} for term in terms]
return jsonify(term_list)


@minor_bp.route('/withdrawOtherExperience/<int:experience_id>', methods=['POST'])
def withdraw_other_experience(experience_id):
try:
experience = OtherExperience.get(OtherExperience.id == experience_id)
experience.delete_instance()
return jsonify({'status': 'success', 'message': 'Experience withdrawn successfully.'})
except Exception as e:
logging.error(f"Error withdrawing other experience: {e}", exc_info=True)
return jsonify({'success': False, 'An error occured while withrawing experience.': str(e)}), 500

@minor_bp.route('/cceMinor/<username>/editOtherEngagement', methods=['POST'])
def edit_other_engagement(username):
try:
form_data = request.form
experience_id = form_data['experience-id']
experience = OtherExperience.get(OtherExperience.id == experience_id)

experience.activity = form_data['experienceName']
experience.term = Term.get(Term.id == form_data['term'])
experience.hours = form_data['totalHours']
experience.weeks = form_data['weeks']
experience.service = form_data['description']
experience.company = form_data['companyOrOrg']
experience.save()

flash(f'Engagement updated successfully by {username}', 'success')
except Exception as e:
flash(f'An error occurred while updating the engagement: {e}', 'danger')
logging.error(f'An error occurred while updating the engagement: {e}', exc_info=True)
return redirect(url_for('minor.viewCceMinor', username=username))

# ###############################################################################



@minor_bp.route('/cceMinor/<username>/getEngagementInformation/<type>/<term>/<id>', methods=['GET'])
def getEngagementInformation(username, type, id, term):
Expand Down Expand Up @@ -85,7 +240,7 @@ def requestOtherEngagement(username):
user=user,
terms=terms)

@minor_bp.route('/cceMinor/<username>/addSummerExperience', methods=['POST'])
# @minor_bp.route('/cceMinor/<username>/addSummerExperience', methods=['POST'])
def addSummerExperience(username):
saveSummerExperience(username, request.form, g.current_user)

Expand All @@ -95,4 +250,4 @@ def addSummerExperience(username):
def deleteSummerExperience(username):
removeSummerExperience(username)

return ""
return ""
63 changes: 63 additions & 0 deletions app/logic/minor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections import defaultdict
from typing import List, Dict
from flask import flash
from playhouse.shortcuts import model_to_dict
from peewee import JOIN, fn, Case, DoesNotExist

Expand All @@ -15,7 +16,69 @@
from app.models.individualRequirement import IndividualRequirement
from app.models.certificationRequirement import CertificationRequirement
from app.models.communityEngagementRequest import CommunityEngagementRequest
from app.models.summerExperience import SummerExperience
from app.models.otherExperience import OtherExperience
import logging


def createSummerExperience(username, form_data):
try:
logging.info(f"Form data received: {form_data}")

user = User.get(User.username == username)
content_area = ', '.join(form_data.getlist('contentArea')) # Combine multiple content areas

# Directly assign the experience type
experience_type = form_data['experienceType'] if form_data['experienceType'] != 'Other' else form_data.get('otherExperienceDescription', '')
if experience_type == '': # Check if the otherExperienceDescription is empty when required
raise ValueError("Other experience description is required.")

SummerExperience.create(
user=user,
studentName=form_data['studentName'],
summerYear=form_data['summerYear'],
roleDescription=form_data['roleDescription'],
experienceType=experience_type,
CceMinorContentArea=content_area,
experienceHoursOver300=form_data['experienceHoursOver300'] == 'Yes',
experienceHoursBelow300=form_data.get('experienceHoursBelow300'),
status='Pending',
company=form_data['company'],
companyAddress=form_data['companyAddress'],
companyPhone=form_data['companyPhone'],
companyWebsite=form_data['companyWebsite'],
supervisorName=form_data['directSupervisor'],
supervisorPhone=form_data['supervisorPhone'],
supervisorEmail=form_data['supervisorEmail'],
created_at=form_data['date']
)
logging.info("Summer experience successfully saved.")
except Exception as e:
logging.error(f"Error saving summer experience: {e}")
raise



def createOtherEngagement(username, form_data):
try:
logging.info(f"Form data received: {form_data}")
user = User.get(User.username == username)
term = Term.get(Term.id == form_data['term'])

OtherExperience.create(
activity=form_data['experienceName'],
term=term,
hours=form_data['totalHours'],
weeks=form_data['weeks'],
service=form_data['description'],
company=form_data['companyOrOrg']
)
logging.info("Engagement successfully saved.")
except Exception as e:
logging.error(f"Error saving engagement: {e}", exc_info=True)
raise

# ################################################
def getEngagementTotal(engagementData):
"""
Count the number of engagements (from all terms) that have matched with a requirement
Expand Down
Empty file added app/models.py
Empty file.
2 changes: 2 additions & 0 deletions app/models/individualRequirement.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from app.models.course import Course
from app.models.program import Program
from app.models.certificationRequirement import CertificationRequirement
from app.models.summerExperience import SummerExperience


class IndividualRequirement(baseModel):
Expand All @@ -17,6 +18,7 @@ class IndividualRequirement(baseModel):
requirement = ForeignKeyField(CertificationRequirement)
addedBy = ForeignKeyField(User)
addedOn = DateTimeField(default=datetime.now)
# summer_experience = ForeignKeyField(SummerExperience, null=True)

class Meta:
constraints = [SQL('UNIQUE (username_id, requirement_id)')]
2 changes: 2 additions & 0 deletions app/models/otherExperience.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from app.models import *
from app.models.term import Term
from app.models.user import User

class OtherExperience(baseModel):
user = ForeignKeyField(User)
activity = CharField()
term = ForeignKeyField(Term)
hours = IntegerField()
Expand Down
23 changes: 23 additions & 0 deletions app/models/summerExperience.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import datetime
from app.models import *
from app.models.user import User

class SummerExperience(baseModel):
user = ForeignKeyField(User)
studentName = CharField()
summerYear = CharField()
roleDescription = TextField()
experienceType = CharField()
contentAreas = TextField() # Store as comma-separated values or use a related table if needed
experienceHoursOver300 = BooleanField()
experienceHoursBelow300 = CharField(null=True) # Optional for hours if less than 300
status = CharField(constraints=[Check("status in ('Approved', 'Pending', 'Denied')")], default='Pending')
company = CharField()
companyAddress = CharField()
companyPhone = CharField()
companyWebsite = CharField()
supervisorName = CharField()
supervisorPhone = CharField()
supervisorEmail = CharField()
createdOn = DateTimeField(default=datetime.datetime.now)

Loading
Loading