How to use the faculty.models.CareerEvent.objects function in faculty

To help you get started, we’ve selected a few faculty 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 / faculty / tests.py View on Github external
def test_annual_teaching(self):
        """
        Test the annual teaching value entry field
        """
        person = Person.objects.get(userid='ggbaker')
        unit = Unit.objects.get(slug='cmpt')
        editor = Person.objects.get(userid='dzhao')
        etype = 'NORM_TEACH'
        event = CareerEvent.objects.filter(unit=unit, person=person, event_type=etype)[0]
        event.config['load'] = 2 # 2 courses/semester in database should be 6/year to the user
        event.get_handler().save(editor)

        c = Client()
        c.login_user(editor.userid)

        # make sure the form renders with value="6"
        url = reverse('faculty.views.change_event', kwargs={'userid': person.userid, 'event_slug': event.slug})
        resp = c.get(url)
        inputs = [l for l in resp.content.split('\n') if 'name="load"' in l]
        inputs_correct_value = [l for l in inputs if 'value="6"' in l]
        self.assertEquals(len(inputs_correct_value), 1)

        # POST a change and make sure the right value ends up in the DB
        data = {
            'start_date_0': '2000-09-01',
github sfu-fas / coursys / faculty / tests.py View on Github external
self.Handler.IS_EXCLUSIVE = True
        handler1 = self.Handler(CareerEvent(person=self.person,
                                            unit=self.unit))
        handler1.event.title = 'hello world'
        handler1.event.start_date = date.today()
        handler1.save(self.person)

        handler2 = self.Handler(CareerEvent(person=self.person,
                                            unit=self.unit))
        handler2.event.title = 'Foobar'
        handler2.event.start_date = date.today() + timedelta(days=1)
        handler2.save(self.person)

        # XXX: handler1's event won't be automatically refreshed after we've 'closed' it
        #      so we must grab a fresh copy to verify.
        handler1_modified_event = CareerEvent.objects.get(id=handler1.event.id)

        self.assertEqual(handler1_modified_event.end_date, handler2.event.start_date - datetime.timedelta(days=1))
github sfu-fas / coursys / faculty / management / commands / faculty_test_data.py View on Github external
def event_get_or_create(**kwargs):
    """
    CareerEvent.objects.get_or_create, but doesn't save and returns a Handler
    """
    try:
        e = CareerEvent.objects.get(**kwargs)
    except CareerEvent.DoesNotExist:
        e = CareerEvent(**kwargs)

    h = EVENT_TYPES[e.event_type](event=e)
    return e, h
github sfu-fas / coursys / faculty / event_types / career.py View on Github external
def post_init(self):
            # find the last-known rank as a default
            if self.person:
                from faculty.models import CareerEvent
                event = CareerEvent.objects.filter(person=self.person, event_type='SALARY').effective_now().last()
                if event:
                    self.fields['rank'].initial = event.config['rank']
github sfu-fas / coursys / faculty / models.py View on Github external
def current_ranks(cls, person_id):
        """
        Return a string representing the current rank(s) for this person
        """
        salaries = CareerEvent.objects.filter(person__id=person_id, event_type='SALARY').effective_now()
        if not salaries:
            return 'unknown'

        ranks = set(s.get_handler().get_rank_display() for s in salaries)
        return ', '.join(ranks)
github sfu-fas / coursys / dashboard / letters.py View on Github external
data['year3'] = event.config.get('year3') or ''
    data['institution3'] = event.config.get('institution3') or ''
    data['location3'] = event.config.get('location3') or ''
    data['unit'] = event.unit.informal_name()
    data['start_date'] = event.start_date
    data['end_date'] = event.end_date
    data['position_number'] = event.config.get('position_number') or ''
    # Let's get the current salary event(s) for this person so we can get the rank and step
    salaries = CareerEvent.objects.filter(person=person, event_type='SALARY', unit=event.unit).effective_now()
    if salaries:
        # There should only be one of these effective in this unit, but just in case
        s = salaries[0]
        data['rank'] = s.get_handler().get_rank_display() or ''
        data['step'] = s.config.get('step') or ''

    stipends = CareerEvent.objects.filter(person=person, event_type='STIPEND', unit=event.unit).effective_now()
    for stipend in stipends:
        if stipend.config.get('source') == 'MARKETDIFF':
            data['marketdiff'] = stipend.config.get('amount') or ''
            break
    return data
github sfu-fas / coursys / faculty / views.py View on Github external
def _get_visible_flags(viewer, offering, instructor):
    return set(event.config['flag']
               for event in CareerEvent.objects.not_deleted()
                                               .by_type(AccreditationFlagEventHandler)
                                               .filter(unit=offering.owner)
                                               .filter(person=instructor)
                                               .overlaps_semester(offering.semester)
                                               .filter(status='A')
               if event.get_handler().can_view(viewer))
github sfu-fas / coursys / faculty / event_types / base.py View on Github external
def neaten_exclusive_end_dates(self, editor):
        """
        Tidy up the end dates of exclusive events: at least closes and previous open events, but also handles
        the case of events being entered out-of-order.
        """
        assert self.IS_EXCLUSIVE and not self.IS_INSTANT
        from faculty.models import CareerEvent

        similar_events = CareerEvent.objects.not_deleted().filter(person=self.event.person,
                unit=self.event.unit, event_type=self.EVENT_TYPE).order_by('start_date')
        similar_events = list(similar_events)
        for event, next_event in zip(similar_events, similar_events[1:]):
            event.end_date = next_event.start_date - datetime.timedelta(days=1)
            event.save(editor, call_from_handler=True)
github sfu-fas / coursys / faculty / views.py View on Github external
def _fallout_report_data(request, start_date, end_date):
    sub_unit_ids = Unit.sub_unit_ids(request.units)
    fac_roles = Role.objects.filter(role='FAC', unit__id__in=sub_unit_ids).select_related('person', 'unit')
    table = []
    tot_fallout = 0
    for role in fac_roles:
        unit = role.unit
        p = role.person
        salary = FacultySummary(p).salary(end_date, units=[unit])
        salary_events = CareerEvent.objects.approved().overlaps_daterange(start_date, end_date) \
            .filter(person=p, unit=unit, flags=CareerEvent.flags.affects_salary)
        for event in salary_events:
            if event.event_type == 'LEAVE' or event.event_type == 'STUDYLEAVE':
                days = event.get_duration_within_range(start_date, end_date)
                fraction = FacultySummary(p).salary_event_info(event)[1]
                d = fraction.denominator
                n = fraction.numerator
                fallout = Decimal((salary - salary*n/d)*days/365).quantize(Decimal('.01'), rounding=ROUND_DOWN)
                tot_fallout += fallout

                table += [(unit.label, p, event, event.start_date, event.end_date, days, salary, fraction, fallout)]
    return table