def find_posts_by_perms(user, verb, qsc=None): """ Fetch a list of relevant posts for a given user and verb """ if qsc == None: return UserBit.find_by_anchor_perms(AnnouncementLink, user, verb) else: return UserBit.find_by_anchor_perms(AnnouncementLink, user, verb, qsc=qsc)
def get_visible_announcements(user, limit, tl): verb = GetNode('V/Subscribe') models_to_search = [Entry, AnnouncementLink] results = [] grand_total = 0 overflowed = False for model in models_to_search: result = UserBit.find_by_anchor_perms(model, user, verb).order_by('-timestamp').filter(Q(highlight_expire__gte = datetime.now()) | Q(highlight_expire__isnull = True)) if tl: result = result.filter(section=tl) if limit: overflowed = ((len(result) - limit) > 0) total = len(result) result = result[:limit] else: overflowed = False total = len(result) results += result grand_total += total return {'announcementList': results, 'overflowed': overflowed, 'total': grand_total}
def getSchedule(program, student): accept_node = GetNode('V/Flags/Registration/Accepted') schedule = """ Student schedule for %s: Time | Class | Room""" % student.name() classes = list(UserBit.find_by_anchor_perms(ClassSubject, student, accept_node).filter(parent_program = program)) # now we sort them by time/title classes.sort() for cls in classes: rooms = cls.prettyrooms() if len(rooms) == 0: rooms = 'N/A' else: rooms = ", ".join(rooms) schedule += """ %s|%s|%s""" % (",".join(cls.friendly_times()).ljust(20), cls.title().ljust(25), rooms) return schedule
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})
def registration_redirect(request): """ A view which returns: - A redirect to the currently open registration if exactly one registration is open - A list of open registration links otherwise """ from esp.users.models import ESPUser, UserBit from esp.program.models import Program # Make sure we have an ESPUser user = ESPUser(request.user) # prepare the rendered page so it points them to open student/teacher reg's ctxt = {} userrole = {} regverb = None if user.isStudent(): userrole['name'] = 'Student' userrole['base'] = 'learn' userrole['reg'] = 'studentreg' regverb = GetNode('V/Deadline/Registration/Student/Classes/OneClass') elif user.isTeacher(): userrole['name'] = 'Teacher' userrole['base'] = 'teach' userrole['reg'] = 'teacherreg' regverb = GetNode('V/Deadline/Registration/Teacher/Classes') else: # Default to student registration (this will only show if the program # is found via the 'allowed_student_types' Tag) userrole['name'] = user.getUserTypes()[0] userrole['base'] = 'learn' userrole['reg'] = 'studentreg' ctxt['userrole'] = userrole ctxt['navnode'] = GetNode('Q/Web/myesp') if regverb: progs_userbit = list( UserBit.find_by_anchor_perms(Program, user=user, verb=regverb)) else: progs_userbit = [] progs_tag = list(t.target \ for t in Tag.objects.filter(key = "allowed_student_types").select_related() \ if isinstance(t.target, Program) \ and (set(user.getUserTypes()) & set(t.value.split(",")))) progs = set(progs_userbit + progs_tag) nextreg = UserBit.objects.filter( user__isnull=True, verb=regverb, startdate__gt=datetime.datetime.now()).order_by('startdate') progs = list(progs) # If we have 1 program, automatically redirect to registration for that program. # Most chapters will want this, but it can be disabled by a Tag. if len(progs) == 1 and Tag.getBooleanTag('automatic_registration_redirect', default=True): ctxt['prog'] = progs[0] ctxt['navnode'] = progs[0].anchor return HttpResponseRedirect( u'/%s/%s/%s' % (userrole['base'], progs[0].getUrlBase(), userrole['reg'])) else: if len(progs) > 0: # Sort available programs newest first progs.sort(key=lambda x: -x.id) ctxt['progs'] = progs ctxt['prog'] = progs[0] ctxt['nextreg'] = list(nextreg) return render_to_response('users/profile_complete.html', request, GetNode('Q/Web'), ctxt)