How to use the faculty.util.ReportingSemester 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 / event_types / fields.py View on Github external
def get_semester(self, code):
        try:
            assert len(code) == 4
            assert code.isdigit()
            #s = Semester.objects.get(name=code)
            s = ReportingSemester(code)
            return s
        except AssertionError:
        #except (AssertionError, Semester.DoesNotExist):
            # Semester does not exist, or its in the wrong format
            return
github sfu-fas / coursys / faculty / event_types / fields.py View on Github external
def to_python(self, value):
        if value in forms.fields.validators.EMPTY_VALUES:
            return None

        if not (len(value) == 4 and value.isdigit()):
            raise ValidationError(_('Invalid semester code'))

        try:
            semester = ReportingSemester(value)
        except ValueError:
            raise ValidationError(_('Invalid semester code'))

        return self.start and semester.start_date or semester.end_date
github sfu-fas / coursys / faculty / event_types / base.py View on Github external
def semester_length(self):
        if self.event.end_date:
            rng = ReportingSemester.range(self.event.start_date, self.event.end_date)
        else:
            rng = ReportingSemester.range(self.event.start_date, datetime.date.today())
        return len(list(rng))
github sfu-fas / coursys / faculty / views.py View on Github external
def teaching_summary(request, userid):
    person, _ = _get_faculty_or_404(request.units, userid)

    credit_balance = 0
    events = []

    if request.GET:
        form = TeachingSummaryForm(request.GET)

        if form.is_valid():
            start = form.cleaned_data['start_semester']
            end = form.cleaned_data['end_semester']
            start_semester = ReportingSemester(start)
            end_semester = ReportingSemester(end)
        else:
            end_semester = ReportingSemester(datetime.date.today())
            start_semester = end_semester.prev().prev()

    else:
        end_semester = ReportingSemester(datetime.date.today())
        start_semester = end_semester.prev().prev()
        initial = { 'start_semester': start_semester.code,
                    'end_semester': end_semester.code }
        form = TeachingSummaryForm(initial=initial)

    curr_semester = start_semester
    while curr_semester <= end_semester:
        cb, event = _teaching_events_data(person, curr_semester)
        credit_balance += cb
        events.extend(event)
github sfu-fas / coursys / faculty / views.py View on Github external
if request.GET:
        form = TeachingSummaryForm(request.GET)

        if form.is_valid():
            start = form.cleaned_data['start_semester']
            end = form.cleaned_data['end_semester']
            start_semester = ReportingSemester(start)
            end_semester = ReportingSemester(end)

            curr_semester = start_semester
        else:
            end_semester = ReportingSemester(datetime.date.today())
            start_semester = end_semester.prev().prev()

    else:
        end_semester = ReportingSemester(datetime.date.today())
        start_semester = end_semester.prev().prev()

    while curr_semester <= end_semester:
        cb, event = _teaching_events_data(person, curr_semester)
        events.extend(event)
        curr_semester = curr_semester.next()

    start = start_semester.code
    end = end_semester.code

    filename = 'teaching_summary_{}-{}.csv'.format(start, end)
    csv, response = make_csv_writer_response(filename)
    csv.writerow([
        'Semester',
        'Course/Event',
        'Credits/Load Effect',
github sfu-fas / coursys / faculty / views.py View on Github external
def teaching_summary_csv(request, userid):
    person, _ = _get_faculty_or_404(request.units, userid)
    events = []

    if request.GET:
        form = TeachingSummaryForm(request.GET)

        if form.is_valid():
            start = form.cleaned_data['start_semester']
            end = form.cleaned_data['end_semester']
            start_semester = ReportingSemester(start)
            end_semester = ReportingSemester(end)

            curr_semester = start_semester
        else:
            end_semester = ReportingSemester(datetime.date.today())
            start_semester = end_semester.prev().prev()

    else:
        end_semester = ReportingSemester(datetime.date.today())
        start_semester = end_semester.prev().prev()

    while curr_semester <= end_semester:
        cb, event = _teaching_events_data(person, curr_semester)
        events.extend(event)
        curr_semester = curr_semester.next()
github sfu-fas / coursys / faculty / forms.py View on Github external
def __init__(self, *args, **kwargs):
        super(AvailableCapacityForm, self).__init__(*args, **kwargs)
        if 'start_semester' not in self.data:
            self.data['start_semester'] = ReportingSemester.current().prev().prev().code
        if 'end_semester' not in self.data:
            self.data['end_semester'] = ReportingSemester.current().code
github sfu-fas / coursys / faculty / forms.py View on Github external
def __init__(self, *args, **kwargs):
        super(AvailableCapacityForm, self).__init__(*args, **kwargs)
        if 'start_semester' not in self.data:
            self.data['start_semester'] = ReportingSemester.current().prev().prev().code
        if 'end_semester' not in self.data:
            self.data['end_semester'] = ReportingSemester.current().code
github sfu-fas / coursys / faculty / views.py View on Github external
def _all_study_events(units, person, start_semester, end_semester):
    # Constructs table of study credits events for a range of semesters
    slc_total = 0
    events = []
    finish_semester = ReportingSemester(max(end_semester.code, ReportingSemester(datetime.date.today()).code)) # in case we want to look into future semesters
    curr_semester = ReportingSemester('0651')
    while curr_semester <= finish_semester:
        if start_semester <= curr_semester <= end_semester:
            event, slc_total = _study_credit_events_data(units, person, curr_semester, True, slc_total)
        else:
            event, slc_total = _study_credit_events_data(units, person, curr_semester, False, slc_total)

        if curr_semester == start_semester.prev():
            events += [('', 'Study Leave Credits prior to '+start_semester.code, '', slc_total , slc_total)]

        events += event
        curr_semester = curr_semester.next()

    return slc_total, events, finish_semester
github sfu-fas / coursys / faculty / views.py View on Github external
if form.is_valid():
            start = form.cleaned_data['start_semester']
            end = form.cleaned_data['end_semester']
        else:
            start = start_semester.code
            end = end_semester.code

    else:
        start = start_semester.code
        end = end_semester.code
        initial = { 'start_semester': start,
                    'end_semester': end }
        form = TeachingSummaryForm(initial=initial)

    start_semester = ReportingSemester(start)
    end_semester = ReportingSemester(end)
    start_label = start_semester.full_label
    end_label = end_semester.full_label
    slc_total, events, finish_semester = _all_study_events(units, person, start_semester, end_semester)

    context = {
        'form': form,
        'start_label': start_label,
        'end_label': end_label,
        'start_code': start,
        'end_code': end,
        'person': person,
        'study_credits': fraction_display(slc_total),
        'events': events,
        'finish_semester': finish_semester.full_label,
    }
    return render(request, 'faculty/reports/study_leave_credits.html', context)