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): quarter = SettingModel.quarter() year = SettingModel.year() user = users.get_current_user() invitation = ndb.Key(urlsafe=self.request.get('confirmed')).get() confirming = StudentModel.get_student_by_email(quarter, year, user.email()) being_confirmed = invitation.invitor.get() for_assign = invitation.assignment_number partnership = None if not confirming and PartnershipModel.student_has_partner_for_assign( being_confirmed, for_assign): message = MessageModel.already_has_partner(False) elif PartnershipModel.student_has_partner_for_assign( being_confirmed, for_assign): message = MessageModel.already_has_partner(False) elif PartnershipModel.student_has_partner_for_assign( confirming, for_assign): message = MessageModel.already_has_partner(False) else: message = MessageModel.confirm_partnership( [being_confirmed, confirming], False, being_confirmed) partnership = PartnershipModel.create_partnership( [being_confirmed, confirming], for_assign) # set invitations between invitor and invitee (for current assignment) to inactive if partnership: InvitationModel.deactivate_invitations_for_students_and_assign( confirming, being_confirmed, for_assign) # SendMail(partnership, 'partner_confirm') time.sleep(0.1) return self.redirect('/partner?message=' + message)
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): # 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 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() user = users.get_current_user() selector = StudentModel.get_student_by_email(quarter, year, user.email()) if not selector: return self.redirect('/partner') # get error message, if any e = self.request.get('error') # get own email to query partner information. assgn_num = int(self.request.get('assgn')) # get list of all partners for student (roundabout solution) all_assigns = sorted(AssignmentModel.get_all_assign(quarter, year), key = lambda x: x.number) partner_history = PartnershipModel.get_all_partner_history_for_student(selector, quarter, year) all_partners = dict([(x.number,PartnershipModel.get_partner_from_partner_history_by_assign(selector, partner_history, x.number)) for x in all_assigns]) # get queried partnership partnership = None for p in partner_history: if p.assignment_number == assgn_num: partnership = p # Redirect to landing if query for that assignment's partnership turns up empty if not len(all_partners[assgn_num]): message = MessageModel.page_not_found() return self.redirect('/partner?message=' + message) 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)) # pass template values... template_values = { 'error': e, 'selector': selector, 'partner': all_partners[assgn_num][0], 'assgn_num': assgn_num, 'partnership': partnership, 'user': user, 'sign_out': users.create_logout_url('/'), } template = JINJA_ENV.get_template('/templates/partner_more_info.html') self.response.write(template.render(template_values))
def get(self): template = JINJA_ENV.get_template('/templates/partner_invitation_history.html') quarter = SettingModel.quarter() year = SettingModel.year() user = users.get_current_user() student = StudentModel.get_student_by_email(quarter, year, user.email()) # redirect to main page if student doesn't exist if not student: return self.redirect('/partner') invites = InvitationModel.get_all_invitations_involving_student(student).order(Invitation.assignment_number).fetch() current_assignment = AssignmentModel.get_active_assign_with_latest_fade_in_date(quarter, year) # if there are no assignments for this quarter, render early to avoid errors if not current_assignment: return self.response.write(template.render({'user': user, 'sign_out': users.create_logout_url('/')})) partners = PartnershipModel.get_active_partner_history_for_student(student, quarter, year) current_partner = PartnershipModel.get_partner_from_partner_history_by_assign(student, partners, current_assignment.number) active_range = set([a.number for a in AssignmentModel.get_active_assigns(quarter, year)]) invite_info = {} # dict for custom ordering of invite info fields ordering = {'Assign Num': 0, 'Who': 1, 'To/From': 2, 'Accepted': 3, 'Active': 4} for invite in invites: # organize invite info by time i = (invite.created - timedelta(hours=7)).strftime('%m-%d-%Y %H:%M:%S') invite_info[i] = {} invite_info[i]['Assign Num'] = invite.assignment_number # determine wheather invite was sent or received in relation to the user invite_info[i]['To/From'] = 'Sent' if invite.invitor == student.key else 'Received' who_key = invite.invitee if invite_info[i]['To/From'] == 'Sent' else invite.invitor who = who_key.get() # add invitor/invitee (depending on 'Sent'/'Received') to invite info invite_info[i]['Who'] = str(who.last_name) + ', ' + str(who.first_name) + ' - ' + str(who.ucinetid) invite_info[i]['Accepted'] = str(invite.accepted) invite_info[i]['Active'] = str(invite.active) invite_info[i]['key'] = invite.key.urlsafe() template_values = { 'invites': sorted(invite_info.items(), reverse=True), 'fields': sorted(ordering.items(), key=lambda x: x[1]), 'user': user, 'sign_out': users.create_logout_url('/'), 'active_range': active_range, } 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): quarter = SettingModel.quarter() year = SettingModel.year() # get user user = users.get_current_user() # get student from user info evaluator = StudentModel.get_student_by_email(quarter, year, user.email()) # get student's partner history partners = PartnershipModel.get_active_partner_history_for_student(evaluator, quarter, year) # grab the active eval assignments eval_assigns = AssignmentModel.get_active_eval_assigns(quarter, year) # grab partners for eval assignments evaluatees = [] for eval_assign in eval_assigns: for partner in PartnershipModel.get_partner_from_partner_history_by_assign(evaluator, partners, eval_assign.number): evaluatees.append((eval_assign.number,partner)) # filter out No Partner partnerships partners = list(filter(lambda x: x[1] != "No Partner" and x[1] != None, evaluatees)) eval_closed = len(eval_assigns) == 0 rate20scale = ["0 -- Never, completely inadequate", "1", "2", "3", "4"] rate20scale += ["5 -- Seldom, poor quality", "6", "7", "8", "9"] rate20scale += ["10 -- About half the time, average", "11", "12", "13", "14"] rate20scale += ["15 -- Most of the time, good quality", "16", "17", "18", "19"] rate20scale += ["20 -- Always, excellent"] rate5scale = ['1 - My partner was much more capable than I was'] rate5scale += ['2 - My partner was a little more capable than I was'] rate5scale += ['3 - We were about evenly matched, on average'] rate5scale += ['4 - I was a little more capable than my partner'] rate5scale += ['5 - I was a lot more capable than my partner'] rate10scale = [str(x / 10.0) for x in range(0, 105, 5)] template_values = { 'eval_closed': eval_closed, 'rate_scale': rate20scale, 'rate5scale': rate5scale, 'rate10scale': rate10scale, 'partners': partners, } template = JINJA_ENV.get_template('/templates/partner_eval.html') 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) 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): quarter = SettingModel.quarter() year = SettingModel.year() user = users.get_current_user() student = StudentModel.get_student_by_email(quarter, year, user.email()) assgn_num = int(self.request.get('n')) assignment = AssignmentModel.get_assign_by_number( quarter, year, assgn_num) partnership = PartnershipModel.get_active_partnerships_involving_students_by_assign( [student], assgn_num).get() # get list of all partners for student (roundabout solution) all_assigns = sorted(AssignmentModel.get_all_assign(quarter, year), key=lambda x: x.number) partner_history = PartnershipModel.get_all_partner_history_for_student( student, quarter, year) all_partners = dict([ (x.number, PartnershipModel.get_partner_from_partner_history_by_assign( student, partner_history, x.number)) for x in all_assigns ]) current_time = datetime.datetime.fromtimestamp(time.time()) current_time = current_time - datetime.timedelta(hours=7) # pass template values... template_values = { 'student': student, 'partnership': partnership, 'partner': all_partners[assgn_num][0], 'assignment': assignment, 'current_time': current_time, 'assgn_num': assgn_num } template = JINJA_ENV.get_template( '/templates/cancel_partner_modal.html') 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 # rethink logic 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') 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) view_by = self.request.get('view_by') # check URL for 'view by' options (lab vs class) view_by = view_by if view_by else 1 if view_by == 'class': # if user wants to view by class, or the view by option wasn't specified... students = StudentModel.get_students_by_active_status(quarter, year).fetch() else: students = StudentModel.get_students_by_lab(quarter, year, int(view_by)).fetch() all_partners = PartnershipModel.get_all_partnerships(quarter, year).fetch() last_assign = AssignmentModel.get_assign_n(quarter, year, -1) last_num = 1 if not last_assign else last_assign.number first_assign = AssignmentModel.get_assign_n(quarter, year, 0) first_num = 0 if not first_assign else first_assign.number keys_to_students = dict(map(lambda x: (x.key,x), students)) # map student objects to keys for easy, fast access from partnership objects keys_to_partnerships = keys_to_partners(all_partners) # map student keys to partnerships for easy, fast access # create mapping of student info to partnership info that the partnership template expects partnership_dict = student_info_to_partner_list(last_num, first_num, keys_to_partnerships, keys_to_students, students) partnership_dict = sorted(partnership_dict.items(), key=lambda x: (x[0][4], x[0][2])) num_labs = SettingModel.num_labs() template_values = { 'partnerships': partnership_dict, 'view_by': str(view_by), 'year': year, 'quarter': quarter, 'num_labs': num_labs if num_labs else 0, 'last_num': last_num, 'first_num': first_num, 'user': users.get_current_user(), 'sign_out': users.create_logout_url('/'), } template = JINJA_ENV.get_template('/templates/admin_partnerships.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 post(self): quarter = SettingModel.quarter() year = SettingModel.year() user = users.get_current_user() selector = StudentModel.get_student_by_email(quarter, year, user.email()) selected = StudentModel.get_student_by_student_id( quarter, year, self.request.get('selected_partner')) try: selected_assign = int(self.request.get('selected_assign')) time.sleep(0.1) except ValueError: return self.redirect( '/partner/selection?error=You must choose an assignment number' ) # redirect with errors... if PartnershipModel.were_partners_previously( [selector, selected]) and not SettingModel.repeat_partners(): return self.redirect('/partner?message=' + MessageModel.worked_previously(selected)) elif InvitationModel.have_open_invitations(selector, selected, selected_assign): return self.redirect('/partner?message=' + MessageModel.have_open_invitations(selected)) elif PartnershipModel.student_has_partner_for_assign( selector, selected_assign): return self.redirect( '/partner?message=' + MessageModel.already_has_partner(False, False)) else: InvitationModel.create_invitation(selector, selected, selected_assign) return self.redirect('/partner?message=' + MessageModel.sent_invitation(selected))
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): quarter = SettingModel.quarter() year = SettingModel.year() user = users.get_current_user() selector = StudentModel.get_student_by_email(quarter, year, user.email()) if not selector: return self.redirect('/partner') # use selector info to find students in same lab section selectees = StudentModel.get_students_by_lab(quarter, year, selector.lab) current_assignment = AssignmentModel.get_active_assign_with_latest_fade_in_date(quarter, year) # if there are no assignments for this quarter, redirect to avoid errors if not current_assignment: return self.redirect('/partner?message=There are no assignments open for partner selection.') # get error message, if any e = self.request.get('error') # check to see if partner selection period has closed selection_closed = (datetime.now() - timedelta(hours=7) > current_assignment.close_date) # get all current_partnerships for partnership status partnerships = PartnershipModel.get_all_partnerships_for_assign(quarter, year, current_assignment.number) members = [] for p in partnerships: members += p.members partnership = members # build dict to store information about partnership status selectees = sorted({s.ucinetid: (s.key in partnerships,s) for s in selectees}.items(), key=lambda x: x[1][1].last_name) # pass template values... template_values = { 'error': e, 'selector': selector, 'selectees': selectees, 'selection_closed': selection_closed, 'current': current_assignment, 'user': user, 'sign_out': users.create_logout_url('/'), } template = JINJA_ENV.get_template('/templates/partner_browse.html') 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): quarter = SettingModel.quarter() year = SettingModel.year() user = users.get_current_user() student = StudentModel.get_student_by_email(quarter, year, user.email()) selector = StudentModel.get_student_by_email(quarter, year, user.email()) selectees = StudentModel.get_students_by_lab(quarter, year, selector.lab) active_assigns = AssignmentModel.get_active_assigns(quarter, year) # get course config repeat = SettingModel.repeat_partners() cross_section = SettingModel.cross_section_partners() # get default parameter default_assgn = int(self.request.get("assgn")) if self.request.get( "assgn") is not "" else -1 # get all current_partnerships for partnership status partnerships = PartnershipModel.get_all_partnerships_for_assign( quarter, year, default_assgn) partner_history = PartnershipModel.get_all_partner_history_for_student( student, quarter, year) members = [] for p in partner_history: if p.active: members += p.members for p in partnerships: if p.members not in members: members += p.members # build dict to store information about partnership status available = [] for s in selectees: if (s.key not in members) or repeat: available.append((s.ucinetid, (s.key in partnerships, s))) available = sorted(available, key=get_result_priority) av_list = [] for av in available: av_list.append((av[0], get_shared_hours(selector.availability, av[1][1].availability))) # get error message, if any e = self.request.get('error') # check to see if partner selection period has closed selection_closed = len(active_assigns) == 0 template_values = { 'error': e, 'selector': selector, 'selectees': available, 'selection_closed': selection_closed, 'assgn': default_assgn, 'active': active_assigns, 'default_assgn': default_assgn, 'repeat': repeat, 'cross_section': cross_section, 'availability_list': av_list, } template = JINJA_ENV.get_template('/templates/partner_selection.html') self.response.write(template.render(template_values))
def post(self): quarter = SettingModel.quarter() year = SettingModel.year() user = users.get_current_user() # these will only have values if this request is coming from an admin confirming_key = self.request.get('admin_confirming') being_confirmed_key = self.request.get('admin_being_confirmed') if confirming_key == '': confirming_key = 'None' # if not admin... if not confirming_key or not being_confirmed_key: invitation = ndb.Key(urlsafe=self.request.get('confirmed')).get() confirming = StudentModel.get_student_by_email( quarter, year, user.email()) being_confirmed = invitation.invitor.get() for_assign = invitation.assignment_number admin = False else: for_assign = int(self.request.get('assign_num')) being_confirmed = ndb.Key(urlsafe=being_confirmed_key).get() confirming = ndb.Key(urlsafe=confirming_key).get( ) if confirming_key != 'None' else None admin = True partnership = None if not confirming and PartnershipModel.student_has_partner_for_assign( being_confirmed, for_assign): message = MessageModel.already_has_partner(admin) elif not confirming: message = MessageModel.confirm_solo_partnership(being_confirmed) partnership = PartnershipModel.create_partnership( [being_confirmed], for_assign) elif PartnershipModel.student_has_partner_for_assign( being_confirmed, for_assign): message = MessageModel.already_has_partner(admin) # message = '' # partnership = PartnershipModel.get_partnerships_for_students_by_assign([being_confirmed], for_assign) # partnership = PartnershipModel.add_members_to_partnership([confirming], partnership[0]) elif PartnershipModel.student_has_partner_for_assign( confirming, for_assign): message = MessageModel.already_has_partner(admin) else: message = MessageModel.confirm_partnership( [being_confirmed, confirming], admin, confirming) partnership = PartnershipModel.create_partnership( [being_confirmed, confirming], for_assign) # set invitations between invitor and invitee (for current assignment) to inactive if partnership: InvitationModel.deactivate_invitations_for_students_and_assign( confirming, being_confirmed, for_assign) # SendMail(partnership, 'partner_confirm') if not admin: time.sleep(0.1) return self.redirect('/partner?message=' + message) else: time.sleep(0.1) return self.redirect('/admin/partners/add?message=' + message)
def get(self): quarter = SettingModel.quarter() year = SettingModel.year() # get user user = users.get_current_user() # get student from user info evaluator = StudentModel.get_student_by_email(quarter, year, user.email()) # get student's partner history partners = PartnershipModel.get_active_partner_history_for_student( evaluator, quarter, year) # grab the active eval assignments eval_assigns = AssignmentModel.get_active_eval_assigns(quarter, year) # grab partners for eval assignments evaluatees = [] for eval_assign in eval_assigns: for partner in PartnershipModel.get_partner_from_partner_history_by_assign( evaluator, partners, eval_assign.number): evaluatees.append((eval_assign.number, partner)) # filter out No Partner partnerships partners = list( filter(lambda x: x[1] != "No Partner" and x[1] != None, evaluatees)) eval_closed = len(eval_assigns) == 0 # Log when eval page is visited #get 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 if the student visited the page with all evals closed if eval_closed: current_log.log.append(cur_date + " Viewed eval page: ALL EVALS CLOSED") else: #log all open evaluations when student visited the page open_evals = "" for ev in evaluatees: open_evals += ev[1].ucinetid + " assgt. " + str(ev[0]) + " , " current_log.log.append(cur_date + " Viewed eval page: " + open_evals) #save to log current_log.put() rate20scale = ["0 -- Never, completely inadequate", "1", "2", "3", "4"] rate20scale += ["5 -- Seldom, poor quality", "6", "7", "8", "9"] rate20scale += [ "10 -- About half the time, average", "11", "12", "13", "14" ] rate20scale += [ "15 -- Most of the time, good quality", "16", "17", "18", "19" ] rate20scale += ["20 -- Always, excellent"] rate5scale = ['1 - My partner was much more capable than I was'] rate5scale += ['2 - My partner was a little more capable than I was'] rate5scale += ['3 - We were about evenly matched, on average'] rate5scale += ['4 - I was a little more capable than my partner'] rate5scale += ['5 - I was a lot more capable than my partner'] rate10scale = [str(x / 10.0) for x in range(0, 105, 5)] template_values = { 'eval_closed': eval_closed, 'rate_scale': rate20scale, 'rate5scale': rate5scale, 'rate10scale': rate10scale, 'partners': partners, } template = JINJA_ENV.get_template('/templates/partner_eval.html') self.response.write(template.render(template_values))
def get(self): quarter = SettingModel.quarter() year = SettingModel.year() user = users.get_current_user() selector = StudentModel.get_student_by_email(quarter, year, user.email()) student = StudentModel.get_student_by_email(quarter, year, user.email()) repeat = SettingModel.repeat_partners() if not selector: return self.redirect('/partner') # use selector info to find students in same lab section selectees = StudentModel.get_students_by_lab(quarter, year, selector.lab) current_assignment = AssignmentModel.get_active_assign_with_latest_fade_in_date( quarter, year) # if there are no assignments for this quarter, redirect to avoid errors if not current_assignment: return self.redirect( '/partner?message=There are no assignments open for partner selection.' ) # get error message, if any e = self.request.get('error') # check to see if partner selection period has closed selection_closed = (datetime.now() - timedelta(hours=7) > current_assignment.close_date) # get all current_partnerships for partnership status partnerships = PartnershipModel.get_all_partnerships_for_assign( quarter, year, current_assignment.number) partner_history = PartnershipModel.get_all_partner_history_for_student( student, quarter, year) members = [] for p in partner_history: if p.active: members += p.members for p in partnerships: if p.members not in members: members += p.members # build dict to store information about partnership status available = [] for s in selectees: if (s.key not in members) or repeat: available.append((s.ucinetid, (s.key in partnerships, s))) available = sorted(available, key=get_result_priority) # pass template values... template_values = { 'error': e, 'student': student, 'selector': selector, 'selectees': available, 'selection_closed': selection_closed, 'current': current_assignment, 'user': user, 'sign_out': users.create_logout_url('/'), } template = JINJA_ENV.get_template('/templates/partner_browse.html') self.response.write(template.render(template_values))
def get(self): template = JINJA_ENV.get_template( '/templates/partner_invitation_history.html') quarter = SettingModel.quarter() year = SettingModel.year() user = users.get_current_user() student = StudentModel.get_student_by_email(quarter, year, user.email()) # redirect to main page if student doesn't exist if not student: return self.redirect('/partner') invites = InvitationModel.get_all_invitations_involving_student( student).order(Invitation.assignment_number).fetch() current_assignment = AssignmentModel.get_active_assign_with_latest_fade_in_date( quarter, year) # if there are no assignments for this quarter, render early to avoid errors if not current_assignment: return self.response.write( template.render({ 'user': user, 'sign_out': users.create_logout_url('/') })) partners = PartnershipModel.get_active_partner_history_for_student( student, quarter, year) current_partner = PartnershipModel.get_partner_from_partner_history_by_assign( student, partners, current_assignment.number) active_range = set([ a.number for a in AssignmentModel.get_active_assigns(quarter, year) ]) invite_info = {} # dict for custom ordering of invite info fields ordering = { 'Assign Num': 0, 'Who': 1, 'To/From': 2, 'Accepted': 3, 'Active': 4 } for invite in invites: # organize invite info by time i = (invite.created - timedelta(hours=7)).strftime('%m-%d-%Y %H:%M:%S') invite_info[i] = {} invite_info[i]['Assign Num'] = invite.assignment_number # determine wheather invite was sent or received in relation to the user invite_info[i][ 'To/From'] = 'Sent' if invite.invitor == student.key else 'Received' who_key = invite.invitee if invite_info[i][ 'To/From'] == 'Sent' else invite.invitor who = who_key.get() # add invitor/invitee (depending on 'Sent'/'Received') to invite info invite_info[i]['Who'] = str(who.last_name) + ', ' + str( who.first_name) + ' - ' + str(who.ucinetid) invite_info[i]['Accepted'] = str(invite.accepted) invite_info[i]['Active'] = str(invite.active) invite_info[i]['key'] = invite.key.urlsafe() template_values = { 'invites': sorted(invite_info.items(), reverse=True), 'fields': sorted(ordering.items(), key=lambda x: x[1]), 'user': user, 'sign_out': users.create_logout_url('/'), 'active_range': active_range, } 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 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))