How to use the faculty.models.CareerEvent 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 setUp(self):
        faculty_test_data.Command().handle()
        self.p = Person.objects.get(userid='ggbaker')
        self.u = Unit.objects.get(id=1)
        self.date = datetime.date(2014, 1, 1)
        self.e = CareerEvent(person=self.p, unit=self.u, event_type="APPOINT", start_date=self.date)
        self.e.get_handler().save(self.p)
github sfu-fas / coursys / reports / reportlib / reports / fas_teaching_by_instructor.py View on Github external
course_history.append_column('School')
        course_history.append_column('Teaching Credits')
        course_history.append_column('Mean Headcount')
        course_history.append_column('Crs per Year')
        course_history.append_column('Unique Crs')
        course_history.append_column('Crs Levels')

        for i, memberships in itertools.groupby(instructors, key=lambda i: i.person):
            memberships = [m for m in memberships if m.teaching_credit() > 0]
            if i is None or not memberships:
                continue

            instr = i.sortname()
            first_semester = memberships[0].offering.semester
            last_semester = memberships[-1].offering.semester
            rank = CareerEvent.current_ranks(i.id)
            roles = Role.objects.filter(person=i, role='FAC').select_related('unit')
            unit = ', '.join(r.unit.label for r in roles)

            if rank == 'unknown':
                rank = 'non-faculty'
            if unit == '':
                unit = ', '.join(m.offering.subject for m in memberships)

            offerings = [m.offering for m in memberships]
            num_offerings = float(sum(m.teaching_credit() for m in memberships))
            headcount = sum(o.enrl_tot for o in offerings)
            duration = last_semester - first_semester + 1
            levels = sorted(list(set(str(o.number)[0] for o in offerings)))
            unique = len(set(o.course_id for o in offerings))

            course_history.append_row([instr, first_semester.name, last_semester.name, rank, unit, round(num_offerings, 2),
github sfu-fas / coursys / reports / reportlib / reports / cmpt_course_history.py View on Github external
label = course.name()
            instr = course.instructors_printing_str()
            enrl = '%i/%i' % (course.enrl_tot, course.enrl_cap)
            if course.campus in CAMPUSES_SHORT:
                campus = CAMPUSES_SHORT[course.campus]
            else:
                campus = 'Unknown'
            if course.config.get('joint_with'):
                joint = str(', '.join(course.config.get('joint_with')))
            else:
                joint = ''
            meeting_times = ''
            mt = [t for t in course.meeting_time.all() if t.meeting_type == 'LEC']
            if mt:
                meeting_times = ', '.join(str("%s %s-%s" % (WEEKDAYS[t.weekday], t.start_time, t.end_time)) for t in mt)
            ranks = "; ".join(CareerEvent.ranks_as_of_semester(p.id, course.semester) for p in course.instructors())
            course_history.append_row([semester, label, instr, enrl, campus, joint, meeting_times, ranks])
        self.artifacts.append(course_history)
github sfu-fas / coursys / faculty / event_types / base.py View on Github external
def create_for(cls, person, form=None):
        """
        Given a person, create a new instance of the handler for them.
        """
        from faculty.models import CareerEvent
        event = CareerEvent(person=person,
                            event_type=cls.EVENT_TYPE)
        ret = cls(event)
        if form:
            ret.load(form)
        return ret
github sfu-fas / coursys / faculty / event_types / base.py View on Github external
# TODO: Log the fact that `editor` made some changes to the CareerEvent.
        self.set_handler_specific_data()

        if self.IS_INSTANT:
            self.event.end_date = self.event.start_date

        self.pre_save()
        self.event.save(editor, call_from_handler=True)

        if self.IS_EXCLUSIVE:
            self.neaten_exclusive_end_dates(editor)

        if self.event.event_type == 'SALARY':
            # invalidate cache of rank
            from faculty.models import CareerEvent
            CareerEvent.current_ranks.invalidate(self.event.person)

        self.post_save()
github sfu-fas / coursys / faculty / models.py View on Github external
'unit': self.unit.name,
                'current_base_salary': CareerEvent.current_base_salary(self.person),
                'current_market_diff': CareerEvent.current_market_diff(self.person),
              }
        ls = dict(list(ls.items()) + list(config_data.items()))
        return ls

    def has_memos(self):
        return Memo.objects.filter(career_event=self, hidden=False).count() > 0

    def has_attachments(self):
        return DocumentAttachment.objects.filter(career_event=self, hidden=False).count() > 0


# https://stackoverflow.com/a/47817197/6871666
CareerEvent.get_event_type_display = CareerEvent.get_event_type_display_


def attachment_upload_to(instance, filename):
    return upload_path('faculty', filename)


def position_attachment_upload_to(instance, filename):
    return upload_path('faculty', 'positions', filename)


class DocumentAttachmentManager(models.Manager):
    def visible(self):
        qs = self.get_queryset()
        return qs.filter(hidden=False)
github sfu-fas / coursys / faculty / models.py View on Github external
super(MemoTemplate, self).save(*args, **kwargs)

    def get_event_type_display_(self):
        "Override to display nicely"
        return EVENT_TYPES[self.event_type].NAME


# https://stackoverflow.com/a/47817197/6871666
MemoTemplate.get_event_type_display = MemoTemplate.get_event_type_display_


class Memo(models.Model):
    """
    A memo created by the system, and attached to a CareerEvent.
    """
    career_event = models.ForeignKey(CareerEvent, null=False, blank=False, on_delete=models.PROTECT)
    unit = models.ForeignKey(Unit, null=False, blank=False, on_delete=models.PROTECT, help_text="The unit producing the memo: will determine the "
                                                                      "letterhead used for the memo.")

    sent_date = models.DateField(default=datetime.date.today, help_text="The sending date of the letter")
    to_lines = models.TextField(verbose_name='Attention', help_text='Recipient of the memo', null=True, blank=True)
    cc_lines = models.TextField(verbose_name='CC lines', help_text='Additional recipients of the memo', null=True,
                                blank=True)
    from_person = models.ForeignKey(Person, null=True, related_name='+', on_delete=models.PROTECT)
    from_lines = models.TextField(verbose_name='From', help_text='Name (and title) of the sender, e.g. "John Smith, '
                                                                 'Applied Sciences, Dean"')
    subject = models.TextField(help_text='The subject of the memo (lines will be formatted separately in the memo '
                                         'header). This will be ignored for letters')

    template = models.ForeignKey(MemoTemplate, null=True, on_delete=models.PROTECT)
    is_letter = models.BooleanField(verbose_name="Make it a letter", help_text="Make it a letter with correct "
                                                                               "letterhead instead of a memo.",
github sfu-fas / coursys / reports / reportlib / reports / ensc_course_history.py View on Github external
label = course.name()
            instr = course.instructors_printing_str()
            enrl = '%i/%i' % (course.enrl_tot, course.enrl_cap)
            if course.campus in CAMPUSES_SHORT:
                campus = CAMPUSES_SHORT[course.campus]
            else:
                campus = 'Unknown'
            if course.config.get('joint_with'):
                joint = str(', '.join(course.config.get('joint_with')))
            else:
                joint = ''
            meeting_times = ''
            mt = [t for t in course.meeting_time.all() if t.meeting_type == 'LEC']
            if mt:
                meeting_times = ', '.join(str("%s %s-%s" % (WEEKDAYS[t.weekday], t.start_time, t.end_time)) for t in mt)
            ranks = "; ".join(CareerEvent.ranks_as_of_semester(p.id, course.semester) for p in course.instructors())
            course_history.append_row([semester, label, instr, enrl, campus, joint, meeting_times, ranks])
        self.artifacts.append(course_history)