Exemplo n.º 1
0
def _schedule_get(year, week, sorting, TeacherID, ClassTypeID, LocationID,
                  LevelID):
    # classes
    data = dict()
    data['classes'] = dict()
    for day in range(1, 8):
        date = iso_to_gregorian(int(year), int(week), int(day))

        class_schedule = ClassSchedule(date,
                                       filter_id_school_classtype=ClassTypeID,
                                       filter_id_school_location=LocationID,
                                       filter_id_school_level=LevelID,
                                       filter_id_teacher=TeacherID,
                                       filter_public=True,
                                       sorting=sorting)

        key = str(NRtoDay(day))

        class_data = dict(classes=class_schedule.get_day_list(), date=date)

        data['classes'][key] = class_data

    # Teachers and classtypes this week
    teacher_ids_this_week = []
    classtype_ids_this_week = []
    location_ids_this_week = []
    weekdays = [
        T('Monday'),
        T('Tuesday'),
        T('Wednesday'),
        T('Thursday'),
        T('Friday'),
        T('Saturday'),
        T('Sunday')
    ]
    for weekday in weekdays:
        for cls in data['classes'][weekday]['classes']:
            # check teachers
            if 'TeacherID' in cls and cls[
                    'TeacherID'] not in teacher_ids_this_week:
                teacher_ids_this_week.append(cls['TeacherID'])
            if 'TeacherID2' in cls and cls[
                    'TeacherID2'] not in teacher_ids_this_week:
                teacher_ids_this_week.append(cls['TeacherID2'])
            # check classtypes
            if 'ClassTypeID' in cls and cls[
                    'ClassTypeID'] not in classtype_ids_this_week:
                classtype_ids_this_week.append(cls['ClassTypeID'])
            # check locations
            if 'LocationID' in cls and cls[
                    'LocationID'] not in location_ids_this_week:
                location_ids_this_week.append(cls['LocationID'])

    # Define caching
    caching = (cache.ram, 120)
    if web2pytest.is_running_under_test(request, request.application):
        caching = None

    # ClassTypes
    classtypes = []
    query = (db.school_classtypes.Archived == False) & \
            (db.school_classtypes.AllowAPI == True) & \
            (db.school_classtypes.id.belongs(classtype_ids_this_week))
    rows = db(query).select(db.school_classtypes.id,
                            db.school_classtypes.Name,
                            db.school_classtypes.Color,
                            db.school_classtypes.Link,
                            db.school_classtypes.Description,
                            db.school_classtypes.thumbsmall,
                            db.school_classtypes.thumblarge,
                            orderby=db.school_classtypes.Name,
                            cache=caching)

    for row in rows:

        thumblarge_url = ''
        thumbsmall_url = ''

        if row.thumblarge:
            thumblarge_url = '%s://%s%s' % (
                request.env.wsgi_url_scheme, request.env.http_host,
                URL('default', 'download', args=row.thumblarge, extension=''))
        if row.thumbsmall:
            thumbsmall_url = '%s://%s%s' % (
                request.env.wsgi_url_scheme, request.env.http_host,
                URL('default', 'download', args=row.thumbsmall, extension=''))

        classtypes.append(
            dict(
                id=row.id,
                Name=row.Name,
                Color=row.Color,
                Link=row.Link,
                LinkThumbSmall=thumbsmall_url,
                LinkThumbLarge=thumblarge_url,
                Description=row.Description,
            ))

    data['classtypes'] = classtypes

    # Teachers
    query = (db.auth_user.trashed == False) & \
            (db.auth_user.teacher == True) & \
            (db.auth_user.id.belongs(teacher_ids_this_week))
    teachers = []
    rows = db(query).select(db.auth_user.id,
                            db.auth_user.full_name,
                            db.auth_user.teacher_role,
                            db.auth_user.teacher_bio,
                            db.auth_user.teacher_bio_link,
                            db.auth_user.teacher_website,
                            db.auth_user.thumbsmall,
                            db.auth_user.thumblarge,
                            orderby=db.auth_user.full_name,
                            cache=caching)
    for row in rows:
        name = row.full_name

        thumblarge_url = ''
        thumbsmall_url = ''

        if row.thumblarge:
            thumblarge_url = '%s://%s%s' % (
                request.env.wsgi_url_scheme, request.env.http_host,
                URL('default', 'download', args=row.thumblarge, extension=''))

        if row.thumbsmall:
            thumbsmall_url = '%s://%s%s' % (
                request.env.wsgi_url_scheme, request.env.http_host,
                URL('default', 'download', args=row.thumbsmall, extension=''))

        teachers.append(
            dict(
                id=row.id,
                name=name,  # for legacy purposes. Was the only one with name.
                Role=row.teacher_role,
                LinkToBio=row.teacher_bio_link,
                Bio=row.teacher_bio,
                Website=row.teacher_website,
                LinkThumbLarge=thumblarge_url,
                LinkThumbSmall=thumbsmall_url,
                Name=name))

    data['teachers'] = teachers

    # Locations
    query = (db.school_locations.AllowAPI == True) & \
            (db.school_locations.Archived == False) & \
            (db.school_locations.id.belongs(location_ids_this_week))
    rows = db(query).select(db.school_locations.id,
                            db.school_locations.Name,
                            db.school_locations.Address,
                            db.school_locations.Color,
                            cache=caching).as_list()
    data['locations'] = rows

    # Practice levels
    query = (db.school_levels.Archived == False)
    rows = db(query).select(db.school_levels.id,
                            db.school_levels.Name,
                            db.school_levels.Color,
                            cache=caching).as_list()
    data['levels'] = rows

    return data
Exemplo n.º 2
0
    def get_day_table(self):
        """
            Calls the schedule_get_day_rows function and formats the rows
            in a desktop friendly table
        """
        from general_helpers import max_string_length
        from general_helpers import NRtoDay

        DATE_FORMAT = current.DATE_FORMAT
        T = current.T
        auth = current.auth

        rows = self.get_day_rows()

        if len(rows) == 0:
            table = DIV()
        else:
            table = TABLE(
                TR(
                    TH(' ', _class='td_status_marker'),  # status marker
                    TH(T('Location'), _class='location'),
                    TH(T('Shift'), _class='classtype'),
                    TH(T('Time'), _class='time'),
                    TH(T('Employee'), _class='teacher'),
                    TH(T('')),
                    _class='os-table_header'),
                _class='os-schedule')
            # Generate list of classes
            for i, row in enumerate(rows):
                repr_row = list(rows[i:i + 1].render())[0]
                shID = row.shifts.id

                get_status = self._get_day_row_status(row)
                status = get_status['status']
                status_marker = get_status['marker']

                # filter status
                if self.filter_id_status:
                    if status != self.filter_id_status:
                        continue

                result = self._get_day_row_staff(row, repr_row, status)

                employee_id = result['employee_id']
                employee_id2 = result['employee_id2']
                employee = result['employee']
                employee2 = result['employee2'] or ''

                # check filter for employees
                if self.filter_id_employee:
                    self.filter_id_employee = int(self.filter_id_employee)
                    filter_check = (self.filter_id_employee == employee_id
                                    or self.filter_id_employee == employee_id2)
                    if not filter_check:
                        # break loop if it's not the employee searched for
                        continue

                location = max_string_length(
                    repr_row.shifts.school_locations_id, 15)
                shift_type = max_string_length(
                    repr_row.shifts.school_shifts_id, 24)
                time = SPAN(repr_row.shifts.Starttime, ' - ',
                            repr_row.shifts.Endtime)

                buttons = self._get_day_table_buttons(shID)

                row_class = TR(TD(status_marker),
                               TD(location),
                               TD(shift_type),
                               TD(time),
                               TD(employee),
                               TD(buttons),
                               _class='os-schedule_class')
                row_tools = TR(TD(' '),
                               TD(_colspan=3),
                               TD(employee2, _class='grey'),
                               TD(),
                               _class='os-schedule_links',
                               _id='class_' + unicode(shID))

                table.append(row_class)
                table.append(row_tools)

        return dict(table=table,
                    weekday=NRtoDay(self.date.isoweekday()),
                    date=self.date.strftime(DATE_FORMAT))
Exemplo n.º 3
0
    def _get_day_table(self):
        """
            Returns table for today
        """
        os_gui = current.globalenv['os_gui']
        DATE_FORMAT = current.DATE_FORMAT
        ORGANIZATIONS = current.globalenv['ORGANIZATIONS']
        T = current.T
        date_formatted = self.date.strftime(DATE_FORMAT)

        table = TABLE(
            TR(
                TH(' ', _class='td_status_marker'),  # status marker
                TH(T('Location'), _class='location'),
                TH(T('Class type'), _class='classtype'),
                TH(T('Time'), _class='time'),
                TH(T('Teacher'), _class='teacher'),
                TH(T('Level'), _class='level'),
                TH(T('Public'), _class='api'),
                TH(T('Trend'), _class='trend'),
                TH(T('')),
                _class='os-table_header'),
            _class='os-schedule')

        rows = self.get_day_rows()

        if len(rows) == 0:
            div_classes = DIV()
        else:
            # Get trend column from cache
            trend_data = self._get_day_get_table_class_trend()
            get_trend_data = trend_data.get

            # avoiding some dots in the loop
            get_status = self._get_day_row_status
            get_teacher_roles = self._get_day_row_teacher_roles
            get_buttons = self._get_day_get_table_get_buttons
            get_reservations = self._get_day_get_table_get_reservations
            get_class_messages = self._get_day_table_get_class_messages

            button_permissions = self._get_day_get_table_get_permissions()

            multiple_organizations = len(ORGANIZATIONS) > 1
            filter_id_status = self.filter_id_status
            msg_no_teacher = SPAN(T('No teacher'), _class='red')

            # Generate list of classes
            for i, row in enumerate(rows):
                repr_row = list(rows[i:i + 1].render())[0]
                clsID = row.classes.id

                status_result = get_status(row)
                status = status_result['status']
                status_marker = status_result['marker']

                if filter_id_status and status != filter_id_status:
                    continue

                result = get_teacher_roles(row, repr_row)
                teacher = result['teacher_role']
                teacher2 = result['teacher_role2']

                api = INPUT(value=row.classes.AllowAPI,
                            _type='checkbox',
                            _value='api',
                            _disabled='disabled')

                trend = get_trend_data(row.classes.id, '')
                buttons = get_buttons(clsID, date_formatted,
                                      button_permissions)
                reservations = get_reservations(clsID, date_formatted, row,
                                                button_permissions)
                class_messages = get_class_messages(row, clsID, date_formatted)

                if multiple_organizations:
                    organization = DIV(
                        repr_row.classes.sys_organizations_id or '',
                        _class='small_font grey pull-right btn-margin')
                else:
                    organization = ''

                row_class = TR(
                    TD(status_marker),
                    TD(max_string_length(repr_row.classes.school_locations_id, 16)),
                    TD(max_string_length(repr_row.classes.school_classtypes_id, 24)),
                    TD(SPAN(repr_row.classes.Starttime, ' - ', repr_row.classes.Endtime)),
                    TD(teacher if (not status == 'open' and
                                   not row.classes_teachers.auth_teacher_id is None) \
                               else msg_no_teacher),
                    TD(max_string_length(repr_row.classes.school_levels_id, 12)),
                    TD(api),
                    TD(trend),
                    TD(buttons),
                   _class='os-schedule_class')
                row_tools = TR(TD(' '),
                               TD(class_messages, _colspan=3, _class='grey'),
                               TD(teacher2 if not status == 'open' else ''),
                               TD(),
                               TD(),
                               TD(DIV(reservations,
                                      _class='os-schedule_links')),
                               TD(organization),
                               _class='os-schedule_links',
                               _id='class_' + unicode(clsID))

                table.append(row_class)
                table.append(row_tools)

        return dict(table=table,
                    weekday=NRtoDay(self.date.isoweekday()),
                    date=date_formatted)