def get(self): quarter = SettingModel.quarter() year = SettingModel.year() user = users.get_current_user() student = StudentModel.get_student_by_email(quarter, year, user.email()) assgn_num = 0 cancel = int(self.request.get('cancel')) partnership = ndb.Key(urlsafe=self.request.get('p')).get() if cancel: assgn_num = partnership.assignment_number if cancel: # refine implementation of cancellation eventually for s in partnership.members: partnership = PartnershipModel.cancel_partnership( s, partnership) if not partnership.active: EvalModel.cancel_evals_for_partnership(partnership) time.sleep(0.1) return self.redirect('/partner?message=' + MessageModel.partnership_cancelled(assgn_num)) else: PartnershipModel.uncancel_partnership(student, partnership) time.sleep(0.1) return self.redirect('/partner?message=' + MessageModel.partnership_uncancelled())
def get(self): user = users.get_current_user() try: quarter = SettingModel.quarter() year = SettingModel.year() student = StudentModel.get_student_by_email(quarter, year, user.email()) active_assigns = map(lambda x: x.number, AssignmentModel.get_active_assigns(quarter, year)) assign_range = AssignmentModel.get_assign_range(quarter, year) partner_history = PartnershipModel.get_active_partner_history_for_student(student, quarter, year, fill_gaps=assign_range) all_partner_history = PartnershipModel.get_all_partner_history_for_student(student, quarter, year) evals = EvalModel.get_eval_history_by_evaluator(student, True, quarter, year).fetch() evals += EvalModel.get_eval_history_by_evaluator(student, False, quarter, year).fetch() evals = sorted(evals, key=lambda x: x.assignment_number) except AttributeError: return self.redirect('/partner') template = JINJA_ENV.get_template('/templates/partner_student_view.html') template_values = { 'student': student, 'partners': partner_history, 'all_partners': all_partner_history, 'assign_range': assign_range, 'active': active_assigns, 'evals': evals, 'user': users.get_current_user(), 'sign_out': users.create_logout_url('/'), } return self.response.write(template.render(template_values))
def get(self): # pass map of quarter DB representations (ints) to string representation # TODO: # quarters should not be hardcoded quarter_map = {1: 'Fall', 2: 'Winter', 3: 'Spring', 4: 'Summer'} quarter = self.request.get('quarter') year = self.request.get('year') # try getting quarter/year from session if not quarter or not year: temp = get_sess_vals(self.session, 'quarter', 'year') if not temp: return self.redirect( '/admin?message=Please set a current quarter and year') quarter, year = temp quarter, year = int(quarter), int(year) student = ndb.Key(urlsafe=self.request.get('student')).get() assign_range = AssignmentModel.get_assign_range(quarter, year) partner_history = PartnershipModel.get_active_partner_history_for_student( student, quarter, year, fill_gaps=assign_range) all_partner_history = PartnershipModel.get_all_partner_history_for_student( student, quarter, year) evals = EvalModel.get_eval_history_by_evaluator( student, True, quarter, year).fetch() evals += EvalModel.get_eval_history_by_evaluator( student, False, quarter, year).fetch() evals = sorted(evals, key=lambda x: x.assignment_number) evals_for = EvalModel.get_eval_history_by_evaluatee( student, True, quarter, year).fetch() evals_for += EvalModel.get_eval_history_by_evaluatee( student, False, quarter, year).fetch() evals_for = sorted(evals_for, key=lambda x: x.assignment_number) log = LogModel.get_log_by_student(student, quarter, year).get() if log: log_arr = log.log else: log_arr = [] template = JINJA_ENV.get_template('/templates/admin_student_view.html') template_values = { 'student': student, 'partners': partner_history, 'all_partners': all_partner_history, 'assign_range': assign_range, 'evals': evals, 'evals_for': evals_for, 'user': users.get_current_user(), 'log': log_arr, 'sign_out': users.create_logout_url('/'), } return self.response.write(template.render(template_values))
def post(self): quarter = SettingModel.quarter() year = SettingModel.year() user = users.get_current_user() evaluator = StudentModel.get_student_by_email(quarter, year, user.email()) partners = PartnershipModel.get_active_partner_history_for_student(evaluator, quarter, year) eval_key,num = split_last(self.request.get('evaluatee')) eval_assign = int(num) current_partner = ndb.Key(urlsafe=eval_key).get() evaluations = EvalModel.get_existing_eval_by_assign(evaluator, current_partner, eval_assign) for eval in evaluations: eval.active = False eval.put() evaluation = Evaluation(evaluator = evaluator.key, evaluatee = current_partner.key) evaluation.assignment_number = eval_assign evaluation.year = evaluator.year evaluation.quarter = evaluator.quarter evaluation.active = True for i in range(1, 11): evaluation.responses.append(self.request.get('q' + str(i))) evaluation.put() message = 'Evaluation for ' + str(current_partner.last_name) + ', ' message += str(current_partner.first_name) + ' successfully submitted' self.redirect('/partner?message=' + message)
def get(self): # pass map of quarter DB representations (ints) to string representation # TODO: # quarters should not be hardcoded quarter_map = {1: 'Fall', 2: 'Winter', 3: 'Spring', 4: 'Summer'} quarter = self.request.get('quarter') year = self.request.get('year') # try getting quarter/year from session if not quarter or not year: temp = get_sess_vals(self.session, 'quarter', 'year') if not temp: return self.redirect('/admin?message=Please set a current quarter and year') quarter,year = temp quarter,year = int(quarter), int(year) student = ndb.Key(urlsafe=self.request.get('student')).get() assign_range = AssignmentModel.get_assign_range(quarter, year) partner_history = PartnershipModel.get_active_partner_history_for_student(student, quarter, year, fill_gaps=assign_range) all_partner_history = PartnershipModel.get_all_partner_history_for_student(student, quarter, year) evals = EvalModel.get_eval_history_by_evaluator(student, True, quarter, year).fetch() evals += EvalModel.get_eval_history_by_evaluator(student, False, quarter, year).fetch() evals = sorted(evals, key=lambda x: x.assignment_number) evals_for = EvalModel.get_eval_history_by_evaluatee(student, True, quarter, year).fetch() evals_for += EvalModel.get_eval_history_by_evaluatee(student, False, quarter, year).fetch() evals_for = sorted(evals_for, key=lambda x: x.assignment_number) template = JINJA_ENV.get_template('/templates/admin_student_view.html') template_values = { 'student': student, 'partners': partner_history, 'all_partners': all_partner_history, 'assign_range': assign_range, 'evals': evals, 'evals_for': evals_for, 'user': users.get_current_user(), 'sign_out': users.create_logout_url('/'), } return self.response.write(template.render(template_values))
def get(self): # pass map of quarter DB representations (ints) to string representation # TODO: # quarters should not be hardcoded quarter_map = {1: 'Fall', 2: 'Winter', 3: 'Spring', 4: 'Summer'} quarter = self.request.get( 'quarter') # try grabbing quarter/year from URL year = self.request.get('year') assign_num = self.request.get( 'assign_num') # try grabbing assignment number from URL if not quarter or not year: # if they don't exist, try grabbing from session temp = get_sess_vals(self.session, 'quarter', 'year') if not temp: # if they don't exist there, redirect with error return self.redirect( '/admin?message=Please set a current quarter and year') quarter, year = temp quarter, year = int(quarter), int(year) current_assignment = AssignmentModel.get_active_assign_with_latest_fade_in_date( quarter, year) if current_assignment and not assign_num: assign_num = current_assignment.number assign_num = int( assign_num ) if assign_num else 1 # (to avoid errors if there are no assignments in the DB last_num = AssignmentModel.get_assign_n(quarter, year, -1) last_num = last_num.number if last_num else assign_num # (to avoid errors if there are no assignments in the DB) first_assign = AssignmentModel.get_assign_n(quarter, year, 0) first_num = 0 if not first_assign else first_assign.number evals = EvalModel.get_all_evals_for_assign( quarter, year, assign_num) # grab evals for assignment... solo_partners = PartnershipModel.get_solo_partnerships_by_assign( quarter, year, assign_num ) # ...and grab endorsed solos (they're exempt from evals) template_values = { 'user': users.get_current_user(), 'sign_out': users.create_logout_url('/'), 'quarter': quarter, 'quarter_name': quarter_map[quarter], 'year': year, 'assign_num': assign_num, 'message': self.request.get('message'), 'evals': evals, 'solos': solo_partners, 'first_num': first_num, 'last_num': last_num, } template = JINJA_ENV.get_template('/templates/admin_evals_view.html') return self.response.write(template.render(template_values))
def get(self): user = users.get_current_user() try: quarter = SettingModel.quarter() year = SettingModel.year() student = StudentModel.get_student_by_email( quarter, year, user.email()) active_assigns = map( lambda x: x.number, AssignmentModel.get_active_assigns(quarter, year)) assign_range = AssignmentModel.get_assign_range(quarter, year) partner_history = PartnershipModel.get_active_partner_history_for_student( student, quarter, year, fill_gaps=assign_range) all_partner_history = PartnershipModel.get_all_partner_history_for_student( student, quarter, year) evals = EvalModel.get_eval_history_by_evaluator( student, True, quarter, year).fetch() evals += EvalModel.get_eval_history_by_evaluator( student, False, quarter, year).fetch() evals = sorted(evals, key=lambda x: x.assignment_number) except AttributeError: return self.redirect('/partner') template = JINJA_ENV.get_template( '/templates/partner_student_view.html') template_values = { 'student': student, 'partners': partner_history, 'all_partners': all_partner_history, 'assign_range': assign_range, 'active': active_assigns, 'evals': evals, 'user': users.get_current_user(), 'sign_out': users.create_logout_url('/'), } return self.response.write(template.render(template_values))
def post(self): quarter = SettingModel.quarter() year = SettingModel.year() user = users.get_current_user() evaluator = StudentModel.get_student_by_email(quarter, year, user.email()) partners = PartnershipModel.get_active_partner_history_for_student( evaluator, quarter, year) eval_key, num = split_last(self.request.get('evaluatee')) eval_assign = int(num) current_partner = ndb.Key(urlsafe=eval_key).get() # Log when eval is submitted #current date for timestamp cur_date = datetime.datetime.now().strftime("%m/%d/%Y %H:%M:%S") #get current log, creating one if it does not exist current_log = LogModel.get_log_by_student(evaluator, quarter, year).get() if current_log == None: current_log = Log() current_log.owner = evaluator.key current_log.quarter = quarter current_log.year = year #log the submission of the eval current_log.log.append(cur_date + " Submitted eval for: " + current_partner.ucinetid + " assgt. " + str(eval_assign)) #save to log current_log.put() evaluations = EvalModel.get_existing_eval_by_assign( evaluator, current_partner, eval_assign) for eval in evaluations: eval.active = False eval.put() evaluation = Evaluation(evaluator=evaluator.key, evaluatee=current_partner.key) evaluation.assignment_number = eval_assign evaluation.year = evaluator.year evaluation.quarter = evaluator.quarter evaluation.active = True for i in range(1, 11): evaluation.responses.append(self.request.get('q' + str(i))) evaluation.put() message = 'Evaluation for ' + str(current_partner.last_name) + ', ' message += str( current_partner.first_name ) + ' confirmed: Please refresh the page and confirm the evaluation was submitted.' self.redirect('/partner?message=' + message)
def get(self): user = users.get_current_user() quarter = SettingModel.quarter() year = SettingModel.year() # grab message from URL, if it exists message = self.request.get('message') if (not quarter or not year) and not message: message = 'Please set a current year and quarter' template_values = { 'message': message, 'user': user, 'sign_out': users.create_logout_url('/'), 'quarter': quarter, 'year': year, } self.session['quarter'] = quarter self.session['year'] = year if quarter and year: template_values['active_students'] = len( StudentModel.get_students_by_active_status(quarter, year).fetch()) template_values['inactive_students'] = len( StudentModel.get_students_by_active_status( quarter, year, active=False).fetch()) cur_assign = AssignmentModel.get_active_assign_with_latest_fade_in_date( quarter, year) if cur_assign: template_values['cur_assign'] = cur_assign # grab number of active partnerships for the current assignment template_values['assign_partners'] = len( PartnershipModel.get_all_partnerships_for_assign( quarter, year, cur_assign.number)) eval_assign = AssignmentModel.get_active_assign_with_earliest_eval_due_date( quarter, year) if eval_assign: template_values['eval_assign'] = eval_assign # grab number of evals for the current eval assignment template_values['assign_eval'] = len( EvalModel.get_all_evals_for_assign( quarter, year, cur_assign.number).fetch()) template = JINJA_ENV.get_template('/templates/admin.html') return self.response.write(template.render(template_values))
def get(self): user = users.get_current_user() quarter = SettingModel.quarter() year = SettingModel.year() # grab message from URL, if it exists message = self.request.get("message") if (not quarter or not year) and not message: message = "Please set a current year and quarter" template_values = { "message": message, "user": user, "sign_out": users.create_logout_url("/"), "quarter": quarter, "year": year, } self.session["quarter"] = quarter self.session["year"] = year if quarter and year: template_values["active_students"] = len(StudentModel.get_students_by_active_status(quarter, year).fetch()) template_values["inactive_students"] = len( StudentModel.get_students_by_active_status(quarter, year, active=False).fetch() ) cur_assign = AssignmentModel.get_active_assign_with_latest_fade_in_date(quarter, year) if cur_assign: template_values["cur_assign"] = cur_assign # grab number of active partnerships for the current assignment template_values["assign_partners"] = len( PartnershipModel.get_all_partnerships_for_assign(quarter, year, cur_assign.number) ) eval_assign = AssignmentModel.get_active_assign_with_earliest_eval_due_date(quarter, year) if eval_assign: template_values["eval_assign"] = eval_assign # grab number of evals for the current eval assignment template_values["assign_eval"] = len( EvalModel.get_all_evals_for_assign(quarter, year, cur_assign.number).fetch() ) template = JINJA_ENV.get_template("/templates/admin.html") return self.response.write(template.render(template_values))
def get(self): # pass map of quarter DB representations (ints) to string representation # TODO: # quarters should not be hardcoded quarter_map = {1: 'Fall', 2: 'Winter', 3: 'Spring', 4: 'Summer'} quarter = self.request.get('quarter') # try grabbing quarter/year from URL year = self.request.get('year') assign_num = self.request.get('assign_num') # try grabbing assignment number from URL if not quarter or not year: # if they don't exist, try grabbing from session temp = get_sess_vals(self.session, 'quarter', 'year') if not temp: # if they don't exist there, redirect with error return self.redirect('/admin?message=Please set a current quarter and year') quarter,year = temp quarter,year = int(quarter), int(year) current_assignment = AssignmentModel.get_active_assign_with_latest_fade_in_date(quarter, year) if current_assignment and not assign_num: assign_num = current_assignment.number assign_num = int(assign_num) if assign_num else 1 # (to avoid errors if there are no assignments in the DB last_num = AssignmentModel.get_assign_n(quarter, year, -1) last_num = last_num.number if last_num else assign_num # (to avoid errors if there are no assignments in the DB) first_assign = AssignmentModel.get_assign_n(quarter, year, 0) first_num = 0 if not first_assign else first_assign.number evals = EvalModel.get_all_evals_for_assign(quarter, year, assign_num) # grab evals for assignment... solo_partners = PartnershipModel.get_solo_partnerships_by_assign(quarter, year, assign_num) # ...and grab endorsed solos (they're exempt from evals) template_values = { 'user': users.get_current_user(), 'sign_out': users.create_logout_url('/'), 'quarter': quarter, 'quarter_name': quarter_map[quarter], 'year': year, 'assign_num': assign_num, 'message': self.request.get('message'), 'evals': evals, 'solos': solo_partners, 'first_num': first_num, 'last_num': last_num, } template = JINJA_ENV.get_template('/templates/admin_evals_view.html') return self.response.write(template.render(template_values))
def get(self): # delcare page template template = JINJA_ENV.get_template('/templates/partners_main.html') # get current user user = users.get_current_user() student = None try: quarter = SettingModel.quarter() year = SettingModel.year() # use user info to find student int DB student = StudentModel.get_student_by_email(quarter, year, user.email()) self.session['quarter'] = quarter self.session['year'] = year self.session['student'] = student.key.urlsafe() # Get current time in UTC, then convert to PDT current_time = datetime.datetime.fromtimestamp(time.time()) current_time = current_time - datetime.timedelta(hours=7) #get all assignments all_assigns = sorted(AssignmentModel.get_all_assign(quarter, year), key = lambda x: x.number) # get active assignments active_assigns = sorted(AssignmentModel.get_active_assigns(quarter, year), key=lambda x: x.number) # get active eval assigns eval_assigns = sorted(AssignmentModel.get_active_eval_assigns(quarter, year), key=lambda x: x.number) # find any active invitations for the current assignment that student has sent sent_invitations = InvitationModel.get_sent_invites_by_student_and_mult_assigns(student, [x.number for x in active_assigns]) # find any active invitations for the current assignment that the student has received received_invitations = InvitationModel.get_recvd_invites_by_student_and_mult_assigns(student, [x.number for x in active_assigns]) # find any partnerships in which the student has been involved partners = PartnershipModel.get_all_partner_history_for_student(student, quarter, year) partners = dict([(x.number,PartnershipModel.get_partner_from_partner_history_by_assign(student, partners, x.number)) for x in all_assigns]) # create list of assignment numbers which student has a partner for (IF PYTHON 3, use .items() instead of .iteritems()) assgn_nums_with_partner = [] for assgn_num, partner in partners.iteritems(): if len(partner): assgn_nums_with_partner.append(assgn_num) # find evals the student has submitted evals = EvalModel.get_eval_history_by_evaluator(student, True, quarter, year) evals = dict([(x.assignment_number,x) for x in evals]) # get activity message, if any message = self.request.get('message') dropped = [] for x in active_assigns: dropped += PartnershipModel.get_inactive_partnerships_by_student_and_assign(student, x.number).fetch() dropped = sorted(dropped, key=lambda x: x.assignment_number) except (AttributeError, IndexError): template_values = { 'user': user, 'student': student, 'sign_out': users.create_logout_url('/'), 'email': user.email() } return self.response.write(template.render(template_values)) template_values = { 'user': user, 'student': student, 'current_time': current_time, 'all_assigns': all_assigns, 'assgn_nums_with_partner': assgn_nums_with_partner, 'active': active_assigns, 'evals': eval_assigns, 'submitted_evals': evals, 'sent_invitations': sorted(sent_invitations, key=lambda x: x.assignment_number), 'received_invitations': sorted(received_invitations.items(), key=lambda x: x[0]), 'partners': partners, 'sign_out': users.create_logout_url('/'), 'message': message, 'profile': student.bio is None or student.availability is None or student.programming_ability is None, 'dropped': dropped, 'show_dropped': len(dropped) > 0 and len(filter(lambda x: x != None, partners.values())) < len(active_assigns), } self.response.write(template.render(template_values))
def get(self): # delcare page template template = JINJA_ENV.get_template('/templates/partners_main.html') # get current user user = users.get_current_user() student = None try: quarter = SettingModel.quarter() year = SettingModel.year() # use user info to find student int DB student = StudentModel.get_student_by_email( quarter, year, user.email()) self.session['quarter'] = quarter self.session['year'] = year self.session['student'] = student.key.urlsafe() # Get current time in UTC, then convert to PDT current_time = datetime.datetime.fromtimestamp(time.time()) current_time = current_time - datetime.timedelta(hours=7) #get all assignments all_assigns = sorted(AssignmentModel.get_all_assign(quarter, year), key=lambda x: x.number) # get active assignments active_assigns = sorted(AssignmentModel.get_active_assigns( quarter, year), key=lambda x: x.number) # get inactive assignments inactive_assigns = sorted(AssignmentModel.get_inactive_assigns( quarter, year), key=lambda x: x.number) # get active eval assigns eval_assigns = sorted(AssignmentModel.get_active_eval_assigns( quarter, year), key=lambda x: x.number) # find any active invitations for the current assignment that student has sent sent_invitations = InvitationModel.get_sent_invites_by_student_and_mult_assigns( student, [x.number for x in active_assigns]) # find any active invitations for the current assignment that the student has received received_invitations = InvitationModel.get_recvd_invites_by_student_and_mult_assigns( student, [x.number for x in active_assigns]) # find any partnerships in which the student has been involved partners = PartnershipModel.get_all_partner_history_for_student( student, quarter, year) partners = dict([ (x.number, PartnershipModel.get_partner_from_partner_history_by_assign( student, partners, x.number)) for x in all_assigns ]) # create list of assignment numbers which student has a partner for (IF PYTHON 3, use .items() instead of .iteritems()) assgn_nums_with_partner = [] for assgn_num, partner in partners.iteritems(): if len(partner): assgn_nums_with_partner.append(assgn_num) # find evals the student has submitted evals = EvalModel.get_eval_history_by_evaluator( student, True, quarter, year) evals = dict([(x.assignment_number, x) for x in evals]) # get activity message, if any message = self.request.get('message') dropped = [] for x in active_assigns: dropped += PartnershipModel.get_inactive_partnerships_by_student_and_assign( student, x.number).fetch() dropped = sorted(dropped, key=lambda x: x.assignment_number) except (AttributeError, IndexError): template_values = { 'user': user, 'student': student, 'sign_out': users.create_logout_url('/'), 'email': user.email() } return self.response.write(template.render(template_values)) template_values = { 'user': user, 'student': student, 'current_time': current_time, 'all_assigns': all_assigns, 'inactive_assigns': inactive_assigns, 'assgn_nums_with_partner': assgn_nums_with_partner, 'active': active_assigns, 'evals': eval_assigns, 'submitted_evals': evals, 'sent_invitations': sorted(sent_invitations, key=lambda x: x.assignment_number), 'received_invitations': sorted(received_invitations.items(), key=lambda x: x[0]), 'partners': partners, 'sign_out': users.create_logout_url('/'), 'message': message, 'profile': student.bio is None or student.availability is None or student.programming_ability is None, 'dropped': dropped, 'show_dropped': len(dropped) > 0 and len(filter(lambda x: x != None, partners.values())) < len(active_assigns), } self.response.write(template.render(template_values))