Пример #1
0
def myesp_onsite(request, module):
	
	user = ESPUser(request.user)
	if not user.isOnsite():
		raise ESPError(False), 'You are not a valid on-site user, please go away.'
	verb = GetNode('V/Registration/OnSite')
	
	progs = UserBit.find_by_anchor_perms(Program, user = user, verb = verb)

        # Order them decreasing by id
        # - Currently reverse the list in Python, otherwise fbap's cache is ignored
        # TODO: Fix this
        progs = list(progs)
        progs.reverse()

	if len(progs) == 1:
		return HttpResponseRedirect('/onsite/%s/main' % progs[0].getUrlBase())
	else:
		navnode = GetNode('Q/Web/myesp')
		return render_to_response('program/pickonsite.html', request, navnode, {'progs': progs})
Пример #2
0
    def changeslot(self, request, tl, one, two, module, extra, prog):
        """ Display the page to swap a class. Options have either the same name or same timeslot. """
        from esp.cal.models import Event

        user = ESPUser(request.user)
        prereg_url = self.program.get_learn_url() + 'swapclass/' + extra
        user_grade = user.getGrade(self.program)
        is_onsite = user.isOnsite(self.program)

        try:
            extra = int(extra)
        except:
            raise ESPError(
                False), 'Please use the link at the main registration page.'
        ts = Event.objects.filter(id=extra)
        if len(ts) < 1:
            raise Http404()

        ts = ts[0]

        # Determining the old class, if any.
        v_registered = request.get_node('V/Flags/Registration/Preliminary')
        oldclasses = ClassSubject.objects.filter(
            parent_program=self.program,
            anchor__userbit_qsc__verb=v_registered,
            anchor__userbit_qsc__user=request.user).distinct()
        oldclasses = filter(lambda x: ts in x.all_meeting_times, oldclasses)
        # If there isn't a class to replace, let's silently switch over to regular adding of classes.
        if len(oldclasses) < 1:
            return self.fillslot(request, tl, one, two, module, extra, prog)
        # If there's more than one to replace, we don't know how to handle that.
        if len(oldclasses) > 1:
            raise ESPError(
                False
            ), 'Sorry, our website doesn\'t know which class in that time slot you want to change! You\'ll have to go back and do it yourself by clearing the time slot first.'
        # Still here? Okay, continue...
        oldclass = oldclasses[0]

        # .objects.catalog() uses .extra() to select all the category text simultaneously
        # The "friendly_name bit" is to test for classes with the same title without having to call c.title()

        class_qset = ClassSubject.objects.catalog(self.program).filter(
            DjangoQ(meeting_times=ts)
            | DjangoQ(anchor__friendly_name=oldclass.title())
        )  # same time or same title

        class_qset = class_qset.filter(
            grade_min__lte=user_grade,
            grade_max__gte=user_grade)  # filter within grade limits
        classes = [c for c in class_qset if (not c.isFull()) or is_onsite
                   ]  # show only viable classes

        categories = {}

        for cls in classes:
            categories[cls.parent_category.category_id] = {
                'id':
                cls.parent_class.category_id,
                'category':
                cls.category_txt if hasattr(cls, 'category_txt') else
                cls.parent_class.category.category
            }

        return render_to_response(
            self.baseDir() + 'changeslot.html', request, (prog, tl), {
                'classes': classes,
                'oldclass': oldclass,
                'one': one,
                'two': two,
                'categories': categories.values(),
                'timeslot': ts,
                'prereg_url': prereg_url
            })
Пример #3
0
    def fillslot(self, request, tl, one, two, module, extra, prog):
        """ Display the page to fill the timeslot for a program """
        from esp.cal.models import Event

        try:
            extra = int(extra)
        except:
            raise ESPError(
                False), 'Please use the link at the main registration page.'
        user = ESPUser(request.user)
        ts = Event.objects.filter(id=extra)
        if len(ts) < 1:
            raise Http404()

        ts = ts[0]

        prereg_url = self.program.get_learn_url() + 'addclass/'
        user_grade = user.getGrade(self.program)
        user.updateOnsite(request)
        is_onsite = user.isOnsite(self.program)

        #   Override both grade limits and size limits during onsite registration
        if is_onsite and not request.GET.has_key('filter'):
            classes = list(ClassSubject.objects.catalog(self.program, ts))
        else:
            classes = filter(
                lambda c: c.grade_min <= user_grade and c.grade_max
                >= user_grade,
                list(ClassSubject.objects.catalog(self.program, ts)))
            if Tag.getBooleanTag('hide_full_classes', prog, default=False):
                classes = filter(
                    lambda c: not c.isFull(timeslot=ts, ignore_changes=True),
                    classes)
            if user_grade != 0:
                classes = filter(
                    lambda c: c.grade_min <= user_grade and c.grade_max >=
                    user_grade, classes)
            classes = filter(lambda c: not c.isRegClosed(), classes)

        #   Sort class list
        classes = sorted(classes,
                         key=lambda cls: cls.num_students() - cls.capacity)
        classes = sorted(classes, key=lambda cls: cls.category.category)

        categories = {}

        for cls in classes:
            categories[cls.category_id] = {
                'id':
                cls.category_id,
                'category':
                cls.category_txt
                if hasattr(cls, 'category_txt') else cls.category.category
            }

        return render_to_response(
            self.baseDir() + 'fillslot.html', request, (prog, tl), {
                'classes': classes,
                'one': one,
                'two': two,
                'categories': categories.values(),
                'timeslot': ts,
                'prereg_url': prereg_url
            })
Пример #4
0
    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
Пример #5
0
def get_primary_nav(context):
    try:
        user = context['user']
    except KeyError:
        user = AnonymousUser()

    try:
        request = context['request']
    except KeyError:
        return {}

    path = request.path
    
    path_list = path.strip('/').split('/')
    
    if path_list[0] not in known_navlinks:
        return {}

    page_setup = {}
    curuser = ESPUser(user)
    
    is_admin = curuser.isAdmin()
    
    is_onsite = curuser.isOnsite()

    if is_onsite and is_admin:
        cache_key = 'NAVBAR__%s' % urlencode(path)
    else:
        cache_key = None

    try:
        retVal = cache.get(cache_key)
    except:
        retVal = None

    if retVal and cache_key:
        return {'page_setup': retVal,
                'user':       curuser}
    
    
    # if we are at a level 2 site, like /myesp/home/
    if len(path_list) == 2 and path.lower() in [ x[2] for x in sections.values() ]:
        page_setup['navlinks'] = []
        page_setup['buttonlocation'] = 'lev2'
        page_setup['stylesheet']     = [ x for x in basic_navlinks if sections[x][0] == path_list[0]][0]+'2'
        for section in basic_navlinks:
            page_setup['navlinks'].append({'id'       : section,
                                           'alt'      : sections[section][1],
                                           'highlight': path.lower() == sections[section][2],
                                           'href'     : sections[section][2]})
            if path.lower() == sections[section][2]:
                page_setup['section'] = {'id': section+'/lev2', 'alt': sections[section][1]}
                context['page_section'] = page_setup['section']
        if is_admin:
            section = 'admin'
            page_setup['navlinks'].append({'id'       : section,
                                           'alt'      : sections[section][1],
                                           'highlight': path.lower() == sections[section][2],
                                           'href'     : sections[section][2]})
        if is_onsite:
            section = 'onsite'
            page_setup['navlinks'].append({'id'       : section,
                                           'alt'      : sections[section][1],
                                           'highlight': path.lower() == sections[section][2],
                                           'href'     : sections[section][2]})
        if cache_key:
            cache.set(cache_key, page_setup, 99999)
            
        return {'page_setup': page_setup,
                'user':       curuser}
    
    # this is now level 3
    elif path_list[0] in [ x[0] for x in sections.values() ]:
        page_setup['navlinks'] = []
        page_setup['stylesheet'] = [ x for x in basic_navlinks if sections[x][0] == path_list[0]][0]+'3'

        for section in basic_navlinks:
            if path_list[0] == sections[section][0] and sections[section][4]:
                
                page_setup['section'] = {'id': section+'/lev3',
                                         'alt': sections[section][1],
                                         'cursection': section}
                context['page_section'] = page_setup['section']
                current_section = section
                
        for section in basic_navlinks:
            if path_list[0] == sections[section][0]:
                curbuttonloc = 'lev3'
            elif section in sections[current_section][3]:
                curbuttonloc = current_section + '/lev3'
            else:
                curbuttonloc = 'lev3'
                
            page_setup['navlinks'].append({'id'       : section,
                                           'alt'      : sections[section][1],
                                           'highlight': path_list[0] == sections[section][0] and sections[section][4],
                                           'href'     : sections[section][2],
                                           'buttonloc': curbuttonloc})
            

        if is_admin:
            section = 'admin'
            page_setup['navlinks'].append({'id'       : section,
                                           'alt'      : sections[section][1],
                                           'highlight': False,
                                           'href'     : sections[section][2],
                                           'buttonloc': 'lev2'})
        if is_onsite:
            section = 'onsite'
            page_setup['navlinks'].append({'id'       : section,
                                           'alt'      : sections[section][1],
                                           'highlight': False,
                                           'href'     : sections[section][2],
                                           'buttonloc': 'lev2'})

        if cache_key:
            cache.set(cache_key, page_setup, 99999)
            
        return {'page_setup': page_setup,
                'user':       curuser}

    return {'user': curuser}
Пример #6
0
    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

        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:
            #   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]

        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