How to use the ta.models.Skill.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 / coredata / data_migration / cortez_import.py View on Github external
continue
            subj, num = course.split()
            courses = Course.objects.filter(subject=subj, number=num)
            if courses.count() > 1:
                raise "Multiple Courses found for %r" % (course)
            elif courses.count() == 1:
                crs = courses[0]
                CoursePreference.objects.get_or_create(app=app, course=crs, rank=rank+1)

        # skills
        self.db.execute("SELECT skillType, skillLevel FROM tasearch.dbo.taskills "
                        "WHERE appId=%s", (appid,))
        for skillname, level in self.db:
            if not skillname:
                continue
            skills = Skill.objects.filter(posting=posting, name=skillname)
            if skills:
                skill = skills[0]
            else:
                maxpos = Skill.objects.filter(posting=posting).aggregate(max_pos=Max('position'))['max_pos']
                if maxpos:
                    pos = maxpos+1
                else:
                    pos = 1
                skill = Skill(posting=posting, name=skillname, position=pos)
                skill.save()
            
            lvls = SkillLevel.objects.filter(skill=skill, app=app)
            if lvls:
                lvl = lvls[0]
            else:
                lvl = SkillLevel(skill=skill, app=app)
github sfu-fas / coursys / ta / forms.py View on Github external
def clean_skills(self):
        skills = self.cleaned_data['skills']
        skills = [s.strip() for s in skills.split("\n") if len(s.strip()) > 0]
        old_skills = Skill.objects.filter(posting=self.instance)
        res = []
        for i, skill in enumerate(skills):
            if len(old_skills) < i+1:
                # nothing existing
                new = Skill(posting=self.instance, name=skill, position=i)
                res.append(new)
            else:
                # update old
                old = old_skills[i]
                old.name = skill
                res.append(old)
        return res
github sfu-fas / coursys / ta / views.py View on Github external
is_ta_admin = False
    
    if editing:
        if userid == request.user.username and posting.is_open():
            # can edit own application until closes
            pass
        elif has_role('TAAD', request) and posting.unit in request.units:
            is_ta_admin = True
            pass
        else:
            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
github sfu-fas / coursys / coredata / data_migration / cortez_import.py View on Github external
raise "Multiple Courses found for %r" % (course)
            elif courses.count() == 1:
                crs = courses[0]
                CoursePreference.objects.get_or_create(app=app, course=crs, rank=rank+1)

        # skills
        self.db.execute("SELECT skillType, skillLevel FROM tasearch.dbo.taskills "
                        "WHERE appId=%s", (appid,))
        for skillname, level in self.db:
            if not skillname:
                continue
            skills = Skill.objects.filter(posting=posting, name=skillname)
            if skills:
                skill = skills[0]
            else:
                maxpos = Skill.objects.filter(posting=posting).aggregate(max_pos=Max('position'))['max_pos']
                if maxpos:
                    pos = maxpos+1
                else:
                    pos = 1
                skill = Skill(posting=posting, name=skillname, position=pos)
                skill.save()
            
            lvls = SkillLevel.objects.filter(skill=skill, app=app)
            if lvls:
                lvl = lvls[0]
            else:
                lvl = SkillLevel(skill=skill, app=app)
            
            lvl.level = self.SKILL_LEVEL_MAP[level]
            lvl.save()
github sfu-fas / coursys / ta / views.py View on Github external
form.fields['contact'].choices = contact_choices
        for f in form.fields['accounts'].fields:
            f.choices = account_choices
        for w in form.fields['accounts'].widget.widgets:
            w.choices = account_choices
        if form.is_valid():
            form.instance.slug = None
            form.save()
            found_skills = set()
            for s in form.cleaned_data['skills']:
                s.posting = form.instance
                s.save()
                found_skills.add(s.id)
            
            # if any skills were dropped, remove them
            Skill.objects.filter(posting=form.instance).exclude(id__in=found_skills).delete()
            
            l = LogEntry(userid=request.user.username,
                  description="Edited TAPosting for %s in %s." % (form.instance.unit, form.instance.semester),
                  related_object=form.instance)
            l.save()
            if editing:
                messages.success(request, "Edited TA posting for %s in %s." % (form.instance.unit, form.instance.semester))
            else:
                messages.success(request, "Created TA posting for %s in %s." % (form.instance.unit, form.instance.semester))
            return HttpResponseRedirect(reverse('ta:view_postings', kwargs={}))
    else:
        form = TAPostingForm(instance=posting)
        form.fields['unit'].choices = unit_choices
        form.fields['semester'].choices = semester_choices
        form.fields['excluded'].choices = excluded_choices
        form.fields['contact'].choices = contact_choices
github sfu-fas / coursys / ta / forms.py View on Github external
# populate initial data fron instance.config
        self.initial['salary'] = self.instance.salary()
        self.initial['scholarship'] = self.instance.scholarship()
        self.initial['start'] = self.instance.start()
        self.initial['accounts'] = self.instance.accounts()
        self.initial['end'] = self.instance.end()
        self.initial['payroll_start'] = self.instance.payroll_start()
        self.initial['payroll_end'] = self.instance.payroll_end()
        self.initial['deadline'] = self.instance.deadline()
        self.initial['excluded'] = self.instance.excluded()
        self.initial['max_courses'] = self.instance.max_courses()
        self.initial['min_courses'] = self.instance.min_courses()
        self.initial['payperiods'] = decimal.Decimal(self.instance.payperiods())
        self.initial['contact'] = self.instance.contact().id
        self.initial['offer_text'] = self.instance.offer_text()
        skills = Skill.objects.filter(posting=self.instance)
        self.initial['extra_questions'] = '\n'.join(self.instance.extra_questions())
        self.initial['skills'] = '\n'.join((s.name for s in skills))
        self.initial['instructions'] = self.instance.instructions()
        self.initial['hide_campuses'] = self.instance.hide_campuses()