def prepare(self, context={}): from esp.program.controllers.studentclassregmodule import RegistrationTypeController as RTC verbs = RTC.getVisibleRegistrationTypeNames(prog=self.program) regProf = RegistrationProfile.getLastForProgram( get_current_request().user, self.program) timeslots = self.program.getTimeSlots( types=['Class Time Block', 'Compulsory']) classList = ClassSection.prefetch_catalog_data( regProf.preregistered_classes(verbs=verbs)) prevTimeSlot = None blockCount = 0 user = get_current_request().user is_onsite = user.isOnsite(self.program) scrmi = self.program.studentclassregmoduleinfo # Filter out volunteer timeslots timeslots = [ x for x in timeslots if x.event_type.description != 'Volunteer' ] schedule = [] timeslot_dict = {} for sec in classList: # Get the verbs all the time in order for the schedule to show # the student's detailed enrollment status. (Performance hit, I know.) # - Michael P, 6/23/2009 # if scrmi.use_priority: sec.verbs = sec.getRegVerbs(user, allowed_verbs=verbs) sec.verb_names = [v.name for v in sec.verbs] sec.is_enrolled = True if "Enrolled" in sec.verb_names else False # While iterating through the meeting times for a section, # we use this variable to keep track of the first timeslot. # In the section_dict appended to timeslot_dict, # we save whether or not this is the first timeslot for this # section. If it isn't, the student schedule will indicate # this, and will not display the option to remove the # section. This is to prevent students from removing what # they have mistaken to be duplicated classes from their # schedules. first_meeting_time = True for mt in sec.get_meeting_times().order_by('start'): section_dict = { 'section': sec, 'first_meeting_time': first_meeting_time } first_meeting_time = False if mt.id in timeslot_dict: timeslot_dict[mt.id].append(section_dict) else: timeslot_dict[mt.id] = [section_dict] for i in range(len(timeslots)): timeslot = timeslots[i] daybreak = False if prevTimeSlot != None: if not Event.contiguous(prevTimeSlot, timeslot): blockCount += 1 daybreak = True if timeslot.id in timeslot_dict: cls_list = timeslot_dict[timeslot.id] doesnt_have_enrollment = not any(sec['section'].is_enrolled for sec in cls_list) schedule.append((timeslot, cls_list, blockCount + 1, doesnt_have_enrollment)) else: schedule.append((timeslot, [], blockCount + 1, False)) prevTimeSlot = timeslot context['num_classes'] = len(classList) context['timeslots'] = schedule context['use_priority'] = scrmi.use_priority context['allow_removal'] = self.deadline_met('/Removal') return context
def prepare(self, context={}): from esp.program.controllers.studentclassregmodule import RegistrationTypeController as RTC verbs = RTC.getVisibleRegistrationTypeNames(prog=self.program) regProf = RegistrationProfile.getLastForProgram( get_current_request().user, self.program) timeslots = self.program.getTimeSlotList(exclude_compulsory=False) classList = ClassSection.prefetch_catalog_data( regProf.preregistered_classes(verbs=verbs)) prevTimeSlot = None blockCount = 0 if not isinstance(get_current_request().user, ESPUser): user = ESPUser(get_current_request().user) else: user = get_current_request().user is_onsite = user.isOnsite(self.program) scrmi = self.program.getModuleExtension('StudentClassRegModuleInfo') # Hack, to hide the Saturday night timeslots from grades 7-8 if not is_onsite and not user.getGrade() > 8: timeslots = [x for x in timeslots if x.start.hour < 19] # Filter out volunteer timeslots timeslots = [ x for x in timeslots if x.event_type.description != 'Volunteer' ] schedule = [] timeslot_dict = {} for sec in classList: # TODO: Fix this bit (it was broken, and may need additional queries # or a parameter added to ClassRegModuleInfo). show_changeslot = False # Get the verbs all the time in order for the schedule to show # the student's detailed enrollment status. (Performance hit, I know.) # - Michael P, 6/23/2009 # if scrmi.use_priority: sec.verbs = sec.getRegVerbs(user, allowed_verbs=verbs) for mt in sec.get_meeting_times(): section_dict = {'section': sec, 'changeable': show_changeslot} if mt.id in timeslot_dict: timeslot_dict[mt.id].append(section_dict) else: timeslot_dict[mt.id] = [section_dict] user_priority = user.getRegistrationPriorities( self.program, [t.id for t in timeslots]) for i in range(len(timeslots)): timeslot = timeslots[i] daybreak = False if prevTimeSlot != None: if not Event.contiguous(prevTimeSlot, timeslot): blockCount += 1 daybreak = True if timeslot.id in timeslot_dict: cls_list = timeslot_dict[timeslot.id] schedule.append( (timeslot, cls_list, blockCount + 1, user_priority[i])) else: schedule.append( (timeslot, [], blockCount + 1, user_priority[i])) prevTimeSlot = timeslot context['num_classes'] = len(classList) context['timeslots'] = schedule context['use_priority'] = scrmi.use_priority context['allow_removal'] = self.deadline_met('/Removal') return context
def studentreg2phase(self, request, tl, one, two, module, extra, prog): """ Serves the two-phase student reg page. This page includes instructions for registration, and links to the phase1/phase2 sub-pages. """ context = {} timeslot_dict = {} # Populate the timeslot dictionary with the priority to class title # mappings for each timeslot. priority_regs = StudentRegistration.valid_objects().filter( user=request.user, relationship__name__startswith='Priority') priority_regs = priority_regs.select_related('relationship', 'section', 'section__parent_class') for student_reg in priority_regs: rel = student_reg.relationship title = student_reg.section.parent_class.title sec = student_reg.section times = sec.meeting_times.all().order_by('start') if times.count() == 0: continue timeslot = times[0].id if not timeslot in timeslot_dict: timeslot_dict[timeslot] = {rel: title} else: timeslot_dict[timeslot][rel] = title star_counts = {} interests = StudentSubjectInterest.valid_objects().filter( user=request.user, subject__parent_program=prog) interests = interests.select_related('subject').prefetch_related( 'subject__sections__meeting_times') for interest in interests: cls = interest.subject for sec in cls.sections.all(): times = sec.meeting_times.all() if len(times) == 0: continue timeslot = min(times, key=lambda t: t.start).id if not timeslot in star_counts: star_counts[timeslot] = 1 else: star_counts[timeslot] += 1 # Iterate through timeslots and create a list of tuples of information prevTimeSlot = None blockCount = 0 schedule = [] timeslots = prog.getTimeSlots(types=['Class Time Block', 'Compulsory']) context['num_priority'] = prog.priorityLimit() context['num_star'] = Tag.getProgramTag("num_stars", program=prog, default=10) for i in range(len(timeslots)): timeslot = timeslots[i] if prevTimeSlot != None: if not Event.contiguous(prevTimeSlot, timeslot): blockCount += 1 if timeslot.id in timeslot_dict: priority_dict = timeslot_dict[timeslot.id] # (relationship, class_title) -> relationship.name priority_list = sorted(priority_dict.items(), key=lambda item: item[0].name) else: priority_list = [] temp_list = [] for i in range(0, context['num_priority']): if i < len(priority_list): temp_list.append( ("Priority " + str(i + 1), priority_list[i][1])) else: temp_list.append(("Priority " + str(i + 1), "")) priority_list = temp_list star_count = 0 if timeslot.id in star_counts: star_count = star_counts[timeslot.id] schedule.append( (timeslot, priority_list, blockCount + 1, star_count, float(star_count) / context['num_star'] * 100)) prevTimeSlot = timeslot context['timeslots'] = schedule return render_to_response(self.baseDir() + 'studentregtwophase.html', request, context)
def prepare(self, context={}): from esp.program.controllers.studentclassregmodule import RegistrationTypeController as RTC verbs = RTC.getVisibleRegistrationTypeNames(prog=self.program) regProf = RegistrationProfile.getLastForProgram(get_current_request().user, self.program) timeslots = self.program.getTimeSlots(types=['Class Time Block', 'Compulsory']) classList = ClassSection.prefetch_catalog_data(regProf.preregistered_classes(verbs=verbs)) prevTimeSlot = None blockCount = 0 user = get_current_request().user is_onsite = user.isOnsite(self.program) scrmi = self.program.studentclassregmoduleinfo # Filter out volunteer timeslots timeslots = [x for x in timeslots if x.event_type.description != 'Volunteer'] schedule = [] timeslot_dict = {} for sec in classList: # Get the verbs all the time in order for the schedule to show # the student's detailed enrollment status. (Performance hit, I know.) # - Michael P, 6/23/2009 # if scrmi.use_priority: sec.verbs = sec.getRegVerbs(user, allowed_verbs=verbs) sec.verb_names = [v.name for v in sec.verbs] sec.is_enrolled = True if "Enrolled" in sec.verb_names else False # While iterating through the meeting times for a section, # we use this variable to keep track of the first timeslot. # In the section_dict appended to timeslot_dict, # we save whether or not this is the first timeslot for this # section. If it isn't, the student schedule will indicate # this, and will not display the option to remove the # section. This is to prevent students from removing what # they have mistaken to be duplicated classes from their # schedules. first_meeting_time = True for mt in sec.get_meeting_times().order_by('start'): section_dict = {'section': sec, 'first_meeting_time': first_meeting_time} first_meeting_time = False if mt.id in timeslot_dict: timeslot_dict[mt.id].append(section_dict) else: timeslot_dict[mt.id] = [section_dict] for i in range(len(timeslots)): timeslot = timeslots[i] daybreak = False if prevTimeSlot != None: if not Event.contiguous(prevTimeSlot, timeslot): blockCount += 1 daybreak = True if timeslot.id in timeslot_dict: cls_list = timeslot_dict[timeslot.id] doesnt_have_enrollment = not any(sec['section'].is_enrolled for sec in cls_list) schedule.append((timeslot, cls_list, blockCount + 1, doesnt_have_enrollment)) else: schedule.append((timeslot, [], blockCount + 1, False)) prevTimeSlot = timeslot context['num_classes'] = len(classList) context['timeslots'] = schedule context['use_priority'] = scrmi.use_priority context['allow_removal'] = self.deadline_met('/Removal') return context
def studentreg2phase(self, request, tl, one, two, module, extra, prog): """ Serves the two-phase student reg page. This page includes instructions for registration, and links to the phase1/phase2 sub-pages. """ timeslot_dict = {} # Populate the timeslot dictionary with the priority to class title # mappings for each timeslot. priority_regs = StudentRegistration.valid_objects().filter( user=request.user, relationship__name__startswith='Priority') priority_regs = priority_regs.select_related( 'relationship', 'section', 'section__parent_class') for student_reg in priority_regs: rel = student_reg.relationship title = student_reg.section.parent_class.title sec = student_reg.section times = sec.meeting_times.all().order_by('start') if times.count() == 0: continue timeslot = times[0].id if not timeslot in timeslot_dict: timeslot_dict[timeslot] = {rel: title} else: timeslot_dict[timeslot][rel] = title star_counts = {} interests = StudentSubjectInterest.valid_objects().filter( user=request.user, subject__parent_program=prog) interests = interests.select_related( 'subject').prefetch_related('subject__sections__meeting_times') for interest in interests: cls = interest.subject for sec in cls.sections.all(): times = sec.meeting_times.all() if len(times) == 0: continue timeslot = min(times, key=lambda t: t.start).id if not timeslot in star_counts: star_counts[timeslot] = 1 else: star_counts[timeslot] += 1 # Iterate through timeslots and create a list of tuples of information prevTimeSlot = None blockCount = 0 schedule = [] timeslots = prog.getTimeSlots(types=['Class Time Block', 'Compulsory']) for i in range(len(timeslots)): timeslot = timeslots[i] if prevTimeSlot != None: if not Event.contiguous(prevTimeSlot, timeslot): blockCount += 1 if timeslot.id in timeslot_dict: priority_dict = timeslot_dict[timeslot.id] priority_list = sorted(priority_dict.items()) else: priority_list = [] if timeslot.id in star_counts: priority_list.append(( 'Starred', "(%d classes)" % star_counts[timeslot.id])) schedule.append((timeslot, priority_list, blockCount + 1)) prevTimeSlot = timeslot context = {} context['timeslots'] = schedule return render_to_response( self.baseDir()+'studentregtwophase.html', request, context)