How to use the ta.models.CoursePreference.objects.filter function in ta

To help you get started, we’ve selected a few ta examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sfu-fas / coursys / ta / views.py View on Github external
val = request.POST.get('campus-'+c, None)
                    if val not in PREFERENCES:
                        val = 'WIL'
                    cp = CampusPreference(app=app, campus=c, pref=val)
                    cp.save()
                
                SkillLevel.objects.filter(app=app).delete()
                for s in skills:
                    val = request.POST.get('skill-'+str(s.position), None)
                    if val not in LEVELS:
                        val = 'NONE'
                    sl = SkillLevel(skill=s, app=app, level=val)
                    sl.save()
                
                # save course preferences: update existing or create new, as needed
                old_pref = set(CoursePreference.objects.filter(app=app))
                used_pref = set()
                for (rank,form) in enumerate(courses_formset):
                    existing_crs = CoursePreference.objects.filter(app=app, course=form.cleaned_data['course'])
                    if existing_crs:
                        course = existing_crs[0]
                        #course.exper = form.cleaned_data['exper']
                        #course.taken = form.cleaned_data['taken']
                    else:
                        course = form.save(commit=False)
                    course.app = app
                    course.rank = rank+1
                    if course.course_id:
                        course.save()
                        used_pref.add(course)
                
                # any removed courses: set to rank=0, but don't delete (since we assume one exists if it has been assigned already)
github sfu-fas / coursys / ta / views.py View on Github external
cp = CampusPreference(app=app, campus=c, pref=val)
                    cp.save()
                
                SkillLevel.objects.filter(app=app).delete()
                for s in skills:
                    val = request.POST.get('skill-'+str(s.position), None)
                    if val not in LEVELS:
                        val = 'NONE'
                    sl = SkillLevel(skill=s, app=app, level=val)
                    sl.save()
                
                # save course preferences: update existing or create new, as needed
                old_pref = set(CoursePreference.objects.filter(app=app))
                used_pref = set()
                for (rank,form) in enumerate(courses_formset):
                    existing_crs = CoursePreference.objects.filter(app=app, course=form.cleaned_data['course'])
                    if existing_crs:
                        course = existing_crs[0]
                        #course.exper = form.cleaned_data['exper']
                        #course.taken = form.cleaned_data['taken']
                    else:
                        course = form.save(commit=False)
                    course.app = app
                    course.rank = rank+1
                    if course.course_id:
                        course.save()
                        used_pref.add(course)
                
                # any removed courses: set to rank=0, but don't delete (since we assume one exists if it has been assigned already)
                for course in old_pref - used_pref:
                    course.rank = 0
                    course.save()
github sfu-fas / coursys / ta / models.py View on Github external
def applicant_count(self, offering):
        """
        Number of people who have applied to TA this offering
        """
        prefs = CoursePreference.objects.filter(app__posting=self, app__late=False, course=offering.course).exclude(rank=0)
        return prefs.count()
github sfu-fas / coursys / ta / views.py View on Github external
def print_all_applications_by_course(request,post_slug):
    posting = get_object_or_404(TAPosting, slug=post_slug, unit__in=request.units)
    
    all_offerings = CourseOffering.objects.filter(semester=posting.semester, owner=posting.unit).select_related('course')
    excl = set(posting.excluded())
    offerings = [o for o in all_offerings if o.course_id not in excl]
    
    # collect all course preferences in a sensible way
    prefs = CoursePreference.objects.filter(app__posting=posting).exclude(rank=0).order_by('app__person').select_related('app', 'course')
    
    for offering in offerings: 
        offering.applications = []
        applications_for_this_offering = [pref.app for pref in prefs if 
            (pref.course.number == offering.course.number and pref.course.subject == offering.course.subject)]
        for application in applications_for_this_offering:
            if not hasattr(application, 'extra_data_done'):
                application.courses = CoursePreference.objects.filter(app=application).exclude(rank=0).order_by('rank')
                application.skills = SkillLevel.objects.filter(app=application).select_related('skill')
                application.campuses = CampusPreference.objects.filter(app=application)
                application.contracts = TAContract.objects.filter(application=application)
                application.previous_experience = TACourse.objects.filter(contract__application__person=application.person) \
                    .exclude(contract__application=application).select_related('course__semester')
                application.grad_programs = GradStudent.objects \
                     .filter(program__unit__in=request.units, person=application.person)
                application.extra_data_done = True
github sfu-fas / coursys / ta / views.py View on Github external
return ForbiddenResponse(request)

    course_choices = [(c.id, str(c) + " (" + c.title + ")") for c in posting.selectable_courses()]
    course_choices = [(None, '\u2014')] + course_choices
    used_campuses = set((vals['campus'] for vals in posting.selectable_offerings().order_by('campus').values('campus').distinct()))
    skills = Skill.objects.filter(posting=posting)    
    max_courses = posting.max_courses()
    min_courses = posting.min_courses()
    CoursesFormSet = formset_factory(CoursePreferenceForm, min_num=max_courses, max_num=max_courses)

    sin = None
    # build basic objects, whether new or editing application
    if editing:
        person = Person.objects.get(userid=userid)
        application = get_object_or_404(TAApplication, posting=posting, person__userid=userid)
        old_coursepref = CoursePreference.objects.filter(app=application).exclude(rank=0).order_by('rank')
    else:
        application = None
    
    if not manual:
        """
        Don't change the person in the case of a TA Admin editing, as we don't want to save this application as the
        Admin's, but as the original user's.
        """
        if not is_ta_admin:
            try:
                person = ensure_person_from_userid(request.user.username)
            except SIMSProblem:
                return HttpError(request, status=503, title="Service Unavailable", error="Currently unable to handle the request.", errormsg="Problem with SIMS connection while trying to find your account info")

        if not person:
            return NotFoundResponse(request, "Unable to find your computing account in the system: this is likely because your account was recently activated, and it should be fixed tomorrow. If not, email %s." % (help_email(request),))
github sfu-fas / coursys / ta / views.py View on Github external
course = request.POST['course']
                co = get_object_or_404(CourseOffering, pk=course)
                req_bu = posting.required_bu(co)
                assigned_bu = posting.assigned_bu(co)
                #subtracting assigned_bu from req_bu
                if(assigned_bu > req_bu):
                    req_bu = 0.0
                else:
                    req_bu -= assigned_bu
                return HttpResponse(str(req_bu))
        elif form.is_valid():
            contract = form.save(commit=False)
            formset = TACourseFormset(request.POST, instance=contract)
            if formset.is_valid():
                #If course isn't in applicants prefered courses, add it with rank 0
                course_prefs = [c.course for c in CoursePreference.objects.filter(app=application)]
                for form in formset:
                    if 'course' not in form.cleaned_data:
                        continue
                    offering = form.cleaned_data['course']
                    if offering.course not in course_prefs:
                        new_course_pref = CoursePreference(app=application, course=offering.course, taken='YES', exper='FAM', rank=0)
                        new_course_pref.save()

                contract.application = application
                contract.posting = posting
                contract.created_by = request.user.username
                
                #create news item
                # if contract.status == "OPN":
                person = application.person
github sfu-fas / coursys / ta / views.py View on Github external
posting = get_object_or_404(TAPosting, slug=post_slug, unit__in=request.units)
    
    all_offerings = CourseOffering.objects.filter(semester=posting.semester, owner=posting.unit).select_related('course')
    excl = set(posting.excluded())
    offerings = [o for o in all_offerings if o.course_id not in excl]
    
    # collect all course preferences in a sensible way
    prefs = CoursePreference.objects.filter(app__posting=posting).exclude(rank=0).order_by('app__person').select_related('app', 'course')
    
    for offering in offerings: 
        offering.applications = []
        applications_for_this_offering = [pref.app for pref in prefs if 
            (pref.course.number == offering.course.number and pref.course.subject == offering.course.subject)]
        for application in applications_for_this_offering:
            if not hasattr(application, 'extra_data_done'):
                application.courses = CoursePreference.objects.filter(app=application).exclude(rank=0).order_by('rank')
                application.skills = SkillLevel.objects.filter(app=application).select_related('skill')
                application.campuses = CampusPreference.objects.filter(app=application)
                application.contracts = TAContract.objects.filter(application=application)
                application.previous_experience = TACourse.objects.filter(contract__application__person=application.person) \
                    .exclude(contract__application=application).select_related('course__semester')
                application.grad_programs = GradStudent.objects \
                     .filter(program__unit__in=request.units, person=application.person)
                application.extra_data_done = True

            offering.applications.append(application)

    context = {
            'offerings': offerings,
            'posting': posting,
            }
    return render(request, 'ta/print_all_applications_by_course.html', context)