Beispiel #1
0
    def get_teachers_list_classes_in_month(self, year, month):
        """
        :param year: int
        :param month: int
        :return: dict(teacher_id=[classes])
        """
        from openstudio.os_class_schedule import ClassSchedule
        from general_helpers import get_last_day_month

        ids = self.get_teacher_ids()

        start_date = datetime.date(year, month, 1)
        last_day = get_last_day_month(start_date)

        data = {}

        for teID in ids:
            teID = int(teID)
            data[teID] = {}
            data[teID]['classes'] = {}
            data[teID]['classes_count'] = 0
            for each_day in range(1, last_day.day + 1):
                # list days
                day = datetime.date(year, month, each_day)
                weekday = day.isoweekday()

                class_schedule = ClassSchedule(date=day,
                                               filter_id_teacher=int(teID))

                rows = class_schedule.get_day_rows()

                data[teID]['classes'][day] = rows
                data[teID]['classes_count'] += len(rows)

        return data
Beispiel #2
0
def classes():
    """
        Function returns a list of classes today
    """
    locID = request.vars['locID']

    # Set today while looking at configured timezone
    now = pytz.utc.localize(datetime.datetime.now())
    tz = pytz.timezone(TIMEZONE)
    local_dt = now.astimezone(tz)
    today = datetime.date(local_dt.year, local_dt.month, local_dt.day)

    date_formatted = today.strftime(DATE_FORMAT)
    date = datestr_to_python(DATE_FORMAT, date_formatted)
    pretty_date = date.strftime('%B %d, %Y')

    location = db.school_locations(locID)
    # go_back
    response.back = A(SPAN(_class='glyphicon glyphicon-chevron-left'),
                      _href=URL('index'),
                      _class='pull-right')
    response.title = location.Name
    response.subtitle = SPAN(T('Classes'), ' ', ' ', pretty_date)
    response.view = 'selfcheckin/default.html'
    response.logout = get_logout()

    cs = ClassSchedule(date, filter_id_school_location=locID)

    rows = cs.get_day_rows()

    header = THEAD(TR(
        TH(T('Time')),
        TH(T('Class type')),
        TH(),
    ))
    table = TABLE(header, _class='table table-striped table-hover')

    for i, row in enumerate(rows):
        repr_row = list(rows[i:i + 1].render())[0]

        time = repr_row.classes.Starttime + ' - ' + repr_row.classes.Endtime
        link = os_gui.get_button('noicon',
                                 URL('checkin',
                                     vars={
                                         'clsID': row.classes.id,
                                         'date': date_formatted
                                     }),
                                 title=T("Go to check-in"),
                                 _class='pull-right')

        tr = TR(TD(time), TD(repr_row.classes.school_classtypes_id), TD(link))

        table.append(tr)

    return dict(content=table, logout=get_logout())
Beispiel #3
0
def my_classes():
    """
    creates page that displays the classes tought montlhy
    :return:
    """
    response.title = T("Employee Portal")
    response.subtitle = SPAN(T("My classes"), XML(' • '))
    response.view = 'ep/only_content.html'

    if session.ep_my_classes_month is None or session.ep_my_classes_year is None:
        session.ep_my_classes_year = TODAY_LOCAL.year
        session.ep_my_classes_month = TODAY_LOCAL.month

    table = TABLE(_class='table table-hover')
    table.append(
        THEAD(
            TR(
                TH(),
                TH(T('Date')),
                TH(T('Time')),
                TH(T('Location')),
                TH(T('Class Type')),
                TH(),  #sub requested
                #TH(),  # actions
            )))

    date = datetime.date(session.ep_my_classes_year,
                         session.ep_my_classes_month, 1)
    last_day = get_last_day_month(date)

    for each_day in range(1, last_day.day + 1):
        # list days
        day = datetime.date(session.ep_my_classes_year,
                            session.ep_my_classes_month, each_day)

        class_schedule = ClassSchedule(date=day,
                                       filter_id_teacher=auth.user.id)

        rows = class_schedule.get_day_rows()
        for i, row in enumerate(rows):
            repr_row = list(rows[i:i + 1].render())[0]

            result = class_schedule._get_day_row_status(row)
            status_marker = result['marker']

            button = ''
            sub_requested = ''
            if day >= TODAY_LOCAL:
                open_class = db.classes_otc(classes_id=row.classes.id,
                                            ClassDate=day,
                                            Status='open')

                if not open_class:
                    button = os_gui.get_button('noicon',
                                               URL('request_sub',
                                                   vars={
                                                       'clsID': row.classes.id,
                                                       'date': day,
                                                       'teachers_id':
                                                       auth.user.id
                                                   }),
                                               title='Find sub',
                                               _class='pull-right',
                                               btn_class='btn-success')
                else:
                    sub_requested = os_gui.get_label('primary',
                                                     T("Sub requested"))
                    button = os_gui.get_button(
                        'noicon',
                        URL('cancel_request_sub',
                            vars={'cotcID': open_class.id}),
                        title='Cancel',
                        _class='pull-right',
                        btn_class='btn-warning')

            tr = TR(
                TD(status_marker, _class='td_status_marker'),
                TD(day.strftime(DATE_FORMAT)),
                TD(repr_row.classes.Starttime, '- ', repr_row.classes.Endtime),
                TD(repr_row.classes.school_locations_id),
                TD(repr_row.classes.school_classtypes_id), TD(sub_requested),
                TD(button))

            table.append(tr)

    form_subtitle = get_form_subtitle(session.ep_my_classes_month,
                                      session.ep_my_classes_year,
                                      request.function,
                                      _class='col-md-8')
    response.subtitle.append(form_subtitle['subtitle'])
    month_chooser = form_subtitle['month_chooser']
    current_month = form_subtitle['current_month']

    header_tools = month_chooser + current_month
    return dict(header_tools=header_tools, content=table)
Beispiel #4
0
def staff_holidays_set_status(sthID, status, apply_teacher2):
    """
        This function sets the status for classes during a teachers' holiday
    """
    from openstudio.os_shift import Shift

    holiday = db.teachers_holidays(sthID)
    teachers_id = holiday.auth_teacher_id
    startdate = holiday.Startdate
    enddate = holiday.Enddate
    # Find classes
    delta = datetime.timedelta(days=1)
    current_date = startdate
    changed = 0

    while current_date <= enddate:
        # find all classes for teacher and set them as open
        weekday = current_date.isoweekday()

        cs = ClassSchedule(current_date, filter_id_teacher=teachers_id)

        rows = cs.get_day_rows()

        for row in rows:
            cotcID = row.classes_otc.id

            if cotcID:
                record = db.classes_otc(cotcID)
                if not record is None:  # final check to see if we really get something from the db
                    # we have a record
                    if status != 'normal':
                        record.Status = status
                        record.update_record()
                    else:
                        """
                         if the status is normal:
                            check if there are any other changes
                            otherwise just delete. """
                        change = False
                        fields = [
                            record.school_locations_id,
                            record.school_classtypes_id, record.Starttime,
                            record.Endtime, record.auth_teacher_id,
                            record.auth_teacher_id2, record.Description
                        ]
                        for field in fields:
                            if not field is None or field == '':
                                change = True

                        if not change:
                            query = (db.classes_otc.id == cotcID)
                            result = db(query).delete()

            elif status != 'normal':
                # no record found, insert one (status normal doesn't need a record)
                db.classes_otc.insert(classes_id=row.classes.id,
                                      ClassDate=current_date,
                                      Status=status)

        # Shift status
        staff_schedule = StaffSchedule(current_date,
                                       filter_id_employee=teachers_id)
        shifts = staff_schedule.get_day_list(show_id=True)
        for shift in shifts:
            shift = Shift(shift['id'], current_date)
            # apply new status
            if status == 'normal':
                shift.set_status_normal()
            elif status == 'open':
                shift.set_status_open()
            elif status == 'cancelled':
                shift.set_status_cancelled()

        current_date += delta

    session.flash = T("Changed class statuses")