def ensure_member(person, offering, role, cred, added_reason, career, labtut_section=None, grade=None, sched_print_instr=None): """ Make sure this member exists with the right properties. """ if person.emplid in [200133427, 200133425, 200133426]: # these are: ["Faculty", "Tba", "Sessional"]. Ignore them: they're ugly. return m_old = Member.objects.filter(person=person, offering=offering) if len(m_old) > 1: # may be other manually-created dropped entries: that's okay. m_old = Member.objects.filter(person=person, offering=offering).exclude(role="DROP") if len(m_old) > 1: raise KeyError("Already duplicate entries: %r" % (m_old)) elif len(m_old) == 0: m_old = Member.objects.filter(person=person, offering=offering) if len(m_old) >= 1: m = m_old[0] else: m = Member(person=person, offering=offering) m.role = role m.labtut_section = labtut_section m.credits = cred m.added_reason = added_reason m.career = career # record official grade if we have it (and might need it) if has_letter_activities(m.offering): m.official_grade = grade or None else: m.official_grade = None # record sched_print_instr status for instructors if role == 'INST' and sched_print_instr: m.config['sched_print_instr'] = sched_print_instr == 'Y' # if offering is being given lab/tutorial sections, flag it as having them # there must be some way to detect this in ps_class_tbl, but I can't see it. if labtut_section and not offering.labtut(): offering.set_labtut(True) offering.save_if_dirty() m.save_if_dirty() return m
def ensure_member(person, offering, role, cred, added_reason, career, labtut_section=None, grade=None, sched_print_instr=None): """ Make sure this member exists with the right properties. """ if person.emplid in [200133427, 200133425, 200133426]: # these are: ["Faculty", "Tba", "Sessional"]. Ignore them: they're ugly. return m_old = Member.objects.filter(person=person, offering=offering) if len(m_old)>1: # may be other manually-created dropped entries: that's okay. m_old = Member.objects.filter(person=person, offering=offering).exclude(role="DROP") if len(m_old)>1: raise KeyError("Already duplicate entries: %r" % (m_old)) elif len(m_old)==0: m_old = Member.objects.filter(person=person, offering=offering) if len(m_old)>=1: m = m_old[0] else: m = Member(person=person, offering=offering) m.role = role m.labtut_section = labtut_section m.credits = cred m.added_reason = added_reason m.career = career # record official grade if we have it (and might need it) if has_letter_activities(m.offering): m.official_grade = grade or None else: m.official_grade = None # record sched_print_instr status for instructors if role=='INST' and sched_print_instr: m.config['sched_print_instr'] = sched_print_instr == 'Y' # if offering is being given lab/tutorial sections, flag it as having them # there must be some way to detect this in ps_class_tbl, but I can't see it. if labtut_section and not offering.labtut(): offering.set_labtut(True) offering.save_if_dirty() m.save_if_dirty() return m
def add_membership_for(tacrs, reason, memberships): if not tacrs.contract.should_be_added_to_the_course or tacrs.total_bu <= 0: return # Find existing membership for this person+offering if it exists # (Behaviour here implies you can't be both TA and other role in one offering: I'm okay with that.) for m in memberships: if m.person == person and m.offering == tacrs.course: break else: # there was no membership: create m = Member(person=person, offering=tacrs.course) memberships.append(m) m.role = 'TA' m.credits = 0 m.career = 'NONS' m.added_reason = reason m.config['bu'] = str(tacrs.total_bu)
def save(self, *args, **kwargs): super(TAContract, self).save(*args, **kwargs) # set SIN field on any GradStudent objects for this person from grad.models import GradStudent for gs in GradStudent.objects.filter(person=self.application.person): dummy_sins = ['999999999', '000000000', '123456789'] if (('sin' not in gs.config or ('sin' in gs.config and gs.config['sin'] in dummy_sins)) and not self.sin in dummy_sins ): gs.person.set_sin(self.sin) gs.person.save() # if signed, create the Member objects so they have access to the courses. courses = TACourse.objects.filter(contract=self) for crs in courses: members = Member.objects.filter(person=self.application.person, offering=crs.course).exclude(role='DROP') # assert( len(members) <= 1 ) dropped_members = Member.objects.filter(person=self.application.person, offering=crs.course, role='DROP') # Should Member just have an optional FK to TACourse rather than getting a copy of the BU? if (self.status in ['SGN', 'ACC'] and crs.bu > 0) and not members: if dropped_members: m = dropped_members[0] # if this student was added/dropped by the prof, then added_reason might not be CTA m.added_reason='CTA' m.role = "TA" else: # signed, but not a member: create m = Member(person=self.application.person, offering=crs.course, role='TA', added_reason='CTA', credits=0, career='NONS') m.config['bu'] = crs.total_bu m.save() elif (self.status in ['SGN', 'ACC'] and crs.bu > 0 ) and members: # change in BU -> change in BU for Member m = members[0] if not 'bu' in m.config or m.config['bu'] != crs.total_bu: # if this student was added by the prof, then added_reason might not be CTA m.config['bu'] = crs.total_bu m.added_reason='CTA' m.save() elif ( (not self.status in ['SGN', 'ACC']) or crs.bu == 0) and members: # already in course, but status isn't signed: remove m = members[0] if m.role == 'TA' and m.added_reason == 'CTA': m.role = 'DROP' m.save() else: # (self.status not in ['SGN', 'ACC'] or crs.bu == 0) and not members # there is no contract and this student doesn't exist as a Member in the course pass if self.status in ('CAN', 'REJ'): # These students should be removed from their courses. crs.bu = 0 crs.save() # If this course has 0 BUs and a course Member record, clear that record. if crs.bu == 0 and members: m = members[0] if m.role == 'TA' and m.added_reason == 'CTA': m.role = 'DROP' m.save() # If they are CTA-added members of any other course this semester, they probably shouldn't be members = Member.objects.filter(person=self.application.person, role='TA', added_reason='CTA', offering__semester=self.posting.semester ) courseofferings = [crs.course for crs in courses if crs.bu > 0] for member in members: if member.offering not in courseofferings: member.role = 'DROP' member.save()
def sync_course_member(self): """ Once a contract is Signed, we should create a Member object for them. If a contract is Cancelled, we should DROP the Member object. This operation should be idempotent - run it as many times as you want, the result should always be the same. """ # if signed, create the Member objects so they have access to the courses. courses = self.course.all() for crs in courses: members = Member.objects.filter(person=self.person, role='TA', offering=crs.course) # the student should either be in the course (1) or not (0) # any other number of responses is unacceptable. assert (len(members) == 1 or len(members) == 0) dropped_members = Member.objects.filter(person=self.person, offering=crs.course, role='DROP') assert (len(dropped_members) == 1 or len(dropped_members) == 0) # this shouldn't be. if members and dropped_members: d = dropped_members[0] d.delete() dropped_members = [] # the student must be in one of these three states exists_and_is_in_the_course = len(members) > 0 exists_and_is_dropped = len(dropped_members) > 0 does_not_exist = len(members) == 0 and len(dropped_members) == 0 assert (exists_and_is_in_the_course or exists_and_is_dropped or does_not_exist) assert (not (exists_and_is_in_the_course and exists_and_is_dropped)) assert (not (exists_and_is_dropped and does_not_exist)) assert (not (exists_and_is_in_the_course and does_not_exist)) assert (len(dropped_members) < 2) assert (len(members) < 2) if self.should_be_added_to_the_course: if exists_and_is_dropped: m = dropped_members[0] elif exists_and_is_in_the_course: m = members[0] elif does_not_exist: m = Member(person=self.person, offering=crs.course, role='TA', added_reason='TAC', credits=0, career='NONS') else: assert (False) m.added_reason = 'TAC' m.role = 'TA' m.config['bu'] = crs.total_bu m.save() crs.member = m crs.save(always_allow=True) else: if exists_and_is_dropped: pass elif exists_and_is_in_the_course: m = members[0] if m.added_reason == 'TAC': m.role = 'DROP' m.save() crs.member = None crs.save(always_allow=True) elif does_not_exist: pass # If they are TAC-added members of any other course this semester, # they probably shouldn't be. members = Member.objects.filter( person=self.person, role='TA', added_reason='TAC', offering__semester=self.category.hiring_semester.semester) courseofferings = [crs.course for crs in courses] for member in members: if member.offering not in courseofferings: member.role = 'DROP' member.save()
def sync_course_member(self): """ Once a contract is Signed, we should create a Member object for them. If a contract is Cancelled, we should DROP the Member object. This operation should be idempotent - run it as many times as you want, the result should always be the same. """ # if signed, create the Member objects so they have access to the courses. courses = self.course.all() for crs in courses: members = Member.objects.filter(person=self.person, role='TA', offering=crs.course) # the student should either be in the course (1) or not (0) # any other number of responses is unacceptable. assert( len(members) == 1 or len(members) == 0 ) dropped_members = Member.objects.filter(person=self.person, offering=crs.course, role='DROP') assert( len(dropped_members) == 1 or len(dropped_members) == 0) # this shouldn't be. if members and dropped_members: d = dropped_members[0] d.delete() dropped_members = [] # the student must be in one of these three states exists_and_is_in_the_course = len(members) > 0 exists_and_is_dropped = len(dropped_members) > 0 does_not_exist = len(members) == 0 and len(dropped_members) == 0 assert(exists_and_is_in_the_course or exists_and_is_dropped or does_not_exist) assert(not(exists_and_is_in_the_course and exists_and_is_dropped)) assert(not(exists_and_is_dropped and does_not_exist)) assert(not(exists_and_is_in_the_course and does_not_exist)) assert(len(dropped_members) < 2) assert(len(members) < 2) if self.should_be_added_to_the_course: if exists_and_is_dropped: m = dropped_members[0] elif exists_and_is_in_the_course: m = members[0] elif does_not_exist: m = Member(person=self.person, offering=crs.course, role='TA', added_reason='TAC', credits=0, career='NONS') else: assert(False) m.added_reason='TAC' m.role = 'TA' m.config['bu'] = crs.total_bu m.save() crs.member = m crs.save(always_allow=True) else: if exists_and_is_dropped: pass elif exists_and_is_in_the_course: m = members[0] if m.added_reason == 'TAC': m.role = 'DROP' m.save() crs.member = None crs.save(always_allow=True) elif does_not_exist: pass # If they are TAC-added members of any other course this semester, # they probably shouldn't be. members = Member.objects.filter(person=self.person, role='TA', added_reason='TAC', offering__semester=self.category.hiring_semester.semester) courseofferings = [crs.course for crs in courses] for member in members: if member.offering not in courseofferings: member.role = 'DROP' member.save()