How to use the ta.models.TAContract.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 / tests.py View on Github external
tug.config[f] = {'weekly': 1, 'total': 13, 'note': 'somenote'}
        tug.save()
        test_views(self, c, 'ta.views.', ['view_tug', 'edit_tug'], {'course_slug': offering.slug, 'userid': ta.person.userid})

        # admin views
        c.login_user('dzhao')
        test_views(self, c, 'ta.views.', ['all_tugs_admin', 'view_postings'], {})
        post = TAPosting.objects.filter(unit__label='CMPT')[0]
        test_views(self, c, 'ta.views.', ['new_application', 'new_application_manual', 'view_all_applications',
                    'print_all_applications', 'print_all_applications_by_course', 'view_late_applications',
                    'assign_tas', 'all_contracts'],
                {'post_slug': post.slug})
        test_views(self, c, 'ta.views.', ['assign_bus'],
                {'post_slug': post.slug, 'course_slug': offering.slug})

        contr = TAContract.objects.filter(posting=post)[0]
        test_views(self, c, 'ta.views.', ['edit_application', 'view_application', 'preview_offer', 'view_contract',
                                          'edit_contract'],
                   {'post_slug': post.slug, 'userid': contr.application.person.userid})

        # applicant views
        c.login_user(contr.application.person.userid)
        test_views(self, c, 'ta.views.', ['accept_contract'],
                   {'post_slug': post.slug, 'userid': contr.application.person.userid})
github sfu-fas / coursys / ta / views.py View on Github external
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)
github sfu-fas / coursys / coredata / data_migration / cortez_import.py View on Github external
posting = self.create_fake_posting(offering.semester)
        
        # create TAApplication
        apps = TAApplication.objects.filter(posting=posting, person=p)
        if apps:
            app = apps[0]
        else:
            app = TAApplication(posting=posting, person=p)
        
        app.category = self.CATEGORY_MAP[cat]
        app.base_units = app_bu or 0
        app.sin = sin
        app.save()
        
        # create TAContract
        contracts = TAContract.objects.filter(posting=posting, application=app)
        if contracts:
            contract = contracts[0]
        else:
            contract = TAContract(posting=posting, application=app)

        try:
            pos_id = self.positions[posnum]
        except KeyError:
            pos_id = posting.config['accounts'][self.CATEGORY_INDEX[app.category]]
        
        contract.sin = sin
        contract.pay_start = payst or offering.semester.start
        contract.pay_end = payen or offering.semester.end
        contract.appt_category = app.category
        contract.position_number_id = pos_id
        contract.appt = self.INITIAL_MAP[initial]
github sfu-fas / coursys / ta / views.py View on Github external
def edit_contract(request, post_slug, userid):
    posting = get_object_or_404(TAPosting, slug=post_slug, unit__in=request.units)
    if posting.unit not in request.units:
        ForbiddenResponse(request, 'You cannot access this page')
        
    course_choices = [('','---------')] + [(c.id, c.name()) for c in posting.selectable_offerings()]
    position_choices = [(a.id, "%s (%s)" % (a.position_number, a.title)) for a in Account.objects.filter(unit=posting.unit, hidden=False)]
    description_choices = [('', '---------')] + [(d.id, d.description + _lab_or_tutorial(d) ) 
                                for d in CourseDescription.objects.filter(unit=posting.unit, hidden=False)]
    
    #number of course form to populate
    num = 3
    contract = TAContract.objects.filter(posting=posting, application__person__userid=userid)
    if contract.count() > 0:
        contract = contract[0]
        application = contract.application
        cnum = contract.tacourse_set.all().count()
        if cnum > num:
            num = 0
        else:
            num = num - contract.tacourse_set.all().count()
        old_status = contract.get_status_display()
        if contract.status not in ['NEW', 'OPN']:
            # after editing, revert to open
            contract.status = 'OPN'
        editing = True
    else:
        # creating new contract
        contract = TAContract()
github sfu-fas / coursys / ta / views.py View on Github external
unit = "*"
            startsem = "*"
        
        campuspref = ''
        for cp in CampusPreference.objects.filter(app=app):
            if cp.pref == 'PRF':
                campuspref += cp.campus[0].upper()
            elif cp.pref == 'WIL':
                campuspref += cp.campus[0].lower()

        # Get all TAContracts that match this posting and application, then the matching TACourses
        # so we can find out if a course/courses have been assigned to this TA

        assigned_courses = ''
        assigned_bus = ''
        ta_contracts = TAContract.objects.filter(posting=posting, application=app).exclude(status__in=['CAN', 'REJ'])
        if len(ta_contracts) > 0:
            ta_courses = TACourse.objects.filter(contract__in=ta_contracts)
            if len(ta_courses) > 0:
                assigned_courses = ', '.join([tacourse.course.name() for tacourse in ta_courses])
                assigned_bus = sum([t.total_bu for t in ta_courses])

        row = [rank, app.person.sortname(), app.category, app.get_current_program_display(), system_program, status, unit, startsem,
               app.base_units, campuspref, assigned_courses, assigned_bus]
        
        for off in offerings:
            crs = off.course
            if app in course_prefs and crs in course_prefs[app]:
                pref = course_prefs[app][crs]
                row.append(pref.rank)
            else:
                row.append(None)
github sfu-fas / coursys / ta / views.py View on Github external
def _contact_people(posting, statuses):
    """
    The set of people to be contacted with the given statuses in the given posting.
    """
    contracts = TAContract.objects.filter(posting=posting, status__in=statuses).select_related('application__person')
    people = set((c.application.person for c in contracts))
    if '_APPLIC' in statuses:
        # they want applicants
        apps = TAApplication.objects.filter(posting=posting, late=False).select_related('person')
        people |= set((app.person for app in apps))
    if '_LATEAPP' in statuses:
        # they want applicants
        apps = TAApplication.objects.filter(posting=posting, late=True).select_related('person')
        people |= set((app.person for app in apps))
    return people
github sfu-fas / coursys / ta / views.py View on Github external
def accept_contract(request, post_slug, userid, preview=False):
    if not preview and request.user.username != userid:
        return ForbiddenResponse(request, 'You cannot access this page')

    posting = get_object_or_404(TAPosting, slug=post_slug)
    person = get_object_or_404(Person, userid=request.user.username)
    
    contract = TAContract.objects.filter(posting=posting, application__person__userid=userid)
    #  If you have at least one contract for this posting, return the first one that matches.
    if contract.count() > 0:
        contract = contract[0]
        application = TAApplication.objects.get(person__userid=userid, posting=posting)
    #  Otherwise, someone is probably trying to guess/make up a URL, or the contract has been deleted since they
    #  got the URL.
    else:
        return ForbiddenResponse(request)

    courses = TACourse.objects.filter(contract=contract)
    total = contract.total_bu()
    bu = contract.bu()
    
    #this could be refactored used in multiple places
    pp = posting.payperiods()
    pdead = posting.config['deadline']
github sfu-fas / coursys / ta / views.py View on Github external
#Save ranks and BU's
    if request.method == "POST":
        formset = AssignBUFormSet(request.POST)
        if formset.is_valid():
            descr_error = False
            for i in range(len(applicants)):
                #update rank
                applicant = applicants[i]
                applicant.rank = formset[i]['rank'].value()
                applicant.save()
                
                if not applicant.assigned_course: 
                    #create new TACourse if bu field is nonempty
                    if formset[i]['bu'].value() != '' and formset[i]['bu'].value() != '0':
                        #create new TAContract if there isn't one
                        contracts = TAContract.objects.filter(application=applicants[i], posting=posting)
                        if contracts.count() > 0: #count is 1
                            # if we've added to the contract, we've invalidated it. 
                            contract = contracts[0]
                            contract.status = "NEW"
                        else:
                            contract = TAContract(created_by=request.user.username)
                            contract.first_assign(applicants[i], posting)
                        bu = formset[i]['bu'].value()
                        tacourse = TACourse(course=offering, contract=contract, bu=bu)
                        try:
                            tacourse.description = tacourse.default_description()
                        except ValueError:
                            # handle the case where no appropriate default CourseDescription object can be found
                            descr_error = True
                            formset[i]._errors['bu'] = formset[i].error_class(["Can't find a contract description to assign to the contract."])
                        else: