def post(self): """ This method handles post request from editStudent.html Input: only self Output: prompt to the user error message if the inputs are invalid Add new info to the database and return to studentDashboard.html """ student = gbmodel.students() student_name = validate_student().name user_name = validate_student().id new_name = request.form.get('student_new_name') new_email = request.form.get('student_new_email') caps = gbmodel.students().get_user_sessions(user_name) # Only check email validation if new email is entered if new_email != '': if self.valid_email(str(new_email)) is False: error = "Invalid Email Address" return render_template('editStudent.html', error=error, user_name=user_name) student.edit_student(user_name, new_name, new_email) # Get new name student_name = validate_student().name return render_template('studentDashboard.html', name=student_name, user_name=user_name, caps=caps)
def get_done(self, user_id, capstone_id): """ check if the user is done with their review input: id of user to check, capstone session to check output: none if no result, otherwise the midterm or final done attribute of the student record """ try: student = gbmodel.students().get_student_in_session( user_id, capstone_id) if student is None: return None # check the user's active reports state = self.get_state(user_id, capstone_id) if state == 'Error': return None # depending on the user's active state, check if the user is done done = 0 if state == 'midterm': # check if already submitted done = student.midterm_done elif state == 'final': # check if already submitted done = student.final_done else: return None return done except SQLAlchemyError: return None
def post(self): """ Handles student registration requests, which come in the form of POST requests submitted via the form that is generated in GET requests Input: self Output: a rendering of the student register page: with a success message and link to the student dashboard if everything went well, or with an error message if there was a problem """ # Get the database objects we will need students = gbmodel.students() teams = gbmodel.teams() # Continue processing the POST request try: # Get the student_id and information the student submitted via the form student_id = CAS().username name = request.form.getlist('name')[0] email_address = request.form.getlist('email_address')[0] session_id = request.form.getlist('session_id')[0] # Verify that the student isn't already registered for the target session if students.get_student_in_session(student_id, session_id) is not None: logging.warning(( "A student tried to register for a Capstone session, but the student was " "already registered for the session")) return self.display_error("You are already in this session") # Add the student to the database # The student won't be on a team when they first sign up, so we have to assign them to the # empty team for the target session. We start by checking if the empty team exists. If the # target session doesn't have one yet, we create it if teams.get_tid_from_name("", session_id) is None: teams.insert_team(session_id, "") # Insert the student into the database (as a part of the empty team) students.insert_student(name, email_address, student_id, session_id, "") # Log the event and render the page with a message telling the student that they have been # registered (along with a link to the student page) logging.info("A student registered for a Capstone session") return render_template('studentRegister.html', message="Successfully registered!", is_error=False) # https://stackoverflow.com/questions/47719838/how-to-catch-all-exceptions-in-try-catch-block-python except Exception as error: logging.error("Student Registration Failure: " + str(error)) return self.display_error("Something went wrong")
def validate_student(): """ function to grab cas username and passes the value to gbmmodel to vaidate INPUT: none OUTPUT: return False if the id does not exist return student infomation otherwise """ cas = CAS() username = cas.username students = gbmodel.students() found_student = students.validate(username) if found_student is False: return False return found_student
def get(self): """ This method handles get requests to studentDashboard.html Input: only self Output: return to index.html if the student id is not in the student table, rendering the studentDashboard.html template """ if validate_student() is False: msg = "Student not found" return render_template('errorMsg.html', msg=msg, student_register=True) else: student_name = validate_student().name user_name = validate_student().id caps = gbmodel.students().get_user_sessions(user_name) # get user's capstone sessions return render_template('studentDashboard.html', name=student_name, user_name=user_name, caps=caps)
def get_self_name(self, user_id, capstone_id): """ This method returns the current user's name to display on the web page input: only self output: A string representing the user's name """ # query database to get student try: student = gbmodel.students().get_student_in_session( user_id, capstone_id) # get name name = student.name except SQLAlchemyError: self.display_error('student look up error - getting their name') # get name if name is None: self.display_error('The user has no name') return name
def confirm_user(self, user_id, capstone_id): """ This method checks to ensure that the user trying to access the review exists and has an open review. Input: self and user_id Output: A boolean indication for if the user was successfully confirmed (true) or not (false) """ # check if the current user is found in the database student = gbmodel.students().get_student_in_session( user_id, capstone_id) if student is None: return False # check review availability available = self.check_available(user_id, capstone_id) if available is False: return False # check the user's active reports state = self.get_state(user_id, capstone_id) if state == 'Error': return False # depending on the user's active state, check if the user is done done = 0 if state == 'midterm': # check if already submitted done = student.midterm_done elif state == 'final': # check if already submitted done = student.final_done else: return False if done == 0: return True # no errors, so return true return True
def check_available(self, user_id, capstone_id): """ This method checks if a student's reviews are open or clocked Inputs: user_id -- the student's id in the database, capstone_id -- the capstone session the student belongs to Outputs: True -- the student can proceed with reviews. False -- The student cannot proceed with reviews. """ try: # get student student = gbmodel.students().get_student_in_session( user_id, capstone_id) if student is None: return False # check if reviews are 'open' if student.active == 'open': return True else: return False except SQLAlchemyError: return False
def get_tid(self, user_id, capstone_id): """ This method returns the current user's team id value while testing if the user exists in the database. input: only self output: the user's tid as an integer """ # get the user's team id tid = 0 try: student = gbmodel.students().get_student_in_session( user_id, capstone_id) # get tid tid = student.tid except SQLAlchemyError: self.display_error('student look up error - tid') # get tid if tid is None: self.display_error('No user tid found in database') return tid
def get(self): """ This method handled get requests for assignTeam.html Input: self Output: none """ if not validate_professor(): return display_access_control_error() s_id = request.args.get('session_id') students_table = gbmodel.students() team_table = gbmodel.teams() unassigned_students = students_table.get_unassigned_students(s_id) if unassigned_students is None: error = "No students unassigned to a team." return render_template('errorPage.html', msg=error) sessions = team_table.dashboard(s_id) return render_template('assignTeam.html', lists=unassigned_students, sessions=sessions, session_id=s_id, error=None)
def post(self): """ Determines how the class will handle POST requests INPUT: self OUTPUT: It looks like it will return a rendering of the viewReview.html file. The information included in this rendering depends on the POST request parameters. Used as reference: http://flask.pocoo.org/docs/1.0/api/#flask.render_template """ # Validate that the one making the request is a professor if not validate_professor(): return display_access_control_error() # Get the database object we will need reports = gbmodel.reports() teams = gbmodel.teams() students = gbmodel.students() # Validate that the one making the request is a professor # Might want to consider noting things like these or forcefuly logging the person out if not validate_professor(): return self.display_error(("A student (or someone else) tried to access the view_review page (a " "page that professors should only have access to)")) try: # Get data from the POST request # This helped: https://stackoverflow.com/questions/23205577/python-flask-immutablemultidict session_id = request.form.getlist('session_id')[0] reviewer_id = request.form.getlist('reviewer_id')[0] reviewee_id = request.form.getlist('reviewee_id')[0] is_final = request.form.getlist('is_final')[0] # Query the database for the the reviewing student reviewer = students.get_student_in_session(reviewer_id, session_id) if reviewer is None: return self.display_error("Reviewer not found in the database") # Query the database for the student being reviewed reviewee = students.get_student_in_session(reviewee_id, session_id) if reviewee is None: return self.display_error("Reviewee not found in the database") # Verify the reviewer and reviewee are are on the same team if reviewer.tid != reviewee.tid: return self.display_error("Reviewer and reviewee don't appear to be on the same team") # Get the the name of the team the reviewer and reviewee are on team = teams.get_team_from_id(reviewer.tid) if team is None: return self.display_error("Reviewer and reviewee's team not found in database") # Finally, get the review and parse it (if we find it in the database) report = reports.get_report(reviewer_id, reviewee_id, reviewer.tid, is_final) if report is not None: # Get some general report details review_details = {"time": report.time, "reviewer": reviewer.name, "reviewee": reviewee.name, "team_name": team.name, "is_late": report.is_late, "is_final": is_final} # Get the main part of the review parsed_review = [ {"category": "Technical Skill", "content": self.interperate_rating(report.tech_mastery)}, {"category": "Work Ethic", "content": self.interperate_rating(report.work_ethic)}, {"category": "Communication Skills", "content": self.interperate_rating(report.communication)}, {"category": "Cooperation", "content": self.interperate_rating(report.cooperation)}, {"category": "Initiative", "content": self.interperate_rating(report.initiative)}, {"category": "Team Focus", "content": self.interperate_rating(report.team_focus)}, {"category": "Contribution", "content": self.interperate_rating(report.contribution)}, {"category": "Leadership", "content": self.interperate_rating(report.leadership)}, {"category": "Organization", "content": self.interperate_rating(report.organization)}, {"category": "Delegation", "content": self.interperate_rating(report.delegation)}, {"category": "Points", "content": report.points}, {"category": "Strengths", "content": report.strengths}, {"category": "Weaknesses", "content": report.weaknesses}, {"category": "Trait work on to become a better team member", "content": report.traits_to_work_on}] # Final self reviews will have some extra details if reviewer_id == reviewee_id: parsed_review.append({"category": "What the student learned from the experience", "content": report.what_you_learned}) if report.is_final: parsed_review.append({"category": "If the student is proud of their accomplishment", "content": report.proud_of_accomplishment}) # Send the data off to the client return render_template("viewReview.html", details=review_details, review_data=parsed_review) else: # Might consider adding more detail so the problem can be addressed more easly return self.display_error("We couldn't find the report we were looking for in the database") # https://stackoverflow.com/questions/47719838/how-to-catch-all-exceptions-in-try-catch-block-python except Exception as error: return self.display_error(error)
def post(self): """ A function that determines how the viewStudent class handles POST requests INPUT: self OUTPUT: a rendering of the viewStudent.html file. The information included in the rendering depends on the information we get from the POST request """ # Get the database object we will need students = gbmodel.students() teams = gbmodel.teams() reports = gbmodel.reports() # Validate that the one making the request is a professor # Might want to consider noting things like these or forcefuly logging the person out if not validate_professor(): return display_access_control_error() # Otherwise, load the student page try: # Get the student and session id from the post request, and try to find the student in the db student_id = request.form.getlist('student_id')[0] session_id = request.form.getlist('session_id')[0] student = students.get_student_in_session(student_id, session_id) # If the student is found, find all of the student's team members and see if the student filled # out reviews for those team members if student is not None: # Get team name team = teams.get_team_from_id(student.tid) if team is None: return self.display_error(( "Students' team not found in database (when searching via team" " id)")) # Record it, along with some other information about the student student_details = { "name": student.name, "id": student.id, "team_name": team.name } # See if the student completed a midterm and final review for their team members and # record it reviews = [] team_members = students.get_team_members(student.tid) for team_member in team_members: midterm_review_completed = self.check_review_done( reports, student.id, team_member.id, student.tid, False) final_review_completed = self.check_review_done( reports, student.id, team_member.id, student.tid, True) reviews.append({ "reviewee_name": team_member.name, "reviewee_id": team_member.id, "completed": (midterm_review_completed, final_review_completed) }) # Combine the recorded data with the viewStudent.html template and render the viewStudent # page return render_template('viewStudent.html', student=student_details, review_data=reviews, session_id=session_id) else: return self.display_error( ("Student was not found in the database " "(when we searched via student ID)")) # https://stackoverflow.com/questions/47719838/how-to-catch-all-exceptions-in-try-catch-block-python except Exception as error: return self.display_error(error)
def post(self, capstone_id): """ This method handles post requests from review.html. Input: only self Output: rendering the review.html template with errors reported to the user or rendering the success page to indicate the user was successful in submitting their report """ # check if user exists user_id = request.form.get('user_id') test_user = self.confirm_user(user_id, capstone_id) if test_user is False: logging.error('Fill Out Review - Error when identifiyng user') return render_template( 'review.html', mems=None, state=None, input_error=None, fatal_error='You have no open reviews.', ) # get user's team id tid = self.get_tid(user_id, capstone_id) # get users state state = self.get_state(user_id, capstone_id) if state == 'Error': logging.error( 'Fill Out Review - Error while retrieving student state') return render_template( 'review.html', name=self.get_self_name(user_id), mems=None, state=None, input_error=None, fatal_error='You have no open reviews.', ) # get user's team members try: mems = gbmodel.students().get_team_members(tid) except SQLAlchemyError: logging.error( 'Fill Out Review - Error while retrieving team members') return render_template( 'review.html', name=self.get_self_name(), mems=None, state=None, input_error=None, fatal_error= 'There was an error while retrieving user team members.', ) # get student's cid cid = capstone_id # generate a list of the DB ids for students on the team id_list = [] for mem in mems: if mem is not None: id_list.append(mem.id) # check points total total = 0 points_pass = True # check that conditions for points match requirements for j in id_list: logging.info('checking points') # check points for being in bounds and adding to 100 points = request.form[('points_' + str(j))] try: try: # ensure that points are all integers points = int(points) except ValueError: flash('points must be an integer') points = 0 points_pass = False if (points_pass is True) and points < 0: flash('Points must be 0 or greater') points = 0 points_pass = False if points_pass is True: # add up the total points total = total + points if j == user_id: # make sure own score is 0 if points > 0 or points < 0: flash('Points must be 0 for self') points_pass = False except ValueError: self.display_error('Invalid input for points') points = 0 points_pass = False # check that total is 100 if total != 100: flash('Points total must be 100') points = 0 points_pass = False done = self.get_done(user_id, capstone_id) # get form inputs and submit to the database if points_pass is True: logging.info('Retrieving Form Input') pass_insert = True # will test if all insertions are successful for i in id_list: # Get each radio input and verify that it's an integer tech = request.form[('tech_mast_' + str(i))] tech = self.convert_to_int(tech) ethic = request.form[('work_ethic_' + str(i))] ethic = self.convert_to_int(ethic) com = request.form[('comm_' + str(i))] com = self.convert_to_int(com) coop = request.form[('coop_' + str(i))] coop = self.convert_to_int(coop) init = request.form[('init_' + str(i))] init = self.convert_to_int(init) focus = request.form[('team_focus_' + str(i))] focus = self.convert_to_int(focus) cont = request.form[('contr_' + str(i))] cont = self.convert_to_int(cont) # default leader skills to None for Null in database lead = None org = None dlg = None # check if current student is leader try: is_lead = gbmodel.students().check_team_lead( i, capstone_id) except SQLAlchemyError: self.display_error('student look up error') if is_lead is True: # get leader values lead = request.form[('lead_' + str(i))] lead = self.convert_to_int(lead) org = request.form[('org_' + str(i))] org = self.convert_to_int(org) dlg = request.form[('dlg_' + str(i))] dlg = self.convert_to_int(dlg) # Get string inputs strn = request.form[('str_' + str(i))] strn = strn.strip() wkn = request.form[('wkn_' + str(i))] wkn = wkn.strip() traits = request.form[('traits_' + str(i))] traits = traits.strip() learned = None if i == user_id: learned = request.form[('learned')] learned = learned.strip() if len(learned) > 30000: logging.error('learned string too long') abort(422) proud = None # only get 'proud' if the student is filling out final review if self.get_state(user_id, capstone_id) == 'final': if i == user_id: proud = request.form[('proud')] proud = proud.strip() if len(proud) > 30000: logging.error('proud string too long') abort(422) points = request.form[('points_' + str(i))] points = points.strip() if ((len(strn) > 30000) or (len(wkn) > 30000) or (len(traits) > 30000)): logging.error('str/wkn/traits string too long') abort(422) points = self.convert_to_int(points) # default to not late late = False is_final = False try: logging.info('Checking if Late') is_not_late = gbmodel.capstone_session().check_not_late( cid, datetime.now(), self.get_state( user_id, capstone_id, ), ) if is_not_late is False: late = True except SQLAlchemyError: self.display_error('student look up error - capstone') logging.info('checking student state') if self.get_state(user_id, capstone_id) == 'midterm': # for midterm set final to false is_final = False elif self.get_state(user_id, capstone_id) == 'final': # for midterm set final to false is_final = True if done == 1: # update existing record try: logging.info('updating report') report = gbmodel.reports().get_report( user_id, i, tid, is_final, ) if report is not None: report.tech_mastery = tech report.work_ethic = ethic report.communication = com report.cooperation = coop report.initiative = init report.team_focus = focus report.contribution = cont report.leadership = lead report.organization = org report.delegation = dlg report.points = points report.strengths = strn report.weaknesses = wkn report.traits_to_work_on = traits report.what_you_learned = learned report.proud_of_accomplishment = proud else: test_sub = gbmodel.reports().insert_report( cid, datetime.now(), user_id, tid, i, tech, ethic, com, coop, init, focus, cont, lead, org, dlg, points, strn, wkn, traits, learned, proud, is_final, late) if test_sub is False: logging.error('report creation failure') pass_insert = False except SQLAlchemyError: pass_insert = False else: logging.info('creating report') # insert new record # add report, but do not commit yet test_sub = gbmodel.reports().insert_report( cid, datetime.now(), user_id, tid, i, tech, ethic, com, coop, init, focus, cont, lead, org, dlg, points, strn, wkn, traits, learned, proud, is_final, late, ) # remember if this report submission failed if test_sub is False: logging.error('report creation failure') pass_insert = False if done == 1: # commit updates logging.info('committing edits') test_commit = gbmodel.reports().commit_updates(pass_insert) else: logging.info('committing reports') # commit reports and update the user's state. # roll back changes if insertion failed test_commit = gbmodel.reports().commit_reports( user_id, self.get_state(user_id, capstone_id), capstone_id, pass_insert, ) if test_commit is True: # success return render_template('submitted.html') else: self.display_error('Submission Error') return render_template('review.html', name=self.get_self_name(user_id, capstone_id), mems=mems, human_fields=self.human_fields, code_fields=self.code_fields, state=self.get_state(user_id, capstone_id), input_error=True, fatal_error=None)
def get(self, capstone_id): """ This method handles get requests to review.html. Input: only self Output: rendering the review.html template with given conditions -- team members to displate, the student's open reports state, if there are any user input errors to report, and if there are any fatal errors to report as a result of user action. """ # check if user exists # user_id = request.args.get('user_name') if validate_student() is False: return render_template('index.html') else: user_id = validate_student().id # get user's team id tid = self.get_tid(user_id, capstone_id) # check if the user is not on the empty team (a.k.a: if the user is not on a team) try: empty_team = gbmodel.teams().get_tid_from_name("", capstone_id) if tid == empty_team: return render_template( 'review.html', mems=None, state=None, input_error=None, fatal_error="You aren't assigned to a team yet") except SQLAlchemyError: return render_template( 'review.html', mems=None, state=None, input_error=None, fatal_error='There was an error verifying you are on a team') test_user = self.confirm_user(user_id, capstone_id) if test_user is False: return render_template('review.html', mems=None, state=None, input_error=None, fatal_error='You have no open reviews.') # get user name user_name = self.get_self_name(user_id, capstone_id) # get user's team members try: mems = gbmodel.students().get_team_members(tid) except SQLAlchemyError: return render_template( 'review.html', mems=None, state=None, input_error=None, fatal_error= 'There was an error while retrieving user team members.') if mems is None: return render_template( 'reivew.html', mems=None, state=None, input_error=None, fatal_error='There are no team members to review') # get user's state of open/closed reports state = self.get_state(user_id, capstone_id) if state == 'Error': return render_template( 'review.html', mems=None, state=None, input_error=None, fatal_error= 'There was an error while retrieving user information.') # for editing, check if the user is done and get their prior data data = self.get_data(user_id, capstone_id) done = self.get_done(user_id, capstone_id) # If all successful, render the page with team members and the state return render_template('review.html', name=user_name, user_id=user_id, mems=mems, state=state, data=data, is_done=done, human_fields=self.human_fields, code_fields=self.code_fields, input_error=None, fatal_error=None)
def post(self): """ This method handles all the functionalities from proDashboard includes add/remove students/teams, add new session, set review midterm/final start/end dates, setting reviews to be open/closed, and set team lead """ if not validate_professor(): return display_access_control_error() session = gbmodel.capstone_session() student = gbmodel.students() team = gbmodel.teams() professor = gbmodel.professors() # Get current session id from dropdowns in profDashboard.html session_id = request.form['session_id'] if 'student_name' in request.form: # Add New Student (student name, student id and student email) # Get team name and session id from profDashboard.html, # new student id, name, email from addStudent.html team_name = request.form.get('team_name') if not student.check_dup_student(request.form['student_id'], session_id): # If student id in a current session already exists # Return to addStudent.html with error msg and request a new form error = "Student id " + str( request.form['student_id']) + " already exists" return render_template('addStudent.html', team_name=team_name, session_id=session_id, error=error) if request.form['student_email'] != '': # If new email is invalid, return to addStudent.html # with error msg and request a new form if self.valid_email(str( request.form['student_email'])) is False: error = "Invalid Email Address" return render_template('addStudent.html', team_name=team_name, session_id=session_id, error=error) # Insert new student information into the database student.insert_student(request.form['student_name'], request.form['student_email'], request.form['student_id'], session_id, team_name) # Update new list of students to reflect on profDashboard.html lists, sessions = team.dashboard(session_id) return render_template('profDashboard.html', lists=lists, sessions=sessions, session_id=session_id) elif 'team' in request.form: # Remove a student/students from a team # get list of students and team name from profDashboard.html students = request.form.getlist('removed_student') team_name = request.form.get('team') # Remove student/students from database student.remove_student(students, team_name, session_id) lists, sessions = team.dashboard(session_id) return render_template('profDashboard.html', lists=lists, sessions=sessions, session_id=session_id) elif 'removed_team' in request.form: # Remove a team in a session # Get team name in current session from profDashboard.html team_name = request.form.get('removed_team') # There was a problem removing teams with blank names, so (in remove team requests) a '_' # character was added to the beginning of the name. # We will want to remove it before we continue # https://stackoverflow.com/questions/4945548/remove-the-first-character-of-a-string team_name = team_name[1:] # Remove team and students in the team from database team.remove_team(team_name, session_id) lists, sessions = team.dashboard(session_id) return render_template('profDashboard.html', lists=lists, sessions=sessions, session_id=session_id) elif 'start_term' in request.form: # Add a new session to the profDashboard # Gets all professors in DB and stores into prof_list professors = gbmodel.professors() prof_list = professors.get_all_professors() while not session.check_term_name(request.form['start_term']): error = "Enter a valid term (Example: Summer)" return render_template('addSession.html', error=error, session_id=session_id, prof_list=prof_list) while not session.check_term_year(request.form['start_year']): error = "Enter a valid year (Example: 2019)" return render_template('addSession.html', error=error, session_id=session_id, prof_list=prof_list) while not professor.check_professor(request.form['professor_id']): error = "Enter a valid professor ID" return render_template('addSession.html', error=error, session_id=session_id, prof_list=prof_list) while not session.check_dup_session(request.form['start_term'], request.form['start_year'], request.form['professor_id']): error = "Session already exists" return render_template('addSession.html', error=error, session_id=session_id, prof_list=prof_list) start_term = request.form.get('start_term') start_year = request.form.get('start_year') start_term = start_term.replace("_", " ") start_year = start_year.replace("_", " ") professor_id = request.form.get('professor_id') professor_id = professor_id.replace("_", " ") session_id = session.insert_session(start_term, start_year, professor_id) lists, sessions = team.dashboard(session_id) return render_template('profDashboard.html', lists=lists, sessions=sessions, session_id=session_id) # If REMOVE SESSION was submitted (removed_session) elif 'removed_session' in request.form: while not session.check_session_id_valid( request.form['removed_session']): error = "Invalid session ID" return render_template('profDashboard.html', lists=lists, sessions=sessions, session_id=session_id) remove_session = request.form.get('removed_session') remove_session = remove_session.replace("_", " ") session.remove_session(session_id) session_id = session.get_max() - 1 lists, sessions = team.dashboard(session_id) return render_template('profDashboard.html', lists=lists, sessions=sessions, session_id=session_id) # If ADD TEAM was submitted (addTeam) elif 'team_name' in request.form: # Add a new team to a current session # Request new team name from addTeam.html if not team.check_dup_team(request.form['team_name'], session_id): # If new name already exists in current session # Rentering the addTeam.html with given error message error = "Team name already exists" return render_template('addTeam.html', error=error, session_id=session_id) team_name = request.form.get('team_name') # Add new team to the given session from profDashboard.html team.insert_team(session_id, team_name) # Update new list of sessions, teams, students to reflect on profDashboard.html lists, sessions = team.dashboard(session_id) return render_template('profDashboard.html', lists=lists, sessions=sessions, session_id=session_id) # if ASSIGNED TEAMS for to place new students on teams was submitted elif 'assigned_teams' in request.form: size = request.form.get('size') size = int(size) unassigned_students = student.get_unassigned_students(session_id) team_names = [] i = 1 while i <= size: team_name = (request.form.get('assigned_team' + str(i))) if team.check_dup_team(team_name, session_id) is False: t_id = team.get_tid_from_name(team_name, session_id) student.update_team(unassigned_students[i - 1].name, session_id, t_id) else: team.insert_team(session_id, team_name) t_id = team.get_tid_from_name(team_name, session_id) student.update_team(unassigned_students[i - 1].name, session_id, t_id) team_names.append(team_name) i += 1 lists, sessions = team.dashboard(session_id) return render_template('profDashboard.html', lists=lists, sessions=sessions, session_id=session_id) # If IMPORT STUDENTS was submitted (addTeamCSV) elif 'student_data_csv' in request.files: session_id = int(request.form['session_id']) teams_table = gbmodel.teams() # Accessor to the teams table students_table = gbmodel.students( ) # Accessor to the students table file = request.files['student_data_csv'] # If 'Create from File' was selected with no file # return back to import student page. if (file.filename == ''): return render_template('csvAddTeam.html', session_id=session_id, error="Please select a file to upload") stream = io.StringIO(file.stream.read().decode("UTF8"), newline=None) csv_reader = csv.reader(stream, delimiter=',') uninserted_students = [] for row in csv_reader: if len(row) > 3: return render_template('csvAddTeam.html', session_id=session_id, error="Incorrect csv Format") try: student_name = row[0] student_id = row[1] team_name = row[2] except IndexError: logging.warning( "CSV Add Students/Team - Problem parsing csv") return render_template('csvAddTeam.html', session_id=session_id, error="Incorrect csv Format") # Create team if it doesn't exist, then create the student. try: if teams_table.check_dup_team(team_name, session_id) is True: teams_table.insert_team(session_id, team_name) except SQLAlchemyError: logging.error(( 'CSV Add Students/Team - Error checking for existing team and/or' ' inserting a new one')) return render_template('csvAddTeam.html', session_id=session_id, error="Something went wrong") try: if students_table.check_dup_student( student_id, session_id) is True: students_table.insert_student(student_name, "", student_id, session_id, team_name) else: # Keep track of what students weren't added to the database (and make a note it) logging.warning( "CSV Add Students/Team -" " Error inserting student into the database") uninserted_students.append(student_name) except SQLAlchemyError: logging.error(( 'CSV Add Students/Team -' ' Error inserting students or checking if they exist in the database' )) return render_template('csvAddTeam.html', session_id=session_id, error="Something went wrong") # If everything went well, reload the professor dashboard if len(uninserted_students) == 0: logging.info( "CSV Add Students/Team - added student data from uploaded csv file" ) lists, sessions = team.dashboard(session_id) return render_template('profDashboard.html', lists=lists, sessions=sessions, session_id=session_id) # If there were some problems, let the user know else: error_str = "There was a problem inserting the following students into the database: " error_str = error_str + ", ".join(uninserted_students) error_str = error_str + ". They are already in this session." return render_template('csvAddTeam.html', session_id=session_id, error=error_str) # If SET DATE for reviews was submitted (setDate) elif 'midterm_start' in request.form: # Add midterm/final start/end dates for review form # Request start and end dates for midterm and final from setDate.html midterm_start = request.form.get('midterm_start') midterm_end = request.form.get('midterm_end') final_start = request.form.get('final_start') final_end = request.form.get('final_end') params = { 'midterm_start': midterm_start, 'midterm_end': midterm_end, 'final_start': final_start, 'final_end': final_end } if session.date_error(params) is not None: # Check if the dates are valid, rendering to setDate.html # with a error message error_msg = session.date_error(params) return render_template('setDate.html', error=error_msg, session_id=session_id) # Insert dates into database session.insert_dates(midterm_start, midterm_end, final_start, final_end, session_id) # Update new list of sessions, teams, students to reflect on profDashboard.html lists, sessions = team.dashboard(session_id) return render_template('profDashboard.html', lists=lists, sessions=sessions, session_id=session_id) elif 'team_lead' in request.form: # Set team lead for a team in current session # Get team name and lead from checkboxes in profDashboard.html team_name = request.form.get('team_lead') student_name = request.form.get('is_lead') # Set lead for chosen team in current sesison student.set_lead(session_id, team_name, student_name) # Update new list of sessions, teams, students to reflect on profDashboard.html lists, sessions = team.dashboard(session_id) return render_template('profDashboard.html', lists=lists, sessions=sessions, session_id=session_id) elif 'set_review_available' in request.form: # update students' review availability setting = request.form.get('set_review_available') result = student.set_active(session_id, setting) if result is True: # back to page lists, sessions = team.dashboard(session_id) return render_template('profDashboard.html', lists=lists, sessions=sessions, session_id=session_id) else: error_msg = "Error When Selecting Option" return render_template('setAvailable.html', error=error_msg, session_id=session_id)