-
Notifications
You must be signed in to change notification settings - Fork 8
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
base: development
Are you sure you want to change the base?
Changes from all commits
34b93d5
3067b1a
0263d7e
21954ab
0eaf1c9
85826e0
45ceed4
9f91bf1
95ad2c9
a311d35
22857d3
9637377
eeb1dc5
3ada839
87323ca
3e84f24
652e258
ab2b6a3
2106b77
e518367
15e975b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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): | ||
|
@@ -28,7 +30,159 @@ 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 addSummerExperience(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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This field in the db doesn't exist. Use contentAreas instead. |
||
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets move this to a different PR where we are implementing the addOtherEngagement functionality. |
||
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets move this to a different PR where we are implementing the addOtherEngagement functionality. |
||
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) | ||
|
||
|
||
|
||
|
||
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets move this to a different PR where we are implementing the addOtherEngagement functionality. |
||
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets move this to a different PR where we are implementing the addOtherEngagement functionality. |
||
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): | ||
|
@@ -84,8 +238,6 @@ def requestOtherEngagement(username): | |
return render_template("/minor/requestOtherEngagement.html", | ||
user=user, | ||
terms=terms) | ||
|
||
@minor_bp.route('/cceMinor/<username>/addSummerExperience', methods=['POST']) | ||
def addSummerExperience(username): | ||
saveSummerExperience(username, request.form, g.current_user) | ||
|
||
|
@@ -95,4 +247,4 @@ def addSummerExperience(username): | |
def deleteSummerExperience(username): | ||
removeSummerExperience(username) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can probably delete this route. |
||
|
||
return "" | ||
return "" |
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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like there may be some redundancy here with the two experienceHours... fields. We should think of a way to make these better. |
||
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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets move this code to a different PR since it can't be tested in this one.