Пример #1
0
    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))
Пример #2
0
    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))
Пример #3
0
    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))
Пример #4
0
    def get(self):
        quarter = SettingModel.quarter()
        year = SettingModel.year()
        user = users.get_current_user()
        student = StudentModel.get_student_by_email(quarter, year,
                                                    user.email())

        active_assigns = AssignmentModel.get_active_assigns(quarter, year)
        invitations = InvitationModel.get_recvd_invites_by_student_and_mult_assigns(
            student, [x.number for x in active_assigns], as_dict=False)

        # check to see if partner selection is still active
        selection_closed = len(active_assigns) == 0

        # pass template values...
        template_values = {
            'student': student,
            'selection_closed': selection_closed,
            'invitations': invitations,
        }
        template = JINJA_ENV.get_template('/templates/partner_confirm.html')
        self.response.write(template.render(template_values))
Пример #5
0
    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))
Пример #6
0
    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))
Пример #7
0
    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))
Пример #8
0
    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))